From 75ee2c969755417bd853d4704cd0cf905a8408aa Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 19 Sep 2018 10:16:42 +0200 Subject: [PATCH] Remove entity handling --- .../inventory/ContainerOfHolding.java | 11 ----- .../inventory/InventoryOfHolding.java | 44 ++----------------- .../unicopia/inventory/gui/GuiOfHolding.java | 20 --------- .../unicopia/item/ItemOfHolding.java | 4 -- 4 files changed, 4 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java b/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java index 5836dfd3..1602fda0 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java @@ -1,8 +1,5 @@ package com.minelittlepony.unicopia.inventory; -import java.util.List; - -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; @@ -10,18 +7,14 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; public class ContainerOfHolding extends Container { private final InventoryOfHolding inventory; - private final World world; - private ItemStack sourceStack; public ContainerOfHolding(EntityPlayer player) { - world = player.world; sourceStack = player.getHeldItem(EnumHand.MAIN_HAND); inventory = InventoryOfHolding.getInventoryFromStack(sourceStack); @@ -61,10 +54,6 @@ public class ContainerOfHolding extends Container { return true; } - public List getEntities() { - return inventory.getEntities(world); - } - public ITextComponent getDisplayName() { return inventory.getDisplayName(); } diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java b/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java index 49390aba..6dfeb537 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java @@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.inventory; import java.util.ArrayList; import java.util.List; import java.util.function.BiFunction; -import java.util.function.Consumer; import com.minelittlepony.unicopia.InbtSerialisable; import com.minelittlepony.unicopia.advancements.UAdvancements; @@ -13,9 +12,6 @@ import com.minelittlepony.util.MagicalDamageSource; import net.minecraft.block.Block; import net.minecraft.block.BlockEnderChest; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.gui.advancements.AdvancementState; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -37,34 +33,22 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab public static final int NBT_COMPOUND = 10; public static final int MIN_SIZE = 18; - List entities; - - private boolean entitiesLoaded = false; - - List livingEntities = new ArrayList<>(); - static InventoryOfHolding empty() { - List items = new ArrayList<>(); - List entities = new ArrayList<>(); - - return new InventoryOfHolding(items, entities); + return new InventoryOfHolding(new ArrayList<>()); } public static InventoryOfHolding getInventoryFromStack(ItemStack stack) { List items = new ArrayList<>(); - List entities = new ArrayList<>(); iterateContents(stack, (i, item) -> { items.add(item); return true; - }, tag -> { - entities.add((NBTTagCompound)tag); }); - return new InventoryOfHolding(items, entities); + return new InventoryOfHolding(items); } - public static void iterateContents(ItemStack stack, BiFunction itemConsumer, Consumer entityConsumer) { + public static void iterateContents(ItemStack stack, BiFunction itemConsumer) { if (stack.hasTagCompound() && stack.getTagCompound().hasKey("inventory")) { NBTTagCompound compound = stack.getOrCreateSubCompound("inventory"); @@ -82,20 +66,14 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab } } - private InventoryOfHolding(List items, List entities) { + private InventoryOfHolding(List items) { super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9)); - this.entities = entities; - for (int i = 0; i < items.size(); i++) { setInventorySlotContents(i, items.get(i)); } } - public List getEntities(World world) { - return livingEntities; - } - public void addBlockEntity(World world, BlockPos pos, IBlockState state, T blockInventory) { ItemStack blockStack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); @@ -119,20 +97,6 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab world.playSound(null, pos, SoundEvents.UI_TOAST_IN, SoundCategory.PLAYERS, 3.5F, 0.25F); } - public void addPrisoner(EntityLiving entity) { - getEntities(entity.world).add(entity); - - NBTTagCompound compound = new NBTTagCompound(); - compound.setString("id", EntityList.getKey(entity).toString()); - entity.writeToNBT(compound); - entities.add(compound); - - entity.setDead(); - - entity.playLivingSound(); - entity.playSound(SoundEvents.UI_TOAST_IN, 3.5F, 0.25F); - } - public void addItem(EntityItem entity) { addItem(entity.getItem()); entity.setDead(); diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java b/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java index dc2b7e57..d3a37804 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java @@ -6,9 +6,7 @@ import com.minelittlepony.unicopia.inventory.ContainerOfHolding; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.EntityLiving; import net.minecraft.init.SoundEvents; import net.minecraft.util.ResourceLocation; import net.minecraft.world.IInteractionObject; @@ -88,13 +86,9 @@ public class GuiOfHolding extends GuiContainer { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - ContainerOfHolding coh = (ContainerOfHolding)inventorySlots; fontRenderer.drawString(coh.getDisplayName().getUnformattedText(), 8, 6, 4210752); - - - } @Override @@ -111,19 +105,5 @@ public class GuiOfHolding extends GuiContainer { drawTexturedModalRect(midX, midY + (18 * (i + 1)), 0, 18, xSize, 18); } drawTexturedModalRect(midX, midY + inventoryRows * 18 + 17, 0, 193, xSize, 30); - - ContainerOfHolding coh = (ContainerOfHolding)inventorySlots; - - int left = (width - xSize) / 2; - int top = (height - ySize) / 2; - - int i = 0; - for (EntityLiving entity : coh.getEntities()) { - int x = i % 9; - int y = i / 9; - GuiInventory.drawEntityOnScreen(left + x * 18, top + y * 30, 18, xSize - mouseX, guiTop + 30 - mouseY, entity); - - i++; - } } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java index b45a0f95..c7f888b0 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java @@ -60,10 +60,6 @@ public class ItemOfHolding extends Item implements IMagicalItem { counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount()); return true; - }, tag -> { - String name = tag.getString("id"); - - counts.put(name, counts.getOrDefault(name, 0) + 1); }); for (String name : counts.keySet()) {