mirror of https://github.com/PaperMC/Paper.git
expand to more types
This commit is contained in:
parent
084e4355e1
commit
2f52bfd733
|
@ -0,0 +1,163 @@
|
|||
package org.bukkit.damage;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Translatable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represent a type of damage that an entity can receive.
|
||||
* <p>
|
||||
* Constants in this class include the base types provided by the vanilla
|
||||
* server. Data packs are capable of registering more types of damage which may
|
||||
* be obtained through the {@link Registry#DAMAGE_TYPE}.
|
||||
*
|
||||
* @see <a href="https://minecraft.wiki/w/Damage_type">Minecraft Wiki</a>
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public interface DamageType extends Keyed, Translatable {
|
||||
|
||||
// Paper start - Generated/DamageType
|
||||
// @GeneratedFrom 1.20.4
|
||||
DamageType ARROW = getDamageType("arrow");
|
||||
|
||||
DamageType BAD_RESPAWN_POINT = getDamageType("bad_respawn_point");
|
||||
|
||||
DamageType CACTUS = getDamageType("cactus");
|
||||
|
||||
DamageType CRAMMING = getDamageType("cramming");
|
||||
|
||||
DamageType DRAGON_BREATH = getDamageType("dragon_breath");
|
||||
|
||||
DamageType DROWN = getDamageType("drown");
|
||||
|
||||
DamageType DRY_OUT = getDamageType("dry_out");
|
||||
|
||||
DamageType EXPLOSION = getDamageType("explosion");
|
||||
|
||||
DamageType FALL = getDamageType("fall");
|
||||
|
||||
DamageType FALLING_ANVIL = getDamageType("falling_anvil");
|
||||
|
||||
DamageType FALLING_BLOCK = getDamageType("falling_block");
|
||||
|
||||
DamageType FALLING_STALACTITE = getDamageType("falling_stalactite");
|
||||
|
||||
DamageType FIREBALL = getDamageType("fireball");
|
||||
|
||||
DamageType FIREWORKS = getDamageType("fireworks");
|
||||
|
||||
DamageType FLY_INTO_WALL = getDamageType("fly_into_wall");
|
||||
|
||||
DamageType FREEZE = getDamageType("freeze");
|
||||
|
||||
DamageType GENERIC = getDamageType("generic");
|
||||
|
||||
DamageType GENERIC_KILL = getDamageType("generic_kill");
|
||||
|
||||
DamageType HOT_FLOOR = getDamageType("hot_floor");
|
||||
|
||||
DamageType IN_FIRE = getDamageType("in_fire");
|
||||
|
||||
DamageType IN_WALL = getDamageType("in_wall");
|
||||
|
||||
DamageType INDIRECT_MAGIC = getDamageType("indirect_magic");
|
||||
|
||||
DamageType LAVA = getDamageType("lava");
|
||||
|
||||
DamageType LIGHTNING_BOLT = getDamageType("lightning_bolt");
|
||||
|
||||
DamageType MAGIC = getDamageType("magic");
|
||||
|
||||
DamageType MOB_ATTACK = getDamageType("mob_attack");
|
||||
|
||||
DamageType MOB_ATTACK_NO_AGGRO = getDamageType("mob_attack_no_aggro");
|
||||
|
||||
DamageType MOB_PROJECTILE = getDamageType("mob_projectile");
|
||||
|
||||
DamageType ON_FIRE = getDamageType("on_fire");
|
||||
|
||||
DamageType OUT_OF_WORLD = getDamageType("out_of_world");
|
||||
|
||||
DamageType OUTSIDE_BORDER = getDamageType("outside_border");
|
||||
|
||||
DamageType PLAYER_ATTACK = getDamageType("player_attack");
|
||||
|
||||
DamageType PLAYER_EXPLOSION = getDamageType("player_explosion");
|
||||
|
||||
DamageType SONIC_BOOM = getDamageType("sonic_boom");
|
||||
|
||||
DamageType STALAGMITE = getDamageType("stalagmite");
|
||||
|
||||
DamageType STARVE = getDamageType("starve");
|
||||
|
||||
DamageType STING = getDamageType("sting");
|
||||
|
||||
DamageType SWEET_BERRY_BUSH = getDamageType("sweet_berry_bush");
|
||||
|
||||
DamageType THORNS = getDamageType("thorns");
|
||||
|
||||
DamageType THROWN = getDamageType("thrown");
|
||||
|
||||
DamageType TRIDENT = getDamageType("trident");
|
||||
|
||||
DamageType UNATTRIBUTED_FIREBALL = getDamageType("unattributed_fireball");
|
||||
|
||||
DamageType WITHER = getDamageType("wither");
|
||||
|
||||
DamageType WITHER_SKULL = getDamageType("wither_skull");
|
||||
// Paper end - Generated/DamageType
|
||||
|
||||
@NotNull
|
||||
private static DamageType getDamageType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
return Preconditions.checkNotNull(Registry.DAMAGE_TYPE.get(namespacedKey), "No DamageType found for %s. This is a bug.", namespacedKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* The returned key is that of the death message sent when this damage type
|
||||
* is responsible for the death of an entity.
|
||||
* <p>
|
||||
* <strong>Note</strong> This translation key is only used if
|
||||
* {@link #getDeathMessageType()} is {@link DeathMessageType#DEFAULT}
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey();
|
||||
|
||||
/**
|
||||
* Get the {@link DamageScaling} for this damage type.
|
||||
*
|
||||
* @return the damage scaling
|
||||
*/
|
||||
@NotNull
|
||||
public DamageScaling getDamageScaling();
|
||||
|
||||
/**
|
||||
* Get the {@link DamageEffect} for this damage type.
|
||||
*
|
||||
* @return the damage effect
|
||||
*/
|
||||
@NotNull
|
||||
public DamageEffect getDamageEffect();
|
||||
|
||||
/**
|
||||
* Get the {@link DeathMessageType} for this damage type.
|
||||
*
|
||||
* @return the death message type
|
||||
*/
|
||||
@NotNull
|
||||
public DeathMessageType getDeathMessageType();
|
||||
|
||||
/**
|
||||
* Get the amount of hunger exhaustion caused by this damage type.
|
||||
*
|
||||
* @return the exhaustion
|
||||
*/
|
||||
public float getExhaustion();
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.bukkit.entity;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Meow.
|
||||
*/
|
||||
public interface Cat extends Tameable, Sittable, io.papermc.paper.entity.CollarColorable { // Paper - CollarColorable
|
||||
|
||||
/**
|
||||
* Gets the current type of this cat.
|
||||
*
|
||||
* @return Type of the cat.
|
||||
*/
|
||||
@NotNull
|
||||
public Type getCatType();
|
||||
|
||||
/**
|
||||
* Sets the current type of this cat.
|
||||
*
|
||||
* @param type New type of this cat.
|
||||
*/
|
||||
public void setCatType(@NotNull Type type);
|
||||
|
||||
/**
|
||||
* Get the collar color of this cat
|
||||
*
|
||||
* @return the color of the collar
|
||||
*/
|
||||
@NotNull
|
||||
@Override // Paper
|
||||
public DyeColor getCollarColor();
|
||||
|
||||
/**
|
||||
* Set the collar color of this cat
|
||||
*
|
||||
* @param color the color to apply
|
||||
*/
|
||||
@Override // Paper
|
||||
public void setCollarColor(@NotNull DyeColor color);
|
||||
|
||||
/**
|
||||
* Represents the various different cat types there are.
|
||||
*/
|
||||
public enum Type implements Keyed {
|
||||
// Paper start - Generated/CatType
|
||||
// @GeneratedFrom 1.20.4
|
||||
ALL_BLACK("all_black"),
|
||||
BLACK("black"),
|
||||
BRITISH_SHORTHAIR("british_shorthair"),
|
||||
CALICO("calico"),
|
||||
JELLIE("jellie"),
|
||||
PERSIAN("persian"),
|
||||
RAGDOLL("ragdoll"),
|
||||
RED("red"),
|
||||
SIAMESE("siamese"),
|
||||
TABBY("tabby"),
|
||||
WHITE("white");
|
||||
// Paper end - Generated/CatType
|
||||
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Type(String key) {
|
||||
this.key = NamespacedKey.minecraft(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
// Paper start - More cat api
|
||||
/**
|
||||
* Sets if the cat is lying down.
|
||||
* This is visual and does not affect the behaviour of the cat.
|
||||
*
|
||||
* @param lyingDown whether the cat should lie down
|
||||
*/
|
||||
public void setLyingDown(boolean lyingDown);
|
||||
|
||||
/**
|
||||
* Gets if the cat is lying down.
|
||||
*
|
||||
* @return whether the cat is lying down
|
||||
*/
|
||||
public boolean isLyingDown();
|
||||
|
||||
/**
|
||||
* Sets if the cat has its head up.
|
||||
* This is visual and does not affect the behaviour of the cat.
|
||||
*
|
||||
* @param headUp head is up
|
||||
*/
|
||||
public void setHeadUp(boolean headUp);
|
||||
|
||||
/**
|
||||
* Gets if the cat has its head up.
|
||||
*
|
||||
* @return head is up
|
||||
*/
|
||||
public boolean isHeadUp();
|
||||
// Paper end - More cat api
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package org.bukkit.entity;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A Frog.
|
||||
*/
|
||||
public interface Frog extends Animals {
|
||||
|
||||
/**
|
||||
* Gets the tongue target of this frog.
|
||||
*
|
||||
* @return tongue target or null if not set
|
||||
*/
|
||||
@Nullable
|
||||
Entity getTongueTarget();
|
||||
|
||||
/**
|
||||
* Sets the tongue target of this frog.
|
||||
*
|
||||
* @param target tongue target or null to clear
|
||||
*/
|
||||
void setTongueTarget(@Nullable Entity target);
|
||||
|
||||
/**
|
||||
* Get the variant of this frog.
|
||||
*
|
||||
* @return frog variant
|
||||
*/
|
||||
@NotNull
|
||||
Variant getVariant();
|
||||
|
||||
/**
|
||||
* Set the variant of this frog.
|
||||
*
|
||||
* @param variant frog variant
|
||||
*/
|
||||
void setVariant(@NotNull Variant variant);
|
||||
|
||||
/**
|
||||
* Represents the variant of a frog - ie its color.
|
||||
*/
|
||||
public enum Variant implements Keyed {
|
||||
|
||||
// Paper start - Generated/FrogVariant
|
||||
// @GeneratedFrom 1.20.4
|
||||
COLD,
|
||||
TEMPERATE,
|
||||
WARM;
|
||||
// Paper end - Generated/FrogVariant
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Variant() {
|
||||
this.key = NamespacedKey.minecraft(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,334 @@
|
|||
package org.bukkit.entity;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map; // Paper
|
||||
import java.util.UUID; // Paper
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a villager NPC
|
||||
*/
|
||||
public interface Villager extends AbstractVillager {
|
||||
|
||||
/**
|
||||
* Gets the current profession of this villager.
|
||||
*
|
||||
* @return Current profession.
|
||||
*/
|
||||
@NotNull
|
||||
public Profession getProfession();
|
||||
|
||||
/**
|
||||
* Sets the new profession of this villager.
|
||||
*
|
||||
* @param profession New profession.
|
||||
*/
|
||||
public void setProfession(@NotNull Profession profession);
|
||||
|
||||
/**
|
||||
* Gets the current type of this villager.
|
||||
*
|
||||
* @return Current type.
|
||||
*/
|
||||
@NotNull
|
||||
public Type getVillagerType();
|
||||
|
||||
/**
|
||||
* Sets the new type of this villager.
|
||||
*
|
||||
* @param type New type.
|
||||
*/
|
||||
public void setVillagerType(@NotNull Type type);
|
||||
|
||||
/**
|
||||
* Gets the level of this villager.
|
||||
*
|
||||
* A villager with a level of 1 and no experience is liable to lose its
|
||||
* profession.
|
||||
*
|
||||
* @return this villager's level
|
||||
*/
|
||||
public int getVillagerLevel();
|
||||
|
||||
/**
|
||||
* Sets the level of this villager.
|
||||
*
|
||||
* A villager with a level of 1 and no experience is liable to lose its
|
||||
* profession.
|
||||
*
|
||||
* This doesn't update the trades of this villager.
|
||||
*
|
||||
* @param level the new level
|
||||
* @throws IllegalArgumentException if level not between [1, 5]
|
||||
* @see #increaseLevel(int)
|
||||
*/
|
||||
public void setVillagerLevel(int level);
|
||||
|
||||
/**
|
||||
* Gets the trading experience of this villager.
|
||||
*
|
||||
* @return trading experience
|
||||
*/
|
||||
public int getVillagerExperience();
|
||||
|
||||
/**
|
||||
* Sets the trading experience of this villager.
|
||||
*
|
||||
* @param experience new experience
|
||||
* @throws IllegalArgumentException if experience < 0
|
||||
*/
|
||||
public void setVillagerExperience(int experience);
|
||||
|
||||
// Paper start
|
||||
/**
|
||||
* Increases the level of this villager.
|
||||
* The villager will also unlock new recipes unlike the raw
|
||||
* method {@link #setVillagerLevel(int)}.
|
||||
* <p>
|
||||
* A villager with a level of 1 and no experience is liable to lose its
|
||||
* profession.
|
||||
* <p>
|
||||
* A master villager has a level of 5 in its profession and
|
||||
* will unlock 10 trades (2 per level).
|
||||
*
|
||||
* @param amount The amount of level
|
||||
* @return Whether trades are unlocked
|
||||
* @throws IllegalArgumentException if current level plus the amount
|
||||
* isn't between [1, 5] or the amount isn't positive
|
||||
* @see #setVillagerLevel(int)
|
||||
*/
|
||||
boolean increaseLevel(int amount);
|
||||
|
||||
/**
|
||||
* Gives to this villager some potential new trades
|
||||
* based to its profession and level.
|
||||
* @param amount The amount of trades to give
|
||||
* @return Whether trades are added
|
||||
* @throws IllegalArgumentException if the amount isn't positive
|
||||
*/
|
||||
boolean addTrades(int amount);
|
||||
|
||||
/**
|
||||
* Gets the amount of times a villager has restocked their trades today
|
||||
* @return The amount of trade restocks.
|
||||
*/
|
||||
public int getRestocksToday();
|
||||
|
||||
/**
|
||||
* Sets the amount of times a villager has restocked their trades today
|
||||
* @param restocksToday new restock count
|
||||
*/
|
||||
public void setRestocksToday(int restocksToday);
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
* Attempts to make this villager sleep at the given location.
|
||||
* <br>
|
||||
* The location must be in the current world and have a bed placed at the
|
||||
* location. The villager will put its head on the specified block while
|
||||
* sleeping.
|
||||
*
|
||||
* @param location the location of the bed
|
||||
* @return whether the sleep was successful
|
||||
*/
|
||||
public boolean sleep(@NotNull Location location);
|
||||
|
||||
/**
|
||||
* Causes this villager to wake up if he's currently sleeping.
|
||||
*
|
||||
* @throws IllegalStateException if not sleeping
|
||||
*/
|
||||
public void wakeup();
|
||||
|
||||
/**
|
||||
* Causes this villager to shake his head.
|
||||
*/
|
||||
public void shakeHead();
|
||||
|
||||
/**
|
||||
* Convert this Villager into a ZombieVillager as if it was killed by a
|
||||
* Zombie.
|
||||
*
|
||||
* <b>Note:</b> this will fire a EntityTransformEvent
|
||||
*
|
||||
* @return the converted entity {@link ZombieVillager} or null if the
|
||||
* conversion its cancelled
|
||||
*/
|
||||
@Nullable
|
||||
public ZombieVillager zombify();
|
||||
|
||||
/**
|
||||
* Represents Villager type, usually corresponding to what biome they spawn
|
||||
* in.
|
||||
*/
|
||||
public enum Type implements Keyed {
|
||||
|
||||
// Paper start - Generated/VillagerType
|
||||
// @GeneratedFrom 1.20.4
|
||||
DESERT,
|
||||
JUNGLE,
|
||||
PLAINS,
|
||||
SAVANNA,
|
||||
SNOW,
|
||||
SWAMP,
|
||||
TAIGA;
|
||||
// Paper end - Generated/VillagerType
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Type() {
|
||||
this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the various different Villager professions there may be.
|
||||
* Villagers have different trading options depending on their profession,
|
||||
*/
|
||||
public enum Profession implements Keyed, net.kyori.adventure.translation.Translatable { // Paper
|
||||
NONE,
|
||||
/**
|
||||
* Armorer profession. Wears a black apron. Armorers primarily trade for
|
||||
* iron armor, chainmail armor, and sometimes diamond armor.
|
||||
*/
|
||||
ARMORER,
|
||||
/**
|
||||
* Butcher profession. Wears a white apron. Butchers primarily trade for
|
||||
* raw and cooked food.
|
||||
*/
|
||||
BUTCHER,
|
||||
/**
|
||||
* Cartographer profession. Wears a white robe. Cartographers primarily
|
||||
* trade for explorer maps and some paper.
|
||||
*/
|
||||
CARTOGRAPHER,
|
||||
/**
|
||||
* Cleric profession. Wears a purple robe. Clerics primarily trade for
|
||||
* rotten flesh, gold ingot, redstone, lapis, ender pearl, glowstone,
|
||||
* and bottle o' enchanting.
|
||||
*/
|
||||
CLERIC,
|
||||
/**
|
||||
* Farmer profession. Wears a brown robe. Farmers primarily trade for
|
||||
* food-related items.
|
||||
*/
|
||||
FARMER,
|
||||
/**
|
||||
* Fisherman profession. Wears a brown robe. Fisherman primarily trade
|
||||
* for fish, as well as possibly selling string and/or coal.
|
||||
*/
|
||||
FISHERMAN,
|
||||
/**
|
||||
* Fletcher profession. Wears a brown robe. Fletchers primarily trade
|
||||
* for string, bows, and arrows.
|
||||
*/
|
||||
FLETCHER,
|
||||
/**
|
||||
* Leatherworker profession. Wears a white apron. Leatherworkers
|
||||
* primarily trade for leather, and leather armor, as well as saddles.
|
||||
*/
|
||||
LEATHERWORKER,
|
||||
/**
|
||||
* Librarian profession. Wears a white robe. Librarians primarily trade
|
||||
* for paper, books, and enchanted books.
|
||||
*/
|
||||
LIBRARIAN,
|
||||
/**
|
||||
* Mason profession.
|
||||
*/
|
||||
MASON,
|
||||
/**
|
||||
* Nitwit profession. Wears a green apron, cannot trade. Nitwit
|
||||
* villagers do not do anything. They do not have any trades by default.
|
||||
*/
|
||||
NITWIT,
|
||||
/**
|
||||
* Shepherd profession. Wears a brown robe. Shepherds primarily trade for
|
||||
* wool items, and shears.
|
||||
*/
|
||||
SHEPHERD,
|
||||
/**
|
||||
* Toolsmith profession. Wears a black apron. Tool smiths primarily
|
||||
* trade for iron and diamond tools.
|
||||
*/
|
||||
TOOLSMITH,
|
||||
/**
|
||||
* Weaponsmith profession. Wears a black apron. Weapon smiths primarily
|
||||
* trade for iron and diamond weapons, sometimes enchanted.
|
||||
*/
|
||||
WEAPONSMITH;
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Profession() {
|
||||
this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public @NotNull String translationKey() {
|
||||
return "entity.minecraft.villager." + this.key.getKey();
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
// Paper start - Add villager reputation API
|
||||
/**
|
||||
* Get the {@link com.destroystokyo.paper.entity.villager.Reputation reputation}
|
||||
* for a specific player by {@link UUID}.
|
||||
*
|
||||
* @param uniqueId The {@link UUID} of the player to get the reputation of.
|
||||
* @return The player's copied reputation with this villager.
|
||||
*/
|
||||
@Nullable
|
||||
public com.destroystokyo.paper.entity.villager.Reputation getReputation(@NotNull UUID uniqueId);
|
||||
|
||||
/**
|
||||
* Get all {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
|
||||
* for all players mapped by their {@link UUID unique IDs}.
|
||||
*
|
||||
* @return All {@link com.destroystokyo.paper.entity.villager.Reputation reputations} for all players
|
||||
* in a copied map.
|
||||
*/
|
||||
@NotNull
|
||||
public Map<UUID, com.destroystokyo.paper.entity.villager.Reputation> getReputations();
|
||||
|
||||
/**
|
||||
* Set the {@link com.destroystokyo.paper.entity.villager.Reputation reputation}
|
||||
* for a specific player by {@link UUID}.
|
||||
*
|
||||
* @param uniqueId The {@link UUID} of the player to set the reputation of.
|
||||
* @param reputation The {@link com.destroystokyo.paper.entity.villager.Reputation reputation} to set.
|
||||
*/
|
||||
public void setReputation(@NotNull UUID uniqueId, @NotNull com.destroystokyo.paper.entity.villager.Reputation reputation);
|
||||
|
||||
/**
|
||||
* Set all {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
|
||||
* for all players mapped by their {@link UUID unique IDs}.
|
||||
*
|
||||
* @param reputations All {@link com.destroystokyo.paper.entity.villager.Reputation reputations}
|
||||
* for all players mapped by their {@link UUID unique IDs}.
|
||||
*/
|
||||
public void setReputations(@NotNull Map<UUID, com.destroystokyo.paper.entity.villager.Reputation> reputations);
|
||||
|
||||
/**
|
||||
* Clear all reputations from this villager. This removes every single
|
||||
* reputation regardless of its impact and the player associated.
|
||||
*/
|
||||
public void clearReputations();
|
||||
// Paper end
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package org.bukkit.generator.structure;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represent a Structure from the world.
|
||||
*
|
||||
* Listed structures are present in the default server. Depending on the server
|
||||
* there might be additional structures present (for example structures added by
|
||||
* data packs), which can be received via {@link Registry#STRUCTURE}.
|
||||
*/
|
||||
public abstract class Structure implements Keyed {
|
||||
|
||||
// Paper start - Generated/Structure
|
||||
// @GeneratedFrom 1.20.4
|
||||
public static final Structure ANCIENT_CITY = getStructure("ancient_city");
|
||||
|
||||
public static final Structure BASTION_REMNANT = getStructure("bastion_remnant");
|
||||
|
||||
public static final Structure BURIED_TREASURE = getStructure("buried_treasure");
|
||||
|
||||
public static final Structure DESERT_PYRAMID = getStructure("desert_pyramid");
|
||||
|
||||
public static final Structure END_CITY = getStructure("end_city");
|
||||
|
||||
public static final Structure FORTRESS = getStructure("fortress");
|
||||
|
||||
public static final Structure IGLOO = getStructure("igloo");
|
||||
|
||||
public static final Structure JUNGLE_PYRAMID = getStructure("jungle_pyramid");
|
||||
|
||||
public static final Structure MANSION = getStructure("mansion");
|
||||
|
||||
public static final Structure MINESHAFT = getStructure("mineshaft");
|
||||
|
||||
public static final Structure MINESHAFT_MESA = getStructure("mineshaft_mesa");
|
||||
|
||||
public static final Structure MONUMENT = getStructure("monument");
|
||||
|
||||
public static final Structure NETHER_FOSSIL = getStructure("nether_fossil");
|
||||
|
||||
public static final Structure OCEAN_RUIN_COLD = getStructure("ocean_ruin_cold");
|
||||
|
||||
public static final Structure OCEAN_RUIN_WARM = getStructure("ocean_ruin_warm");
|
||||
|
||||
public static final Structure PILLAGER_OUTPOST = getStructure("pillager_outpost");
|
||||
|
||||
public static final Structure RUINED_PORTAL = getStructure("ruined_portal");
|
||||
|
||||
public static final Structure RUINED_PORTAL_DESERT = getStructure("ruined_portal_desert");
|
||||
|
||||
public static final Structure RUINED_PORTAL_JUNGLE = getStructure("ruined_portal_jungle");
|
||||
|
||||
public static final Structure RUINED_PORTAL_MOUNTAIN = getStructure("ruined_portal_mountain");
|
||||
|
||||
public static final Structure RUINED_PORTAL_NETHER = getStructure("ruined_portal_nether");
|
||||
|
||||
public static final Structure RUINED_PORTAL_OCEAN = getStructure("ruined_portal_ocean");
|
||||
|
||||
public static final Structure RUINED_PORTAL_SWAMP = getStructure("ruined_portal_swamp");
|
||||
|
||||
public static final Structure SHIPWRECK = getStructure("shipwreck");
|
||||
|
||||
public static final Structure SHIPWRECK_BEACHED = getStructure("shipwreck_beached");
|
||||
|
||||
public static final Structure STRONGHOLD = getStructure("stronghold");
|
||||
|
||||
public static final Structure SWAMP_HUT = getStructure("swamp_hut");
|
||||
|
||||
public static final Structure TRAIL_RUINS = getStructure("trail_ruins");
|
||||
|
||||
@org.bukkit.MinecraftExperimental(value = "update 1.21")
|
||||
@org.jetbrains.annotations.ApiStatus.Experimental
|
||||
public static final Structure TRIAL_CHAMBERS = getStructure("trial_chambers");
|
||||
|
||||
public static final Structure VILLAGE_DESERT = getStructure("village_desert");
|
||||
|
||||
public static final Structure VILLAGE_PLAINS = getStructure("village_plains");
|
||||
|
||||
public static final Structure VILLAGE_SAVANNA = getStructure("village_savanna");
|
||||
|
||||
public static final Structure VILLAGE_SNOWY = getStructure("village_snowy");
|
||||
|
||||
public static final Structure VILLAGE_TAIGA = getStructure("village_taiga");
|
||||
// Paper end - Generated/Structure
|
||||
|
||||
private static Structure getStructure(String name) {
|
||||
return Registry.STRUCTURE.get(NamespacedKey.minecraft(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the structure.
|
||||
*
|
||||
* @return the type of structure
|
||||
*/
|
||||
@NotNull
|
||||
public abstract StructureType getStructureType();
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.bukkit.generator.structure;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
|
||||
/**
|
||||
* Represent a StructureType of a {@link Structure}.
|
||||
*
|
||||
* Listed structure types are present in the default server. Depending on the
|
||||
* server there might be additional structure types present (for example
|
||||
* structure types added by data packs), which can be received via
|
||||
* {@link Registry#STRUCTURE_TYPE}.
|
||||
*/
|
||||
public abstract class StructureType implements Keyed {
|
||||
|
||||
// Paper start - Generated/StructureType
|
||||
// @GeneratedFrom 1.20.4
|
||||
public static final StructureType BURIED_TREASURE = getStructureType("buried_treasure");
|
||||
|
||||
public static final StructureType DESERT_PYRAMID = getStructureType("desert_pyramid");
|
||||
|
||||
public static final StructureType END_CITY = getStructureType("end_city");
|
||||
|
||||
public static final StructureType FORTRESS = getStructureType("fortress");
|
||||
|
||||
public static final StructureType IGLOO = getStructureType("igloo");
|
||||
|
||||
public static final StructureType JIGSAW = getStructureType("jigsaw");
|
||||
|
||||
public static final StructureType JUNGLE_TEMPLE = getStructureType("jungle_temple");
|
||||
|
||||
public static final StructureType MINESHAFT = getStructureType("mineshaft");
|
||||
|
||||
public static final StructureType NETHER_FOSSIL = getStructureType("nether_fossil");
|
||||
|
||||
public static final StructureType OCEAN_MONUMENT = getStructureType("ocean_monument");
|
||||
|
||||
public static final StructureType OCEAN_RUIN = getStructureType("ocean_ruin");
|
||||
|
||||
public static final StructureType RUINED_PORTAL = getStructureType("ruined_portal");
|
||||
|
||||
public static final StructureType SHIPWRECK = getStructureType("shipwreck");
|
||||
|
||||
public static final StructureType STRONGHOLD = getStructureType("stronghold");
|
||||
|
||||
public static final StructureType SWAMP_HUT = getStructureType("swamp_hut");
|
||||
|
||||
public static final StructureType WOODLAND_MANSION = getStructureType("woodland_mansion");
|
||||
// Paper end - Generated/StructureType
|
||||
|
||||
private static StructureType getStructureType(String name) {
|
||||
return Registry.STRUCTURE_TYPE.get(NamespacedKey.minecraft(name));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.bukkit.inventory.meta.trim;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
|
||||
/**
|
||||
* Represents a material that may be used in an {@link ArmorTrim}.
|
||||
*/
|
||||
public interface TrimMaterial extends Keyed {
|
||||
|
||||
// Paper start - Generated/TrimMaterial
|
||||
// @GeneratedFrom 1.20.4
|
||||
TrimMaterial AMETHYST = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("amethyst"));
|
||||
|
||||
TrimMaterial COPPER = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("copper"));
|
||||
|
||||
TrimMaterial DIAMOND = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("diamond"));
|
||||
|
||||
TrimMaterial EMERALD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("emerald"));
|
||||
|
||||
TrimMaterial GOLD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("gold"));
|
||||
|
||||
TrimMaterial IRON = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("iron"));
|
||||
|
||||
TrimMaterial LAPIS = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("lapis"));
|
||||
|
||||
TrimMaterial NETHERITE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("netherite"));
|
||||
|
||||
TrimMaterial QUARTZ = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("quartz"));
|
||||
|
||||
TrimMaterial REDSTONE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("redstone"));
|
||||
// Paper end - Generated/TrimMaterial
|
||||
// Paper start
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_MATERIAL}. TrimMaterials
|
||||
* can exist without a key.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
||||
// Paper end
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.bukkit.inventory.meta.trim;
|
||||
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
|
||||
/**
|
||||
* Represents a pattern that may be used in an {@link ArmorTrim}.
|
||||
*/
|
||||
public interface TrimPattern extends Keyed {
|
||||
|
||||
// Paper start - Generated/TrimPattern
|
||||
// @GeneratedFrom 1.20.4
|
||||
TrimPattern COAST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("coast"));
|
||||
|
||||
TrimPattern DUNE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("dune"));
|
||||
|
||||
TrimPattern EYE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("eye"));
|
||||
|
||||
TrimPattern HOST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("host"));
|
||||
|
||||
TrimPattern RAISER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("raiser"));
|
||||
|
||||
TrimPattern RIB = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("rib"));
|
||||
|
||||
TrimPattern SENTRY = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("sentry"));
|
||||
|
||||
TrimPattern SHAPER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("shaper"));
|
||||
|
||||
TrimPattern SILENCE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("silence"));
|
||||
|
||||
TrimPattern SNOUT = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("snout"));
|
||||
|
||||
TrimPattern SPIRE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("spire"));
|
||||
|
||||
TrimPattern TIDE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("tide"));
|
||||
|
||||
TrimPattern VEX = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("vex"));
|
||||
|
||||
TrimPattern WARD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("ward"));
|
||||
|
||||
TrimPattern WAYFINDER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("wayfinder"));
|
||||
|
||||
TrimPattern WILD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("wild"));
|
||||
// Paper end - Generated/TrimPattern
|
||||
// Paper start
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_PATTERN}. TrimPatterns
|
||||
* can exist without a key.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.4")
|
||||
@Override
|
||||
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
||||
// Paper end
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
package org.bukkit.potion;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This enum reflects and matches each potion state that can be obtained from
|
||||
* the Creative mode inventory
|
||||
*/
|
||||
public enum PotionType implements Keyed {
|
||||
// Paper start - Generated/PotionType
|
||||
// @GeneratedFrom 1.20.4
|
||||
AWKWARD("awkward"),
|
||||
UNCRAFTABLE("empty"),
|
||||
FIRE_RESISTANCE("fire_resistance"),
|
||||
HARMING("harming"),
|
||||
HEALING("healing"),
|
||||
INVISIBILITY("invisibility"),
|
||||
LEAPING("leaping"),
|
||||
LONG_FIRE_RESISTANCE("long_fire_resistance"),
|
||||
LONG_INVISIBILITY("long_invisibility"),
|
||||
LONG_LEAPING("long_leaping"),
|
||||
LONG_NIGHT_VISION("long_night_vision"),
|
||||
LONG_POISON("long_poison"),
|
||||
LONG_REGENERATION("long_regeneration"),
|
||||
LONG_SLOW_FALLING("long_slow_falling"),
|
||||
LONG_SLOWNESS("long_slowness"),
|
||||
LONG_STRENGTH("long_strength"),
|
||||
LONG_SWIFTNESS("long_swiftness"),
|
||||
LONG_TURTLE_MASTER("long_turtle_master"),
|
||||
LONG_WATER_BREATHING("long_water_breathing"),
|
||||
LONG_WEAKNESS("long_weakness"),
|
||||
LUCK("luck"),
|
||||
MUNDANE("mundane"),
|
||||
NIGHT_VISION("night_vision"),
|
||||
POISON("poison"),
|
||||
REGENERATION("regeneration"),
|
||||
SLOW_FALLING("slow_falling"),
|
||||
SLOWNESS("slowness"),
|
||||
STRENGTH("strength"),
|
||||
STRONG_HARMING("strong_harming"),
|
||||
STRONG_HEALING("strong_healing"),
|
||||
STRONG_LEAPING("strong_leaping"),
|
||||
STRONG_POISON("strong_poison"),
|
||||
STRONG_REGENERATION("strong_regeneration"),
|
||||
STRONG_SLOWNESS("strong_slowness"),
|
||||
STRONG_STRENGTH("strong_strength"),
|
||||
STRONG_SWIFTNESS("strong_swiftness"),
|
||||
STRONG_TURTLE_MASTER("strong_turtle_master"),
|
||||
SWIFTNESS("swiftness"),
|
||||
THICK("thick"),
|
||||
TURTLE_MASTER("turtle_master"),
|
||||
WATER("water"),
|
||||
WATER_BREATHING("water_breathing"),
|
||||
WEAKNESS("weakness");
|
||||
// Paper end - Generated/PotionType
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final Supplier<InternalPotionData> internalPotionDataSupplier;
|
||||
|
||||
PotionType(String key) {
|
||||
this.key = NamespacedKey.minecraft(key);
|
||||
this.internalPotionDataSupplier = Suppliers.memoize(() -> Bukkit.getUnsafe().getInternalPotionData(this.key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the potion effect type of this potion type
|
||||
* @deprecated Potions can have multiple effects use {@link #getPotionEffects()}
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public PotionEffectType getEffectType() {
|
||||
return internalPotionDataSupplier.get().getEffectType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a list of all effects this potion type has
|
||||
*/
|
||||
@NotNull
|
||||
public List<PotionEffect> getPotionEffects() {
|
||||
return internalPotionDataSupplier.get().getPotionEffects();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if this potion type is instant
|
||||
* @deprecated PotionType can have multiple effects, some of which can be instant and others not.
|
||||
* Use {@link PotionEffectType#isInstant()} in combination with {@link #getPotionEffects()} and {@link PotionEffect#getType()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isInstant() {
|
||||
return internalPotionDataSupplier.get().isInstant();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the potion type has an upgraded state.
|
||||
* This refers to whether or not the potion type can be Tier 2,
|
||||
* such as Potion of Fire Resistance II.
|
||||
*
|
||||
* @return true if the potion type can be upgraded;
|
||||
*/
|
||||
public boolean isUpgradeable() {
|
||||
return internalPotionDataSupplier.get().isUpgradeable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the potion type has an extended state.
|
||||
* This refers to the extended duration potions
|
||||
*
|
||||
* @return true if the potion type can be extended
|
||||
*/
|
||||
public boolean isExtendable() {
|
||||
return internalPotionDataSupplier.get().isExtendable();
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return internalPotionDataSupplier.get().getMaxLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param effectType the effect to get by
|
||||
* @return the matching potion type
|
||||
* @deprecated Misleading
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static PotionType getByEffect(@Nullable PotionEffectType effectType) {
|
||||
if (effectType == null)
|
||||
return WATER;
|
||||
for (PotionType type : PotionType.values()) {
|
||||
if (effectType.equals(type.getEffectType()))
|
||||
return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do not use, interface will get removed, and the plugin won't run
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.Internal
|
||||
public interface InternalPotionData {
|
||||
|
||||
PotionEffectType getEffectType();
|
||||
|
||||
List<PotionEffect> getPotionEffects();
|
||||
|
||||
boolean isInstant();
|
||||
|
||||
boolean isUpgradeable();
|
||||
|
||||
boolean isExtendable();
|
||||
|
||||
int getMaxLevel();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package io.papermc.generator;
|
|||
|
||||
import io.papermc.generator.rewriter.SourceRewriter;
|
||||
import io.papermc.generator.rewriter.types.EnumRegistryRewriter;
|
||||
import io.papermc.generator.rewriter.types.RegistryFieldRewriter;
|
||||
import io.papermc.generator.utils.ExperimentalSounds;
|
||||
import io.papermc.generator.types.registry.GeneratedKeyType;
|
||||
import io.papermc.generator.types.SourceGenerator;
|
||||
|
@ -21,11 +22,15 @@ import org.bukkit.block.Biome;
|
|||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.Frog;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.generator.structure.Structure;
|
||||
import org.bukkit.generator.structure.StructureType;
|
||||
import org.bukkit.inventory.meta.trim.TrimMaterial;
|
||||
import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public interface Generators {
|
||||
|
||||
|
@ -65,9 +70,18 @@ public interface Generators {
|
|||
return ExperimentalSounds.findExperimentalValue(reference.key().location());
|
||||
}
|
||||
},
|
||||
new EnumRegistryRewriter<>(Attribute.class, Registries.ATTRIBUTE, "Attribute", true),
|
||||
new EnumRegistryRewriter<>(Biome.class, Registries.BIOME, "Biome", false),
|
||||
//new EnumRegistryRewriter<>(EntityType.class, Registries.ENTITY_TYPE, "EntityType", false) seems complex to get the typeId?
|
||||
new EnumRegistryRewriter<>(Frog.Variant.class, Registries.FROG_VARIANT, "FrogVariant", false),
|
||||
new EnumRegistryRewriter<>(Villager.Type.class, Registries.VILLAGER_TYPE, "VillagerType", false),
|
||||
new EnumRegistryRewriter<>(Attribute.class, Registries.ATTRIBUTE, "Attribute", true),
|
||||
new EnumRegistryRewriter<>(Cat.Type.class, Registries.CAT_VARIANT, "CatType", true),
|
||||
new EnumRegistryRewriter<>(PotionType.class, Registries.POTION, "PotionType", true),
|
||||
//new EnumRegistryRewriter<>(EntityType.class, Registries.ENTITY_TYPE, "EntityType", false), seems complex to get the typeId?
|
||||
new RegistryFieldRewriter<>(Structure.class, Registries.STRUCTURE, "Structure", "getStructure"),
|
||||
new RegistryFieldRewriter<>(StructureType.class, Registries.STRUCTURE_TYPE, "StructureType", "getStructureType"),
|
||||
new RegistryFieldRewriter<>(TrimPattern.class, Registries.TRIM_PATTERN, "TrimPattern", null),
|
||||
new RegistryFieldRewriter<>(TrimMaterial.class, Registries.TRIM_MATERIAL, "TrimMaterial", null),
|
||||
new RegistryFieldRewriter<>(DamageType.class, Registries.DAMAGE_TYPE, "DamageType", "getDamageType"),
|
||||
};
|
||||
|
||||
private static <T, A> SourceGenerator simpleKey(final String className, final Class<A> apiType, final ResourceKey<? extends Registry<T>> registryKey, final RegistryKey<A> apiRegistryKey, final boolean publicCreateKeyMethod) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.papermc.generator.rewriter;
|
|||
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.rewriter.utils.Annotations;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.minecraft.SharedConstants;
|
||||
import java.io.IOException;
|
||||
|
@ -16,7 +17,7 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
private static final String PAPER_START_FORMAT = "Paper start";
|
||||
private static final String PAPER_END_FORMAT = "Paper end";
|
||||
|
||||
private final Class<?> rewriteClass;
|
||||
protected final Class<?> rewriteClass;
|
||||
private final String pattern;
|
||||
private final boolean equalsSize;
|
||||
|
||||
|
@ -32,28 +33,24 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
// only when equalsSize = true
|
||||
public void replaceLine(SearchMetadata metadata, StringBuilder builder) {}
|
||||
|
||||
private String getIndent(String unit, Class<?> clazz) { // todo move in formatting
|
||||
Class<?> parent = clazz.getEnclosingClass();
|
||||
StringBuilder indentBuilder = new StringBuilder(unit);
|
||||
while (parent != null) {
|
||||
indentBuilder.append(unit);
|
||||
parent = parent.getEnclosingClass();
|
||||
}
|
||||
return indentBuilder.toString();
|
||||
}
|
||||
|
||||
private boolean framed;
|
||||
|
||||
@Override
|
||||
public void writeToFile(Path parent) throws IOException {
|
||||
String indent = getIndent(INDENT, this.rewriteClass);
|
||||
String indent = Formatting.incrementalIndent(INDENT, this.rewriteClass);
|
||||
String startPattern = String.format("%s// %s - Generated/%s", indent, PAPER_START_FORMAT, this.pattern);
|
||||
String endPattern = String.format("%s// %s - Generated/%s", indent, PAPER_END_FORMAT, this.pattern);
|
||||
|
||||
Path path = parent.resolve(this.rewriteClass.getCanonicalName().replace('.', '/') + ".java");
|
||||
String filePath = "%s/%s.java".formatted(
|
||||
this.rewriteClass.getPackageName().replace('.', '/'),
|
||||
Formatting.retrieveFileName(this.rewriteClass)
|
||||
);
|
||||
|
||||
Path path = parent.resolve(filePath);
|
||||
StringBuilder content = new StringBuilder();
|
||||
StringBuilder strippedContent = new StringBuilder();
|
||||
|
||||
// todo support multiple passes
|
||||
// strip the replaced content first or apply directly the change when the replaced content size is equals to the new content size
|
||||
{
|
||||
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
|
||||
|
@ -129,7 +126,7 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
}
|
||||
|
||||
// Files.writeString(path, content.toString(), StandardCharsets.UTF_8); // todo
|
||||
Path createdPath = Main.generatedPath.resolve(this.rewriteClass.getCanonicalName().replace('.', '/') + ".java");
|
||||
Path createdPath = Main.generatedPath.resolve(filePath);
|
||||
Files.createDirectories(createdPath.getParent());
|
||||
Files.writeString(createdPath, content.toString(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class EnumRegistryRewriter<T, A extends Enum<A>> extends SearchReplaceRew
|
|||
ResourceKey<T> resourceKey = reference.key();
|
||||
String pathKey = resourceKey.location().getPath();
|
||||
|
||||
String fieldName = Formatting.formatKeyAsField(pathKey);
|
||||
String fieldName = this.rewriteFieldName(reference);
|
||||
String experimentalValue = this.getExperimentalValue(reference);
|
||||
if (experimentalValue != null) {
|
||||
Annotations.experimentalAnnotations(builder, metadata::indent, experimentalValue);
|
||||
|
@ -61,6 +61,10 @@ public class EnumRegistryRewriter<T, A extends Enum<A>> extends SearchReplaceRew
|
|||
}
|
||||
}
|
||||
|
||||
public String rewriteFieldName(Holder.Reference<T> reference) {
|
||||
return Formatting.formatKeyAsField(reference.key().location().getPath());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getExperimentalValue(Holder.Reference<T> reference) {
|
||||
if (this.isFilteredRegistry && reference.value() instanceof FeatureElement element && FeatureFlags.isExperimental(element.requiredFeatures())) {
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package io.papermc.generator.rewriter.types;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.rewriter.SearchMetadata;
|
||||
import io.papermc.generator.rewriter.SearchReplaceRewriter;
|
||||
import io.papermc.generator.rewriter.utils.Annotations;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import io.papermc.generator.utils.RegistryUtils;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.flag.FeatureElement;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class RegistryFieldRewriter<T, A> extends SearchReplaceRewriter {
|
||||
|
||||
public static final Map<Class<?>, String> REGISTRY_FIELD_NAMES;
|
||||
static {
|
||||
final Map<Class<?>, String> map = new IdentityHashMap<>();
|
||||
for (final Field field : org.bukkit.Registry.class.getDeclaredFields()) {
|
||||
if (field.isAnnotationPresent(Deprecated.class) || field.getType() != org.bukkit.Registry.class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int mod = field.getModifiers();
|
||||
if (Modifier.isPublic(mod) & Modifier.isStatic(mod) & Modifier.isFinal(mod)) {
|
||||
map.put((Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0], field.getName());
|
||||
}
|
||||
}
|
||||
REGISTRY_FIELD_NAMES = Map.copyOf(map);
|
||||
}
|
||||
|
||||
private final Registry<T> registry;
|
||||
private final Supplier<Set<ResourceKey<T>>> experimentalKeys;
|
||||
private final boolean isFilteredRegistry;
|
||||
private final String fetchMethod;
|
||||
private final boolean isInterface;
|
||||
|
||||
public RegistryFieldRewriter(final Class<A> rewriteClass, final ResourceKey<? extends Registry<T>> registryKey, final String pattern, final @Nullable String fetchMethod) {
|
||||
super(rewriteClass, pattern, false);
|
||||
this.registry = Main.REGISTRY_ACCESS.registryOrThrow(registryKey);
|
||||
this.experimentalKeys = Suppliers.memoize(() -> RegistryUtils.collectExperimentalDataDrivenKeys(this.registry));
|
||||
this.isFilteredRegistry = FeatureElement.FILTERED_REGISTRIES.contains(registryKey);
|
||||
this.isInterface = rewriteClass.isInterface();
|
||||
this.fetchMethod = fetchMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(final SearchMetadata metadata, final StringBuilder builder) {
|
||||
List<Holder.Reference<T>> references = this.registry.holders().sorted(Formatting.alphabeticKeyOrder(reference -> reference.key().location().getPath())).toList();
|
||||
Iterator<Holder.Reference<T>> referenceIterator = references.iterator();
|
||||
|
||||
while (referenceIterator.hasNext()) {
|
||||
Holder.Reference<T> reference = referenceIterator.next();
|
||||
ResourceKey<T> resourceKey = reference.key();
|
||||
String pathKey = resourceKey.location().getPath();
|
||||
|
||||
String fieldName = Formatting.formatKeyAsField(pathKey);
|
||||
String experimentalValue = this.getExperimentalValue(reference);
|
||||
if (experimentalValue != null) {
|
||||
Annotations.experimentalAnnotations(builder, metadata::indent, experimentalValue);
|
||||
}
|
||||
|
||||
builder.append(metadata.indent());
|
||||
if (!this.isInterface) {
|
||||
builder.append("public static final ");
|
||||
}
|
||||
builder.append(this.rewriteClass.getSimpleName()).append(' ').append(fieldName);
|
||||
builder.append(" = ");
|
||||
if (this.fetchMethod == null) {
|
||||
builder.append("%s.%s.get(%s.minecraft(\"%s\"))".formatted(org.bukkit.Registry.class.getSimpleName(), REGISTRY_FIELD_NAMES.get(this.rewriteClass), NamespacedKey.class.getSimpleName(), pathKey));
|
||||
} else {
|
||||
builder.append("%s(\"%s\")".formatted(this.fetchMethod, pathKey)); // todo search with reflection or smth?
|
||||
}
|
||||
|
||||
builder.append(';');
|
||||
builder.append('\n');
|
||||
if (referenceIterator.hasNext()) {
|
||||
builder.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getExperimentalValue(Holder.Reference<T> reference) {
|
||||
if (this.isFilteredRegistry && reference.value() instanceof FeatureElement element && FeatureFlags.isExperimental(element.requiredFeatures())) {
|
||||
return Formatting.formatFeatureFlagSet(element.requiredFeatures());
|
||||
}
|
||||
if (this.experimentalKeys.get().contains(reference.key())) {
|
||||
return Formatting.formatFeatureFlag(FeatureFlags.UPDATE_1_21);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -70,6 +70,26 @@ public final class Formatting {
|
|||
return Optional.of(resourcePath.substring(tagsIndex + tagDir.length() + 1, dotIndex)); // namespace/tags/registry_key/[tag_key].json
|
||||
}
|
||||
|
||||
public static String incrementalIndent(String unit, Class<?> clazz) {
|
||||
Class<?> parent = clazz.getEnclosingClass();
|
||||
StringBuilder indentBuilder = new StringBuilder(unit);
|
||||
while (parent != null) {
|
||||
indentBuilder.append(unit);
|
||||
parent = parent.getEnclosingClass();
|
||||
}
|
||||
return indentBuilder.toString();
|
||||
}
|
||||
|
||||
public static String retrieveFileName(Class<?> clazz) {
|
||||
String name = clazz.getSimpleName();
|
||||
Class<?> parent = clazz.getEnclosingClass();
|
||||
while (parent != null) {
|
||||
name = parent.getSimpleName();
|
||||
parent = parent.getEnclosingClass();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Comparator<String> ALPHABETIC_KEY_ORDER = alphabeticKeyOrder(path -> path);
|
||||
|
||||
public static <T> Comparator<T> alphabeticKeyOrder(Function<T, String> mapper) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public class RegistryUtils {
|
|||
static {
|
||||
final Map<RegistryKey<?>, String> map = new IdentityHashMap<>();
|
||||
try {
|
||||
for (final Field field : RegistryKey.class.getFields()) {
|
||||
for (final Field field : RegistryKey.class.getDeclaredFields()) {
|
||||
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isFinal(field.getModifiers()) || field.getType() != RegistryKey.class) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -84,3 +84,183 @@ index 5d8fa5b39a5d50cca48ba63af3a84b80f279b649..c6ea69c0d05aef5a29b758dbd3ea4c84
|
|||
/**
|
||||
* Represents a custom Biome
|
||||
*/
|
||||
diff --git a/src/main/java/org/bukkit/damage/DamageType.java b/src/main/java/org/bukkit/damage/DamageType.java
|
||||
index 5fef0f8b7957d5daef864de8547104f552215f29..de742b029409e2c4d74f854ca802130d6422ec88 100644
|
||||
--- a/src/main/java/org/bukkit/damage/DamageType.java
|
||||
+++ b/src/main/java/org/bukkit/damage/DamageType.java
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
@ApiStatus.Experimental
|
||||
public interface DamageType extends Keyed, Translatable {
|
||||
|
||||
+ // Paper start - Generated/DamageType
|
||||
public static final DamageType IN_FIRE = getDamageType("in_fire");
|
||||
public static final DamageType LIGHTNING_BOLT = getDamageType("lightning_bolt");
|
||||
public static final DamageType ON_FIRE = getDamageType("on_fire");
|
||||
@@ -64,6 +65,7 @@ public interface DamageType extends Keyed, Translatable {
|
||||
public static final DamageType BAD_RESPAWN_POINT = getDamageType("bad_respawn_point");
|
||||
public static final DamageType OUTSIDE_BORDER = getDamageType("outside_border");
|
||||
public static final DamageType GENERIC_KILL = getDamageType("generic_kill");
|
||||
+ // Paper end - Generated/DamageType
|
||||
|
||||
@NotNull
|
||||
private static DamageType getDamageType(@NotNull String key) {
|
||||
diff --git a/src/main/java/org/bukkit/entity/Cat.java b/src/main/java/org/bukkit/entity/Cat.java
|
||||
index d03adfaa4176617ef2ace2754fe02b63860e3aee..fceb2f0a452a1ce72988bbd1ecca599cfb6af6d9 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Cat.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Cat.java
|
||||
@@ -46,6 +46,7 @@ public interface Cat extends Tameable, Sittable, io.papermc.paper.entity.CollarC
|
||||
* Represents the various different cat types there are.
|
||||
*/
|
||||
public enum Type implements Keyed {
|
||||
+ // Paper start - Generated/CatType
|
||||
TABBY("tabby"),
|
||||
BLACK("black"),
|
||||
RED("red"),
|
||||
@@ -57,6 +58,7 @@ public interface Cat extends Tameable, Sittable, io.papermc.paper.entity.CollarC
|
||||
WHITE("white"),
|
||||
JELLIE("jellie"),
|
||||
ALL_BLACK("all_black");
|
||||
+ // Paper end - Generated/CatType
|
||||
|
||||
private final NamespacedKey key;
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/Frog.java b/src/main/java/org/bukkit/entity/Frog.java
|
||||
index 0960bdbb3253bfe109dc6283244b8c9d95a850f7..d11cfd431cee09886ecd9d9416de85f56ac90462 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Frog.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Frog.java
|
||||
@@ -46,6 +46,7 @@ public interface Frog extends Animals {
|
||||
*/
|
||||
public enum Variant implements Keyed {
|
||||
|
||||
+ // Paper start - Generated/FrogVariant
|
||||
/**
|
||||
* Temperate (brown-orange) frog.
|
||||
*/
|
||||
@@ -58,6 +59,7 @@ public interface Frog extends Animals {
|
||||
* Cold (green) frog.
|
||||
*/
|
||||
COLD;
|
||||
+ // Paper end - Generated/FrogVariant
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Variant() {
|
||||
diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
|
||||
index 3bc24457d143449e6a338d79becf7c39b9f81054..b6f07418ab7267cc43d1174fc023930e04eba360 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Villager.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Villager.java
|
||||
@@ -167,6 +167,7 @@ public interface Villager extends AbstractVillager {
|
||||
*/
|
||||
public enum Type implements Keyed {
|
||||
|
||||
+ // Paper start - Generated/VillagerType
|
||||
DESERT,
|
||||
JUNGLE,
|
||||
PLAINS,
|
||||
@@ -174,6 +175,7 @@ public interface Villager extends AbstractVillager {
|
||||
SNOW,
|
||||
SWAMP,
|
||||
TAIGA;
|
||||
+ // Paper end - Generated/VillagerType
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Type() {
|
||||
diff --git a/src/main/java/org/bukkit/generator/structure/Structure.java b/src/main/java/org/bukkit/generator/structure/Structure.java
|
||||
index 8e39f282c771ddafe5d890dcf065c56f0c633647..5505705a63e9ed8a820f7f4e164d6c1dd2936b05 100644
|
||||
--- a/src/main/java/org/bukkit/generator/structure/Structure.java
|
||||
+++ b/src/main/java/org/bukkit/generator/structure/Structure.java
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public abstract class Structure implements Keyed {
|
||||
|
||||
+ // Paper start - Generated/Structure
|
||||
public static final Structure PILLAGER_OUTPOST = getStructure("pillager_outpost");
|
||||
public static final Structure MINESHAFT = getStructure("mineshaft");
|
||||
public static final Structure MINESHAFT_MESA = getStructure("mineshaft_mesa");
|
||||
@@ -51,6 +52,7 @@ public abstract class Structure implements Keyed {
|
||||
@MinecraftExperimental
|
||||
@org.jetbrains.annotations.ApiStatus.Experimental // Paper - add missing annotation
|
||||
public static final Structure TRIAL_CHAMBERS = getStructure("trial_chambers");
|
||||
+ // Paper end - Generated/Structure
|
||||
|
||||
private static Structure getStructure(String name) {
|
||||
return Registry.STRUCTURE.get(NamespacedKey.minecraft(name));
|
||||
diff --git a/src/main/java/org/bukkit/generator/structure/StructureType.java b/src/main/java/org/bukkit/generator/structure/StructureType.java
|
||||
index 2f908d5545d76ea25e26f6a4be579460512b5faf..77a03c7c35da902a802a90a41d8583172a9ca992 100644
|
||||
--- a/src/main/java/org/bukkit/generator/structure/StructureType.java
|
||||
+++ b/src/main/java/org/bukkit/generator/structure/StructureType.java
|
||||
@@ -14,6 +14,7 @@ import org.bukkit.Registry;
|
||||
*/
|
||||
public abstract class StructureType implements Keyed {
|
||||
|
||||
+ // Paper start - Generated/StructureType
|
||||
public static final StructureType BURIED_TREASURE = getStructureType("buried_treasure");
|
||||
public static final StructureType DESERT_PYRAMID = getStructureType("desert_pyramid");
|
||||
public static final StructureType END_CITY = getStructureType("end_city");
|
||||
@@ -30,6 +31,7 @@ public abstract class StructureType implements Keyed {
|
||||
public static final StructureType STRONGHOLD = getStructureType("stronghold");
|
||||
public static final StructureType SWAMP_HUT = getStructureType("swamp_hut");
|
||||
public static final StructureType WOODLAND_MANSION = getStructureType("woodland_mansion");
|
||||
+ // Paper end - Generated/StructureType
|
||||
|
||||
private static StructureType getStructureType(String name) {
|
||||
return Registry.STRUCTURE_TYPE.get(NamespacedKey.minecraft(name));
|
||||
diff --git a/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java b/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
||||
index 178d83cb3ccff2d12477d3c13ca4f108fa17e619..86e5957c70bd369f08c86d8ed588d2dc285a61f9 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.Registry;
|
||||
*/
|
||||
public interface TrimMaterial extends Keyed {
|
||||
|
||||
+ // Paper start - Generated/TrimMaterial
|
||||
/**
|
||||
* {@link Material#QUARTZ}.
|
||||
*/
|
||||
@@ -50,6 +51,7 @@ public interface TrimMaterial extends Keyed {
|
||||
* {@link Material#AMETHYST_SHARD}.
|
||||
*/
|
||||
public static final TrimMaterial AMETHYST = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("amethyst"));
|
||||
+ // Paper end - Generated/TrimMaterial
|
||||
// Paper start
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_MATERIAL}. TrimMaterials
|
||||
diff --git a/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java b/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
||||
index e29fc42ae2b9c555db63d10d20552748e28ba60e..ae7f73f391b514266371021e4171fde6e8fda6b3 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.Registry;
|
||||
*/
|
||||
public interface TrimPattern extends Keyed {
|
||||
|
||||
+ // Paper start - Generated/TrimPattern
|
||||
/**
|
||||
* {@link Material#SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
@@ -74,6 +75,7 @@ public interface TrimPattern extends Keyed {
|
||||
* {@link Material#HOST_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern HOST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("host"));
|
||||
+ // Paper end - Generated/TrimPattern
|
||||
// Paper start
|
||||
/**
|
||||
* @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_PATTERN}. TrimPatterns
|
||||
diff --git a/src/main/java/org/bukkit/potion/PotionType.java b/src/main/java/org/bukkit/potion/PotionType.java
|
||||
index 70456f08668733a9a2840be6b08b078ad63e6825..13e1db8778adea4591dbb85870ff366fd565aa9e 100644
|
||||
--- a/src/main/java/org/bukkit/potion/PotionType.java
|
||||
+++ b/src/main/java/org/bukkit/potion/PotionType.java
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* the Creative mode inventory
|
||||
*/
|
||||
public enum PotionType implements Keyed {
|
||||
+ // Paper start - Generated/PotionType
|
||||
UNCRAFTABLE("empty"),
|
||||
WATER("water"),
|
||||
MUNDANE("mundane"),
|
||||
@@ -59,6 +60,7 @@ public enum PotionType implements Keyed {
|
||||
SLOW_FALLING("slow_falling"),
|
||||
LONG_SLOW_FALLING("long_slow_falling"),
|
||||
;
|
||||
+ // Paper end - Generated/PotionType
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final Supplier<InternalPotionData> internalPotionDataSupplier;
|
||||
|
|
Loading…
Reference in New Issue