Remove entity handling

This commit is contained in:
Sollace 2018-09-19 10:16:42 +02:00
parent 61a6a29d14
commit 75ee2c9697
4 changed files with 4 additions and 75 deletions

View file

@ -1,8 +1,5 @@
package com.minelittlepony.unicopia.inventory; package com.minelittlepony.unicopia.inventory;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -10,18 +7,14 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
public class ContainerOfHolding extends Container { public class ContainerOfHolding extends Container {
private final InventoryOfHolding inventory; private final InventoryOfHolding inventory;
private final World world;
private ItemStack sourceStack; private ItemStack sourceStack;
public ContainerOfHolding(EntityPlayer player) { public ContainerOfHolding(EntityPlayer player) {
world = player.world;
sourceStack = player.getHeldItem(EnumHand.MAIN_HAND); sourceStack = player.getHeldItem(EnumHand.MAIN_HAND);
inventory = InventoryOfHolding.getInventoryFromStack(sourceStack); inventory = InventoryOfHolding.getInventoryFromStack(sourceStack);
@ -61,10 +54,6 @@ public class ContainerOfHolding extends Container {
return true; return true;
} }
public List<EntityLiving> getEntities() {
return inventory.getEntities(world);
}
public ITextComponent getDisplayName() { public ITextComponent getDisplayName() {
return inventory.getDisplayName(); return inventory.getDisplayName();
} }

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.inventory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer;
import com.minelittlepony.unicopia.InbtSerialisable; import com.minelittlepony.unicopia.InbtSerialisable;
import com.minelittlepony.unicopia.advancements.UAdvancements; import com.minelittlepony.unicopia.advancements.UAdvancements;
@ -13,9 +12,6 @@ import com.minelittlepony.util.MagicalDamageSource;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockEnderChest; import net.minecraft.block.BlockEnderChest;
import net.minecraft.block.state.IBlockState; 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.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; 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 NBT_COMPOUND = 10;
public static final int MIN_SIZE = 18; public static final int MIN_SIZE = 18;
List<NBTTagCompound> entities;
private boolean entitiesLoaded = false;
List<EntityLiving> livingEntities = new ArrayList<>();
static InventoryOfHolding empty() { static InventoryOfHolding empty() {
List<ItemStack> items = new ArrayList<>(); return new InventoryOfHolding(new ArrayList<>());
List<NBTTagCompound> entities = new ArrayList<>();
return new InventoryOfHolding(items, entities);
} }
public static InventoryOfHolding getInventoryFromStack(ItemStack stack) { public static InventoryOfHolding getInventoryFromStack(ItemStack stack) {
List<ItemStack> items = new ArrayList<>(); List<ItemStack> items = new ArrayList<>();
List<NBTTagCompound> entities = new ArrayList<>();
iterateContents(stack, (i, item) -> { iterateContents(stack, (i, item) -> {
items.add(item); items.add(item);
return true; return true;
}, tag -> {
entities.add((NBTTagCompound)tag);
}); });
return new InventoryOfHolding(items, entities); return new InventoryOfHolding(items);
} }
public static void iterateContents(ItemStack stack, BiFunction<Integer, ItemStack, Boolean> itemConsumer, Consumer<NBTTagCompound> entityConsumer) { public static void iterateContents(ItemStack stack, BiFunction<Integer, ItemStack, Boolean> itemConsumer) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("inventory")) { if (stack.hasTagCompound() && stack.getTagCompound().hasKey("inventory")) {
NBTTagCompound compound = stack.getOrCreateSubCompound("inventory"); NBTTagCompound compound = stack.getOrCreateSubCompound("inventory");
@ -82,20 +66,14 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab
} }
} }
private InventoryOfHolding(List<ItemStack> items, List<NBTTagCompound> entities) { private InventoryOfHolding(List<ItemStack> items) {
super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9)); super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9));
this.entities = entities;
for (int i = 0; i < items.size(); i++) { for (int i = 0; i < items.size(); i++) {
setInventorySlotContents(i, items.get(i)); setInventorySlotContents(i, items.get(i));
} }
} }
public List<EntityLiving> getEntities(World world) {
return livingEntities;
}
public <T extends TileEntity & IInventory> void addBlockEntity(World world, BlockPos pos, IBlockState state, T blockInventory) { public <T extends TileEntity & IInventory> void addBlockEntity(World world, BlockPos pos, IBlockState state, T blockInventory) {
ItemStack blockStack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); 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); 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) { public void addItem(EntityItem entity) {
addItem(entity.getItem()); addItem(entity.getItem());
entity.setDead(); entity.setDead();

View file

@ -6,9 +6,7 @@ import com.minelittlepony.unicopia.inventory.ContainerOfHolding;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IInteractionObject; import net.minecraft.world.IInteractionObject;
@ -88,13 +86,9 @@ public class GuiOfHolding extends GuiContainer {
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
ContainerOfHolding coh = (ContainerOfHolding)inventorySlots; ContainerOfHolding coh = (ContainerOfHolding)inventorySlots;
fontRenderer.drawString(coh.getDisplayName().getUnformattedText(), 8, 6, 4210752); fontRenderer.drawString(coh.getDisplayName().getUnformattedText(), 8, 6, 4210752);
} }
@Override @Override
@ -111,19 +105,5 @@ public class GuiOfHolding extends GuiContainer {
drawTexturedModalRect(midX, midY + (18 * (i + 1)), 0, 18, xSize, 18); drawTexturedModalRect(midX, midY + (18 * (i + 1)), 0, 18, xSize, 18);
} }
drawTexturedModalRect(midX, midY + inventoryRows * 18 + 17, 0, 193, xSize, 30); 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++;
}
} }
} }

View file

@ -60,10 +60,6 @@ public class ItemOfHolding extends Item implements IMagicalItem {
counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount()); counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount());
return true; return true;
}, tag -> {
String name = tag.getString("id");
counts.put(name, counts.getOrDefault(name, 0) + 1);
}); });
for (String name : counts.keySet()) { for (String name : counts.keySet()) {