protected void initHorseChest() { ContainerHorseChest containerhorsechest = this.horseChest; this.horseChest = new ContainerHorseChest("HorseChest", this.func_190686_di()); this.horseChest.setCustomName(this.getName()); if (containerhorsechest != null) { containerhorsechest.removeInventoryChangeListener(this); int i = Math.min(containerhorsechest.getSizeInventory(), this.horseChest.getSizeInventory()); for (int j = 0; j < i; ++j) { ItemStack itemstack = containerhorsechest.getStackInSlot(j); if (!itemstack.func_190926_b()) { this.horseChest.setInventorySlotContents(j, itemstack.copy()); } } } this.horseChest.addInventoryChangeListener(this); this.updateHorseSlots(); }
@SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { GuiScreen gui = event.getGui(); if(gui !=null && gui instanceof GuiScreenHorseInventory){ GuiScreenHorseInventory horseGui = (GuiScreenHorseInventory)gui; EntityHorse horse = (EntityHorse)ReflectionUtils.getPrivateValue(horseGui, GuiScreenHorseInventory.class, ObfuscatedNames.GuiScreenHorseInventory_horseEntity); if(horse !=null && HorseAccessories.hasEnderChest(horse)){ ContainerHorseChest animalchest = new ContainerHorseChest("HorseChest", 2); animalchest.setCustomName(horse.getName()); event.setGui(new GuiHorseEnderChest(CrystalMod.proxy.getClientPlayer().inventory, animalchest, horse)); PacketGuiMessage pkt = new PacketGuiMessage("Gui"); pkt.setOpenGui(GuiHandler.GUI_ID_ENTITY, horse.getEntityId(), 0, 0); CrystalModNetwork.sendToServer(pkt); } } }
public static boolean addEnderChest(AbstractHorse horse){ if(horse == null || !(horse instanceof AbstractChestHorse) || horse.getGrowingAge() != 0 || hasEnderChest(horse)) return false; AbstractChestHorse horseChest = (AbstractChestHorse)horse; if(horseChest.hasChest()){ ContainerHorseChest chest = getHorseChest(horse); if (!horse.world.isRemote && chest != null) { for (int i = 0; i < chest.getSizeInventory(); ++i) { ItemStack itemstack = chest.getStackInSlot(i); if (!itemstack.isEmpty()) { horse.entityDropItem(itemstack, 0.0F); } } } } setHasEnderChest(horse, true); return true; }
protected void initChest() { ContainerHorseChest containerhorsechest = this.chest; this.chest = new ContainerHorseChest("chest", this.getInventorySize()); this.chest.setCustomName(this.getName()); if (containerhorsechest != null) { containerhorsechest.removeInventoryChangeListener(this); int i = Math.min(containerhorsechest.getSizeInventory(), this.chest.getSizeInventory()); for (int j = 0; j < i; ++j) { ItemStack itemstack = containerhorsechest.getStackInSlot(j); if (!itemstack.isEmpty()) { this.chest.setInventorySlotContents(j, itemstack.copy()); } } } this.chest.addInventoryChangeListener(this); this.updateSlots(); this.itemHandler = new net.minecraftforge.items.wrapper.InvWrapper(this.chest); }
/** * Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table, * Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse */ public void handleOpenWindow(SPacketOpenWindow packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); EntityPlayerSP entityplayersp = this.gameController.player; if ("minecraft:container".equals(packetIn.getGuiId())) { entityplayersp.displayGUIChest(new InventoryBasic(packetIn.getWindowTitle(), packetIn.getSlotCount())); entityplayersp.openContainer.windowId = packetIn.getWindowId(); } else if ("minecraft:villager".equals(packetIn.getGuiId())) { entityplayersp.displayVillagerTradeGui(new NpcMerchant(entityplayersp, packetIn.getWindowTitle())); entityplayersp.openContainer.windowId = packetIn.getWindowId(); } else if ("EntityHorse".equals(packetIn.getGuiId())) { Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); if (entity instanceof AbstractHorse) { entityplayersp.openGuiHorseInventory((AbstractHorse)entity, new ContainerHorseChest(packetIn.getWindowTitle(), packetIn.getSlotCount())); entityplayersp.openContainer.windowId = packetIn.getWindowId(); } } else if (!packetIn.hasSlots()) { entityplayersp.displayGui(new LocalBlockIntercommunication(packetIn.getGuiId(), packetIn.getWindowTitle())); entityplayersp.openContainer.windowId = packetIn.getWindowId(); } else { IInventory iinventory = new ContainerLocalMenu(packetIn.getGuiId(), packetIn.getWindowTitle(), packetIn.getSlotCount()); entityplayersp.displayGUIChest(iinventory); entityplayersp.openContainer.windowId = packetIn.getWindowId(); } }
public static ContainerHorseChest getHorseChest(AbstractHorse horse){ try{ Object obj = ReflectionUtils.getPrivateValue(horse, AbstractHorse.class, ObfuscatedNames.AbstractHorse_horseChest); if(obj !=null && obj instanceof ContainerHorseChest){ return (ContainerHorseChest)obj; } } catch(Exception e){ throw new RuntimeException("Error when trying to get the Horses chest check MCP mapping"); } return null; }
/** * Sets up the entity's inventory. */ private void inventoryInit() { ContainerHorseChest inventoryExisting = this.inventory; this.inventory = new ContainerHorseChest("container.wolfarmor.wolf", 7); String customName = this.getCustomNameTag(); if (!customName.isEmpty()) { this.inventory.setCustomName(customName); } if (inventoryExisting != null) { inventoryExisting.removeInventoryChangeListener(this); int numberOfItemsExisting = Math.min(this.inventory.getSizeInventory(), inventoryExisting.getSizeInventory()); for (int slotIndex = 0; slotIndex < numberOfItemsExisting; slotIndex++) { ItemStack stackInSlot = inventoryExisting.getStackInSlot(slotIndex); if (!stackInSlot.isEmpty()) { this.inventory.setInventorySlotContents(slotIndex, stackInSlot.copy()); } } } this.inventory.addInventoryChangeListener(this); this.inventory.markDirty(); }