Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BoilerMenu extends AbstractContainerMenu {
- public final BoilerBlockEntity blockEntity;
- private final Level level;
- private final ContainerData data;
- private FluidStack waterFluidStack;
- private FluidStack ppFluidStack;
- public BoilerMenu(int id, Inventory inv, FriendlyByteBuf data) {
- this(id, inv, inv.player.level.getBlockEntity(data.readBlockPos()), new SimpleContainerData(2));
- }
- public BoilerMenu(int id, Inventory inv, BlockEntity entity, ContainerData data) {
- super(ModMenus.BOILER.get(), id);
- checkContainerSize(inv, Constants.BOILER_SLOTS);
- blockEntity = (BoilerBlockEntity) entity;
- this.level = inv.player.level;
- this.data = data;
- this.waterFluidStack = blockEntity.getWaterFluid();
- this.ppFluidStack = blockEntity.getPPFluid();
- addPlayerInventory(inv);
- addPlayerHotbar(inv);
- this.blockEntity.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler -> {
- this.addSlot(new SlotItemHandler(handler, 0, 8,17 - 25));
- this.addSlot(new SlotItemHandler(handler, 1, 8, 103 - 25));
- this.addSlot(new SlotItemHandler(handler, 2, 152, 17 - 25));
- this.addSlot(new SlotItemHandler(handler, 3, 152, 103 - 25));
- int o = 4;
- for (int y = 0; y < 3; y++) {
- for (int x = 0; x < 3; x++) {
- this.addSlot(new SlotItemHandler(handler, o, 46 + x * 18, (29 + y * 18) - 25));
- o++;
- }
- }
- });
- addDataSlots(data);
- }
- public boolean isCrafting() {
- return data.get(0) > 0;
- }
- public int getScaledProgress() {
- int progress = this.data.get(0);
- int maxProgress = this.data.get(1);
- int progressArrowSize = 24;
- return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
- }
- // CREDIT GOES TO: diesieben07 | https://github.com/diesieben07/SevenCommons
- // must assign a slot number to each of the slots used by the GUI.
- // For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar.
- // Each time we add a Slot to the container, it automatically increases the slotIndex, which means
- // 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - 8)
- // 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35)
- // 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - 8)
- private static final int HOTBAR_SLOT_COUNT = 9;
- private static final int PLAYER_INVENTORY_ROW_COUNT = 3;
- private static final int PLAYER_INVENTORY_COLUMN_COUNT = 9;
- private static final int PLAYER_INVENTORY_SLOT_COUNT = PLAYER_INVENTORY_COLUMN_COUNT * PLAYER_INVENTORY_ROW_COUNT;
- private static final int VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT;
- private static final int VANILLA_FIRST_SLOT_INDEX = 0;
- private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;
- @Override
- public ItemStack quickMoveStack(Player playerIn, int index) {
- Slot sourceSlot = slots.get(index);
- if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
- ItemStack sourceStack = sourceSlot.getItem();
- ItemStack copyOfSourceStack = sourceStack.copy();
- // Check if the slot clicked is one of the vanilla container slots
- if (index < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
- // This is a vanilla container slot so merge the stack into the tile inventory
- if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
- + Constants.BOILER_SLOTS, false)) {
- return ItemStack.EMPTY; // EMPTY_ITEM
- }
- } else if (index < TE_INVENTORY_FIRST_SLOT_INDEX + Constants.BOILER_SLOTS) {
- // This is a TE slot so merge the stack into the players inventory
- if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) {
- return ItemStack.EMPTY;
- }
- } else {
- System.out.println("Invalid slotIndex:" + index);
- return ItemStack.EMPTY;
- }
- // If stack size == 0 (the entire stack was moved) set slot contents to null
- if (sourceStack.getCount() == 0) {
- sourceSlot.set(ItemStack.EMPTY);
- } else {
- sourceSlot.setChanged();
- }
- sourceSlot.onTake(playerIn, sourceStack);
- return copyOfSourceStack;
- }
- @Override
- public boolean stillValid(Player player) {
- return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()),
- player, ModBlocks.BOILER.get());
- }
- private void addPlayerInventory(Inventory playerInventory) {
- for (int i = 0; i < 3; ++i) {
- for (int l = 0; l < 9; ++l) {
- this.addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, (86 + i * 18) + 23));
- }
- }
- }
- private void addPlayerHotbar(Inventory playerInventory) {
- for (int i = 0; i < 9; ++i) {
- this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 144 + 23));
- }
- }
- public FluidStack getWaterFluid() {
- return this.waterFluidStack;
- }
- public void setWaterFluid(FluidStack fluid) {
- this.waterFluidStack = fluid;
- }
- public FluidStack getPPFluid() {
- return this.ppFluidStack;
- }
- public void setPPFluid(FluidStack fluid) {
- this.ppFluidStack = fluid;
- }
- }
Add Comment
Please, Sign In to add comment