@Override public Container createContainer(InventoryPlayer playerInventory, EntityPlayer entityPlayer) { ContainerWorkbench container = new ContainerWorkbench(playerInventory, this.world, this.position); for(int i = 0; i < used.length; i++) { if(used[i] == null) continue; ItemStack playerStack = entityPlayer.inventory.mainInventory.get(used[i]); if(playerStack != null && playerStack.getCount() > 0) { ItemStack stackUsed = playerStack.copy(); stackUsed.setCount(1); playerStack.setCount(playerStack.getCount() - 1); if(playerStack.getCount() == 0) { entityPlayer.inventory.mainInventory.remove(used[i]); } container.craftMatrix.setInventorySlotContents(i, stackUsed); } } return container; }
public void displayGUIWorkbench(int p_71058_1_, int p_71058_2_, int p_71058_3_) { // CraftBukkit start - Inventory open hook Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerWorkbench(this.inventory, this.worldObj, p_71058_1_, p_71058_2_, p_71058_3_)); if (container == null) { return; } // CraftBukkit end this.getNextWindowId(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); this.openContainer = container; // CraftBukkit - Use container we passed to event this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); }
public static ItemStack getGridItem(int nr) { GuiContainer menu = (GuiContainer)getMenu(); Container slots = menu.inventorySlots; if (menu instanceof GuiCrafting) { return ((ContainerWorkbench)slots).craftMatrix.getStackInSlot(nr); } else if (menu instanceof GuiInventory) { return ((ContainerPlayer)slots).craftMatrix.getStackInSlot(nr); } return null; }
private void createItem(EntitySheep entity, World worldObj) { final ContainerWorkbench container = new ContainerWorkbench(new InventoryPlayer(null), worldObj, entity.getPosition()); for (int i = 0; i < 9; ++i) { container.craftMatrix.setInventorySlotContents(i, itemsConsumed[i]); } final CraftingManager instance = CraftingManager.getInstance(); final ItemStack craftedItem = instance.findMatchingRecipe(container.craftMatrix, worldObj); if (craftedItem != null) { EntityItem entityItem = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, craftedItem); worldObj.spawnEntityInWorld(entityItem); entityItem.rotationYaw = entity.renderYawOffset + 180; entityItem.moveRelative(0, 0.3f, 1); final ItemStack[] remainingItems = instance.getRemainingItems(container.craftMatrix, worldObj); for (final ItemStack remainingItem : remainingItems) { if (remainingItem == null) continue; entityItem = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, remainingItem); worldObj.spawnEntityInWorld(entityItem); entityItem.rotationYaw = entity.renderYawOffset + 180; entityItem.moveRelative(0, 0.3f, 1); } } System.arraycopy(originalCraftingGrid, 0, itemsToCollect, 0, 9); itemsConsumed = new ItemStack[9]; updateItemsConsumed(); }
/** * Simulates an inventory with the given inputs as * @param inputs The inputs * @param width The width of the inventory to simulate * @param height The height of the inventory to simulate * @return The crafting inventory */ public static InventoryCrafting simulateInventoryOf(ItemStack[] inputs, int width, int height) { if(inputs == null) return null; // Make a container... Container c = new ContainerWorkbench(new InventoryPlayer(null), null, BlockPos.ORIGIN); // Figure out our sizes: if(width <= 0 && height <= 0) { width = height = inputs.length > 4 ? 3 : 2; } if(width <= 0) { width = (int)Math.ceil((double)inputs.length / height); } if(height <= 0) { height = (int)Math.ceil((double)inputs.length / width); } InventoryCrafting inv = new InventoryCrafting(c, width, height); for (int i = 0; i < inputs.length; i++) { inv.setInventorySlotContents(i, inputs[i]); } // And pretend we're crafting: return inv; }
/** * Displays the crafting GUI for a workbench. */ public void displayGUIWorkbench(int par1, int par2, int par3) { this.getNextWindowId(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); this.openContainer = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3); this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); }
@Override public void executeClient(EntityPlayer player) { if(player.openContainer instanceof ContainerWorkbench) { EventHandler.index = index; ((ContainerWorkbench)player.openContainer).craftResult.setInventorySlotContents(0, stack); } }
@Override public void executeServer(EntityPlayer player) { if(player.openContainer instanceof ContainerWorkbench) { ((ContainerWorkbench)player.openContainer).craftResult.setInventorySlotContents(0, stack); PacketHandler.sendPacketToPlayer(new CraftResultPacket(index, stack), (EntityPlayerMP) player); } }
public void displayGUIWorkbench(int p_71058_1_, int p_71058_2_, int p_71058_3_) { this.getNextWindowId(); this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); this.openContainer = new ContainerWorkbench(this.inventory, this.worldObj, p_71058_1_, p_71058_2_, p_71058_3_); this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); }
public void func_71058_b(int p_71058_1_, int p_71058_2_, int p_71058_3_) { this.func_71117_bO(); this.field_71135_a.func_72567_b(new Packet100OpenWindow(this.field_71139_cq, 1, "Crafting", 9, true)); this.field_71070_bA = new ContainerWorkbench(this.field_71071_by, this.field_70170_p, p_71058_1_, p_71058_2_, p_71058_3_); this.field_71070_bA.field_75152_c = this.field_71139_cq; this.field_71070_bA.func_75132_a(this); }
/** * Displays the crafting GUI for a workbench. */ public void displayGUIWorkbench(int par1, int par2, int par3) { this.incrementWindowID(); this.playerNetServerHandler.sendPacketToPlayer(new Packet100OpenWindow(this.currentWindowId, 1, "Crafting", 9, true)); this.openContainer = new ContainerWorkbench(this.inventory, this.worldObj, par1, par2, par3); this.openContainer.windowId = this.currentWindowId; this.openContainer.addCraftingToCrafters(this); }
@SubscribeEvent public void onTooltip(ItemTooltipEvent event) { if (ItemStack.areItemStacksEqual(lastOutput, event.getItemStack())) { if ((event.getEntityPlayer().openContainer instanceof ContainerWorkbench && ((ContainerWorkbench) event.getEntityPlayer().openContainer).craftResult.getStackInSlot(0) == event.getItemStack()) || (event.getEntityPlayer().openContainer instanceof ContainerPlayer && ((ContainerPlayer) event.getEntityPlayer().openContainer).craftResult.getStackInSlot(0) == event.getItemStack())) { event.getToolTip().add(Lang.RECIPE_CLEAR.get()); } } }
public boolean doesRecipeExist(ICraftingPatternMAC pattern) { InventoryCrafting inv = new InventoryCrafting(new ContainerWorkbench(new InventoryPlayer(null), gridTE.getWorld(), 0, 0, 0) { public void onCraftMatrixChanged(IInventory par1IInventory) { } }, 3, 3); for (int i = 0; i < pattern.getCraftingMatrix().length; i++) { inv.setInventorySlotContents(i, pattern.getCraftingMatrix()[i]); } ItemStack thing = CraftingManager.getInstance().findMatchingRecipe(inv, gridTE.getWorld()); return ItemStack.areItemStacksEqual(thing, pattern.getOutput()); }
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerWorkbench(playerInventory, this.world, this.position); }
public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition) { super(new ContainerWorkbench(playerInv, worldIn, blockPosition)); }
public GuiCrafting(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5) { super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5)); }
public GuiCrafting(InventoryPlayer p_i1084_1_, World p_i1084_2_, int p_i1084_3_, int p_i1084_4_, int p_i1084_5_) { super(new ContainerWorkbench(p_i1084_1_, p_i1084_2_, p_i1084_3_, p_i1084_4_, p_i1084_5_)); }