Java Code Examples for net.minecraft.inventory.Container
The following examples show how to use
net.minecraft.inventory.Container. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SkyblockAddons Source File: GuiContainerHook.java License: MIT License | 6 votes |
public static void drawGradientRect(GuiContainer guiContainer, int left, int top, int right, int bottom, int startColor, int endColor, Slot theSlot) { if (freezeBackpack) return; SkyblockAddons main = SkyblockAddons.getInstance(); Container container = Minecraft.getMinecraft().thePlayer.openContainer; if (theSlot != null) { int slotNum = theSlot.slotNumber + main.getInventoryUtils().getSlotDifference(container); main.getUtils().setLastHoveredSlot(slotNum); if (main.getConfigValues().isEnabled(Feature.LOCK_SLOTS) && main.getUtils().isOnSkyblock() && main.getConfigValues().getLockedSlots().contains(slotNum) && (slotNum >= 9 || container instanceof ContainerPlayer && slotNum >= 5)) { drawRightGradientRect(guiContainer, left, top, right, bottom, OVERLAY_RED, OVERLAY_RED); return; } } drawRightGradientRect(guiContainer, left, top, right, bottom, startColor, endColor); }
Example 2
Source Project: customstuff4 Source File: DamageableShapelessOreRecipeTest.java License: GNU General Public License v3.0 | 6 votes |
private void doTest(boolean inOrder, boolean enoughDamage) { DamageableShapelessOreRecipe recipe = new DamageableShapelessOreRecipe(new ResourceLocation("group"), new int[] {enoughDamage ? 5 : 5000, 0}, new ItemStack(Blocks.DIRT), new ItemStack(Items.WOODEN_SWORD), new ItemStack(Items.APPLE)); InventoryCrafting inv = new InventoryCrafting(new Container() { @Override public boolean canInteractWith(EntityPlayer playerIn) { return false; } }, 3, 3); inv.setInventorySlotContents(inOrder ? 3 : 4, new ItemStack(Items.WOODEN_SWORD)); inv.setInventorySlotContents(inOrder ? 4 : 3, new ItemStack(Items.APPLE)); assertSame(enoughDamage, recipe.matches(inv, null)); if (enoughDamage) { NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv); assertSame(Items.WOODEN_SWORD, remaining.get(inOrder ? 3 : 4).getItem()); assertEquals(5, remaining.get(inOrder ? 3 : 4).getItemDamage()); } }
Example 3
Source Project: NotEnoughItems Source File: FastTransferManager.java License: MIT License | 6 votes |
private void generateSlotMap(Container container, ItemStack stack) { stack = stack.copy(); stack.stackSize = 1; for (int slotNo = 0; slotNo < container.inventorySlots.size(); slotNo++) { if (slotZoneMap.containsKey(slotNo) || !container.getSlot(slotNo).isItemValid(stack)) continue; HashSet<Integer> connectedSlots = new HashSet<Integer>(); findConnectedSlots(container, slotNo, connectedSlots); LinkedList<Integer> zoneSlots = new LinkedList<Integer>(connectedSlots); Collections.sort(zoneSlots, new SlotPositionComparator(container)); slotZones.add(zoneSlots); for (int i : zoneSlots) { slotZoneMap.put(i, slotZones.size() - 1); } } }
Example 4
Source Project: CraftingKeys Source File: InputUtil.java License: MIT License | 6 votes |
/** * Returns the Slot at the current Mouse Position. [FROM GUICONTAINER] * * @param guiContainer The (Inventory) Container to work with. * @return Returns the slot (or null) */ public static Slot getSlotAtMousePosition(GuiContainer guiContainer) { if (guiContainer != null) { Container container = guiContainer.inventorySlots; int x = getMouseX(guiContainer); int y = getMouseY(guiContainer); for (int k = 0; k < container.inventorySlots.size(); k++) { Slot slot = (Slot) container.inventorySlots.get(k); if (getIsMouseOverSlot(guiContainer, slot, x, y)) { return slot; } } return null; } else { Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null"); return null; } }
Example 5
Source Project: AgriCraft Source File: MessageGuiSeedStorageClearSeed.java License: MIT License | 5 votes |
@Override protected void processMessage(MessageContext ctx) { final Container container = this.player.openContainer; if (container instanceof ContainerSeedStorageBase) { final ContainerSeedStorageBase storage = ((ContainerSeedStorageBase) container); final TileEntity tileEntity = storage.getTile(); if (tileEntity instanceof ISeedStorageControllable) { ((ISeedStorageControllable) tileEntity).clearLockedSeed(); } } }
Example 6
Source Project: NotEnoughItems Source File: FastTransferManager.java License: MIT License | 5 votes |
public void restoreContainer(Container container, LinkedList<ItemStack> items) { for (int i = 0; i < container.inventorySlots.size(); i++) { container.getSlot(i).putStack(items.get(i)); } container.slotClick(-999, 0, 0, Minecraft.getMinecraft().thePlayer); }
Example 7
Source Project: BigReactors Source File: GuiReactorStatus.java License: MIT License | 5 votes |
public GuiReactorStatus(Container container, TileEntityReactorPart tileEntityReactorPart) { super(container); ySize = 186; this.part = tileEntityReactorPart; this.reactor = part.getReactorController(); }
Example 8
Source Project: NotEnoughItems Source File: TaggedInventoryArea.java License: MIT License | 5 votes |
public TaggedInventoryArea(String name, int first, int last, Container container) { this.container = container; tagName = name; for(int i = first; i <= last; i++) slots.add(i); }
Example 9
Source Project: TFC2 Source File: PlayerInventory.java License: GNU General Public License v3.0 | 5 votes |
protected static Slot addSlotToContainer(Container container, Slot par1Slot) { par1Slot.slotNumber = container.inventorySlots.size(); container.inventorySlots.add(par1Slot); container.inventoryItemStacks.add(ItemStack.EMPTY); return par1Slot; }
Example 10
Source Project: Kettle Source File: CraftPlayer.java License: GNU General Public License v3.0 | 5 votes |
@Override public boolean setWindowProperty(Property prop, int value) { Container container = getHandle().openContainer; if (container.getBukkitView().getType() != prop.getType()) { return false; } getHandle().sendWindowProperty(container, prop.getId(), value); return true; }
Example 11
Source Project: Translocators Source File: TileCraftingGrid.java License: MIT License | 5 votes |
private InventoryCrafting getCraftMatrix() { InventoryCrafting craftMatrix = new InventoryCrafting(new Container() { @Override public boolean canInteractWith(EntityPlayer entityplayer) { return true; } }, 3, 3); for (int i = 0; i < 9; i++) craftMatrix.setInventorySlotContents(i, items[i]); return craftMatrix; }
Example 12
Source Project: TFC2 Source File: SlotSpecialCraftingOutput.java License: GNU General Public License v3.0 | 5 votes |
public SlotSpecialCraftingOutput(Container container, EntityPlayer entityplayer, IInventory iinventory, IInventory iinventory1, int i, int j, int k) { super(iinventory1, i, j, k); this.container = container; thePlayer = entityplayer; craftMatrix = iinventory; }
Example 13
Source Project: TFC2 Source File: PlayerInventory.java License: GNU General Public License v3.0 | 5 votes |
public static void loadBagInventory(ItemStack is, Container c) { if(is != null && is.hasTagCompound()) { NBTTagList nbttaglist = is.getTagCompound().getTagList("Items", 10); containerInv = new InventoryCrafting(c, 4, 2); for(int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte byte0 = nbttagcompound1.getByte("Slot"); if(byte0 >= 0 && byte0 < 8) containerInv.setInventorySlotContents(byte0, new ItemStack(nbttagcompound1)); } } }
Example 14
Source Project: AdvancedRocketry Source File: ModulePlanetSelector.java License: MIT License | 5 votes |
@Override public void sendChanges(Container container, IContainerListener crafter, int variableId, int localId) { for(ModuleBase module : staticModuleList) { if(localId >= 0 && localId < module.numberOfChangesToSend()) { module.sendChanges(container, crafter, variableId, localId); return; } localId -= module.numberOfChangesToSend(); } }
Example 15
Source Project: BigReactors Source File: GuiCyaniteReprocessor.java License: MIT License | 5 votes |
public GuiCyaniteReprocessor(Container container, TileEntityCyaniteReprocessor entity) { super(container, entity); _entity = entity; xSize = 245; ySize = 175; }
Example 16
Source Project: TFC2 Source File: PlayerInventory.java License: GNU General Public License v3.0 | 5 votes |
private static void addToolbarSlots(Container container, InventoryPlayer inventory, int x, int y, boolean freezeSlot) { for(int j = 0; j < 9; ++j) { if(freezeSlot && j == inventory.currentItem) addSlotToContainer(container, new SlotForShowOnly(inventory, j, x + j * 18, y+58)); else addSlotToContainer(container, new Slot(inventory, j, x + j * 18, y+58)); } }
Example 17
Source Project: Signals Source File: PacketUpdateGui.java License: GNU General Public License v3.0 | 5 votes |
@Override public void handleClientSide(EntityPlayer player){ Container container = player.openContainer; if(container instanceof ContainerBase) { ((ContainerBase<?>)container).updateField(syncId, value); } }
Example 18
Source Project: PneumaticCraft Source File: PacketUpdateGui.java License: GNU General Public License v3.0 | 5 votes |
@Override public void handleClientSide(PacketUpdateGui message, EntityPlayer player){ Container container = player.openContainer; if(container instanceof ContainerPneumaticBase) { ((ContainerPneumaticBase)container).updateField(message.syncId, message.value); } }
Example 19
Source Project: NotEnoughItems Source File: GuiContainer.java License: MIT License | 5 votes |
/** * Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY, * lastButtonClicked & timeSinceMouseClick. */ protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { Slot slot = this.getSlotAtPosition(mouseX, mouseY); ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); manager.mouseDragged(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) { if (clickedMouseButton == 0 || clickedMouseButton == 1) { if (this.draggedStack == null) { if (slot != this.clickedSlot && this.clickedSlot.getStack() != null) { this.draggedStack = this.clickedSlot.getStack().copy(); } } else if (this.draggedStack.stackSize > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false)) { long i = Minecraft.getSystemTime(); if (this.currentDragTargetSlot == slot) { if (i - this.dragItemDropDelay > 500L) { managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); managerHandleMouseClick(slot, slot.slotNumber, 1, ClickType.PICKUP); managerHandleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); this.dragItemDropDelay = i + 750L; --this.draggedStack.stackSize; } } else { this.currentDragTargetSlot = slot; this.dragItemDropDelay = i; } } } } else if (this.dragSplitting && slot != null && itemstack != null && itemstack.stackSize > this.dragSplittingSlots.size() && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) { this.dragSplittingSlots.add(slot); this.updateActivePotionEffects(); } }
Example 20
Source Project: NotEnoughItems Source File: FastTransferManager.java License: MIT License | 5 votes |
public static int findSlotWithItem(Container container, ItemStack teststack) { for (int slotNo = 0; slotNo < container.inventorySlots.size(); slotNo++) { ItemStack stack = container.getSlot(slotNo).getStack(); if (!stack.isEmpty() && areStacksSameType(stack, teststack)) { return slotNo; } } return -1; }
Example 21
Source Project: CraftingKeys Source File: AnvilManager.java License: MIT License | 5 votes |
/** * Returns a Anvil Manager Instance operating on the given container * * @param container A container from a GUI * @return manager-singleton */ public static AnvilManager getInstance(Container container) { if (instance == null) { instance = new AnvilManager(container); } else { instance.container = container; } return instance; }
Example 22
Source Project: CraftingKeys Source File: VillagerManager.java License: MIT License | 5 votes |
/** * Returns a Villager Manager Instance operating on the given container * * @param container A container from a GUI * @return manager-singleton */ public static VillagerManager getInstance(Container container) { if (instance == null) { instance = new VillagerManager(container); } else { instance.container = container; } return instance; }
Example 23
Source Project: BigReactors Source File: GuiReactorRedNetPort.java License: MIT License | 5 votes |
public GuiReactorRedNetPort(Container container, TileEntityReactorRedNetPort redNetPort) { super(container); port = redNetPort; xSize = 255; ySize = 214; _guiBackground = new ResourceLocation(BigReactors.GUI_DIRECTORY + "RedNetPort.png"); }
Example 24
Source Project: WearableBackpacks Source File: SlotBackpackWrapper.java License: MIT License | 5 votes |
/** When a backpack is equipped, go through the currently open container, see if * any slot contains the player's equipped backpack. If so, replace that slot with * a wrapper that prevents the backpack from being unequipped though normal means. */ public static void replace(EntityPlayer player, ItemStack backpack) { Container container = player.openContainer; if (container == null) return; for (Slot slot : container.inventorySlots) { if (slot.getStack() != backpack) continue; if (slot instanceof SlotBackpackWrapper) continue; Slot newSlot = new SlotBackpackWrapper(slot); newSlot.slotNumber = slot.slotNumber; container.inventorySlots.set(slot.slotNumber, newSlot); // Keep going, there may be more slots to fix! } }
Example 25
Source Project: NotEnoughItems Source File: NEIClientUtils.java License: MIT License | 5 votes |
public static void deleteItemsOfType(ItemStack type) { Container c = getGuiContainer().inventorySlots; for (int i = 0; i < c.inventorySlots.size(); i++) { Slot slot = c.getSlot(i); if (slot == null) continue; ItemStack stack = slot.getStack(); if (stack != null && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) { setSlotContents(i, null, true); slot.putStack(null); } } }
Example 26
Source Project: NotEnoughItems Source File: GuiContainer.java License: MIT License | 5 votes |
private void updateDragSplitting() { ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); if (itemstack != null && this.dragSplitting) { this.dragSplittingRemnant = itemstack.stackSize; ItemStack itemstack1; int i; for (Iterator iterator = this.dragSplittingSlots.iterator(); iterator.hasNext(); this.dragSplittingRemnant -= itemstack1.stackSize - i) { Slot slot = (Slot)iterator.next(); itemstack1 = itemstack.copy(); i = slot.getStack() == null ? 0 : slot.getStack().stackSize; Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i); if (itemstack1.stackSize > itemstack1.getMaxStackSize()) { itemstack1.stackSize = itemstack1.getMaxStackSize(); } if (itemstack1.stackSize > slot.getItemStackLimit(itemstack1)) { itemstack1.stackSize = slot.getItemStackLimit(itemstack1); } } } }
Example 27
Source Project: NOVA-Core Source File: MCCraftingGrid.java License: GNU Lesser General Public License v3.0 | 5 votes |
private MCCraftingGrid(InventoryCrafting inventory) { this.inventory = inventory; width = height = (int) Math.sqrt(inventory.getSizeInventory()); items = new nova.core.item.Item[width * height]; original = new ItemStack[items.length]; itemCount = 0; update(); Container container = ReflectionUtil.getCraftingContainer(inventory); if (container != null) { @SuppressWarnings("unchecked") List<Slot> slots = container.inventorySlots; EntityPlayer playerOrig = null; Optional<Player> player = Optional.empty(); for (Slot slot : slots) { if (slot instanceof SlotCrafting) { playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot); player = WrapUtility.getNovaPlayer(playerOrig); if (player.isPresent()) { break; } } } this.playerOrig = playerOrig; this.player = player; } else { playerOrig = null; player = Optional.empty(); } }
Example 28
Source Project: Chisel-2 Source File: BlockPresent.java License: GNU General Public License v2.0 | 5 votes |
@Override public int getComparatorInputOverride(World world, int x, int y, int z, int strength) { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof TileEntityPresent) { return Container.calcRedstoneFromInventory((TileEntityPresent) te); } return 0; }
Example 29
Source Project: NOVA-Core Source File: ReflectionUtil.java License: GNU Lesser General Public License v3.0 | 5 votes |
public static Container getCraftingContainer(InventoryCrafting inventory) { try { return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory); } catch (IllegalAccessException ex) { Game.logger().error("could not get inventory eventhandler"); return null; } }
Example 30
Source Project: NOVA-Core Source File: MCCraftingGrid.java License: GNU Lesser General Public License v3.0 | 5 votes |
private MCCraftingGrid(InventoryCrafting inventory) { this.inventory = inventory; width = height = (int) Math.sqrt(inventory.getSizeInventory()); items = new nova.core.item.Item[width * height]; original = new net.minecraft.item.ItemStack[items.length]; itemCount = 0; update(); Container container = ReflectionUtil.getCraftingContainer(inventory); if (container != null) { @SuppressWarnings("unchecked") List<Slot> slots = container.inventorySlots; EntityPlayer playerOrig = null; Optional<Player> player = Optional.empty(); for (Slot slot : slots) { if (slot instanceof SlotCrafting) { playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot); player = WrapUtility.getNovaPlayer(playerOrig); if (player.isPresent()) { break; } } } this.playerOrig = playerOrig; this.player = player; } else { playerOrig = null; player = Optional.empty(); } }