diff --git a/src/main/java/vazkii/botania/common/core/command/CommandShare.java b/src/main/java/vazkii/botania/common/core/command/CommandShare.java index a7697737c..ff0d3e601 100644 --- a/src/main/java/vazkii/botania/common/core/command/CommandShare.java +++ b/src/main/java/vazkii/botania/common/core/command/CommandShare.java @@ -41,7 +41,7 @@ public class CommandShare extends CommandBase { json = json.replaceAll("%entryname%", I18n.translateToLocal(args[0])); ITextComponent component = ITextComponent.Serializer.jsonToComponent(json); - server.getPlayerList().sendChatMsg(component); + server.getPlayerList().sendMessage(component); } diff --git a/src/main/java/vazkii/botania/common/core/handler/SheddingHandler.java b/src/main/java/vazkii/botania/common/core/handler/SheddingHandler.java index 883995fd2..a68269a13 100644 --- a/src/main/java/vazkii/botania/common/core/handler/SheddingHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/SheddingHandler.java @@ -13,6 +13,7 @@ package vazkii.botania.common.core.handler; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; +import java.util.Objects; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -24,9 +25,12 @@ import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.EntityEntry; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.lexicon.page.PageShedding; +// todo 1.11 made this use registry names, but that's incompatible with the old names, work out migration or use old names instead public final class SheddingHandler { private SheddingHandler() {} @@ -65,7 +69,7 @@ public final class SheddingHandler { int i = 1; for(ShedPattern pattern : patterns) { - PageShedding page = new PageShedding(String.valueOf(i), EntityList.CLASS_TO_NAME.get(pattern.EntityClass), pattern.lexiconSize, pattern.getItemStack()); + PageShedding page = new PageShedding(String.valueOf(i), Objects.toString(EntityList.getKey(pattern.EntityClass)), pattern.lexiconSize, pattern.getItemStack()); LexiconData.shedding.addPage(page); } } @@ -87,9 +91,9 @@ public final class SheddingHandler { defaultNames.add(pattern.getEntityString()); } - for(Entry> entry : EntityList.NAME_TO_CLASS.entrySet()) { - if(EntityLiving.class.isAssignableFrom(entry.getValue())) { - String name = entry.getKey(); + for(Entry entry : ForgeRegistries.ENTITIES.getEntries()) { + if(EntityLiving.class.isAssignableFrom(entry.getValue().getEntityClass())) { + String name = entry.getKey().toString(); if(!defaultNames.contains(name)) loadFromConfig(config, name, null); } @@ -117,7 +121,7 @@ public final class SheddingHandler { lexiconSize = config.get("Shedding", key + ".lexiconDisplaySize", lexiconSize).getInt(); if(itemName != null && Item.REGISTRY.getObject(new ResourceLocation(itemName)) != null && rate != -1) - patterns.add(new ShedPattern(EntityList.NAME_TO_CLASS.get(key), new ItemStack(Item.REGISTRY.getObject(new ResourceLocation(itemName)), 1, metadata), rate, lexiconSize)); + patterns.add(new ShedPattern(EntityList.getClass(new ResourceLocation(key)), new ItemStack(Item.REGISTRY.getObject(new ResourceLocation(itemName)), 1, metadata), rate, lexiconSize)); } private static class ShedPattern { @@ -142,7 +146,7 @@ public final class SheddingHandler { } public String getEntityString() { - return EntityList.CLASS_TO_NAME.get(EntityClass); + return Objects.toString(EntityList.getKey(EntityClass)); } } diff --git a/src/main/java/vazkii/botania/common/core/helper/PlayerHelper.java b/src/main/java/vazkii/botania/common/core/helper/PlayerHelper.java index e7e32f23b..b9c09aec5 100644 --- a/src/main/java/vazkii/botania/common/core/helper/PlayerHelper.java +++ b/src/main/java/vazkii/botania/common/core/helper/PlayerHelper.java @@ -11,13 +11,13 @@ public final class PlayerHelper { // Checks if either of the player's hands has an item. public static boolean hasAnyHeldItem(EntityPlayer player) { - return player.getHeldItemMainhand() != null || player.getHeldItemOffhand() != null; + return !player.getHeldItemMainhand().isEmpty() || !player.getHeldItemOffhand().isEmpty(); } // Checks main hand, then off hand for this item. public static boolean hasHeldItem(EntityPlayer player, Item item) { - return player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == item - || player.getHeldItemOffhand() != null && player.getHeldItemOffhand().getItem() == item; + return !player.getHeldItemMainhand().isEmpty() && player.getHeldItemMainhand().getItem() == item + || !player.getHeldItemOffhand().isEmpty() && player.getHeldItemOffhand().getItem() == item; } // Checks main hand, then off hand for this item class. @@ -27,30 +27,30 @@ public final class PlayerHelper { // Checks main hand, then off hand for this item class. public static boolean hasHeldItemClass(EntityPlayer player, Class template) { - return player.getHeldItemMainhand() != null && template.isAssignableFrom(player.getHeldItemMainhand().getItem().getClass()) - || player.getHeldItemOffhand() != null && template.isAssignableFrom(player.getHeldItemOffhand().getItem().getClass()); + return !player.getHeldItemMainhand().isEmpty() && template.isAssignableFrom(player.getHeldItemMainhand().getItem().getClass()) + || !player.getHeldItemOffhand().isEmpty() && template.isAssignableFrom(player.getHeldItemOffhand().getItem().getClass()); } // Checks main hand, then off hand for this item. Null otherwise. public static ItemStack getFirstHeldItem(EntityPlayer player, Item item) { ItemStack main = player.getHeldItemMainhand(); ItemStack offhand = player.getHeldItemOffhand(); - if(main != null && item == main.getItem()) { + if(!main.isEmpty() && item == main.getItem()) { return main; - } else if(offhand != null && item == offhand.getItem()) { + } else if(!offhand.isEmpty() && item == offhand.getItem()) { return offhand; - } else return null; + } else return ItemStack.EMPTY; } // Checks main hand, then off hand for this item class. Null otherwise. public static ItemStack getFirstHeldItemClass(EntityPlayer player, Class template) { ItemStack main = player.getHeldItemMainhand(); ItemStack offhand = player.getHeldItemOffhand(); - if(main != null && template.isAssignableFrom(main.getItem().getClass())) { + if(!main.isEmpty() && template.isAssignableFrom(main.getItem().getClass())) { return main; - } else if(offhand != null && template.isAssignableFrom(offhand.getItem().getClass())) { + } else if(!offhand.isEmpty() && template.isAssignableFrom(offhand.getItem().getClass())) { return offhand; - } else return null; + } else return ItemStack.EMPTY; } public static ItemStack getAmmo(EntityPlayer player, Predicate ammoFunc) { @@ -75,20 +75,18 @@ public final class PlayerHelper { } } - return null; + return ItemStack.EMPTY; } } public static boolean hasAmmo(EntityPlayer player, Predicate ammoFunc) { - return getAmmo(player, ammoFunc) != null; + return !getAmmo(player, ammoFunc).isEmpty(); } public static void consumeAmmo(EntityPlayer player, Predicate ammoFunc) { ItemStack ammo = getAmmo(player, ammoFunc); - if(ammo != null) { - ammo.stackSize--; - if(ammo.stackSize == 0) - player.inventory.deleteStack(ammo); + if(!ammo.isEmpty()) { + ammo.shrink(1); } } diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/KeepIvyRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/KeepIvyRecipe.java index 64a9860fd..175f2aa30 100644 --- a/src/main/java/vazkii/botania/common/crafting/recipe/KeepIvyRecipe.java +++ b/src/main/java/vazkii/botania/common/crafting/recipe/KeepIvyRecipe.java @@ -31,7 +31,7 @@ public class KeepIvyRecipe implements IRecipe { for(int i = 0; i < var1.getSizeInventory(); i++) { ItemStack stack = var1.getStackInSlot(i); - if(stack != null) { + if(!stack.isEmpty()) { if(stack.getItem() == ModItems.keepIvy) foundIvy = true; else if(!foundItem && !(ItemNBTHelper.detectNBT(stack) && ItemNBTHelper.getBoolean(stack, ItemKeepIvy.TAG_KEEP, false)) && !stack.getItem().hasContainerItem(stack)) @@ -43,19 +43,20 @@ public class KeepIvyRecipe implements IRecipe { return foundIvy && foundItem; } + @Nonnull @Override public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) { - ItemStack item = null; + ItemStack item = ItemStack.EMPTY; for(int i = 0; i < var1.getSizeInventory(); i++) { ItemStack stack = var1.getStackInSlot(i); - if(stack != null && stack.getItem() != ModItems.keepIvy) + if(!stack.isEmpty() && stack.getItem() != ModItems.keepIvy) item = stack; } ItemStack copy = item.copy(); ItemNBTHelper.setBoolean(copy, ItemKeepIvy.TAG_KEEP, true); - copy.stackSize = 1; + copy.setCount(1); return copy; } @@ -64,9 +65,10 @@ public class KeepIvyRecipe implements IRecipe { return 10; } + @Nonnull @Override public ItemStack getRecipeOutput() { - return null; + return ItemStack.EMPTY; } @Nonnull diff --git a/src/main/java/vazkii/botania/common/lexicon/page/PageEntity.java b/src/main/java/vazkii/botania/common/lexicon/page/PageEntity.java index 1c853b3ec..824627a66 100644 --- a/src/main/java/vazkii/botania/common/lexicon/page/PageEntity.java +++ b/src/main/java/vazkii/botania/common/lexicon/page/PageEntity.java @@ -18,8 +18,10 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import vazkii.botania.api.internal.IGuiLexiconEntry; @@ -35,7 +37,7 @@ public class PageEntity extends LexiconPage{ public PageEntity(String unlocalizedName, String entity, int size) { super(unlocalizedName); - Class EntityClass = EntityList.NAME_TO_CLASS.get(entity); + Class EntityClass = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entity)).getEntityClass(); this.size = size; try { entityConstructor = EntityClass.getConstructor(World.class); diff --git a/src/main/java/vazkii/botania/common/lexicon/page/PageMultiblock.java b/src/main/java/vazkii/botania/common/lexicon/page/PageMultiblock.java index 2991eeea3..cbf051d8a 100644 --- a/src/main/java/vazkii/botania/common/lexicon/page/PageMultiblock.java +++ b/src/main/java/vazkii/botania/common/lexicon/page/PageMultiblock.java @@ -105,7 +105,7 @@ public class PageMultiblock extends LexiconPage { List mats = new ArrayList<>(); mats.add(I18n.format("botaniamisc.materialsRequired")); for(ItemStack stack : mb.materials) { - String size = "" + stack.stackSize; + String size = "" + stack.getCount(); if(size.length() < 2) size = "0" + size; mats.add(" " + TextFormatting.AQUA + size + " " + TextFormatting.GRAY + stack.getDisplayName()); diff --git a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java index 91b546ff5..07ca79122 100644 --- a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java +++ b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java @@ -72,7 +72,7 @@ public final class SkyblockWorldEvents { public static void onPlayerInteract(PlayerInteractEvent.RightClickBlock event) { if(WorldTypeSkyblock.isWorldSkyblock(event.getWorld())) { ItemStack equipped = event.getItemStack(); - if(equipped == null && event.getEntityPlayer().isSneaking()) { + if(equipped.isEmpty() && event.getEntityPlayer().isSneaking()) { Block block = event.getWorld().getBlockState(event.getPos()).getBlock(); if(ImmutableSet.of(Blocks.GRASS, Blocks.GRASS_PATH, Blocks.FARMLAND, Blocks.DIRT, ModBlocks.altGrass).contains(block)) { if(event.getWorld().isRemote) @@ -84,14 +84,14 @@ public final class SkyblockWorldEvents { event.getEntityPlayer().dropItem(new ItemStack(ModItems.manaResource, 1, 21), false); } } - } else if(equipped != null && equipped.getItem() == Items.BOWL && !event.getWorld().isRemote) { + } else if(!equipped.isEmpty() && equipped.getItem() == Items.BOWL && !event.getWorld().isRemote) { RayTraceResult RayTraceResult = ToolCommons.raytraceFromEntity(event.getWorld(), event.getEntityPlayer(), true, 4.5F); if(RayTraceResult != null) { if (RayTraceResult.typeOfHit == net.minecraft.util.math.RayTraceResult.Type.BLOCK) { if(event.getWorld().getBlockState(RayTraceResult.getBlockPos()).getMaterial() == Material.WATER) { - --equipped.stackSize; + equipped.shrink(1); - if(equipped.stackSize <= 0) + if(equipped.isEmpty()) event.getEntityPlayer().setHeldItem(event.getHand(), new ItemStack(ModItems.waterBowl)); else event.getEntityPlayer().dropItem(new ItemStack(ModItems.waterBowl), false); }