#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

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