net.minecraft.screen.slot.Slot Java Examples
The following examples show how to use
net.minecraft.screen.slot.Slot.
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 File: OxygenCollectorScreenHandler.java From Galacticraft-Rewoven with MIT License | 6 votes |
public OxygenCollectorScreenHandler(int syncId, PlayerEntity playerEntity, OxygenCollectorBlockEntity blockEntity) { super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.OXYGEN_COLLECTOR_HANDLER); Inventory inventory = blockEntity.getInventory().asInventory(); addProperty(status); addProperty(oxygen); addProperty(lastCollectAmount); // Charging slot this.addSlot(new ChargeSlot(inventory, 0, 20, 70)); // Player inventory slots int playerInvYOffset = 99; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58)); } }
Example #2
Source File: Peek.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
public void drawMapToolTip(MatrixStack matrix, Slot slot, int mX, int mY) { if (slot.getStack().getItem() != Items.FILLED_MAP) return; MapState data = FilledMapItem.getMapState(slot.getStack(), mc.world); byte[] colors = data.colors; double size = getSettings().get(3).toSlider().getValue(); GL11.glPushMatrix(); GL11.glScaled(size, size, 1.0); GL11.glTranslatef(0.0F, 0.0F, 300.0F); int x = (int) (mX*(1/size) + 12*(1/size)); int y = (int) (mY*(1/size) - 12*(1/size) - 140); renderTooltipBox(x - 12, y + 12, 128, 128, false); for (byte c: colors) { int c1 = c & 255; if (c1 / 4 != 0) Screen.fill(matrix, x, y, x+1, y+1, getRenderColorFix(MaterialColor.COLORS[c1 / 4].color, c1 & 3)); if (x - (int) (mX*(1/size)+12*(1/size)) == 127) { x = (int) (mX*(1/size)+12*(1/size)); y++; } else x++; } GL11.glPopMatrix(); }
Example #3
Source File: CoalGeneratorScreenHandler.java From Galacticraft-Rewoven with MIT License | 6 votes |
public CoalGeneratorScreenHandler(int syncId, PlayerEntity playerEntity, CoalGeneratorBlockEntity generator) { super(syncId, playerEntity, generator, GalacticraftScreenHandlerTypes.COAL_GENERATOR_HANDLER); Inventory inventory = blockEntity.getInventory().asInventory(); addProperty(status); // Coal Generator fuel slot this.addSlot(new ItemSpecificSlot(inventory, 0, 8, 72, fuel)); this.addSlot(new ChargeSlot(inventory, 1, 8, 8)); // Player inventory slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 152)); } }
Example #4
Source File: BasicSolarPanelScreenHandler.java From Galacticraft-Rewoven with MIT License | 6 votes |
public BasicSolarPanelScreenHandler(int syncId, PlayerEntity playerEntity, BasicSolarPanelBlockEntity blockEntity) { super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.BASIC_SOLAR_PANEL_HANDLER); Inventory inventory = blockEntity.getInventory().asInventory(); addProperty(status); this.addSlot(new ChargeSlot(inventory, 0, 8, 53)); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 142)); } }
Example #5
Source File: Peek.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
public void drawShulkerToolTip(Slot slot, int mX, int mY) { if (!(slot.getStack().getItem() instanceof BlockItem)) return; if (!(((BlockItem) slot.getStack().getItem()).getBlock() instanceof ShulkerBoxBlock) && !(((BlockItem) slot.getStack().getItem()).getBlock() instanceof ChestBlock) && !(((BlockItem) slot.getStack().getItem()).getBlock() instanceof DispenserBlock) && !(((BlockItem) slot.getStack().getItem()).getBlock() instanceof HopperBlock)) return; List<ItemStack> items = ItemContentUtils.getItemsInContainer(slot.getStack()); Block block = ((BlockItem) slot.getStack().getItem()).getBlock(); int count = block instanceof HopperBlock || block instanceof DispenserBlock ? 18 : 0; if (block instanceof HopperBlock) renderTooltipBox(mX, mY - 21, 13, 82, true); else if (block instanceof DispenserBlock) renderTooltipBox(mX, mY - 21, 13, 150, true); else renderTooltipBox(mX, mY - 55, 47, 150, true); for (ItemStack i: items) { if (count > 26) break; int x = mX + 10 + (17 * (count % 9)); int y = mY - 69 + (17 * (count / 9)); mc.getItemRenderer().renderGuiItemIcon(i, x, y); mc.getItemRenderer().renderGuiItemOverlay(mc.textRenderer, i, x, y, i.getCount() > 1 ? i.getCount() + "" : ""); count++; } }
Example #6
Source File: EnergyStorageModuleScreenHandler.java From Galacticraft-Rewoven with MIT License | 6 votes |
public EnergyStorageModuleScreenHandler(int syncId, PlayerEntity playerEntity, EnergyStorageModuleBlockEntity blockEntity) { super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.ENERGY_STORAGE_MODULE_HANDLER); Inventory inventory = blockEntity.getInventory().asInventory(); // Battery slots this.addSlot(new ChargeSlot(inventory, 0, 18 * 6 - 6, 18 + 6)); this.addSlot(new ChargeSlot(inventory, 1, 18 * 6 - 6, 18 * 2 + 12)); // Player inventory slots int playerInvYOffset = 84; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58)); } }
Example #7
Source File: ContainerScreen54Mixin.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void shiftClickSlots(int from, int to, int mode) { this.mode = mode; for(int i = from; i < to; i++) { Slot slot = handler.slots.get(i); if(slot.getStack().isEmpty()) continue; waitForDelay(); if(this.mode != mode || client.currentScreen == null) break; onMouseClick(slot, slot.id, 0, SlotActionType.QUICK_MOVE); } }
Example #8
Source File: SyncedGuiDescription.java From LibGui with MIT License | 6 votes |
/** WILL MODIFY toInsert! Returns true if anything was inserted. */ private boolean insertIntoEmpty(ItemStack toInsert, Slot slot) { ItemStack curSlotStack = slot.getStack(); if (curSlotStack.isEmpty() && slot.canInsert(toInsert)) { if (toInsert.getCount() > slot.getMaxStackAmount()) { slot.setStack(toInsert.split(slot.getMaxStackAmount())); } else { slot.setStack(toInsert.split(toInsert.getCount())); } slot.markDirty(); return true; } return false; }
Example #9
Source File: SyncedGuiDescription.java From LibGui with MIT License | 6 votes |
/** WILL MODIFY toInsert! Returns true if anything was inserted. */ private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) { ItemStack curSlotStack = slot.getStack(); if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canTakeItems(player)) { int combinedAmount = curSlotStack.getCount() + toInsert.getCount(); if (combinedAmount <= toInsert.getMaxCount()) { toInsert.setCount(0); curSlotStack.setCount(combinedAmount); slot.markDirty(); return true; } else if (curSlotStack.getCount() < toInsert.getMaxCount()) { toInsert.decrement(toInsert.getMaxCount() - curSlotStack.getCount()); curSlotStack.setCount(toInsert.getMaxCount()); slot.markDirty(); return true; } } return false; }
Example #10
Source File: CircuitFabricatorScreenHandler.java From Galacticraft-Rewoven with MIT License | 5 votes |
public CircuitFabricatorScreenHandler(int syncId, PlayerEntity playerEntity, CircuitFabricatorBlockEntity blockEntity) { super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.CIRCUIT_FABRICATOR_HANDLER); addProperty(progress); addProperty(status); Inventory inventory = blockEntity.getInventory().asInventory(); // Energy slot this.addSlot(new ChargeSlot(inventory, 0, 8, 79)); this.addSlot(new ItemSpecificSlot(inventory, 1, 8, 15, Items.DIAMOND)); this.addSlot(new ItemSpecificSlot(inventory, 2, 8 + (18 * 3), 79, GalacticraftItems.RAW_SILICON)); this.addSlot(new ItemSpecificSlot(inventory, 3, 8 + (18 * 3), 79 - 18, GalacticraftItems.RAW_SILICON)); this.addSlot(new ItemSpecificSlot(inventory, 4, 8 + (18 * 6), 79 - 18, Items.REDSTONE)); this.addSlot(new ItemSpecificSlot(inventory, 5, 8 + (18 * 7), 15, materials)); this.addSlot(new FurnaceOutputSlot(playerEntity, inventory, 6, 8 + (18 * 8), 79)); // Player inventory slots for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, 110 + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, 168)); } }
Example #11
Source File: Peek.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public void drawBookToolTip(MatrixStack matrix, Slot slot, int mX, int mY) { if (slot.getStack().getItem() != Items.WRITABLE_BOOK && slot.getStack().getItem() != Items.WRITTEN_BOOK) return; if (pages == null) pages = ItemContentUtils.getTextInBook(slot.getStack()); if (pages.isEmpty()) return; /* Cycle through pages */ if (mc.player.age % 80 == 0 && !shown) { shown = true; if (pageCount == pages.size() - 1) pageCount = 0; else pageCount++; } else if (mc.player.age % 80 != 0) shown = false; int lenght = mc.textRenderer.getWidth("Page: " + (pageCount + 1) + "/" + pages.size()); renderTooltipBox(mX + 56 - lenght / 2, mY - pages.get(pageCount).size() * 10 - 19, 5, lenght, true); renderTooltipBox(mX, mY - pages.get(pageCount).size() * 10 - 6, pages.get(pageCount).size() * 10 - 2, 120, true); mc.textRenderer.drawWithShadow(matrix, "Page: " + (pageCount + 1) + "/" + pages.size(), mX + 68 - lenght / 2, mY - pages.get(pageCount).size() * 10 - 32, -1); int count = 0; for (String s: pages.get(pageCount)) { mc.textRenderer.drawWithShadow(matrix, s, mX + 12, mY - 18 - pages.get(pageCount).size() * 10 + count * 10, 0x00c0c0); count++; } }
Example #12
Source File: RecipeBook_1_12.java From multiconnect with MIT License | 5 votes |
private PlaceRecipeC2SPacket_1_12.Transaction findAndMoveToCraftMatrix(int destSlotIndex, Slot destSlot, ItemStack stackNeeded) { assert mc.player != null; PlayerInventory playerInv = mc.player.inventory; int fromSlot = playerInv.method_7371(stackNeeded); if (fromSlot == -1) { return null; } else { ItemStack stack = playerInv.getStack(fromSlot).copy(); if (stack.isEmpty()) { LogManager.getLogger().error("Matched: " + stackNeeded.getTranslationKey() + " with empty item."); return null; } else { if (stack.getCount() > 1) { playerInv.removeStack(fromSlot, 1); } else { playerInv.removeStack(fromSlot); } ItemStack originalStack = stack.copy(); stack.setCount(1); if (destSlot.getStack().isEmpty()) { destSlot.setStack(stack); } else { destSlot.getStack().increment(1); } return new PlaceRecipeC2SPacket_1_12.Transaction(originalStack, stack, destSlotIndex, fromSlot); } } }
Example #13
Source File: RecipeBook_1_12.java From multiconnect with MIT License | 5 votes |
private void placeRecipe(Recipe<C> recipe, List<Slot> slots, int placeCount, IntList inputItemIds, List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsToMatrix) { int width = container.getCraftingWidth(); int height = container.getCraftingHeight(); if (recipe instanceof ShapedRecipe) { ShapedRecipe shaped = (ShapedRecipe) recipe; width = shaped.getWidth(); height = shaped.getHeight(); } int serverSlot = 1; Iterator<Integer> inputItemItr = inputItemIds.iterator(); // :thonkjang: probably meant to swap craftingWidth and craftingHeight here, but oh well because width = height for (int y = 0; y < container.getCraftingWidth() && y != height; y++) { for (int x = 0; x < container.getCraftingHeight(); x++) { if (x == width || !inputItemItr.hasNext()) { serverSlot += container.getCraftingWidth() - x; break; } Slot slot = slots.get(serverSlot); ItemStack stackNeeded = RecipeFinder.getStackFromId(inputItemItr.next()); if (!stackNeeded.isEmpty()) { for (int i = 0; i < placeCount; i++) { PlaceRecipeC2SPacket_1_12.Transaction transaction = findAndMoveToCraftMatrix(serverSlot, slot, stackNeeded); if (transaction != null) { transactionsToMatrix.add(transaction); } } } serverSlot++; } if (!inputItemItr.hasNext()) { break; } } }
Example #14
Source File: MachineScreenHandler.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override public ItemStack transferSlot(PlayerEntity playerEntity, int slotId) { ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.slots.get(slotId); if (slot != null && slot.hasStack()) { ItemStack itemStack1 = slot.getStack(); itemStack = itemStack1.copy(); if (itemStack.isEmpty()) { return itemStack; } if (slotId < this.blockEntity.getInventory().getSize()) { if (!this.insertItem(itemStack1, this.blockEntity.getInventory().getSize(), this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.insertItem(itemStack1, 0, this.blockEntity.getInventory().getSize(), false)) { return ItemStack.EMPTY; } if (itemStack1.getCount() == 0) { slot.setStack(ItemStack.EMPTY); } else { slot.markDirty(); } } return itemStack; }
Example #15
Source File: ElectricCompressorScreenHandler.java From Galacticraft-Rewoven with MIT License | 5 votes |
public ElectricCompressorScreenHandler(int syncId, PlayerEntity player, ElectricCompressorBlockEntity blockEntity) { super(syncId, player, blockEntity, GalacticraftScreenHandlerTypes.ELECTRIC_COMPRESSOR_HANDLER); this.inventory = blockEntity.getInventory().asInventory(); addProperty(status); addProperty(progress); // 3x3 comprerssor input grid int slot = 0; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { this.addSlot(new Slot(this.inventory, slot, x * 18 + 19, y * 18 + 18)); slot++; } } // Output slot this.addSlot(new FurnaceOutputSlot(playerEntity, this.inventory, CompressorBlockEntity.OUTPUT_SLOT, getOutputSlotPos()[0], getOutputSlotPos()[1])); // Player inventory slots int playerInvYOffset = 117; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58)); } addProperty(energy); addSlot(new FurnaceOutputSlot(player, this.inventory, ElectricCompressorBlockEntity.SECOND_OUTPUT_SLOT, getOutputSlotPos()[0], getOutputSlotPos()[1] + 18)); addSlot(new ChargeSlot(this.inventory, CompressorBlockEntity.FUEL_INPUT_SLOT, 3 * 18 + 1, 75)); }
Example #16
Source File: CompressorScreenHandler.java From Galacticraft-Rewoven with MIT License | 5 votes |
public CompressorScreenHandler(int syncId, PlayerEntity playerEntity, CompressorBlockEntity blockEntity) { super(syncId, playerEntity, blockEntity, GalacticraftScreenHandlerTypes.COMPRESSOR_HANDLER); this.inventory = blockEntity.getInventory().asInventory(); addProperty(status); addProperty(progress); addProperty(fuelTime); // 3x3 compressor input grid int slot = 0; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { this.addSlot(new Slot(this.inventory, slot, x * 18 + 19, y * 18 + 18)); slot++; } } // Fuel slot this.addSlot(new ItemSpecificSlot(this.inventory, CompressorBlockEntity.FUEL_INPUT_SLOT, 3 * 18 + 1, 75, AbstractFurnaceBlockEntity.createFuelTimeMap().keySet().toArray(new Item[0]))); // Output slot this.addSlot(new FurnaceOutputSlot(playerEntity, this.inventory, CompressorBlockEntity.OUTPUT_SLOT, getOutputSlotPos()[0], getOutputSlotPos()[1])); // Player inventory slots int playerInvYOffset = 110; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerEntity.inventory, j + i * 9 + 9, 8 + j * 18, playerInvYOffset + i * 18)); } } // Hotbar slots for (int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerEntity.inventory, i, 8 + i * 18, playerInvYOffset + 58)); } }
Example #17
Source File: MixinMerchantContainer.java From multiconnect with MIT License | 4 votes |
@Inject(method = "canInsertIntoSlot", at = @At("HEAD"), cancellable = true) private void modifyCanInsertIntoSlot(ItemStack stack, Slot slot, CallbackInfoReturnable<Boolean> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) ci.setReturnValue(true); }
Example #18
Source File: SyncedGuiDescription.java From LibGui with MIT License | 4 votes |
@Override public ItemStack onSlotClick(int slotNumber, int button, SlotActionType action, PlayerEntity player) { if (action==SlotActionType.QUICK_MOVE) { if (slotNumber < 0) { return ItemStack.EMPTY; } if (slotNumber>=this.slots.size()) return ItemStack.EMPTY; Slot slot = this.slots.get(slotNumber); if (slot == null || !slot.canTakeItems(player)) { return ItemStack.EMPTY; } ItemStack remaining = ItemStack.EMPTY; if (slot != null && slot.hasStack()) { ItemStack toTransfer = slot.getStack(); remaining = toTransfer.copy(); //if (slot.inventory==blockInventory) { if (blockInventory!=null) { if (slot.inventory==blockInventory) { //Try to transfer the item from the block into the player's inventory if (!this.insertItem(toTransfer, this.playerInventory, true, player)) { return ItemStack.EMPTY; } } else if (!this.insertItem(toTransfer, this.blockInventory, false, player)) { //Try to transfer the item from the player to the block return ItemStack.EMPTY; } } else { //There's no block, just swap between the player's storage and their hotbar if (!swapHotbar(toTransfer, slotNumber, this.playerInventory, player)) { return ItemStack.EMPTY; } } if (toTransfer.isEmpty()) { slot.setStack(ItemStack.EMPTY); } else { slot.markDirty(); } } return remaining; } else { return super.onSlotClick(slotNumber, button, action, player); } }
Example #19
Source File: RecipeBook_1_12.java From multiconnect with MIT License | 4 votes |
private void tryPlaceRecipe(Recipe<C> recipe, List<Slot> slots) { assert mc.player != null; assert mc.getNetworkHandler() != null; boolean alreadyPlaced = container.matches(recipe); int possibleCraftCount = iRecipeBookWidget.getRecipeFinder().countRecipeCrafts(recipe, null); if (alreadyPlaced) { // check each item in the input to see if we're already at the max crafts possible boolean canPlaceMore = false; for (int i = 0; i < container.getCraftingSlotCount(); i++) { if (i == container.getCraftingResultSlotIndex()) continue; ItemStack stack = container.getSlot(i).getStack(); if (!stack.isEmpty() && stack.getCount() < possibleCraftCount) { canPlaceMore = true; } } if (!canPlaceMore) { return; } } int craftCount = calcCraftCount(possibleCraftCount, alreadyPlaced); IntList inputItemIds = new IntArrayList(); if (iRecipeBookWidget.getRecipeFinder().findRecipe(recipe, inputItemIds, craftCount)) { // take into account max stack sizes now we've found the actual inputs int actualCount = craftCount; for (int itemId : inputItemIds) { int maxCount = RecipeFinder.getStackFromId(itemId).getMaxCount(); if (actualCount > maxCount) { actualCount = maxCount; } } if (iRecipeBookWidget.getRecipeFinder().findRecipe(recipe, inputItemIds, actualCount)) { // clear the craft matrix and place the recipe List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsFromMatrix = clearCraftMatrix(); List<PlaceRecipeC2SPacket_1_12.Transaction> transactionsToMatrix = new ArrayList<>(); placeRecipe(recipe, slots, actualCount, inputItemIds, transactionsToMatrix); short transactionId = mc.player.currentScreenHandler.getNextActionId(mc.player.inventory); mc.getNetworkHandler().sendPacket(new PlaceRecipeC2SPacket_1_12(container.syncId, transactionId, transactionsFromMatrix, transactionsToMatrix)); mc.player.inventory.markDirty(); } } }