Remap CraftBukkit to Mojang+Yarn Mappings

By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:55 +01:00
parent a265d64138
commit 30e4583dbe
1780 changed files with 44628 additions and 41274 deletions

View File

@@ -47,30 +47,30 @@ public final class CraftEvil {
}
public static int getBlockTypeIdAt(World world, int x, int y, int z) {
return getId(world.getBlockAt(x, y, z).getType());
return CraftEvil.getId(world.getBlockAt(x, y, z).getType());
}
public static int getBlockTypeIdAt(World world, Location location) {
return getId(world.getBlockAt(location).getType());
return CraftEvil.getId(world.getBlockAt(location).getType());
}
public static int getTypeId(Block block) {
return getId(block.getType());
return CraftEvil.getId(block.getType());
}
public static boolean setTypeId(Block block, int type) {
block.setType(getMaterial(type));
block.setType(CraftEvil.getMaterial(type));
return true;
}
public static boolean setTypeId(Block block, int type, boolean applyPhysics) {
block.setType(getMaterial(type), applyPhysics);
block.setType(CraftEvil.getMaterial(type), applyPhysics);
return true;
}
public static boolean setTypeIdAndData(Block block, int type, byte data, boolean applyPhysics) {
block.setType(getMaterial(type), applyPhysics);
setData(block, data);
block.setType(CraftEvil.getMaterial(type), applyPhysics);
CraftEvil.setData(block, data);
return true;
}
@@ -83,24 +83,24 @@ public final class CraftEvil {
}
public static int getTypeId(BlockState state) {
return getId(state.getType());
return CraftEvil.getId(state.getType());
}
public static boolean setTypeId(BlockState state, int type) {
state.setType(getMaterial(type));
state.setType(CraftEvil.getMaterial(type));
return true;
}
public static int getTypeId(ItemStack stack) {
return getId(stack.getType());
return CraftEvil.getId(stack.getType());
}
public static void setTypeId(ItemStack stack, int type) {
stack.setType(getMaterial(type));
stack.setType(CraftEvil.getMaterial(type));
}
public static Material getMaterial(int id) {
return byId.get(id);
return CraftEvil.byId.get(id);
}
public static int getId(Material material) {

View File

@@ -10,23 +10,23 @@ import java.util.Optional;
import java.util.Set;
import net.minecraft.SharedConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.DynamicOpsNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.DispenserRegistry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.datafix.DataConverterRegistry;
import net.minecraft.util.datafix.fixes.DataConverterFlattenData;
import net.minecraft.util.datafix.fixes.DataConverterMaterialId;
import net.minecraft.util.datafix.fixes.DataConverterTypes;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.util.datafix.fixes.BlockStateData;
import net.minecraft.util.datafix.fixes.ItemIdFix;
import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockStateList;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.properties.IBlockState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.Property;
import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.EntityType;
@@ -49,8 +49,8 @@ public final class CraftLegacy {
private static final Set<String> whitelistedStates = new HashSet<>(Arrays.asList("explode", "check_decay", "decayable", "facing"));
private static final Map<MaterialData, Item> materialToItem = new HashMap<>(16384);
private static final Map<Item, MaterialData> itemToMaterial = new HashMap<>(1024);
private static final Map<MaterialData, IBlockData> materialToData = new HashMap<>(4096);
private static final Map<IBlockData, MaterialData> dataToMaterial = new HashMap<>(4096);
private static final Map<MaterialData, BlockState> materialToData = new HashMap<>(4096);
private static final Map<BlockState, MaterialData> dataToMaterial = new HashMap<>(4096);
private static final Map<MaterialData, Block> materialToBlock = new HashMap<>(4096);
private static final Map<Block, MaterialData> blockToMaterial = new HashMap<>(1024);
@@ -63,11 +63,11 @@ public final class CraftLegacy {
return material;
}
return toLegacyData(material).getItemType();
return CraftLegacy.toLegacyData(material).getItemType();
}
public static MaterialData toLegacyData(Material material) {
return toLegacyData(material, false);
return CraftLegacy.toLegacyData(material, false);
}
public static MaterialData toLegacyData(Material material, boolean itemPriority) {
@@ -76,44 +76,44 @@ public final class CraftLegacy {
if (itemPriority) {
Item item = CraftMagicNumbers.getItem(material);
mappedData = itemToMaterial.get(item);
mappedData = CraftLegacy.itemToMaterial.get(item);
}
if (mappedData == null && material.isBlock()) {
Block block = CraftMagicNumbers.getBlock(material);
IBlockData blockData = block.defaultBlockState();
BlockState blockData = block.defaultBlockState();
// Try exact match first
mappedData = dataToMaterial.get(blockData);
mappedData = CraftLegacy.dataToMaterial.get(blockData);
// Fallback to any block
if (mappedData == null) {
mappedData = blockToMaterial.get(block);
mappedData = CraftLegacy.blockToMaterial.get(block);
// Fallback to matching item
if (mappedData == null) {
mappedData = itemToMaterial.get(block.asItem());
mappedData = CraftLegacy.itemToMaterial.get(block.asItem());
}
}
} else if (!itemPriority) {
Item item = CraftMagicNumbers.getItem(material);
mappedData = itemToMaterial.get(item);
mappedData = CraftLegacy.itemToMaterial.get(item);
}
return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData;
}
public static IBlockData fromLegacyData(Material material, byte data) {
public static BlockState fromLegacyData(Material material, byte data) {
Preconditions.checkArgument(material.isLegacy(), "fromLegacyData on modern Material");
MaterialData materialData = new MaterialData(material, data);
// Try exact match first
IBlockData converted = materialToData.get(materialData);
BlockState converted = CraftLegacy.materialToData.get(materialData);
if (converted != null) {
return converted;
}
// Fallback to any block
Block convertedBlock = materialToBlock.get(materialData);
Block convertedBlock = CraftLegacy.materialToBlock.get(materialData);
if (convertedBlock != null) {
return convertedBlock.defaultBlockState();
}
@@ -128,7 +128,7 @@ public final class CraftLegacy {
MaterialData materialData = new MaterialData(material, (byte) data);
// First try matching item
Item convertedItem = materialToItem.get(materialData);
Item convertedItem = CraftLegacy.materialToItem.get(materialData);
if (convertedItem != null) {
return convertedItem;
}
@@ -136,13 +136,13 @@ public final class CraftLegacy {
// Fallback to matching block
if (material.isBlock()) {
// Try exact match first
IBlockData converted = materialToData.get(materialData);
BlockState converted = CraftLegacy.materialToData.get(materialData);
if (converted != null) {
return converted.getBlock().asItem();
}
// Fallback to any block
Block convertedBlock = materialToBlock.get(materialData);
Block convertedBlock = CraftLegacy.materialToBlock.get(materialData);
if (convertedBlock != null) {
return convertedBlock.asItem();
}
@@ -152,22 +152,22 @@ public final class CraftLegacy {
return Items.AIR;
}
public static byte toLegacyData(IBlockData blockData) {
return toLegacy(blockData).getData();
public static byte toLegacyData(BlockState blockData) {
return CraftLegacy.toLegacy(blockData).getData();
}
public static Material toLegacyMaterial(IBlockData blockData) {
return toLegacy(blockData).getItemType();
public static Material toLegacyMaterial(BlockState blockData) {
return CraftLegacy.toLegacy(blockData).getItemType();
}
public static MaterialData toLegacy(IBlockData blockData) {
public static MaterialData toLegacy(BlockState blockData) {
MaterialData mappedData;
// Try exact match first
mappedData = dataToMaterial.get(blockData);
mappedData = CraftLegacy.dataToMaterial.get(blockData);
// Fallback to any block
if (mappedData == null) {
mappedData = blockToMaterial.get(blockData.getBlock());
mappedData = CraftLegacy.blockToMaterial.get(blockData.getBlock());
}
return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData;
@@ -178,11 +178,11 @@ public final class CraftLegacy {
return material;
}
return fromLegacy(new MaterialData(material));
return CraftLegacy.fromLegacy(new MaterialData(material));
}
public static Material fromLegacy(MaterialData materialData) {
return fromLegacy(materialData, false);
return CraftLegacy.fromLegacy(materialData, false);
}
public static Material fromLegacy(MaterialData materialData, boolean itemPriority) {
@@ -195,7 +195,7 @@ public final class CraftLegacy {
// Try item first
if (itemPriority) {
Item item = materialToItem.get(materialData);
Item item = CraftLegacy.materialToItem.get(materialData);
if (item != null) {
mappedData = CraftMagicNumbers.getMaterial(item);
}
@@ -203,14 +203,14 @@ public final class CraftLegacy {
if (mappedData == null) {
// Try exact match first
IBlockData iblock = materialToData.get(materialData);
BlockState iblock = CraftLegacy.materialToData.get(materialData);
if (iblock != null) {
mappedData = CraftMagicNumbers.getMaterial(iblock.getBlock());
}
// Fallback to any block
if (mappedData == null) {
Block block = materialToBlock.get(materialData);
Block block = CraftLegacy.materialToBlock.get(materialData);
if (block != null) {
mappedData = CraftMagicNumbers.getMaterial(block);
}
@@ -219,7 +219,7 @@ public final class CraftLegacy {
// Fallback to matching item
if (!itemPriority && mappedData == null) {
Item item = materialToItem.get(materialData);
Item item = CraftLegacy.materialToItem.get(materialData);
if (item != null) {
mappedData = CraftMagicNumbers.getMaterial(item);
}
@@ -256,7 +256,7 @@ public final class CraftLegacy {
}
public static String toString(Material material) {
return name(material);
return CraftLegacy.name(material);
}
public static void init() {
@@ -323,7 +323,7 @@ public final class CraftLegacy {
SPAWN_EGGS.put((byte) EntityType.ZOMBIE_VILLAGER.getTypeId(), Material.ZOMBIE_VILLAGER_SPAWN_EGG);
SharedConstants.tryDetectVersion();
DispenserRegistry.bootStrap();
Bootstrap.bootStrap();
for (Material material : Material.values()) {
if (!material.isLegacy()) {
@@ -334,26 +334,26 @@ public final class CraftLegacy {
if (isBlock(material)) { // Use custom method instead of Material#isBlock since it relies on this being already run
for (byte data = 0; data < 16; data++) {
MaterialData matData = new MaterialData(material, data);
Dynamic blockTag = DataConverterFlattenData.getTag(material.getId() << 4 | data);
blockTag = DataConverterRegistry.getDataFixer().update(DataConverterTypes.BLOCK_STATE, blockTag, 100, CraftMagicNumbers.INSTANCE.getDataVersion());
Dynamic blockTag = BlockStateData.getTag(material.getId() << 4 | data);
blockTag = DataFixers.getDataFixer().update(References.BLOCK_STATE, blockTag, 100, CraftMagicNumbers.INSTANCE.getDataVersion());
// TODO: better skull conversion, chests
if (blockTag.get("Name").asString("").contains("%%FILTER_ME%%")) {
continue;
}
String name = blockTag.get("Name").asString("");
Block block = BuiltInRegistries.BLOCK.getValue(MinecraftKey.parse(name));
Block block = BuiltInRegistries.BLOCK.getValue(ResourceLocation.parse(name));
if (block == null) {
continue;
}
IBlockData blockData = block.defaultBlockState();
BlockStateList states = block.getStateDefinition();
BlockState blockData = block.defaultBlockState();
StateDefinition states = block.getStateDefinition();
Optional<NBTTagCompound> propMap = blockTag.getElement("Properties").result();
Optional<CompoundTag> propMap = blockTag.getElement("Properties").result();
if (propMap.isPresent()) {
NBTTagCompound properties = propMap.get();
CompoundTag properties = propMap.get();
for (String dataKey : properties.getAllKeys()) {
IBlockState state = states.getProperty(dataKey);
Property state = states.getProperty(dataKey);
if (state == null) {
Preconditions.checkArgument(whitelistedStates.contains(dataKey), "No state for %s", dataKey);
@@ -397,17 +397,17 @@ public final class CraftLegacy {
continue;
}
// Skip non item stacks for now (18w19b)
if (DataConverterMaterialId.getItem(material.getId()) == null) {
if (ItemIdFix.getItem(material.getId()) == null) {
continue;
}
MaterialData matData = new MaterialData(material, data);
NBTTagCompound stack = new NBTTagCompound();
CompoundTag stack = new CompoundTag();
stack.putInt("id", material.getId());
stack.putShort("Damage", data);
Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ITEM_STACK, new Dynamic<NBTBase>(DynamicOpsNBT.INSTANCE, stack), -1, CraftMagicNumbers.INSTANCE.getDataVersion());
Dynamic<Tag> converted = DataFixers.getDataFixer().update(References.ITEM_STACK, new Dynamic<Tag>(NbtOps.INSTANCE, stack), -1, CraftMagicNumbers.INSTANCE.getDataVersion());
String newId = converted.get("id").asString("");
// Recover spawn eggs with invalid data
@@ -416,7 +416,7 @@ public final class CraftLegacy {
}
// Preconditions.checkState(newId.contains("minecraft:"), "Unknown new material for " + matData);
Item newMaterial = BuiltInRegistries.ITEM.getValue(MinecraftKey.parse(newId));
Item newMaterial = BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(newId));
if (newMaterial == Items.AIR) {
continue;

View File

@@ -35,18 +35,18 @@ public class FieldRename {
}
return switch (owner) {
case "org/bukkit/block/banner/PatternType" -> convertPatternTypeName(apiVersion, from);
case "org/bukkit/enchantments/Enchantment" -> convertEnchantmentName(apiVersion, from);
case "org/bukkit/block/Biome" -> convertBiomeName(apiVersion, from);
case "org/bukkit/entity/EntityType" -> convertEntityTypeName(apiVersion, from);
case "org/bukkit/potion/PotionEffectType" -> convertPotionEffectTypeName(apiVersion, from);
case "org/bukkit/potion/PotionType" -> convertPotionTypeName(apiVersion, from);
case "org/bukkit/MusicInstrument" -> convertMusicInstrumentName(apiVersion, from);
case "org/bukkit/Particle" -> convertParticleName(apiVersion, from);
case "org/bukkit/loot/LootTables" -> convertLootTablesName(apiVersion, from);
case "org/bukkit/attribute/Attribute" -> convertAttributeName(apiVersion, from).replace('.', '_');
case "org/bukkit/map/MapCursor$Type" -> convertMapCursorTypeName(apiVersion, from);
case "org/bukkit/inventory/ItemFlag" -> convertItemFlagName(apiVersion, from);
case "org/bukkit/block/banner/PatternType" -> FieldRename.convertPatternTypeName(apiVersion, from);
case "org/bukkit/enchantments/Enchantment" -> FieldRename.convertEnchantmentName(apiVersion, from);
case "org/bukkit/block/Biome" -> FieldRename.convertBiomeName(apiVersion, from);
case "org/bukkit/entity/EntityType" -> FieldRename.convertEntityTypeName(apiVersion, from);
case "org/bukkit/potion/PotionEffectType" -> FieldRename.convertPotionEffectTypeName(apiVersion, from);
case "org/bukkit/potion/PotionType" -> FieldRename.convertPotionTypeName(apiVersion, from);
case "org/bukkit/MusicInstrument" -> FieldRename.convertMusicInstrumentName(apiVersion, from);
case "org/bukkit/Particle" -> FieldRename.convertParticleName(apiVersion, from);
case "org/bukkit/loot/LootTables" -> FieldRename.convertLootTablesName(apiVersion, from);
case "org/bukkit/attribute/Attribute" -> FieldRename.convertAttributeName(apiVersion, from).replace('.', '_');
case "org/bukkit/map/MapCursor$Type" -> FieldRename.convertMapCursorTypeName(apiVersion, from);
case "org/bukkit/inventory/ItemFlag" -> FieldRename.convertItemFlagName(apiVersion, from);
default -> from;
};
}
@@ -73,13 +73,13 @@ public class FieldRename {
@DoNotReroute
public static String convertPatternTypeName(ApiVersion version, String from) {
return PATTERN_TYPE_DATA.getReplacement(version, from);
return FieldRename.PATTERN_TYPE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/block/banner/PatternType")
public static PatternType valueOf_PatternType(String value, @InjectPluginVersion ApiVersion version) {
return PatternType.valueOf(convertPatternTypeName(version, value));
return PatternType.valueOf(FieldRename.convertPatternTypeName(version, value));
}
// Enchantment
@@ -112,14 +112,14 @@ public class FieldRename {
@DoNotReroute
public static String convertEnchantmentName(ApiVersion version, String from) {
return ENCHANTMENT_DATA.getReplacement(version, from);
return FieldRename.ENCHANTMENT_DATA.getReplacement(version, from);
}
@RerouteMethodName("getByName")
@RerouteStatic("org/bukkit/enchantments/Enchantment")
public static Enchantment getByName_Enchantment(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return Enchantment.getByName(convertEnchantmentName(ApiVersion.CURRENT, name));
return Enchantment.getByName(FieldRename.convertEnchantmentName(ApiVersion.CURRENT, name));
}
// Biome
@@ -144,14 +144,14 @@ public class FieldRename {
@DoNotReroute
public static String convertBiomeName(ApiVersion version, String from) {
return BIOME_DATA.getReplacement(version, from);
return FieldRename.BIOME_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/block/Biome")
public static Biome valueOf_Biome(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return Biome.valueOf(convertBiomeName(ApiVersion.CURRENT, name));
return Biome.valueOf(FieldRename.convertBiomeName(ApiVersion.CURRENT, name));
}
// EntityType
@@ -197,21 +197,21 @@ public class FieldRename {
@DoNotReroute
public static String convertEntityTypeName(ApiVersion version, String from) {
return ENTITY_TYPE_DATA.getReplacement(version, from);
return FieldRename.ENTITY_TYPE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/entity/EntityType")
public static EntityType valueOf_EntityType(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return EntityType.valueOf(convertEntityTypeName(ApiVersion.CURRENT, name));
return EntityType.valueOf(FieldRename.convertEntityTypeName(ApiVersion.CURRENT, name));
}
@RerouteMethodName("fromName")
@RerouteStatic("org/bukkit/entity/EntityType")
public static EntityType fromName_EntityType(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return EntityType.fromName(convertEntityTypeName(ApiVersion.CURRENT, name));
return EntityType.fromName(FieldRename.convertEntityTypeName(ApiVersion.CURRENT, name));
}
// PotionEffectType
@@ -230,14 +230,14 @@ public class FieldRename {
@DoNotReroute
public static String convertPotionEffectTypeName(ApiVersion version, String from) {
return POTION_EFFECT_TYPE_DATA.getReplacement(version, from);
return FieldRename.POTION_EFFECT_TYPE_DATA.getReplacement(version, from);
}
@RerouteMethodName("getByName")
@RerouteStatic("org/bukkit/potion/PotionEffectType")
public static PotionEffectType getByName_PotionEffectType(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return PotionEffectType.getByName(convertPotionEffectTypeName(ApiVersion.CURRENT, name));
return PotionEffectType.getByName(FieldRename.convertPotionEffectTypeName(ApiVersion.CURRENT, name));
}
// PotionType
@@ -252,14 +252,14 @@ public class FieldRename {
@DoNotReroute
public static String convertPotionTypeName(ApiVersion version, String from) {
return POTION_TYPE_DATA.getReplacement(version, from);
return FieldRename.POTION_TYPE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/potion/PotionType")
public static PotionType valueOf_PotionType(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return PotionType.valueOf(convertPotionTypeName(ApiVersion.CURRENT, name));
return PotionType.valueOf(FieldRename.convertPotionTypeName(ApiVersion.CURRENT, name));
}
// MusicInstrument
@@ -276,7 +276,7 @@ public class FieldRename {
@DoNotReroute
public static String convertMusicInstrumentName(ApiVersion version, String from) {
return MUSIC_INSTRUMENT_DATA.getReplacement(version, from);
return FieldRename.MUSIC_INSTRUMENT_DATA.getReplacement(version, from);
}
// Particle
@@ -322,14 +322,14 @@ public class FieldRename {
@DoNotReroute
public static String convertParticleName(ApiVersion version, String from) {
return PARTICLE_DATA.getReplacement(version, from);
return FieldRename.PARTICLE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/Particle")
public static Particle valueOf_Particle(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return Particle.valueOf(convertParticleName(ApiVersion.CURRENT, name));
return Particle.valueOf(FieldRename.convertParticleName(ApiVersion.CURRENT, name));
}
// LootTables
@@ -340,14 +340,14 @@ public class FieldRename {
@DoNotReroute
public static String convertLootTablesName(ApiVersion version, String from) {
return LOOT_TABLES_DATA.getReplacement(version, from);
return FieldRename.LOOT_TABLES_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/loot/LootTables")
public static LootTables valueOf_LootTables(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return LootTables.valueOf(convertLootTablesName(ApiVersion.CURRENT, name));
return LootTables.valueOf(FieldRename.convertLootTablesName(ApiVersion.CURRENT, name));
}
// Attribute
@@ -393,14 +393,14 @@ public class FieldRename {
@DoNotReroute
public static String convertAttributeName(ApiVersion version, String from) {
return ATTRIBUTE_DATA.getReplacement(version, from);
return FieldRename.ATTRIBUTE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/attribute/Attribute")
public static Attribute valueOf_Attribute(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return Attribute.valueOf(convertAttributeName(ApiVersion.CURRENT, name).replace('.', '_'));
return Attribute.valueOf(FieldRename.convertAttributeName(ApiVersion.CURRENT, name).replace('.', '_'));
}
// MapCursor Type
@@ -425,13 +425,13 @@ public class FieldRename {
@DoNotReroute
public static String convertMapCursorTypeName(ApiVersion version, String from) {
return MAP_CURSOR_TYPE_DATA.getReplacement(version, from);
return FieldRename.MAP_CURSOR_TYPE_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/map/MapCursor$Type")
public static MapCursor.Type valueOf_MapCursorType(String name, @InjectPluginVersion ApiVersion version) {
return MapCursor.Type.valueOf(convertMapCursorTypeName(version, name));
return MapCursor.Type.valueOf(FieldRename.convertMapCursorTypeName(version, name));
}
// ItemFlag
@@ -442,13 +442,13 @@ public class FieldRename {
@DoNotReroute
public static String convertItemFlagName(ApiVersion version, String from) {
return ITEM_FLAG_DATA.getReplacement(version, from);
return FieldRename.ITEM_FLAG_DATA.getReplacement(version, from);
}
@RerouteMethodName("valueOf")
@RerouteStatic("org/bukkit/inventory/ItemFlag")
public static ItemFlag valueOf_ItemFlag(String name) {
// We don't have version-specific changes, so just use current, and don't inject a version
return ItemFlag.valueOf(convertItemFlagName(ApiVersion.CURRENT, name));
return ItemFlag.valueOf(FieldRename.convertItemFlagName(ApiVersion.CURRENT, name));
}
}

View File

@@ -117,45 +117,45 @@ public class MaterialRerouting {
}
public static Material getMaterial(BlockData blockData, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(blockData.getMaterial(), version);
return MaterialRerouting.transformFromBlockType(blockData.getMaterial(), version);
}
public static Material getPlacementMaterial(BlockData blockData, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(blockData.getPlacementMaterial(), version);
return MaterialRerouting.transformFromItemType(blockData.getPlacementMaterial(), version);
}
public static Material getType(Block block, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(block.getType(), version);
return MaterialRerouting.transformFromBlockType(block.getType(), version);
}
public static void setType(Block block, Material type) {
block.setType(transformToBlockType(type));
block.setType(MaterialRerouting.transformToBlockType(type));
}
public static void setType(Block block, Material type, boolean applyPhysics) {
block.setType(transformToBlockType(type), applyPhysics);
block.setType(MaterialRerouting.transformToBlockType(type), applyPhysics);
}
public static Material getType(BlockState blockState, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(blockState.getType(), version);
return MaterialRerouting.transformFromBlockType(blockState.getType(), version);
}
public static void setType(BlockState blockState, Material type) {
blockState.setType(transformToBlockType(type));
blockState.setType(MaterialRerouting.transformToBlockType(type));
}
public static void setSherd(DecoratedPot decoratedPot, DecoratedPot.Side side, Material sherd) {
decoratedPot.setSherd(side, transformToItemType(sherd));
decoratedPot.setSherd(side, MaterialRerouting.transformToItemType(sherd));
}
public static Material getSherd(DecoratedPot decoratedPot, DecoratedPot.Side side, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(decoratedPot.getSherd(side), version);
return MaterialRerouting.transformFromItemType(decoratedPot.getSherd(side), version);
}
public static Map<DecoratedPot.Side, Material> getSherds(DecoratedPot decoratedPot, @InjectPluginVersion ApiVersion version) {
Map<DecoratedPot.Side, Material> result = new EnumMap<>(DecoratedPot.Side.class);
for (Map.Entry<DecoratedPot.Side, Material> entry : decoratedPot.getSherds().entrySet()) {
result.put(entry.getKey(), transformFromItemType(entry.getValue(), version));
result.put(entry.getKey(), MaterialRerouting.transformFromItemType(entry.getValue(), version));
}
return result;
@@ -163,44 +163,44 @@ public class MaterialRerouting {
@Deprecated
public static List<Material> getShards(DecoratedPot decoratedPot, @InjectPluginVersion ApiVersion version) {
return decoratedPot.getSherds().values().stream().map(shard -> transformFromItemType(shard, version)).toList();
return decoratedPot.getSherds().values().stream().map(shard -> MaterialRerouting.transformFromItemType(shard, version)).toList();
}
public static void setPlaying(Jukebox jukebox, Material record) {
jukebox.setPlaying(transformToItemType(record));
jukebox.setPlaying(MaterialRerouting.transformToItemType(record));
}
public static Material getPlaying(Jukebox jukebox, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(jukebox.getPlaying(), version);
return MaterialRerouting.transformFromItemType(jukebox.getPlaying(), version);
}
public static boolean includes(EnchantmentTarget enchantmentTarget, Material item) {
return enchantmentTarget.includes(transformToItemType(item));
return enchantmentTarget.includes(MaterialRerouting.transformToItemType(item));
}
public static boolean isBreedItem(Animals animals, Material material) {
return animals.isBreedItem(transformToItemType(material));
return animals.isBreedItem(MaterialRerouting.transformToItemType(material));
}
public static Material getMaterial(Boat.Type type, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(type.getMaterial(), version);
return MaterialRerouting.transformFromItemType(type.getMaterial(), version);
}
@Deprecated
public static Material getMaterial(FallingBlock fallingBlock, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(fallingBlock.getBlockData().getMaterial(), version);
return MaterialRerouting.transformFromBlockType(fallingBlock.getBlockData().getMaterial(), version);
}
public static boolean hasCooldown(HumanEntity humanEntity, Material material) {
return humanEntity.hasCooldown(transformToItemType(material));
return humanEntity.hasCooldown(MaterialRerouting.transformToItemType(material));
}
public static int getCooldown(HumanEntity humanEntity, Material material) {
return humanEntity.getCooldown(transformToItemType(material));
return humanEntity.getCooldown(MaterialRerouting.transformToItemType(material));
}
public static void setCooldown(HumanEntity humanEntity, Material material, int ticks) {
humanEntity.setCooldown(transformToItemType(material), ticks);
humanEntity.setCooldown(MaterialRerouting.transformToItemType(material), ticks);
}
public static List<Block> getLineOfSight(LivingEntity livingEntity, Set<Material> transparent, int maxDistance) {
@@ -228,27 +228,27 @@ public class MaterialRerouting {
}
public static boolean addBarterMaterial(Piglin piglin, Material material) {
return piglin.addBarterMaterial(transformToItemType(material));
return piglin.addBarterMaterial(MaterialRerouting.transformToItemType(material));
}
public static boolean removeBarterMaterial(Piglin piglin, Material material) {
return piglin.removeBarterMaterial(transformToItemType(material));
return piglin.removeBarterMaterial(MaterialRerouting.transformToItemType(material));
}
public static boolean addMaterialOfInterest(Piglin piglin, Material material) {
return piglin.addMaterialOfInterest(transformToItemType(material));
return piglin.addMaterialOfInterest(MaterialRerouting.transformToItemType(material));
}
public static boolean removeMaterialOfInterest(Piglin piglin, Material material) {
return piglin.removeMaterialOfInterest(transformToItemType(material));
return piglin.removeMaterialOfInterest(MaterialRerouting.transformToItemType(material));
}
public static Set<Material> getInterestList(Piglin piglin, @InjectPluginVersion ApiVersion version) {
return piglin.getInterestList().stream().map(item -> transformFromItemType(item, version)).collect(Collectors.toSet());
return piglin.getInterestList().stream().map(item -> MaterialRerouting.transformFromItemType(item, version)).collect(Collectors.toSet());
}
public static Set<Material> getBarterList(Piglin piglin, @InjectPluginVersion ApiVersion version) {
return piglin.getBarterList().stream().map(item -> transformFromItemType(item, version)).collect(Collectors.toSet());
return piglin.getBarterList().stream().map(item -> MaterialRerouting.transformFromItemType(item, version)).collect(Collectors.toSet());
}
@Deprecated
@@ -257,67 +257,67 @@ public class MaterialRerouting {
}
public static Material getSteerMaterial(Steerable steerable, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(steerable.getSteerMaterial(), version);
return MaterialRerouting.transformFromItemType(steerable.getSteerMaterial(), version);
}
public static Material getMaterial(BlockCanBuildEvent blockCanBuildEvent, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(blockCanBuildEvent.getMaterial(), version);
return MaterialRerouting.transformFromBlockType(blockCanBuildEvent.getMaterial(), version);
}
public static Material getChangedType(BlockPhysicsEvent blockPhysicsEvent, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(blockPhysicsEvent.getChangedType(), version);
return MaterialRerouting.transformFromBlockType(blockPhysicsEvent.getChangedType(), version);
}
public static Material getTo(EntityChangeBlockEvent entityChangeBlockEvent, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(entityChangeBlockEvent.getTo(), version);
return MaterialRerouting.transformFromBlockType(entityChangeBlockEvent.getTo(), version);
}
public static Material getItemType(FurnaceExtractEvent furnaceExtractEvent, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(furnaceExtractEvent.getItemType(), version);
return MaterialRerouting.transformFromItemType(furnaceExtractEvent.getItemType(), version);
}
public static Material getBucket(PlayerBucketEvent playerBucketEvent, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(playerBucketEvent.getBucket(), version);
return MaterialRerouting.transformFromItemType(playerBucketEvent.getBucket(), version);
}
public static Material getMaterial(PlayerInteractEvent playerInteractEvent, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(playerInteractEvent.getMaterial(), version);
return MaterialRerouting.transformFromItemType(playerInteractEvent.getMaterial(), version);
}
public static Material getMaterial(PlayerStatisticIncrementEvent playerStatisticIncrementEvent, @InjectPluginVersion ApiVersion version) {
if (playerStatisticIncrementEvent.getStatistic().getType() == Statistic.Type.BLOCK) {
return transformFromBlockType(playerStatisticIncrementEvent.getMaterial(), version);
return MaterialRerouting.transformFromBlockType(playerStatisticIncrementEvent.getMaterial(), version);
} else if (playerStatisticIncrementEvent.getStatistic().getType() == Statistic.Type.ITEM) {
return transformFromItemType(playerStatisticIncrementEvent.getMaterial(), version);
return MaterialRerouting.transformFromItemType(playerStatisticIncrementEvent.getMaterial(), version);
} else {
// Theoretically this should be null, but just in case convert from block type
// Can probably check if it is not null and print a warning, but for now it should be fine without the check.
return transformFromBlockType(playerStatisticIncrementEvent.getMaterial(), version);
return MaterialRerouting.transformFromBlockType(playerStatisticIncrementEvent.getMaterial(), version);
}
}
public static void setBlock(ChunkGenerator.ChunkData chunkData, int x, int y, int z, Material material) {
chunkData.setBlock(x, y, z, transformToBlockType(material));
chunkData.setBlock(x, y, z, MaterialRerouting.transformToBlockType(material));
}
public static void setRegion(ChunkGenerator.ChunkData chunkData, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material) {
chunkData.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, transformToBlockType(material));
chunkData.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, MaterialRerouting.transformToBlockType(material));
}
public static Material getType(ChunkGenerator.ChunkData chunkData, int x, int y, int z, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(chunkData.getType(x, y, z), version);
return MaterialRerouting.transformFromBlockType(chunkData.getType(x, y, z), version);
}
public static BlockData getBlockData(BlockDataMeta blockDataMeta, Material material) {
return blockDataMeta.getBlockData(transformToBlockType(material));
return blockDataMeta.getBlockData(MaterialRerouting.transformToBlockType(material));
}
public static CookingRecipe<?> setInput(CookingRecipe<?> cookingRecipe, Material material) {
return cookingRecipe.setInput(transformToItemType(material));
return cookingRecipe.setInput(MaterialRerouting.transformToItemType(material));
}
public static FurnaceRecipe setInput(FurnaceRecipe furnaceRecipe, Material material) {
return furnaceRecipe.setInput(transformToItemType(material));
return furnaceRecipe.setInput(MaterialRerouting.transformToItemType(material));
}
@Deprecated
@@ -326,55 +326,55 @@ public class MaterialRerouting {
}
public static boolean contains(Inventory inventory, Material material) {
return inventory.contains(transformToItemType(material));
return inventory.contains(MaterialRerouting.transformToItemType(material));
}
public static boolean contains(Inventory inventory, Material material, int amount) {
return inventory.contains(transformToItemType(material), amount);
return inventory.contains(MaterialRerouting.transformToItemType(material), amount);
}
public static HashMap<Integer, ? extends ItemStack> all(Inventory inventory, Material material) {
return inventory.all(transformToItemType(material));
return inventory.all(MaterialRerouting.transformToItemType(material));
}
public static int first(Inventory inventory, Material material) {
return inventory.first(transformToItemType(material));
return inventory.first(MaterialRerouting.transformToItemType(material));
}
public static void remove(Inventory inventory, Material material) {
inventory.remove(transformToItemType(material));
inventory.remove(MaterialRerouting.transformToItemType(material));
}
public static ItemMeta getItemMeta(ItemFactory itemFactory, Material material) {
return itemFactory.getItemMeta(transformToItemType(material));
return itemFactory.getItemMeta(MaterialRerouting.transformToItemType(material));
}
public static boolean isApplicable(ItemFactory itemFactory, ItemMeta itemMeta, Material material) {
return itemFactory.isApplicable(itemMeta, transformToItemType(material));
return itemFactory.isApplicable(itemMeta, MaterialRerouting.transformToItemType(material));
}
public static ItemMeta asMetaFor(ItemFactory itemFactory, ItemMeta itemMeta, Material material) {
return itemFactory.asMetaFor(itemMeta, transformToItemType(material));
return itemFactory.asMetaFor(itemMeta, MaterialRerouting.transformToItemType(material));
}
public static Material getSpawnEgg(ItemFactory itemFactory, EntityType entityType, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(itemFactory.getSpawnEgg(entityType), version);
return MaterialRerouting.transformFromItemType(itemFactory.getSpawnEgg(entityType), version);
}
public static Material getType(ItemStack itemStack, @InjectPluginVersion ApiVersion version) {
return transformFromItemType(itemStack.getType(), version);
return MaterialRerouting.transformFromItemType(itemStack.getType(), version);
}
public static void setType(ItemStack itemStack, Material material) {
itemStack.setType(transformToItemType(material));
itemStack.setType(MaterialRerouting.transformToItemType(material));
}
public static List<Material> getChoices(RecipeChoice.MaterialChoice materialChoice, @InjectPluginVersion ApiVersion version) {
return materialChoice.getChoices().stream().map(m -> transformFromItemType(m, version)).toList();
return materialChoice.getChoices().stream().map(m -> MaterialRerouting.transformFromItemType(m, version)).toList();
}
public static ShapedRecipe setIngredient(ShapedRecipe shapedRecipe, char key, Material material) {
return shapedRecipe.setIngredient(key, transformToItemType(material));
return shapedRecipe.setIngredient(key, MaterialRerouting.transformToItemType(material));
}
@Deprecated
@@ -383,7 +383,7 @@ public class MaterialRerouting {
}
public static ShapelessRecipe addIngredient(ShapelessRecipe shapelessRecipe, Material material) {
return shapelessRecipe.addIngredient(transformToItemType(material));
return shapelessRecipe.addIngredient(MaterialRerouting.transformToItemType(material));
}
@Deprecated
@@ -392,7 +392,7 @@ public class MaterialRerouting {
}
public static ShapelessRecipe addIngredient(ShapelessRecipe shapelessRecipe, int count, Material material) {
return shapelessRecipe.addIngredient(count, transformToItemType(material));
return shapelessRecipe.addIngredient(count, MaterialRerouting.transformToItemType(material));
}
@Deprecated
@@ -401,11 +401,11 @@ public class MaterialRerouting {
}
public static ShapelessRecipe removeIngredient(ShapelessRecipe shapelessRecipe, Material material) {
return shapelessRecipe.removeIngredient(transformToItemType(material));
return shapelessRecipe.removeIngredient(MaterialRerouting.transformToItemType(material));
}
public static ShapelessRecipe removeIngredient(ShapelessRecipe shapelessRecipe, int count, Material material) {
return shapelessRecipe.removeIngredient(count, transformToItemType(material));
return shapelessRecipe.removeIngredient(count, MaterialRerouting.transformToItemType(material));
}
@Deprecated
@@ -419,143 +419,143 @@ public class MaterialRerouting {
}
public static StonecuttingRecipe setInput(StonecuttingRecipe stonecuttingRecipe, Material material) {
return stonecuttingRecipe.setInput(transformToItemType(material));
return stonecuttingRecipe.setInput(MaterialRerouting.transformToItemType(material));
}
public static boolean isEnabledByFeature(DataPackManager dataPackManager, Material material, World world) {
return dataPackManager.isEnabledByFeature(transformToItemType(material), world);
return dataPackManager.isEnabledByFeature(MaterialRerouting.transformToItemType(material), world);
}
@RerouteStatic("org/bukkit/scoreboard/Criteria")
public static Criteria statistic(Statistic statistic, Material material) {
if (statistic.getType() == Statistic.Type.BLOCK) {
return Criteria.statistic(statistic, transformToBlockType(material));
return Criteria.statistic(statistic, MaterialRerouting.transformToBlockType(material));
} else if (statistic.getType() == Statistic.Type.ITEM) {
return Criteria.statistic(statistic, transformToItemType(material));
return Criteria.statistic(statistic, MaterialRerouting.transformToItemType(material));
} else {
// This is not allowed, the method will throw an error
return Criteria.statistic(statistic, transformToBlockType(material));
return Criteria.statistic(statistic, MaterialRerouting.transformToBlockType(material));
}
}
@RerouteStatic("org/bukkit/Bukkit")
public static BlockData createBlockData(Material material) {
return Bukkit.createBlockData(transformToBlockType(material));
return Bukkit.createBlockData(MaterialRerouting.transformToBlockType(material));
}
@RerouteStatic("org/bukkit/Bukkit")
public static BlockData createBlockData(Material material, Consumer<? super BlockData> consumer) {
return Bukkit.createBlockData(transformToBlockType(material), consumer);
return Bukkit.createBlockData(MaterialRerouting.transformToBlockType(material), consumer);
}
@RerouteStatic("org/bukkit/Bukkit")
public static BlockData createBlockData(Material material, String data) {
return Bukkit.createBlockData(transformToBlockType(material), data);
return Bukkit.createBlockData(MaterialRerouting.transformToBlockType(material), data);
}
public static Material getBlockType(ChunkSnapshot chunkSnapshot, int x, int y, int z, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(chunkSnapshot.getBlockType(x, y, z), version);
return MaterialRerouting.transformFromBlockType(chunkSnapshot.getBlockType(x, y, z), version);
}
public static void incrementStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material) {
if (statistic.getType() == Statistic.Type.BLOCK) {
offlinePlayer.incrementStatistic(statistic, transformToBlockType(material));
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToBlockType(material));
} else if (statistic.getType() == Statistic.Type.ITEM) {
offlinePlayer.incrementStatistic(statistic, transformToItemType(material));
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToItemType(material));
} else {
// This is not allowed, the method will throw an error
offlinePlayer.incrementStatistic(statistic, transformToBlockType(material));
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToBlockType(material));
}
}
public static void decrementStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material) {
if (statistic.getType() == Statistic.Type.BLOCK) {
offlinePlayer.decrementStatistic(statistic, transformToBlockType(material));
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToBlockType(material));
} else if (statistic.getType() == Statistic.Type.ITEM) {
offlinePlayer.decrementStatistic(statistic, transformToItemType(material));
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToItemType(material));
} else {
// This is not allowed, the method will throw an error
offlinePlayer.decrementStatistic(statistic, transformToBlockType(material));
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToBlockType(material));
}
}
public static int getStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material) {
if (statistic.getType() == Statistic.Type.BLOCK) {
return offlinePlayer.getStatistic(statistic, transformToBlockType(material));
return offlinePlayer.getStatistic(statistic, MaterialRerouting.transformToBlockType(material));
} else if (statistic.getType() == Statistic.Type.ITEM) {
return offlinePlayer.getStatistic(statistic, transformToItemType(material));
return offlinePlayer.getStatistic(statistic, MaterialRerouting.transformToItemType(material));
} else {
// This is not allowed, the method will throw an error
return offlinePlayer.getStatistic(statistic, transformToBlockType(material));
return offlinePlayer.getStatistic(statistic, MaterialRerouting.transformToBlockType(material));
}
}
public static void incrementStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material, int amount) {
if (statistic.getType() == Statistic.Type.BLOCK) {
offlinePlayer.incrementStatistic(statistic, transformToBlockType(material), amount);
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToBlockType(material), amount);
} else if (statistic.getType() == Statistic.Type.ITEM) {
offlinePlayer.incrementStatistic(statistic, transformToItemType(material), amount);
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToItemType(material), amount);
} else {
// This is not allowed, the method will throw an error
offlinePlayer.incrementStatistic(statistic, transformToBlockType(material), amount);
offlinePlayer.incrementStatistic(statistic, MaterialRerouting.transformToBlockType(material), amount);
}
}
public static void decrementStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material, int amount) {
if (statistic.getType() == Statistic.Type.BLOCK) {
offlinePlayer.decrementStatistic(statistic, transformToBlockType(material), amount);
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToBlockType(material), amount);
} else if (statistic.getType() == Statistic.Type.ITEM) {
offlinePlayer.decrementStatistic(statistic, transformToItemType(material), amount);
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToItemType(material), amount);
} else {
// This is not allowed, the method will throw an error
offlinePlayer.decrementStatistic(statistic, transformToBlockType(material), amount);
offlinePlayer.decrementStatistic(statistic, MaterialRerouting.transformToBlockType(material), amount);
}
}
public static void setStatistic(OfflinePlayer offlinePlayer, Statistic statistic, Material material, int newValue) {
if (statistic.getType() == Statistic.Type.BLOCK) {
offlinePlayer.setStatistic(statistic, transformToBlockType(material), newValue);
offlinePlayer.setStatistic(statistic, MaterialRerouting.transformToBlockType(material), newValue);
} else if (statistic.getType() == Statistic.Type.ITEM) {
offlinePlayer.setStatistic(statistic, transformToItemType(material), newValue);
offlinePlayer.setStatistic(statistic, MaterialRerouting.transformToItemType(material), newValue);
} else {
// This is not allowed, the method will throw an error
offlinePlayer.setStatistic(statistic, transformToBlockType(material), newValue);
offlinePlayer.setStatistic(statistic, MaterialRerouting.transformToBlockType(material), newValue);
}
}
public static Material getType(RegionAccessor regionAccessor, Location location, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(regionAccessor.getType(location), version);
return MaterialRerouting.transformFromBlockType(regionAccessor.getType(location), version);
}
public static Material getType(RegionAccessor regionAccessor, int x, int y, int z, @InjectPluginVersion ApiVersion version) {
return transformFromBlockType(regionAccessor.getType(x, y, z), version);
return MaterialRerouting.transformFromBlockType(regionAccessor.getType(x, y, z), version);
}
public static void setType(RegionAccessor regionAccessor, Location location, Material material) {
regionAccessor.setType(location, transformToBlockType(material));
regionAccessor.setType(location, MaterialRerouting.transformToBlockType(material));
}
public static void setType(RegionAccessor regionAccessor, int x, int y, int z, Material material) {
regionAccessor.setType(x, y, z, transformToBlockType(material));
regionAccessor.setType(x, y, z, MaterialRerouting.transformToBlockType(material));
}
public static BlockData createBlockData(Server server, Material material) {
return server.createBlockData(transformToBlockType(material));
return server.createBlockData(MaterialRerouting.transformToBlockType(material));
}
public static BlockData createBlockData(Server server, Material material, Consumer<? super BlockData> consumer) {
return server.createBlockData(transformToBlockType(material), consumer);
return server.createBlockData(MaterialRerouting.transformToBlockType(material), consumer);
}
public static BlockData createBlockData(Server server, Material material, String data) {
return server.createBlockData(transformToBlockType(material), data);
return server.createBlockData(MaterialRerouting.transformToBlockType(material), data);
}
public static <T extends Keyed> boolean isTagged(Tag<T> tag, T item) {
if (tag instanceof CraftBlockTag) {
return tag.isTagged((T) transformToBlockType((Material) item));
return tag.isTagged((T) MaterialRerouting.transformToBlockType((Material) item));
} else if (tag instanceof CraftItemTag) {
return tag.isTagged((T) transformToItemType((Material) item));
return tag.isTagged((T) MaterialRerouting.transformToItemType((Material) item));
}
return tag.isTagged(item);
@@ -568,9 +568,9 @@ public class MaterialRerouting {
}
if (tag instanceof CraftBlockTag) {
return values.stream().map(val -> (Material) val).map(val -> transformFromBlockType(val, version)).map(val -> (T) val).collect(Collectors.toSet());
return values.stream().map(val -> (Material) val).map(val -> MaterialRerouting.transformFromBlockType(val, version)).map(val -> (T) val).collect(Collectors.toSet());
} else if (tag instanceof CraftItemTag) {
return values.stream().map(val -> (Material) val).map(val -> transformFromItemType(val, version)).map(val -> (T) val).collect(Collectors.toSet());
return values.stream().map(val -> (Material) val).map(val -> MaterialRerouting.transformFromItemType(val, version)).map(val -> (T) val).collect(Collectors.toSet());
}
return values;
@@ -582,7 +582,7 @@ public class MaterialRerouting {
}
public static ToolComponent.ToolRule addRule(ToolComponent toolComponent, Material block, Float speed, Boolean correctForDrops) {
return toolComponent.addRule(transformToBlockType(block), speed, correctForDrops);
return toolComponent.addRule(MaterialRerouting.transformToBlockType(block), speed, correctForDrops);
}
public static ToolComponent.ToolRule addRule(ToolComponent toolComponent, Collection<Material> blocks, Float speed, Boolean correctForDrops) {
@@ -590,11 +590,11 @@ public class MaterialRerouting {
}
public static Collection<Material> getBlocks(ToolComponent.ToolRule toolRule, @InjectPluginVersion ApiVersion version) {
return toolRule.getBlocks().stream().map(val -> transformFromBlockType(val, version)).toList();
return toolRule.getBlocks().stream().map(val -> MaterialRerouting.transformFromBlockType(val, version)).toList();
}
public static void setBlocks(ToolComponent.ToolRule toolRule, Material block) {
toolRule.setBlocks(transformToBlockType(block));
toolRule.setBlocks(MaterialRerouting.transformToBlockType(block));
}
public static void setBlocks(ToolComponent.ToolRule toolRule, Collection<Material> blocks) {

View File

@@ -66,7 +66,7 @@ public class EnumEvil {
ClassTraverser it = new ClassTraverser(clazz);
LegacyRegistryData registryData;
while (it.hasNext()) {
registryData = REGISTRIES.get(it.next());
registryData = EnumEvil.REGISTRIES.get(it.next());
if (registryData != null) {
return registryData;
}
@@ -77,7 +77,7 @@ public class EnumEvil {
@DoNotReroute
public static Registry<?> getRegistry(Class<?> clazz) {
LegacyRegistryData registryData = getRegistryData(clazz);
LegacyRegistryData registryData = EnumEvil.getRegistryData(clazz);
if (registryData != null) {
return registryData.registry();
@@ -144,7 +144,7 @@ public class EnumEvil {
return Enums.getIfPresent(clazz, name);
}
Registry registry = getRegistry(clazz);
Registry registry = EnumEvil.getRegistry(clazz);
if (registry == null) {
return com.google.common.base.Optional.absent();
}
@@ -167,7 +167,7 @@ public class EnumEvil {
return clazz.getEnumConstants();
}
Registry<?> registry = getRegistry(clazz);
Registry<?> registry = EnumEvil.getRegistry(clazz);
if (registry == null) {
return clazz.getEnumConstants();
@@ -207,16 +207,16 @@ public class EnumEvil {
}
public static Optional<Enum.EnumDesc> describeConstable(@RerouteArgumentType("java/lang/Enum") Object object) {
return getDeclaringClass(object)
return EnumEvil.getDeclaringClass(object)
.describeConstable()
.map(c -> Enum.EnumDesc.of(c, name(object)));
.map(c -> Enum.EnumDesc.of(c, EnumEvil.name(object)));
}
@RerouteStatic("java/lang/Enum")
@RerouteReturnType("java/lang/Enum")
public static Object valueOf(Class enumClass, String name, @InjectPluginVersion ApiVersion apiVersion) {
name = FieldRename.rename(apiVersion, enumClass.getName().replace('.', '/'), name);
LegacyRegistryData registryData = getRegistryData(enumClass);
LegacyRegistryData registryData = EnumEvil.getRegistryData(enumClass);
if (registryData != null) {
return registryData.function().apply(name);
}
@@ -252,11 +252,11 @@ public class EnumEvil {
@Override
protected T doForward(String value) {
if (registryData == null) {
registryData = getRegistryData(clazz);
if (this.registryData == null) {
this.registryData = EnumEvil.getRegistryData(this.clazz);
}
value = FieldRename.rename(apiVersion, clazz.getName().replace('.', '/'), value);
return (T) registryData.function().apply(value);
value = FieldRename.rename(this.apiVersion, this.clazz.getName().replace('.', '/'), value);
return (T) this.registryData.function().apply(value);
}
@Override
@@ -274,12 +274,12 @@ public class EnumEvil {
@Override
public int hashCode() {
return clazz.hashCode();
return this.clazz.hashCode();
}
@Override
public String toString() {
return "Enums.stringConverter(" + clazz.getName() + ".class)";
return "Enums.stringConverter(" + this.clazz.getName() + ".class)";
}
private static final long serialVersionUID = 0L;

View File

@@ -20,7 +20,7 @@ public class ImposterEnumMap extends AbstractMap<Object, Object> {
public ImposterEnumMap(Class<?> objectClass) {
this.objectClass = objectClass;
this.map = getMap(objectClass);
this.map = ImposterEnumMap.getMap(objectClass);
}
public ImposterEnumMap(EnumMap enumMap) {
@@ -31,7 +31,7 @@ public class ImposterEnumMap extends AbstractMap<Object, Object> {
public ImposterEnumMap(Map map) {
if (map instanceof ImposterEnumMap) {
this.objectClass = ((ImposterEnumMap) map).objectClass;
this.map = getMap(objectClass);
this.map = ImposterEnumMap.getMap(this.objectClass);
} else {
this.objectClass = DummyEnum.class;
this.map = new TreeMap();
@@ -52,39 +52,39 @@ public class ImposterEnumMap extends AbstractMap<Object, Object> {
@Override
public int size() {
return map.size();
return this.map.size();
}
@Override
public boolean containsValue(Object value) {
return map.containsValue(value);
return this.map.containsValue(value);
}
@Override
public boolean containsKey(Object key) {
return map.containsKey(key);
return this.map.containsKey(key);
}
@Override
public Object get(Object key) {
return map.get(key);
return this.map.get(key);
}
@Override
public Object put(Object key, Object value) {
typeCheck(key);
return map.put(key, value);
this.typeCheck(key);
return this.map.put(key, value);
}
@Override
public Object remove(Object key) {
return map.remove(key);
return this.map.remove(key);
}
@Override
public void putAll(Map<? extends Object, ?> m) {
if (map instanceof EnumMap<?, ?>) {
map.putAll(m);
if (this.map instanceof EnumMap<?, ?>) {
this.map.putAll(m);
}
super.putAll(m);
@@ -92,45 +92,45 @@ public class ImposterEnumMap extends AbstractMap<Object, Object> {
@Override
public void clear() {
map.clear();
this.map.clear();
}
@Override
public Set<Object> keySet() {
return map.keySet();
return this.map.keySet();
}
@Override
public Collection<Object> values() {
return map.values();
return this.map.values();
}
@Override
public Set<Entry<Object, Object>> entrySet() {
return map.entrySet();
return this.map.entrySet();
}
@Override
public boolean equals(Object o) {
return map.equals(o);
return this.map.equals(o);
}
@Override
public int hashCode() {
return map.hashCode();
return this.map.hashCode();
}
@Override
public ImposterEnumMap clone() {
ImposterEnumMap enumMap = new ImposterEnumMap(objectClass);
enumMap.putAll(map);
ImposterEnumMap enumMap = new ImposterEnumMap(this.objectClass);
enumMap.putAll(this.map);
return enumMap;
}
private void typeCheck(Object object) {
if (objectClass != DummyEnum.class) {
if (!objectClass.isAssignableFrom(object.getClass())) {
throw new ClassCastException(object.getClass() + " != " + objectClass);
if (this.objectClass != DummyEnum.class) {
if (!this.objectClass.isAssignableFrom(object.getClass())) {
throw new ClassCastException(object.getClass() + " != " + this.objectClass);
}
}
}

View File

@@ -26,7 +26,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
}
public static ImposterEnumSet noneOf(Class<?> clazz) {
Set set = createSet(clazz);
Set set = ImposterEnumSet.createSet(clazz);
return new ImposterEnumSet(set, clazz);
}
@@ -65,7 +65,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
}
}
Set newSet = createSet(clazz);
Set newSet = ImposterEnumSet.createSet(clazz);
newSet.addAll(set);
return new ImposterEnumSet(newSet, clazz);
@@ -88,7 +88,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
}
}
Set newSet = createSet(clazz);
Set newSet = ImposterEnumSet.createSet(clazz);
newSet.addAll(collection);
return new ImposterEnumSet(newSet, clazz);
@@ -153,14 +153,14 @@ public class ImposterEnumSet extends AbstractSet<Object> {
}
public static ImposterEnumSet of(Object e) {
Set set = createSet(e.getClass());
Set set = ImposterEnumSet.createSet(e.getClass());
set.add(e);
return new ImposterEnumSet(set, e.getClass());
}
public static ImposterEnumSet of(Object e1, Object e2) {
Set set = createSet(e1.getClass());
Set set = ImposterEnumSet.createSet(e1.getClass());
set.add(e1);
set.add(e2);
@@ -168,7 +168,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
}
public static ImposterEnumSet of(Object e1, Object e2, Object e3) {
Set set = createSet(e1.getClass());
Set set = ImposterEnumSet.createSet(e1.getClass());
set.add(e1);
set.add(e2);
set.add(e3);
@@ -178,7 +178,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
public static ImposterEnumSet of(Object e1, Object e2, Object e3, Object e4) {
Set set = createSet(e1.getClass());
Set set = ImposterEnumSet.createSet(e1.getClass());
set.add(e1);
set.add(e2);
set.add(e3);
@@ -189,7 +189,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
public static ImposterEnumSet of(Object e1, Object e2, Object e3, Object e4, Object e5) {
Set set = createSet(e1.getClass());
Set set = ImposterEnumSet.createSet(e1.getClass());
set.add(e1);
set.add(e2);
set.add(e3);
@@ -201,7 +201,7 @@ public class ImposterEnumSet extends AbstractSet<Object> {
public static ImposterEnumSet of(Object e, Object... rest) {
Set set = createSet(e.getClass());
Set set = ImposterEnumSet.createSet(e.getClass());
set.add(e);
Collections.addAll(set, rest);
@@ -239,71 +239,71 @@ public class ImposterEnumSet extends AbstractSet<Object> {
@Override
public Iterator<Object> iterator() {
return set.iterator();
return this.set.iterator();
}
@Override
public int size() {
return set.size();
return this.set.size();
}
@Override
public boolean equals(Object o) {
return set.equals(o);
return this.set.equals(o);
}
@Override
public int hashCode() {
return set.hashCode();
return this.set.hashCode();
}
@Override
public boolean removeAll(Collection<?> c) {
return set.removeAll(c);
return this.set.removeAll(c);
}
@Override
public boolean isEmpty() {
return set.isEmpty();
return this.set.isEmpty();
}
@Override
public boolean contains(Object o) {
return set.contains(o);
return this.set.contains(o);
}
@NotNull
@Override
public Object[] toArray() {
return set.toArray();
return this.set.toArray();
}
@NotNull
@Override
public <T> T[] toArray(@NotNull T[] a) {
return (T[]) set.toArray(a);
return (T[]) this.set.toArray(a);
}
@Override
public boolean add(Object o) {
typeCheck(o);
return set.add(o);
this.typeCheck(o);
return this.set.add(o);
}
@Override
public boolean remove(Object o) {
return set.remove(o);
return this.set.remove(o);
}
@Override
public boolean containsAll(@NotNull Collection<?> c) {
return set.containsAll(c);
return this.set.containsAll(c);
}
@Override
public boolean addAll(@NotNull Collection<?> c) {
if (set instanceof EnumSet<?>) {
set.addAll(c);
if (this.set instanceof EnumSet<?>) {
this.set.addAll(c);
}
return super.addAll(c);
@@ -311,35 +311,35 @@ public class ImposterEnumSet extends AbstractSet<Object> {
@Override
public boolean retainAll(@NotNull Collection<?> c) {
return set.retainAll(c);
return this.set.retainAll(c);
}
@Override
public void clear() {
set.clear();
this.set.clear();
}
@Override
public String toString() {
return set.toString();
return this.set.toString();
}
public ImposterEnumSet clone() {
Set newSet;
if (set instanceof EnumSet<?> enumSet) {
if (this.set instanceof EnumSet<?> enumSet) {
newSet = enumSet.clone();
} else {
newSet = new HashSet();
newSet.addAll(set);
newSet.addAll(this.set);
}
return new ImposterEnumSet(newSet, objectClass);
return new ImposterEnumSet(newSet, this.objectClass);
}
private void typeCheck(Object object) {
if (objectClass != DummyEnum.class) {
if (!objectClass.isAssignableFrom(object.getClass())) {
throw new ClassCastException(object.getClass() + " != " + objectClass);
if (this.objectClass != DummyEnum.class) {
if (!this.objectClass.isAssignableFrom(object.getClass())) {
throw new ClassCastException(object.getClass() + " != " + this.objectClass);
}
}
}

View File

@@ -16,7 +16,7 @@ public record FieldRenameData(RenameData<String> renameData, RenameData<Namespac
}
from = from.toUpperCase(Locale.ROOT);
return renameData.getReplacement(apiVersion, from);
return this.renameData.getReplacement(apiVersion, from);
}
public NamespacedKey getReplacement(NamespacedKey from, ApiVersion apiVersion) {
@@ -24,7 +24,7 @@ public record FieldRenameData(RenameData<String> renameData, RenameData<Namespac
return null;
}
return keyRenameData.getReplacement(apiVersion, from);
return this.keyRenameData.getReplacement(apiVersion, from);
}
public static class Builder {
@@ -58,34 +58,34 @@ public record FieldRenameData(RenameData<String> renameData, RenameData<Namespac
}
public Builder change(String from, String to) {
if (currentVersion != null) {
versionData.computeIfAbsent(currentVersion, d -> new HashMap<>()).put(from.replace('.', '_'), to);
if (this.currentVersion != null) {
this.versionData.computeIfAbsent(this.currentVersion, d -> new HashMap<>()).put(from.replace('.', '_'), to);
} else {
data.put(from.replace('.', '_'), to);
this.data.put(from.replace('.', '_'), to);
}
if (keyRename) {
if (this.keyRename) {
NamespacedKey fromKey = NamespacedKey.minecraft(from.toLowerCase(Locale.ROOT));
NamespacedKey toKey = NamespacedKey.minecraft(to.toLowerCase(Locale.ROOT));
if (currentVersion != null) {
versionKeyData.computeIfAbsent(currentVersion, d -> new HashMap<>()).put(fromKey, toKey);
if (this.currentVersion != null) {
this.versionKeyData.computeIfAbsent(this.currentVersion, d -> new HashMap<>()).put(fromKey, toKey);
} else {
keyData.put(fromKey, toKey);
this.keyData.put(fromKey, toKey);
}
}
return this;
}
public FieldRenameData build() {
return new FieldRenameData(new RenameData<>(versionData, data), new RenameData<>(versionKeyData, keyData));
return new FieldRenameData(new RenameData<>(this.versionData, this.data), new RenameData<>(this.versionKeyData, this.keyData));
}
}
private record RenameData<T>(NavigableMap<ApiVersion, Map<T, T>> versionData, Map<T, T> data) {
public T getReplacement(ApiVersion apiVersion, T from) {
from = data.getOrDefault(from, from);
from = this.data.getOrDefault(from, from);
for (Map.Entry<ApiVersion, Map<T, T>> entry : versionData.entrySet()) {
for (Map.Entry<ApiVersion, Map<T, T>> entry : this.versionData.entrySet()) {
if (apiVersion.isNewerThanOrSameAs(entry.getKey())) {
continue;
}

View File

@@ -33,11 +33,11 @@ public record RequirePluginVersionData(ApiVersion minInclusive, ApiVersion maxIn
}
public boolean test(ApiVersion pluginVersion) {
if (minInclusive != null && pluginVersion.isOlderThan(minInclusive)) {
if (this.minInclusive != null && pluginVersion.isOlderThan(this.minInclusive)) {
return false;
}
if (maxInclusive != null && pluginVersion.isNewerThan(maxInclusive)) {
if (this.maxInclusive != null && pluginVersion.isNewerThan(this.maxInclusive)) {
return false;
}

View File

@@ -45,7 +45,7 @@ public class Reroute {
(Although some load time testing could be done)
*/
public boolean apply(ApiVersion pluginVersion, String owner, String name, String desc, boolean staticCall, Consumer<RerouteMethodData> consumer) {
RerouteDataHolder rerouteData = rerouteDataMap.get(desc + name);
RerouteDataHolder rerouteData = this.rerouteDataMap.get(desc + name);
if (rerouteData == null) {
return false;
}
@@ -100,21 +100,21 @@ public class Reroute {
final Map<String, RerouteMethodData> rerouteMethodDataMap = new HashMap<>();
public RerouteMethodData get(Class<?> clazz) {
return rerouteMethodDataMap.get(Type.getInternalName(clazz));
return this.rerouteMethodDataMap.get(Type.getInternalName(clazz));
}
private RerouteMethodData get(Type owner) {
return rerouteMethodDataMap.get(owner.getInternalName());
return this.rerouteMethodDataMap.get(owner.getInternalName());
}
void add(RerouteMethodData value) {
RerouteMethodData rerouteMethodData = get(value.sourceOwner());
RerouteMethodData rerouteMethodData = this.get(value.sourceOwner());
if (rerouteMethodData != null) {
throw new IllegalStateException("Reroute method data already exists: " + rerouteMethodData);
}
rerouteMethodDataMap.put(value.sourceOwner().getInternalName(), value);
this.rerouteMethodDataMap.put(value.sourceOwner().getInternalName(), value);
}
}
}

View File

@@ -31,10 +31,10 @@ public record RerouteArgument(Type type, Type sourceType, boolean injectPluginNa
* @return the opcode of the type
*/
public int instruction() {
if (injectPluginName() || injectPluginVersion() || injectCompatibility() != null) {
if (this.injectPluginName() || this.injectPluginVersion() || this.injectCompatibility() != null) {
throw new IllegalStateException(String.format("Cannot get instruction for plugin name / version argument / compatibility: %s", this));
}
return type.getOpcode(Opcodes.ILOAD);
return this.type.getOpcode(Opcodes.ILOAD);
}
}

View File

@@ -27,15 +27,15 @@ public class RerouteBuilder {
}
public RerouteBuilder forClass(Class<?> clazz) {
classes.add(clazz);
this.classes.add(clazz);
return this;
}
public Reroute build() {
Map<String, Reroute.RerouteDataHolder> rerouteDataHolderMap = new HashMap<>();
for (Class<?> clazz : classes) {
List<RerouteMethodData> data = buildFromClass(clazz, compatibilityPresent);
for (Class<?> clazz : this.classes) {
List<RerouteMethodData> data = RerouteBuilder.buildFromClass(clazz, this.compatibilityPresent);
data.forEach(value -> rerouteDataHolderMap.computeIfAbsent(value.methodKey(), v -> new Reroute.RerouteDataHolder()).add(value));
}
@@ -46,18 +46,18 @@ public class RerouteBuilder {
Preconditions.checkArgument(!clazz.isInterface(), "Interface Classes are currently not supported");
List<RerouteMethodData> result = new ArrayList<>();
boolean shouldInclude = shouldInclude(getRequireCompatibility(clazz), true, compatibilityPresent);
boolean shouldInclude = RerouteBuilder.shouldInclude(RerouteBuilder.getRequireCompatibility(clazz), true, compatibilityPresent);
for (Method method : clazz.getDeclaredMethods()) {
if (!isMethodValid(method)) {
if (!RerouteBuilder.isMethodValid(method)) {
continue;
}
if (!shouldInclude(getRequireCompatibility(method), shouldInclude, compatibilityPresent)) {
if (!RerouteBuilder.shouldInclude(RerouteBuilder.getRequireCompatibility(method), shouldInclude, compatibilityPresent)) {
continue;
}
result.add(buildFromMethod(method));
result.add(RerouteBuilder.buildFromMethod(method));
}
return result;

View File

@@ -27,6 +27,6 @@ public record RerouteReturn(Type type) {
* @return the opcode of the type
*/
public int instruction() {
return type.getOpcode(Opcodes.IRETURN);
return this.type.getOpcode(Opcodes.IRETURN);
}
}