#1325: Use CraftBlockType and CraftItemType instead of CraftMagicNumbers to convert between minecraft and bukkit block / item representation

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-12-29 08:36:38 +11:00
parent b245f22351
commit d15575db91
32 changed files with 137 additions and 102 deletions

View file

@ -29,8 +29,8 @@
+import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftItemType;
+import org.bukkit.craftbukkit.util.CraftChatMessage; +import org.bukkit.craftbukkit.util.CraftChatMessage;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.craftbukkit.util.LazyPlayerSet; +import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.craftbukkit.util.Waitable; +import org.bukkit.craftbukkit.util.Waitable;
@ -1462,7 +1462,7 @@
+ ItemStack cursor = this.player.containerMenu.getCarried(); + ItemStack cursor = this.player.containerMenu.getCarried();
+ action = InventoryAction.NOTHING; + action = InventoryAction.NOTHING;
+ // Quick check for if we have any of the item + // 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; + action = InventoryAction.COLLECT_TO_CURSOR;
+ } + }
+ } + }

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/entity/TileEntityFurnace.java --- a/net/minecraft/world/level/block/entity/TileEntityFurnace.java
+++ b/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.level.block.state.IBlockData;
import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.Vec3D;
@ -8,6 +8,7 @@
+import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.inventory.CraftItemType;
+import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player; +import org.bukkit.entity.Player;
+import org.bukkit.event.block.BlockExpEvent; +import org.bukkit.event.block.BlockExpEvent;
@ -21,7 +22,7 @@
public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput { public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput {
protected static final int SLOT_INPUT = 0; protected static final int SLOT_INPUT = 0;
@@ -115,7 +129,7 @@ @@ -115,7 +130,7 @@
} }
}; };
this.recipesUsed = new Object2IntOpenHashMap(); this.recipesUsed = new Object2IntOpenHashMap();
@ -30,7 +31,7 @@
} }
public static Map<Item, Integer> getFuel() { public static Map<Item, Integer> getFuel() {
@@ -183,6 +197,40 @@ @@ -183,6 +198,40 @@
return map; return map;
} }
@ -71,7 +72,7 @@
private static boolean isNeverAFurnaceFuel(Item item) { private static boolean isNeverAFurnaceFuel(Item item) {
return item.builtInRegistryHolder().is(TagsItem.NON_FLAMMABLE_WOOD); return item.builtInRegistryHolder().is(TagsItem.NON_FLAMMABLE_WOOD);
} }
@@ -271,7 +319,7 @@ @@ -271,7 +320,7 @@
RecipeHolder recipeholder; RecipeHolder recipeholder;
if (flag2) { if (flag2) {
@ -80,7 +81,7 @@
} else { } else {
recipeholder = null; recipeholder = null;
} }
@@ -279,9 +327,20 @@ @@ -279,9 +328,20 @@
int i = tileentityfurnace.getMaxStackSize(); int i = tileentityfurnace.getMaxStackSize();
if (!tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { if (!tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) {
@ -103,7 +104,7 @@
flag1 = true; flag1 = true;
if (flag3) { if (flag3) {
Item item = itemstack.getItem(); Item item = itemstack.getItem();
@@ -297,11 +356,23 @@ @@ -297,11 +357,23 @@
} }
if (tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { if (tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) {
@ -128,7 +129,7 @@
tileentityfurnace.setRecipeUsed(recipeholder); 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)) { 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)); nonnulllist.set(1, new ItemStack(Items.WATER_BUCKET));
@@ -374,6 +472,7 @@ @@ -374,6 +473,7 @@
} }
private static int getTotalCookTime(World world, TileEntityFurnace tileentityfurnace) { private static int getTotalCookTime(World world, TileEntityFurnace tileentityfurnace) {
@ -182,7 +183,7 @@
return (Integer) tileentityfurnace.quickCheck.getRecipeFor(tileentityfurnace, world).map((recipeholder) -> { return (Integer) tileentityfurnace.quickCheck.getRecipeFor(tileentityfurnace, world).map((recipeholder) -> {
return ((RecipeCooking) recipeholder.value()).getCookingTime(); return ((RecipeCooking) recipeholder.value()).getCookingTime();
}).orElse(200); }).orElse(200);
@@ -495,8 +594,8 @@ @@ -495,8 +595,8 @@
@Override @Override
public void awardUsedRecipes(EntityHuman entityhuman, List<ItemStack> list) {} public void awardUsedRecipes(EntityHuman entityhuman, List<ItemStack> list) {}
@ -193,7 +194,7 @@
entityplayer.awardRecipes(list); entityplayer.awardRecipes(list);
Iterator iterator = list.iterator(); Iterator iterator = list.iterator();
@@ -513,6 +612,12 @@ @@ -513,6 +613,12 @@
} }
public List<RecipeHolder<?>> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) { public List<RecipeHolder<?>> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) {
@ -206,7 +207,7 @@
List<RecipeHolder<?>> list = Lists.newArrayList(); List<RecipeHolder<?>> list = Lists.newArrayList();
ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator(); ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator();
@@ -521,14 +626,14 @@ @@ -521,14 +627,14 @@
worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((recipeholder) -> { worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((recipeholder) -> {
list.add(recipeholder); list.add(recipeholder);
@ -223,14 +224,14 @@
int j = MathHelper.floor((float) i * f); int j = MathHelper.floor((float) i * f);
float f1 = MathHelper.frac((float) i * f); float f1 = MathHelper.frac((float) i * f);
@@ -536,6 +641,17 @@ @@ -536,6 +642,17 @@
++j; ++j;
} }
+ // CraftBukkit start - fire FurnaceExtractEvent / BlockExpEvent + // CraftBukkit start - fire FurnaceExtractEvent / BlockExpEvent
+ BlockExpEvent event; + BlockExpEvent event;
+ if (amount != 0) { + 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 { + } else {
+ event = new BlockExpEvent(CraftBlock.at(worldserver, blockposition), j); + event = new BlockExpEvent(CraftBlock.at(worldserver, blockposition), j);
+ } + }

View file

@ -16,6 +16,7 @@ import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
@ -99,7 +100,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
public Material getBlockType(int x, int y, int z) { public Material getBlockType(int x, int y, int z) {
validateChunkCoordinates(x, y, 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 @Override

View file

@ -8,7 +8,8 @@ import org.bukkit.Color;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; 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; import org.bukkit.potion.Potion;
public class CraftEffect { public class CraftEffect {
@ -26,7 +27,7 @@ public class CraftEffect {
break; break;
case RECORD_PLAY: case RECORD_PLAY:
Preconditions.checkArgument(data == Material.AIR || ((Material) data).isRecord(), "Invalid record type for Material %s!", data); 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; break;
case SMOKE: case SMOKE:
switch ((BlockFace) data) { switch ((BlockFace) data) {
@ -60,7 +61,7 @@ public class CraftEffect {
break; break;
case STEP_SOUND: case STEP_SOUND:
Preconditions.checkArgument(((Material) data).isBlock(), "Material %s is not a block!", data); 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; break;
case COMPOSTER_FILL_ATTEMPT: case COMPOSTER_FILL_ATTEMPT:
datavalue = ((Boolean) data) ? 1 : 0; datavalue = ((Boolean) data) ? 1 : 0;

View file

@ -33,13 +33,13 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftEntityTypes; import org.bukkit.craftbukkit.entity.CraftEntityTypes;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.BlockStateListPopulator; import org.bukkit.craftbukkit.util.BlockStateListPopulator;
import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.RandomSourceWrapper; import org.bukkit.craftbukkit.util.RandomSourceWrapper;
import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.AbstractHorse;
@ -120,7 +120,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
@Override @Override
public Material getType(int x, int y, int z) { 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) { private IBlockData getData(int x, int y, int z) {

View file

@ -15,8 +15,9 @@ import net.minecraft.world.level.block.Block;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.Statistic.Type; import org.bukkit.Statistic.Type;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.entity.CraftEntityType; 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.entity.EntityType;
public enum CraftStatistic { public enum CraftStatistic {
@ -147,22 +148,22 @@ public enum CraftStatistic {
public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) { public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
try { try {
if (stat == Statistic.MINE_BLOCK) { 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) { 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) { 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) { 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) { 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) { if (stat == Statistic.DROP) {
return StatisticList.ITEM_DROPPED.get(CraftMagicNumbers.getItem(material)); return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
} }
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
return null; return null;
@ -192,10 +193,10 @@ public enum CraftStatistic {
public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic<?> statistic) { public static Material getMaterialFromStatistic(net.minecraft.stats.Statistic<?> statistic) {
if (statistic.getValue() instanceof Item statisticItemValue) { if (statistic.getValue() instanceof Item statisticItemValue) {
return CraftMagicNumbers.getMaterial(statisticItemValue); return CraftItemType.minecraftToBukkit(statisticItemValue);
} }
if (statistic.getValue() instanceof Block statisticBlockValue) { if (statistic.getValue() instanceof Block statisticBlockValue) {
return CraftMagicNumbers.getMaterial(statisticBlockValue); return CraftBlockType.minecraftToBukkit(statisticBlockValue);
} }
return null; return null;
} }

View file

@ -95,6 +95,7 @@ import org.bukkit.boss.DragonBattle;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.boss.CraftDragonBattle; import org.bukkit.craftbukkit.boss.CraftDragonBattle;
import org.bukkit.craftbukkit.entity.CraftEntity; 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.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.craftbukkit.util.CraftBiomeSearchResult; import org.bukkit.craftbukkit.util.CraftBiomeSearchResult;
import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.CraftRayTraceResult; import org.bukkit.craftbukkit.util.CraftRayTraceResult;
import org.bukkit.craftbukkit.util.CraftSpawnCategory; 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 != null, "Material cannot be null");
Preconditions.checkArgument(material.isBlock(), "Material.%s must be a block", material); 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(); return (FallingBlock) entity.getBukkitEntity();
} }

View file

@ -221,7 +221,7 @@ public class CraftBlock implements Block {
@Override @Override
public Material getType() { public Material getType() {
return CraftMagicNumbers.getMaterial(world.getBlockState(position).getBlock()); return CraftBlockType.minecraftToBukkit(world.getBlockState(position).getBlock());
} }
@Override @Override

View file

@ -165,13 +165,13 @@ public class CraftBlockState implements BlockState {
Preconditions.checkArgument(type.isBlock(), "Material must be a block!"); Preconditions.checkArgument(type.isBlock(), "Material must be a block!");
if (this.getType() != type) { if (this.getType() != type) {
this.data = CraftMagicNumbers.getBlock(type).defaultBlockState(); this.data = CraftBlockType.bukkitToMinecraft(type).defaultBlockState();
} }
} }
@Override @Override
public Material getType() { public Material getType() {
return CraftMagicNumbers.getMaterial(data.getBlock()); return CraftBlockType.minecraftToBukkit(data.getBlock());
} }
public void setFlag(int flag) { public void setFlag(int flag) {

View file

@ -61,7 +61,6 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
public final class CraftBlockStates { public final class CraftBlockStates {
@ -121,7 +120,7 @@ public final class CraftBlockStates {
// block with unhandled TileEntity: // block with unhandled TileEntity:
return new CraftBlockEntityState<>(world, 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); return new CraftBlockState(world, blockPosition, blockData);
} }
}; };
@ -377,7 +376,7 @@ public final class CraftBlockStates {
BlockStateFactory<?> factory = getFactory(material); BlockStateFactory<?> factory = getFactory(material);
if (factory instanceof BlockEntityStateFactory) { 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; return null;
@ -401,7 +400,7 @@ public final class CraftBlockStates {
public static BlockState getBlockState(BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) { public static BlockState getBlockState(BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) {
Preconditions.checkNotNull(material, "material is null"); Preconditions.checkNotNull(material, "material is null");
IBlockData blockData = CraftMagicNumbers.getBlock(material).defaultBlockState(); IBlockData blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState();
return getBlockState(blockPosition, blockData, blockEntityTag); return getBlockState(blockPosition, blockData, blockEntityTag);
} }
@ -418,7 +417,7 @@ public final class CraftBlockStates {
// See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity) // See BlockStateFactory#createBlockState(World, BlockPosition, IBlockData, TileEntity)
private static CraftBlockState getBlockState(World world, BlockPosition blockPosition, IBlockData blockData, TileEntity 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; BlockStateFactory<?> factory;
// For some types of TileEntity blocks (eg. moving pistons), Minecraft may in some situations (eg. when using Block#setType or the // 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. // setBlock command) not create a corresponding TileEntity in the world. We return a normal BlockState in this case.

View file

@ -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);
}
}

View file

@ -13,7 +13,7 @@ import org.bukkit.Tag;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.DecoratedPot; import org.bukkit.block.DecoratedPot;
import org.bukkit.craftbukkit.inventory.CraftInventoryDecoratedPot; import org.bukkit.craftbukkit.inventory.CraftInventoryDecoratedPot;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.inventory.DecoratedPotInventory; import org.bukkit.inventory.DecoratedPotInventory;
public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEntity> implements DecoratedPot { public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEntity> implements DecoratedPot {
@ -45,7 +45,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
Preconditions.checkArgument(face != null, "face must not be null"); Preconditions.checkArgument(face != null, "face must not be null");
Preconditions.checkArgument(sherd == null || sherd == Material.BRICK || Tag.ITEMS_DECORATED_POT_SHERDS.isTagged(sherd), "sherd is not a valid sherd material: %s", sherd); Preconditions.checkArgument(sherd == null || sherd == Material.BRICK || Tag.ITEMS_DECORATED_POT_SHERDS.isTagged(sherd), "sherd is not a valid sherd material: %s", sherd);
Item sherdItem = (sherd != null) ? CraftMagicNumbers.getItem(sherd) : Items.BRICK; Item sherdItem = (sherd != null) ? CraftItemType.bukkitToMinecraft(sherd) : Items.BRICK;
DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations(); DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations();
switch (face) { switch (face) {
@ -70,7 +70,7 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
default -> throw new IllegalArgumentException("Unexpected value: " + face); default -> throw new IllegalArgumentException("Unexpected value: " + face);
}; };
return CraftMagicNumbers.getMaterial(sherdItem); return CraftItemType.minecraftToBukkit(sherdItem);
} }
@Override @Override
@ -78,16 +78,16 @@ public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEn
DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations(); DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations();
Map<Side, Material> sherds = new EnumMap<>(Side.class); Map<Side, Material> sherds = new EnumMap<>(Side.class);
sherds.put(Side.BACK, CraftMagicNumbers.getMaterial(decorations.back())); sherds.put(Side.BACK, CraftItemType.minecraftToBukkit(decorations.back()));
sherds.put(Side.LEFT, CraftMagicNumbers.getMaterial(decorations.left())); sherds.put(Side.LEFT, CraftItemType.minecraftToBukkit(decorations.left()));
sherds.put(Side.RIGHT, CraftMagicNumbers.getMaterial(decorations.right())); sherds.put(Side.RIGHT, CraftItemType.minecraftToBukkit(decorations.right()));
sherds.put(Side.FRONT, CraftMagicNumbers.getMaterial(decorations.front())); sherds.put(Side.FRONT, CraftItemType.minecraftToBukkit(decorations.front()));
return sherds; return sherds;
} }
@Override @Override
public List<Material> getShards() { public List<Material> getShards() {
return getSnapshot().getDecorations().sorted().map(CraftMagicNumbers::getMaterial).collect(Collectors.toUnmodifiableList()); return getSnapshot().getDecorations().sorted().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList());
} }
@Override @Override

View file

@ -11,7 +11,7 @@ import org.bukkit.block.Jukebox;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftInventoryJukebox; import org.bukkit.craftbukkit.inventory.CraftInventoryJukebox;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.inventory.JukeboxInventory; import org.bukkit.inventory.JukeboxInventory;
public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> implements Jukebox { public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> implements Jukebox {
@ -68,7 +68,7 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
@Override @Override
public void setPlaying(Material record) { public void setPlaying(Material record) {
if (record == null || CraftMagicNumbers.getItem(record) == null) { if (record == null || CraftItemType.bukkitToMinecraft(record) == null) {
record = Material.AIR; record = Material.AIR;
} }
@ -122,7 +122,7 @@ public class CraftJukebox extends CraftBlockEntityState<TileEntityJukeBox> imple
jukebox.isPlaying = true; jukebox.isPlaying = true;
jukebox.recordStartedTick = jukebox.tickCount; 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; return true;
} }

View file

@ -9,7 +9,6 @@ import org.bukkit.DyeColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.ShulkerBox; import org.bukkit.block.ShulkerBox;
import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> implements ShulkerBox { public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> implements ShulkerBox {
@ -38,7 +37,7 @@ public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> impleme
@Override @Override
public DyeColor getColor() { 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()); return (color == null) ? null : DyeColor.getByWoolData((byte) color.getId());
} }

View file

@ -41,9 +41,10 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.CraftBlockStates; import org.bukkit.craftbukkit.block.CraftBlockStates;
import org.bukkit.craftbukkit.block.CraftBlockSupport; import org.bukkit.craftbukkit.block.CraftBlockSupport;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -62,7 +63,7 @@ public class CraftBlockData implements BlockData {
@Override @Override
public Material getMaterial() { public Material getMaterial() {
return CraftMagicNumbers.getMaterial(state.getBlock()); return CraftBlockType.minecraftToBukkit(state.getBlock());
} }
public IBlockData getState() { 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); Preconditions.checkArgument(material == null || material.isBlock(), "Cannot get data for not block %s", material);
IBlockData blockData; IBlockData blockData;
Block block = CraftMagicNumbers.getBlock(material); Block block = CraftBlockType.bukkitToMinecraft(material);
Map<IBlockState<?>, Comparable<?>> parsed = null; Map<IBlockState<?>, Comparable<?>> parsed = null;
// Data provided, use it // Data provided, use it
@ -646,7 +647,7 @@ public class CraftBlockData implements BlockData {
@Override @Override
public Material getPlacementMaterial() { public Material getPlacementMaterial() {
return CraftMagicNumbers.getMaterial(state.getBlock().asItem()); return CraftItemType.minecraftToBukkit(state.getBlock().asItem());
} }
@Override @Override

View file

@ -46,10 +46,10 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryLectern;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.craftbukkit.inventory.CraftMerchantCustom; import org.bukkit.craftbukkit.inventory.CraftMerchantCustom;
import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.HumanEntity; 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 != null, "Material cannot be null");
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); 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 @Override
@ -497,7 +497,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material != null, "Material cannot be null");
Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); 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); 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(material.isItem(), "Material %s is not an item", material);
Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown"); Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown");
getHandle().getCooldowns().addCooldown(CraftMagicNumbers.getItem(material), ticks); getHandle().getCooldowns().addCooldown(CraftItemType.bukkitToMinecraft(material), ticks);
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import net.minecraft.world.item.Item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftInventory; 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.entity.Piglin;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -33,7 +33,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin {
public boolean addBarterMaterial(Material material) { public boolean addBarterMaterial(Material material) {
Preconditions.checkArgument(material != null, "material cannot be null"); Preconditions.checkArgument(material != null, "material cannot be null");
Item item = CraftMagicNumbers.getItem(material); Item item = CraftItemType.bukkitToMinecraft(material);
return getHandle().allowedBarterItems.add(item); return getHandle().allowedBarterItems.add(item);
} }
@ -41,7 +41,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin {
public boolean removeBarterMaterial(Material material) { public boolean removeBarterMaterial(Material material) {
Preconditions.checkArgument(material != null, "material cannot be null"); Preconditions.checkArgument(material != null, "material cannot be null");
Item item = CraftMagicNumbers.getItem(material); Item item = CraftItemType.bukkitToMinecraft(material);
return getHandle().allowedBarterItems.remove(item); return getHandle().allowedBarterItems.remove(item);
} }
@ -49,7 +49,7 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin {
public boolean addMaterialOfInterest(Material material) { public boolean addMaterialOfInterest(Material material) {
Preconditions.checkArgument(material != null, "material cannot be null"); Preconditions.checkArgument(material != null, "material cannot be null");
Item item = CraftMagicNumbers.getItem(material); Item item = CraftItemType.bukkitToMinecraft(material);
return getHandle().interestItems.add(item); return getHandle().interestItems.add(item);
} }
@ -57,18 +57,18 @@ public class CraftPiglin extends CraftPiglinAbstract implements Piglin {
public boolean removeMaterialOfInterest(Material material) { public boolean removeMaterialOfInterest(Material material) {
Preconditions.checkArgument(material != null, "material cannot be null"); Preconditions.checkArgument(material != null, "material cannot be null");
Item item = CraftMagicNumbers.getItem(material); Item item = CraftItemType.bukkitToMinecraft(material);
return getHandle().interestItems.remove(item); return getHandle().interestItems.remove(item);
} }
@Override @Override
public Set<Material> getInterestList() { public Set<Material> 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 @Override
public Set<Material> getBarterList() { public Set<Material> 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 @Override

View file

@ -102,9 +102,9 @@ import org.bukkit.craftbukkit.entity.CraftRaider;
import org.bukkit.craftbukkit.entity.CraftSpellcaster; import org.bukkit.craftbukkit.entity.CraftSpellcaster;
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.craftbukkit.inventory.CraftMetaBook; import org.bukkit.craftbukkit.inventory.CraftMetaBook;
import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.CraftVector; import org.bukkit.craftbukkit.util.CraftVector;
import org.bukkit.entity.AbstractHorse; 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) { 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(); Player player = (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item); CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem()); Material bucket = CraftItemType.minecraftToBukkit(itemstack.getItem());
CraftServer craftServer = (CraftServer) player.getServer(); CraftServer craftServer = (CraftServer) player.getServer();

View file

@ -13,6 +13,7 @@ import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
@ -95,7 +96,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
@Override @Override
public Material getType(int x, int y, int z) { 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 @Override

View file

@ -11,6 +11,7 @@ import net.minecraft.world.level.chunk.ChunkSection;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
@ -82,7 +83,7 @@ public final class OldCraftChunkData implements ChunkGenerator.ChunkData {
@Override @Override
public Material getType(int x, int y, int z) { 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 @Override

View file

@ -19,7 +19,6 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.craftbukkit.entity.CraftEntityType;
import org.bukkit.craftbukkit.util.CraftLegacy; import org.bukkit.craftbukkit.util.CraftLegacy;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
@ -465,7 +464,7 @@ public final class CraftItemFactory implements ItemFactory {
return null; return null;
} }
return CraftMagicNumbers.getMaterial(nmsItem); return CraftItemType.minecraftToBukkit(nmsItem);
} }
@Override @Override

View file

@ -58,7 +58,7 @@ public final class CraftItemStack extends ItemStack {
if (original.isEmpty()) { if (original.isEmpty()) {
return new ItemStack(Material.AIR); 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)) { if (hasItemMeta(original)) {
stack.setItemMeta(getItemMeta(original)); stack.setItemMeta(getItemMeta(original));
} }
@ -82,7 +82,7 @@ public final class CraftItemStack extends ItemStack {
} }
public static CraftItemStack asNewCraftStack(Item item, int amount) { 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; net.minecraft.world.item.ItemStack handle;
@ -112,7 +112,7 @@ public final class CraftItemStack extends ItemStack {
@Override @Override
public Material getType() { public Material getType() {
return handle != null ? CraftMagicNumbers.getMaterial(handle.getItem()) : Material.AIR; return handle != null ? CraftItemType.minecraftToBukkit(handle.getItem()) : Material.AIR;
} }
@Override @Override
@ -121,12 +121,12 @@ public final class CraftItemStack extends ItemStack {
return; return;
} else if (type == Material.AIR) { } else if (type == Material.AIR) {
handle = null; handle = null;
} else if (CraftMagicNumbers.getItem(type) == null) { // :( } else if (CraftItemType.bukkitToMinecraft(type) == null) { // :(
handle = null; handle = null;
} else if (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 { } else {
handle.setItem(CraftMagicNumbers.getItem(type)); handle.setItem(CraftItemType.bukkitToMinecraft(type));
if (hasItemMeta()) { if (hasItemMeta()) {
// This will create the appropriate item meta, which will contain all the data we intend to keep // This will create the appropriate item meta, which will contain all the data we intend to keep
setItemMeta(handle, getItemMeta(handle)); setItemMeta(handle, getItemMeta(handle));
@ -600,7 +600,7 @@ public final class CraftItemStack extends ItemStack {
case SUSPICIOUS_GRAVEL: case SUSPICIOUS_GRAVEL:
case CRAFTER: case CRAFTER:
case TRIAL_SPAWNER: 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: case TROPICAL_FISH_BUCKET:
return new CraftMetaTropicalFishBucket(item.getTag()); return new CraftMetaTropicalFishBucket(item.getTag());
case AXOLOTL_BUCKET: case AXOLOTL_BUCKET:
@ -628,7 +628,7 @@ public final class CraftItemStack extends ItemStack {
} }
static Material getType(net.minecraft.world.item.ItemStack item) { 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 @Override
@ -652,7 +652,7 @@ public final class CraftItemStack extends ItemStack {
if (itemMeta == null) return true; if (itemMeta == null) return true;
Item oldItem = item.getItem(); 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) { if (oldItem != newItem) {
item.setItem(newItem); item.setItem(newItem);
} }

View file

@ -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);
}
}

View file

@ -136,7 +136,7 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta {
@Override @Override
public void addChargedProjectile(ItemStack item) { public void addChargedProjectile(ItemStack item) {
Preconditions.checkArgument(item != null, "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) { if (chargedProjectiles == null) {
chargedProjectiles = new ArrayList<>(); chargedProjectiles = new ArrayList<>();

View file

@ -59,6 +59,7 @@ import org.bukkit.craftbukkit.CraftEquipmentSlot;
import org.bukkit.craftbukkit.Overridden; import org.bukkit.craftbukkit.Overridden;
import org.bukkit.craftbukkit.attribute.CraftAttribute; import org.bukkit.craftbukkit.attribute.CraftAttribute;
import org.bukkit.craftbukkit.attribute.CraftAttributeInstance; import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific; import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific;
import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer; import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer;
@ -922,7 +923,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
@Override @Override
public BlockData getBlockData(Material material) { 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); return CraftBlockData.fromData((hasBlockData()) ? ItemBlock.getBlockState(defaultData, blockData) : defaultData);
} }

View file

@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.world.item.crafting.RecipeItemStack; import net.minecraft.world.item.crafting.RecipeItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.RecipeChoice;
@ -55,7 +54,7 @@ public interface CraftRecipe extends Recipe {
List<org.bukkit.Material> choices = new ArrayList<>(list.itemStacks.length); List<org.bukkit.Material> choices = new ArrayList<>(list.itemStacks.length);
for (net.minecraft.world.item.ItemStack i : list.itemStacks) { 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); return new RecipeChoice.MaterialChoice(choices);

View file

@ -11,8 +11,9 @@ import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlockType;
import org.bukkit.craftbukkit.entity.CraftEntityType; 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.entity.EntityType;
import org.bukkit.packs.DataPack; import org.bukkit.packs.DataPack;
import org.bukkit.packs.DataPackManager; import org.bukkit.packs.DataPackManager;
@ -81,9 +82,9 @@ public class CraftDataPackManager implements DataPackManager {
CraftWorld craftWorld = ((CraftWorld) world); CraftWorld craftWorld = ((CraftWorld) world);
if (material.isItem()) { if (material.isItem()) {
return CraftMagicNumbers.getItem(material).isEnabled(craftWorld.getHandle().enabledFeatures()); return CraftItemType.bukkitToMinecraft(material).isEnabled(craftWorld.getHandle().enabledFeatures());
} else if (material.isBlock()) { } else if (material.isBlock()) {
return CraftMagicNumbers.getBlock(material).isEnabled(craftWorld.getHandle().enabledFeatures()); return CraftBlockType.bukkitToMinecraft(material).isEnabled(craftWorld.getHandle().enabledFeatures());
} }
return false; return false;
} }

View file

@ -6,7 +6,7 @@ import net.minecraft.core.IRegistry;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.block.CraftBlockType;
public class CraftBlockTag extends CraftTag<Block, Material> { public class CraftBlockTag extends CraftTag<Block, Material> {
@ -16,7 +16,7 @@ public class CraftBlockTag extends CraftTag<Block, Material> {
@Override @Override
public boolean isTagged(Material item) { 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 // SPIGOT-6952: A Material is not necessary a block, in this case return false
if (block == null) { if (block == null) {
@ -28,6 +28,6 @@ public class CraftBlockTag extends CraftTag<Block, Material> {
@Override @Override
public Set<Material> getValues() { public Set<Material> 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());
} }
} }

View file

@ -6,7 +6,7 @@ import net.minecraft.core.IRegistry;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.inventory.CraftItemType;
public class CraftItemTag extends CraftTag<Item, Material> { public class CraftItemTag extends CraftTag<Item, Material> {
@ -16,7 +16,7 @@ public class CraftItemTag extends CraftTag<Item, Material> {
@Override @Override
public boolean isTagged(Material item) { 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 // SPIGOT-6952: A Material is not necessary an item, in this case return false
if (minecraft == null) { if (minecraft == null) {
@ -28,6 +28,6 @@ public class CraftItemTag extends CraftTag<Item, Material> {
@Override @Override
public Set<Material> getValues() { public Set<Material> 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());
} }
} }

View file

@ -7,7 +7,6 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ITileEntity; import net.minecraft.world.level.block.ITileEntity;
import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.entity.TileEntity;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -16,7 +15,7 @@ public class BlockStateTest extends AbstractTestingBase {
@Test @Test
public void testTileEntityBlockStates() { public void testTileEntityBlockStates() {
for (Block block : BuiltInRegistries.BLOCK) { for (Block block : BuiltInRegistries.BLOCK) {
Material material = CraftMagicNumbers.getMaterial(block); Material material = CraftBlockType.minecraftToBukkit(block);
Class<?> blockStateType = CraftBlockStates.getBlockStateType(material); Class<?> blockStateType = CraftBlockStates.getBlockStateType(material);
boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType); boolean isCraftBlockEntityState = CraftBlockEntityState.class.isAssignableFrom(blockStateType);

View file

@ -31,7 +31,6 @@ import org.bukkit.craftbukkit.inventory.ItemStackTest.BukkitWrapper;
import org.bukkit.craftbukkit.inventory.ItemStackTest.CraftWrapper; import org.bukkit.craftbukkit.inventory.ItemStackTest.CraftWrapper;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider; import org.bukkit.craftbukkit.inventory.ItemStackTest.StackProvider;
import org.bukkit.craftbukkit.inventory.ItemStackTest.StackWrapper; import org.bukkit.craftbukkit.inventory.ItemStackTest.StackWrapper;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Axolotl; import org.bukkit.entity.Axolotl;
import org.bukkit.entity.TropicalFish; import org.bukkit.entity.TropicalFish;
@ -197,7 +196,7 @@ public class ItemMetaTest extends AbstractTestingBase {
public void testSpawnEggsHasMeta() { public void testSpawnEggsHasMeta() {
for (Item item : BuiltInRegistries.ITEM) { for (Item item : BuiltInRegistries.ITEM) {
if (item instanceof net.minecraft.world.item.ItemMonsterEgg) { 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); CraftMetaItem baseMeta = (CraftMetaItem) Bukkit.getItemFactory().getItemMeta(material);
ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance()); ItemMeta baseMetaItem = CraftItemStack.getItemMeta(item.getDefaultInstance());

View file

@ -5,7 +5,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.EnchantmentSlotType; import net.minecraft.world.item.enchantment.EnchantmentSlotType;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -30,7 +30,7 @@ public class EnchantmentTargetTest extends AbstractTestingBase {
assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot); assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot);
for (Item item : BuiltInRegistries.ITEM) { for (Item item : BuiltInRegistries.ITEM) {
Material material = CraftMagicNumbers.getMaterial(item); Material material = CraftItemType.minecraftToBukkit(item);
boolean nms = nmsSlot.canEnchant(item); boolean nms = nmsSlot.canEnchant(item);
boolean bukkit = bukkitTarget.includes(material); boolean bukkit = bukkitTarget.includes(material);