diff --git a/src/main/java/com/minelittlepony/unicopia/Predicates.java b/src/main/java/com/minelittlepony/unicopia/Predicates.java index 46c463d7..e69e0f82 100644 --- a/src/main/java/com/minelittlepony/unicopia/Predicates.java +++ b/src/main/java/com/minelittlepony/unicopia/Predicates.java @@ -16,8 +16,12 @@ public final class Predicates { return player != null && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canCast(); }; + public static final Predicate ITEMS = entity -> { + return entity.isEntityAlive() && entity instanceof EntityItem; + }; + public static final Predicate ITEM_INTERACT_WITH_CLOUDS = item -> { - return item != null && PlayerSpeciesList.instance().getEntity(item).getPlayerSpecies().canInteractWithClouds(); + return ITEMS.test(item) && PlayerSpeciesList.instance().getEntity(item).getPlayerSpecies().canInteractWithClouds(); }; public static final Predicate ENTITY_INTERACT_WITH_CLOUDS = entity -> { diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java b/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java index 1602fda0..f42fd631 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/ContainerOfHolding.java @@ -7,8 +7,9 @@ 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.IWorldNameable; -public class ContainerOfHolding extends Container { +public class ContainerOfHolding extends Container implements IWorldNameable { private final InventoryOfHolding inventory; @@ -54,6 +55,18 @@ public class ContainerOfHolding extends Container { return true; } + + @Override + public String getName() { + return getDisplayName().getUnformattedText(); + } + + @Override + public boolean hasCustomName() { + return inventory.hasCustomName(); + } + + @Override 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 6dfeb537..d55b383b 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/InventoryOfHolding.java @@ -45,7 +45,13 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab return true; }); - return new InventoryOfHolding(items); + InventoryOfHolding result = new InventoryOfHolding(items); + + if (stack.hasDisplayName()) { + result.setCustomName(stack.getDisplayName()); + } + + return result; } public static void iterateContents(ItemStack stack, BiFunction itemConsumer) { @@ -69,12 +75,14 @@ public class InventoryOfHolding extends InventoryBasic implements InbtSerialisab private InventoryOfHolding(List items) { super("unicopia.gui.title.bagofholding", false, items.size() + 9 - (items.size() % 9)); + for (int i = 0; i < items.size(); i++) { setInventorySlotContents(i, items.get(i)); } } - public void addBlockEntity(World world, BlockPos pos, IBlockState state, T blockInventory) { + public void addBlockEntity(World world, BlockPos pos, T blockInventory) { + IBlockState state = world.getBlockState(pos); ItemStack blockStack = new ItemStack(state.getBlock(), 1, state.getBlock().damageDropped(state)); blockInventory.writeToNBT(blockStack.getOrCreateSubCompound("BlockEntityTag")); 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 d3a37804..0e7f0289 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/gui/GuiOfHolding.java @@ -88,7 +88,7 @@ public class GuiOfHolding extends GuiContainer { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { ContainerOfHolding coh = (ContainerOfHolding)inventorySlots; - fontRenderer.drawString(coh.getDisplayName().getUnformattedText(), 8, 6, 4210752); + fontRenderer.drawString(coh.getName(), 8, 6, 0x404040); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java index c7f888b0..2bbb9adb 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java @@ -13,13 +13,11 @@ import com.minelittlepony.unicopia.inventory.InventoryOfHolding; import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; import com.minelittlepony.util.vector.VecHelper; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -36,6 +34,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.IInteractionObject; import net.minecraft.world.World; @@ -83,13 +82,12 @@ public class ItemOfHolding extends Item implements IMagicalItem { if (hit.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos pos = hit.getBlockPos(); - IBlockState state = world.getBlockState(pos); TileEntity tile = world.getTileEntity(pos); if (tile instanceof IInventory) { InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); - inventory.addBlockEntity(world, pos, state, (TileEntity & IInventory)tile); + inventory.addBlockEntity(world, pos, (TileEntity & IInventory)tile); inventory.writeTostack(stack); inventory.closeInventory(player); @@ -98,7 +96,7 @@ public class ItemOfHolding extends Item implements IMagicalItem { AxisAlignedBB box = new AxisAlignedBB(pos.offset(hit.sideHit)).grow(0.5); - List itemsAround = world.getEntitiesInAABBexcluding(player, box, e -> e.isEntityAlive() && e instanceof EntityItem); + List itemsAround = world.getEntitiesInAABBexcluding(player, box, Predicates.ITEMS); if (itemsAround.size() > 0) { InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); @@ -109,40 +107,34 @@ public class ItemOfHolding extends Item implements IMagicalItem { return new ActionResult<>(EnumActionResult.SUCCESS, stack); } - - } else if (hit.typeOfHit == RayTraceResult.Type.ENTITY && hit.entityHit instanceof EntityLiving) { - - /*if (!(hit.entityHit instanceof EntityPlayer)) { - InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); - - inventory.addPrisoner((EntityLiving)hit.entityHit); - inventory.writeTostack(stack); - inventory.closeInventory(player); - - return new ActionResult<>(EnumActionResult.SUCCESS, stack); - }*/ } } - return new ActionResult<>(EnumActionResult.FAIL, stack); - } else { - - IInteractionObject inventory = new Inventory(); - - if (UClient.isClientSide() && player instanceof EntityPlayerSP) { - Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory)); - player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1); - } else { - player.displayGui(inventory); - } - - return new ActionResult<>(EnumActionResult.SUCCESS, stack); } + + IInteractionObject inventory = new Inventory(stack); + + if (UClient.isClientSide() && player instanceof EntityPlayerSP) { + Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory)); + player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1); + } else { + player.displayGui(inventory); + } + + return new ActionResult<>(EnumActionResult.SUCCESS, stack); } public class Inventory implements IInteractionObject { + private String customname = null; + + Inventory(ItemStack stack) { + if (stack.hasDisplayName()) { + customname = stack.getDisplayName(); + } + } + @Override public String getName() { return "unicopi.gui.title.itemofholding"; @@ -150,11 +142,14 @@ public class ItemOfHolding extends Item implements IMagicalItem { @Override public boolean hasCustomName() { - return false; + return customname != null; } @Override public ITextComponent getDisplayName() { + if (hasCustomName()) { + return new TextComponentString(customname); + } return new TextComponentTranslation(getName()); }