diff --git a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch index bf221cce92..d29b727c4e 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch @@ -29,8 +29,8 @@ +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.craftbukkit.inventory.CraftItemType; +import org.bukkit.craftbukkit.util.CraftChatMessage; -+import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.LazyPlayerSet; +import org.bukkit.craftbukkit.util.Waitable; @@ -1462,7 +1462,7 @@ + ItemStack cursor = this.player.containerMenu.getCarried(); + action = InventoryAction.NOTHING; + // Quick check for if we have any of the item -+ if (inventory.getTopInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem())) || inventory.getBottomInventory().contains(CraftMagicNumbers.getMaterial(cursor.getItem()))) { ++ if (inventory.getTopInventory().contains(CraftItemType.minecraftToBukkit(cursor.getItem())) || inventory.getBottomInventory().contains(CraftItemType.minecraftToBukkit(cursor.getItem()))) { + action = InventoryAction.COLLECT_TO_CURSOR; + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch index a23e69cbf8..11ce6efca2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityFurnace.java +++ b/net/minecraft/world/level/block/entity/TileEntityFurnace.java -@@ -47,6 +47,20 @@ +@@ -47,6 +47,21 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -8,6 +8,7 @@ +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.craftbukkit.inventory.CraftItemType; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockExpEvent; @@ -21,7 +22,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput { protected static final int SLOT_INPUT = 0; -@@ -115,7 +129,7 @@ +@@ -115,7 +130,7 @@ } }; this.recipesUsed = new Object2IntOpenHashMap(); @@ -30,7 +31,7 @@ } public static Map getFuel() { -@@ -183,6 +197,40 @@ +@@ -183,6 +198,40 @@ return map; } @@ -71,7 +72,7 @@ private static boolean isNeverAFurnaceFuel(Item item) { return item.builtInRegistryHolder().is(TagsItem.NON_FLAMMABLE_WOOD); } -@@ -271,7 +319,7 @@ +@@ -271,7 +320,7 @@ RecipeHolder recipeholder; if (flag2) { @@ -80,7 +81,7 @@ } else { recipeholder = null; } -@@ -279,9 +327,20 @@ +@@ -279,9 +328,20 @@ int i = tileentityfurnace.getMaxStackSize(); if (!tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { @@ -103,7 +104,7 @@ flag1 = true; if (flag3) { Item item = itemstack.getItem(); -@@ -297,11 +356,23 @@ +@@ -297,11 +357,23 @@ } if (tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { @@ -128,7 +129,7 @@ tileentityfurnace.setRecipeUsed(recipeholder); } -@@ -340,17 +411,44 @@ +@@ -340,17 +412,44 @@ } } @@ -174,7 +175,7 @@ if (itemstack.is(Blocks.WET_SPONGE.asItem()) && !((ItemStack) nonnulllist.get(1)).isEmpty() && ((ItemStack) nonnulllist.get(1)).is(Items.BUCKET)) { nonnulllist.set(1, new ItemStack(Items.WATER_BUCKET)); -@@ -374,6 +472,7 @@ +@@ -374,6 +473,7 @@ } private static int getTotalCookTime(World world, TileEntityFurnace tileentityfurnace) { @@ -182,7 +183,7 @@ return (Integer) tileentityfurnace.quickCheck.getRecipeFor(tileentityfurnace, world).map((recipeholder) -> { return ((RecipeCooking) recipeholder.value()).getCookingTime(); }).orElse(200); -@@ -495,8 +594,8 @@ +@@ -495,8 +595,8 @@ @Override public void awardUsedRecipes(EntityHuman entityhuman, List list) {} @@ -193,7 +194,7 @@ entityplayer.awardRecipes(list); Iterator iterator = list.iterator(); -@@ -513,6 +612,12 @@ +@@ -513,6 +613,12 @@ } public List> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) { @@ -206,7 +207,7 @@ List> list = Lists.newArrayList(); ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator(); -@@ -521,14 +626,14 @@ +@@ -521,14 +627,14 @@ worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((recipeholder) -> { list.add(recipeholder); @@ -223,14 +224,14 @@ int j = MathHelper.floor((float) i * f); float f1 = MathHelper.frac((float) i * f); -@@ -536,6 +641,17 @@ +@@ -536,6 +642,17 @@ ++j; } + // CraftBukkit start - fire FurnaceExtractEvent / BlockExpEvent + BlockExpEvent event; + if (amount != 0) { -+ event = new FurnaceExtractEvent((Player) entityhuman.getBukkitEntity(), CraftBlock.at(worldserver, blockposition), org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(itemstack.getItem()), amount, j); ++ event = new FurnaceExtractEvent((Player) entityhuman.getBukkitEntity(), CraftBlock.at(worldserver, blockposition), CraftItemType.minecraftToBukkit(itemstack.getItem()), amount, j); + } else { + event = new BlockExpEvent(CraftBlock.at(worldserver, blockposition), j); + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java index 05dc2415eb..c8852808f6 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java @@ -16,6 +16,7 @@ import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.block.CraftBiome; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; @@ -99,7 +100,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { public Material getBlockType(int x, int y, int z) { validateChunkCoordinates(x, y, z); - return CraftMagicNumbers.getMaterial(blockids[getSectionIndex(y)].get(x, y & 0xF, z).getBlock()); + return CraftBlockType.minecraftToBukkit(blockids[getSectionIndex(y)].get(x, y & 0xF, z).getBlock()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java index 5a5a8945c7..a451976217 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java @@ -8,7 +8,8 @@ import org.bukkit.Color; import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.block.CraftBlockType; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.potion.Potion; public class CraftEffect { @@ -26,7 +27,7 @@ public class CraftEffect { break; case RECORD_PLAY: Preconditions.checkArgument(data == Material.AIR || ((Material) data).isRecord(), "Invalid record type for Material %s!", data); - datavalue = Item.getId(CraftMagicNumbers.getItem((Material) data)); + datavalue = Item.getId(CraftItemType.bukkitToMinecraft((Material) data)); break; case SMOKE: switch ((BlockFace) data) { @@ -60,7 +61,7 @@ public class CraftEffect { break; case STEP_SOUND: Preconditions.checkArgument(((Material) data).isBlock(), "Material %s is not a block!", data); - datavalue = Block.getId(CraftMagicNumbers.getBlock((Material) data).defaultBlockState()); + datavalue = Block.getId(CraftBlockType.bukkitToMinecraft((Material) data).defaultBlockState()); break; case COMPOSTER_FILL_ATTEMPT: datavalue = ((Boolean) data) ? 1 : 0; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index b5c33a1711..96dce74c3e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -33,13 +33,13 @@ import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntityTypes; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.BlockStateListPopulator; import org.bukkit.craftbukkit.util.CraftLocation; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.RandomSourceWrapper; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractHorse; @@ -120,7 +120,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { @Override public Material getType(int x, int y, int z) { - return CraftMagicNumbers.getMaterial(getData(x, y, z).getBlock()); + return CraftBlockType.minecraftToBukkit(getData(x, y, z).getBlock()); } private IBlockData getData(int x, int y, int z) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java index eb3786ab53..c1f07a9314 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStatistic.java @@ -15,8 +15,9 @@ import net.minecraft.world.level.block.Block; import org.bukkit.Material; import org.bukkit.Statistic; import org.bukkit.Statistic.Type; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.entity.CraftEntityType; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.entity.EntityType; public enum CraftStatistic { @@ -147,22 +148,22 @@ public enum CraftStatistic { public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) { try { if (stat == Statistic.MINE_BLOCK) { - return StatisticList.BLOCK_MINED.get(CraftMagicNumbers.getBlock(material)); + return StatisticList.BLOCK_MINED.get(CraftBlockType.bukkitToMinecraft(material)); } if (stat == Statistic.CRAFT_ITEM) { - return StatisticList.ITEM_CRAFTED.get(CraftMagicNumbers.getItem(material)); + return StatisticList.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material)); } if (stat == Statistic.USE_ITEM) { - return StatisticList.ITEM_USED.get(CraftMagicNumbers.getItem(material)); + return StatisticList.ITEM_USED.get(CraftItemType.bukkitToMinecraft(material)); } if (stat == Statistic.BREAK_ITEM) { - return StatisticList.ITEM_BROKEN.get(CraftMagicNumbers.getItem(material)); + return StatisticList.ITEM_BROKEN.get(CraftItemType.bukkitToMinecraft(material)); } if (stat == Statistic.PICKUP) { - return StatisticList.ITEM_PICKED_UP.get(CraftMagicNumbers.getItem(material)); + return StatisticList.ITEM_PICKED_UP.get(CraftItemType.bukkitToMinecraft(material)); } if (stat == Statistic.DROP) { - return StatisticList.ITEM_DROPPED.get(CraftMagicNumbers.getItem(material)); + return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material)); } } catch (ArrayIndexOutOfBoundsException e) { return null; @@ -192,10 +193,10 @@ public enum CraftStatistic { public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic statistic) { if (statistic.getValue() instanceof Item statisticItemValue) { - return CraftMagicNumbers.getMaterial(statisticItemValue); + return CraftItemType.minecraftToBukkit(statisticItemValue); } if (statistic.getValue() instanceof Block statisticBlockValue) { - return CraftMagicNumbers.getMaterial(statisticBlockValue); + return CraftBlockType.minecraftToBukkit(statisticBlockValue); } return null; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index d936b9c8de..71b8fd19de 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -95,6 +95,7 @@ import org.bukkit.boss.DragonBattle; import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.boss.CraftDragonBattle; import org.bukkit.craftbukkit.entity.CraftEntity; @@ -106,7 +107,6 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry; import org.bukkit.craftbukkit.util.CraftBiomeSearchResult; import org.bukkit.craftbukkit.util.CraftLocation; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftRayTraceResult; import org.bukkit.craftbukkit.util.CraftSpawnCategory; @@ -1180,7 +1180,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material.isBlock(), "Material.%s must be a block", material); - EntityFallingBlock entity = EntityFallingBlock.fall(world, BlockPosition.containing(location.getX(), location.getY(), location.getZ()), CraftMagicNumbers.getBlock(material).defaultBlockState(), SpawnReason.CUSTOM); + EntityFallingBlock entity = EntityFallingBlock.fall(world, BlockPosition.containing(location.getX(), location.getY(), location.getZ()), CraftBlockType.bukkitToMinecraft(material).defaultBlockState(), SpawnReason.CUSTOM); return (FallingBlock) entity.getBukkitEntity(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index de66a9bbbb..fe75a6ea82 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -221,7 +221,7 @@ public class CraftBlock implements Block { @Override public Material getType() { - return CraftMagicNumbers.getMaterial(world.getBlockState(position).getBlock()); + return CraftBlockType.minecraftToBukkit(world.getBlockState(position).getBlock()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index c90878017a..306dbd920d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -165,13 +165,13 @@ public class CraftBlockState implements BlockState { Preconditions.checkArgument(type.isBlock(), "Material must be a block!"); if (this.getType() != type) { - this.data = CraftMagicNumbers.getBlock(type).defaultBlockState(); + this.data = CraftBlockType.bukkitToMinecraft(type).defaultBlockState(); } } @Override public Material getType() { - return CraftMagicNumbers.getMaterial(data.getBlock()); + return CraftBlockType.minecraftToBukkit(data.getBlock()); } public void setFlag(int flag) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java index b34505f44f..3c095da61a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java @@ -61,7 +61,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; public final class CraftBlockStates { @@ -121,7 +120,7 @@ public final class CraftBlockStates { // block with unhandled TileEntity: return new CraftBlockEntityState<>(world, tileEntity); } - Preconditions.checkState(tileEntity == null, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); + Preconditions.checkState(tileEntity == null, "Unexpected BlockState for %s", CraftBlockType.minecraftToBukkit(blockData.getBlock())); return new CraftBlockState(world, blockPosition, blockData); } }; @@ -377,7 +376,7 @@ public final class CraftBlockStates { BlockStateFactory factory = getFactory(material); if (factory instanceof BlockEntityStateFactory) { - return ((BlockEntityStateFactory) factory).createTileEntity(BlockPosition.ZERO, CraftMagicNumbers.getBlock(material).defaultBlockState()); + return ((BlockEntityStateFactory) factory).createTileEntity(BlockPosition.ZERO, CraftBlockType.bukkitToMinecraft(material).defaultBlockState()); } return null; @@ -401,7 +400,7 @@ public final class CraftBlockStates { public static BlockState getBlockState(BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) { Preconditions.checkNotNull(material, "material is null"); - IBlockData blockData = CraftMagicNumbers.getBlock(material).defaultBlockState(); + IBlockData blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState(); return getBlockState(blockPosition, blockData, blockEntityTag); } @@ -418,7 +417,7 @@ public final class CraftBlockStates { // See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity) private static CraftBlockState getBlockState(World world, BlockPosition blockPosition, IBlockData blockData, TileEntity tileEntity) { - Material material = CraftMagicNumbers.getMaterial(blockData.getBlock()); + Material material = CraftBlockType.minecraftToBukkit(blockData.getBlock()); BlockStateFactory factory; // For some types of TileEntity blocks (eg. moving pistons), Minecraft may in some situations (eg. when using Block#setType or the // setBlock command) not create a corresponding TileEntity in the world. We return a normal BlockState in this case. diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java new file mode 100644 index 0000000000..22f8b29e7a --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java @@ -0,0 +1,16 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.world.level.block.Block; +import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; + +public class CraftBlockType { + + public static Material minecraftToBukkit(Block block) { + return CraftMagicNumbers.getMaterial(block); + } + + public static Block bukkitToMinecraft(Material material) { + return CraftMagicNumbers.getBlock(material); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java index 7f5030f5b2..7b2332801c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java @@ -13,7 +13,7 @@ import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.DecoratedPot; import org.bukkit.craftbukkit.inventory.CraftInventoryDecoratedPot; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.inventory.DecoratedPotInventory; public class CraftDecoratedPot extends CraftBlockEntityState implements DecoratedPot { @@ -45,7 +45,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState throw new IllegalArgumentException("Unexpected value: " + face); }; - return CraftMagicNumbers.getMaterial(sherdItem); + return CraftItemType.minecraftToBukkit(sherdItem); } @Override @@ -78,16 +78,16 @@ public class CraftDecoratedPot extends CraftBlockEntityState sherds = new EnumMap<>(Side.class); - sherds.put(Side.BACK, CraftMagicNumbers.getMaterial(decorations.back())); - sherds.put(Side.LEFT, CraftMagicNumbers.getMaterial(decorations.left())); - sherds.put(Side.RIGHT, CraftMagicNumbers.getMaterial(decorations.right())); - sherds.put(Side.FRONT, CraftMagicNumbers.getMaterial(decorations.front())); + sherds.put(Side.BACK, CraftItemType.minecraftToBukkit(decorations.back())); + sherds.put(Side.LEFT, CraftItemType.minecraftToBukkit(decorations.left())); + sherds.put(Side.RIGHT, CraftItemType.minecraftToBukkit(decorations.right())); + sherds.put(Side.FRONT, CraftItemType.minecraftToBukkit(decorations.front())); return sherds; } @Override public List getShards() { - return getSnapshot().getDecorations().sorted().map(CraftMagicNumbers::getMaterial).collect(Collectors.toUnmodifiableList()); + return getSnapshot().getDecorations().sorted().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java index 5278a878f6..3906fa6f2a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJukebox.java @@ -11,7 +11,7 @@ import org.bukkit.block.Jukebox; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventoryJukebox; import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.inventory.JukeboxInventory; public class CraftJukebox extends CraftBlockEntityState implements Jukebox { @@ -68,7 +68,7 @@ public class CraftJukebox extends CraftBlockEntityState imple @Override public void setPlaying(Material record) { - if (record == null || CraftMagicNumbers.getItem(record) == null) { + if (record == null || CraftItemType.bukkitToMinecraft(record) == null) { record = Material.AIR; } @@ -122,7 +122,7 @@ public class CraftJukebox extends CraftBlockEntityState imple jukebox.isPlaying = true; jukebox.recordStartedTick = jukebox.tickCount; - getWorld().playEffect(getLocation(), Effect.RECORD_PLAY, CraftMagicNumbers.getMaterial(record.getItem())); + getWorld().playEffect(getLocation(), Effect.RECORD_PLAY, CraftItemType.minecraftToBukkit(record.getItem())); return true; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java index 3968f76856..04a8c1c79f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftShulkerBox.java @@ -9,7 +9,6 @@ import org.bukkit.DyeColor; import org.bukkit.World; import org.bukkit.block.ShulkerBox; import org.bukkit.craftbukkit.inventory.CraftInventory; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.Inventory; public class CraftShulkerBox extends CraftLootable implements ShulkerBox { @@ -38,7 +37,7 @@ public class CraftShulkerBox extends CraftLootable impleme @Override public DyeColor getColor() { - EnumColor color = ((BlockShulkerBox) CraftMagicNumbers.getBlock(this.getType())).color; + EnumColor color = ((BlockShulkerBox) CraftBlockType.bukkitToMinecraft(this.getType())).color; return (color == null) ? null : DyeColor.getByWoolData((byte) color.getId()); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index b822f1eb17..61b37f516c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -41,9 +41,10 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlockStates; import org.bukkit.craftbukkit.block.CraftBlockSupport; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.craftbukkit.util.CraftLocation; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -62,7 +63,7 @@ public class CraftBlockData implements BlockData { @Override public Material getMaterial() { - return CraftMagicNumbers.getMaterial(state.getBlock()); + return CraftBlockType.minecraftToBukkit(state.getBlock()); } public IBlockData getState() { @@ -542,7 +543,7 @@ public class CraftBlockData implements BlockData { Preconditions.checkArgument(material == null || material.isBlock(), "Cannot get data for not block %s", material); IBlockData blockData; - Block block = CraftMagicNumbers.getBlock(material); + Block block = CraftBlockType.bukkitToMinecraft(material); Map, Comparable> parsed = null; // Data provided, use it @@ -646,7 +647,7 @@ public class CraftBlockData implements BlockData { @Override public Material getPlacementMaterial() { - return CraftMagicNumbers.getMaterial(state.getBlock().asItem()); + return CraftItemType.minecraftToBukkit(state.getBlock().asItem()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index aa9b5d5029..42dcde0572 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -46,10 +46,10 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryLectern; import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.craftbukkit.inventory.CraftMerchantCustom; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftLocation; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Firework; import org.bukkit.entity.HumanEntity; @@ -489,7 +489,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); - return getHandle().getCooldowns().isOnCooldown(CraftMagicNumbers.getItem(material)); + return getHandle().getCooldowns().isOnCooldown(CraftItemType.bukkitToMinecraft(material)); } @Override @@ -497,7 +497,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); - ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(CraftMagicNumbers.getItem(material)); + ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(CraftItemType.bukkitToMinecraft(material)); return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount); } @@ -507,7 +507,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown"); - getHandle().getCooldowns().addCooldown(CraftMagicNumbers.getItem(material), ticks); + getHandle().getCooldowns().addCooldown(CraftItemType.bukkitToMinecraft(material), ticks); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java index 382fbf592f..f7d443de8c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java @@ -9,7 +9,7 @@ import net.minecraft.world.item.Item; import org.bukkit.Material; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.inventory.CraftInventory; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.entity.Piglin; import org.bukkit.inventory.Inventory; @@ -33,7 +33,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin { public boolean addBarterMaterial(Material material) { Preconditions.checkArgument(material != null, "material cannot be null"); - Item item = CraftMagicNumbers.getItem(material); + Item item = CraftItemType.bukkitToMinecraft(material); return getHandle().allowedBarterItems.add(item); } @@ -41,7 +41,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin { public boolean removeBarterMaterial(Material material) { Preconditions.checkArgument(material != null, "material cannot be null"); - Item item = CraftMagicNumbers.getItem(material); + Item item = CraftItemType.bukkitToMinecraft(material); return getHandle().allowedBarterItems.remove(item); } @@ -49,7 +49,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin { public boolean addMaterialOfInterest(Material material) { Preconditions.checkArgument(material != null, "material cannot be null"); - Item item = CraftMagicNumbers.getItem(material); + Item item = CraftItemType.bukkitToMinecraft(material); return getHandle().interestItems.add(item); } @@ -57,18 +57,18 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin { public boolean removeMaterialOfInterest(Material material) { Preconditions.checkArgument(material != null, "material cannot be null"); - Item item = CraftMagicNumbers.getItem(material); + Item item = CraftItemType.bukkitToMinecraft(material); return getHandle().interestItems.remove(item); } @Override public Set getInterestList() { - return Collections.unmodifiableSet(getHandle().interestItems.stream().map(CraftMagicNumbers::getMaterial).collect(Collectors.toSet())); + return Collections.unmodifiableSet(getHandle().interestItems.stream().map(CraftItemType::minecraftToBukkit).collect(Collectors.toSet())); } @Override public Set getBarterList() { - return Collections.unmodifiableSet(getHandle().allowedBarterItems.stream().map(CraftMagicNumbers::getMaterial).collect(Collectors.toSet())); + return Collections.unmodifiableSet(getHandle().allowedBarterItems.stream().map(CraftItemType::minecraftToBukkit).collect(Collectors.toSet())); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index be5b0756b2..c2e73cc702 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -102,9 +102,9 @@ import org.bukkit.craftbukkit.entity.CraftRaider; import org.bukkit.craftbukkit.entity.CraftSpellcaster; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.craftbukkit.inventory.CraftMetaBook; import org.bukkit.craftbukkit.potion.CraftPotionUtil; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftVector; import org.bukkit.entity.AbstractHorse; @@ -492,7 +492,7 @@ public class CraftEventFactory { private static PlayerEvent getPlayerBucketEvent(boolean isFilling, WorldServer world, EntityHuman who, BlockPosition changed, BlockPosition clicked, EnumDirection clickedFace, ItemStack itemstack, net.minecraft.world.item.Item item, EnumHand enumhand) { Player player = (Player) who.getBukkitEntity(); CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item); - Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem()); + Material bucket = CraftItemType.minecraftToBukkit(itemstack.getItem()); CraftServer craftServer = (CraftServer) player.getServer(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index eccd6be0c0..00fe52cf4a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -13,6 +13,7 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.block.CraftBiome; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.generator.ChunkGenerator; @@ -95,7 +96,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { @Override public Material getType(int x, int y, int z) { - return CraftMagicNumbers.getMaterial(getTypeId(x, y, z).getBlock()); + return CraftBlockType.minecraftToBukkit(getTypeId(x, y, z).getBlock()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java index 8662f9e251..0e731719c1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/OldCraftChunkData.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.chunk.ChunkSection; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.generator.ChunkGenerator; @@ -82,7 +83,7 @@ public final class OldCraftChunkData implements ChunkGenerator.ChunkData { @Override public Material getType(int x, int y, int z) { - return CraftMagicNumbers.getMaterial(getTypeId(x, y, z).getBlock()); + return CraftBlockType.minecraftToBukkit(getTypeId(x, y, z).getBlock()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index f7e688d46d..c1d9f917cc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -19,7 +19,6 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.util.CraftLegacy; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemFactory; @@ -465,7 +464,7 @@ public final class CraftItemFactory implements ItemFactory { return null; } - return CraftMagicNumbers.getMaterial(nmsItem); + return CraftItemType.minecraftToBukkit(nmsItem); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index b68b9018d1..c8ef909319 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -58,7 +58,7 @@ public final class CraftItemStack extends ItemStack { if (original.isEmpty()) { return new ItemStack(Material.AIR); } - ItemStack stack = new ItemStack(CraftMagicNumbers.getMaterial(original.getItem()), original.getCount()); + ItemStack stack = new ItemStack(CraftItemType.minecraftToBukkit(original.getItem()), original.getCount()); if (hasItemMeta(original)) { stack.setItemMeta(getItemMeta(original)); } @@ -82,7 +82,7 @@ public final class CraftItemStack extends ItemStack { } public static CraftItemStack asNewCraftStack(Item item, int amount) { - return new CraftItemStack(CraftMagicNumbers.getMaterial(item), amount, (short) 0, null); + return new CraftItemStack(CraftItemType.minecraftToBukkit(item), amount, (short) 0, null); } net.minecraft.world.item.ItemStack handle; @@ -112,7 +112,7 @@ public final class CraftItemStack extends ItemStack { @Override public Material getType() { - return handle != null ? CraftMagicNumbers.getMaterial(handle.getItem()) : Material.AIR; + return handle != null ? CraftItemType.minecraftToBukkit(handle.getItem()) : Material.AIR; } @Override @@ -121,12 +121,12 @@ public final class CraftItemStack extends ItemStack { return; } else if (type == Material.AIR) { handle = null; - } else if (CraftMagicNumbers.getItem(type) == null) { // :( + } else if (CraftItemType.bukkitToMinecraft(type) == null) { // :( handle = null; } else if (handle == null) { - handle = new net.minecraft.world.item.ItemStack(CraftMagicNumbers.getItem(type), 1); + handle = new net.minecraft.world.item.ItemStack(CraftItemType.bukkitToMinecraft(type), 1); } else { - handle.setItem(CraftMagicNumbers.getItem(type)); + handle.setItem(CraftItemType.bukkitToMinecraft(type)); if (hasItemMeta()) { // This will create the appropriate item meta, which will contain all the data we intend to keep setItemMeta(handle, getItemMeta(handle)); @@ -600,7 +600,7 @@ public final class CraftItemStack extends ItemStack { case SUSPICIOUS_GRAVEL: case CRAFTER: case TRIAL_SPAWNER: - return new CraftMetaBlockState(item.getTag(), CraftMagicNumbers.getMaterial(item.getItem())); + return new CraftMetaBlockState(item.getTag(), CraftItemType.minecraftToBukkit(item.getItem())); case TROPICAL_FISH_BUCKET: return new CraftMetaTropicalFishBucket(item.getTag()); case AXOLOTL_BUCKET: @@ -628,7 +628,7 @@ public final class CraftItemStack extends ItemStack { } static Material getType(net.minecraft.world.item.ItemStack item) { - return item == null ? Material.AIR : CraftMagicNumbers.getMaterial(item.getItem()); + return item == null ? Material.AIR : CraftItemType.minecraftToBukkit(item.getItem()); } @Override @@ -652,7 +652,7 @@ public final class CraftItemStack extends ItemStack { if (itemMeta == null) return true; Item oldItem = item.getItem(); - Item newItem = CraftMagicNumbers.getItem(CraftItemFactory.instance().updateMaterial(itemMeta, CraftMagicNumbers.getMaterial(oldItem))); + Item newItem = CraftItemType.bukkitToMinecraft(CraftItemFactory.instance().updateMaterial(itemMeta, CraftItemType.minecraftToBukkit(oldItem))); if (oldItem != newItem) { item.setItem(newItem); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java new file mode 100644 index 0000000000..d2ef2a7218 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java @@ -0,0 +1,16 @@ +package org.bukkit.craftbukkit.inventory; + +import net.minecraft.world.item.Item; +import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; + +public class CraftItemType { + + public static Material minecraftToBukkit(Item item) { + return CraftMagicNumbers.getMaterial(item); + } + + public static Item bukkitToMinecraft(Material material) { + return CraftMagicNumbers.getItem(material); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java index 6ede8b9c0b..4b9e62f652 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java @@ -136,7 +136,7 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { @Override public void addChargedProjectile(ItemStack item) { Preconditions.checkArgument(item != null, "item"); - Preconditions.checkArgument(item.getType() == Material.FIREWORK_ROCKET || CraftMagicNumbers.getItem(item.getType()) instanceof ItemArrow, "Item %s is not an arrow or firework rocket", item); + Preconditions.checkArgument(item.getType() == Material.FIREWORK_ROCKET || CraftItemType.bukkitToMinecraft(item.getType()) instanceof ItemArrow, "Item %s is not an arrow or firework rocket", item); if (chargedProjectiles == null) { chargedProjectiles = new ArrayList<>(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 184b6ed92e..16b17c5a62 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -59,6 +59,7 @@ import org.bukkit.craftbukkit.CraftEquipmentSlot; import org.bukkit.craftbukkit.Overridden; import org.bukkit.craftbukkit.attribute.CraftAttribute; import org.bukkit.craftbukkit.attribute.CraftAttributeInstance; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific; import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer; @@ -922,7 +923,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Override public BlockData getBlockData(Material material) { - IBlockData defaultData = CraftMagicNumbers.getBlock(material).defaultBlockState(); + IBlockData defaultData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState(); return CraftBlockData.fromData((hasBlockData()) ? ItemBlock.getBlockState(defaultData, blockData) : defaultData); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java index 16f3a87706..857a64f631 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java @@ -4,7 +4,6 @@ import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; import net.minecraft.world.item.crafting.RecipeItemStack; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.RecipeChoice; @@ -55,7 +54,7 @@ public interface CraftRecipe extends Recipe { List choices = new ArrayList<>(list.itemStacks.length); for (net.minecraft.world.item.ItemStack i : list.itemStacks) { - choices.add(CraftMagicNumbers.getMaterial(i.getItem())); + choices.add(CraftItemType.minecraftToBukkit(i.getItem())); } return new RecipeChoice.MaterialChoice(choices); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java index bdcdaa0a84..dad32e0987 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPackManager.java @@ -11,8 +11,9 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.entity.CraftEntityType; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.entity.EntityType; import org.bukkit.packs.DataPack; import org.bukkit.packs.DataPackManager; @@ -81,9 +82,9 @@ public class CraftDataPackManager implements DataPackManager { CraftWorld craftWorld = ((CraftWorld) world); if (material.isItem()) { - return CraftMagicNumbers.getItem(material).isEnabled(craftWorld.getHandle().enabledFeatures()); + return CraftItemType.bukkitToMinecraft(material).isEnabled(craftWorld.getHandle().enabledFeatures()); } else if (material.isBlock()) { - return CraftMagicNumbers.getBlock(material).isEnabled(craftWorld.getHandle().enabledFeatures()); + return CraftBlockType.bukkitToMinecraft(material).isEnabled(craftWorld.getHandle().enabledFeatures()); } return false; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java index 2760d0baaf..4a92417e1d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java @@ -6,7 +6,7 @@ import net.minecraft.core.IRegistry; import net.minecraft.tags.TagKey; import net.minecraft.world.level.block.Block; import org.bukkit.Material; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.block.CraftBlockType; public class CraftBlockTag extends CraftTag { @@ -16,7 +16,7 @@ public class CraftBlockTag extends CraftTag { @Override public boolean isTagged(Material item) { - Block block = CraftMagicNumbers.getBlock(item); + Block block = CraftBlockType.bukkitToMinecraft(item); // SPIGOT-6952: A Material is not necessary a block, in this case return false if (block == null) { @@ -28,6 +28,6 @@ public class CraftBlockTag extends CraftTag { @Override public Set getValues() { - return getHandle().stream().map((block) -> CraftMagicNumbers.getMaterial(block.value())).collect(Collectors.toUnmodifiableSet()); + return getHandle().stream().map((block) -> CraftBlockType.minecraftToBukkit(block.value())).collect(Collectors.toUnmodifiableSet()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java index 34252ef74f..cbf2f019a5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java @@ -6,7 +6,7 @@ import net.minecraft.core.IRegistry; import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import org.bukkit.Material; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; public class CraftItemTag extends CraftTag { @@ -16,7 +16,7 @@ public class CraftItemTag extends CraftTag { @Override public boolean isTagged(Material item) { - Item minecraft = CraftMagicNumbers.getItem(item); + Item minecraft = CraftItemType.bukkitToMinecraft(item); // SPIGOT-6952: A Material is not necessary an item, in this case return false if (minecraft == null) { @@ -28,6 +28,6 @@ public class CraftItemTag extends CraftTag { @Override public Set getValues() { - return getHandle().stream().map((item) -> CraftMagicNumbers.getMaterial(item.value())).collect(Collectors.toUnmodifiableSet()); + return getHandle().stream().map((item) -> CraftItemType.minecraftToBukkit(item.value())).collect(Collectors.toUnmodifiableSet()); } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java index 68107d4d26..735fdeb864 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/block/BlockStateTest.java @@ -7,7 +7,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.ITileEntity; import net.minecraft.world.level.block.entity.TileEntity; import org.bukkit.Material; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.support.AbstractTestingBase; import org.junit.jupiter.api.Test; @@ -16,7 +15,7 @@ public class BlockStateTest extends AbstractTestingBase { @Test public void testTileEntityBlockStates() { for (Block block : BuiltInRegistries.BLOCK) { - Material material = CraftMagicNumbers.getMaterial(block); + Material material = CraftBlockType.minecraftToBukkit(block); Class blockStateType = CraftBlockStates.getBlockStateType(material); boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType); diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java index ad44e23ca1..4f7b1999e9 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java @@ -31,7 +31,6 @@ import org.bukkit.craftbukkit.inventory.ItemStackTest.BukkitWrapper; import org.bukkit.craftbukkit.inventory.ItemStackTest.CraftWrapper; import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider; import org.bukkit.craftbukkit.inventory.ItemStackTest.StackWrapper; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Axolotl; import org.bukkit.entity.TropicalFish; @@ -197,7 +196,7 @@ public class ItemMetaTest extends AbstractTestingBase { public void testSpawnEggsHasMeta() { for (Item item : BuiltInRegistries.ITEM) { if (item instanceof net.minecraft.world.item.ItemMonsterEgg) { - Material material = CraftMagicNumbers.getMaterial(item); + Material material = CraftItemType.minecraftToBukkit(item); CraftMetaItem baseMeta = (CraftMetaItem) Bukkit.getItemFactory().getItemMeta(material); ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance()); diff --git a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java index d180cc2b64..a4039be1d0 100644 --- a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java +++ b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java @@ -5,7 +5,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.EnchantmentSlotType; import org.bukkit.Material; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.support.AbstractTestingBase; import org.junit.jupiter.api.Test; @@ -30,7 +30,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase { assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot); for (Item item : BuiltInRegistries.ITEM) { - Material material = CraftMagicNumbers.getMaterial(item); + Material material = CraftItemType.minecraftToBukkit(item); boolean nms = nmsSlot.canEnchant(item); boolean bukkit = bukkitTarget.includes(material);