nerovapes/src/main/java/ru/neroduckale/gui/prikolscreenhandler.java
2024-06-23 02:46:03 +05:00

84 lines
3 KiB
Java

package ru.neroduckale.gui;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Hand;
import ru.neroduckale.NeroduckaleVapes;
import ru.neroduckale.register.RegisterGUI;
import ru.neroduckale.vapes.Vape;
public class prikolscreenhandler extends ScreenHandler {
private Inventory inventory;
public ItemStack vape;
public int amountjija;
//This constructor gets called from the BlockEntity on the server without calling the other constructor first, the server knows the inventory of the container
//and can therefore directly provide it as an argument. This inventory will then be synced to the client.
public prikolscreenhandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {
super(RegisterGUI.PRIKOL_SCREEN_HANDLER, syncId);
checkSize(inventory, 2);
this.inventory = inventory;
this.vape = playerInventory.player.getStackInHand(Hand.MAIN_HAND);
this.amountjija = vape.getNbt().getInt("amountjija");
//some inventories do custom logic when a player opens it.
inventory.onOpen(playerInventory.player);
//This will place the slot in the correct locations for a 3x3 Grid. The slots exist on both server and client!
//This will not render the background of the slots however, this is the Screens job
int m;
int l;
//Our inventory
this.addSlot(new Slot(inventory, 0, 16, 32));
this.addSlot(new Slot(inventory, 1, 131, 11));
//The player inventory
for (m = 0; m < 3; ++m) {
for (l = 0; l < 9; ++l) {
this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18));
}
}
//The player Hotbar
for (m = 0; m < 9; ++m) {
this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 142));
}
}
public prikolscreenhandler(int i, PlayerInventory playerInventory) {
this(i, playerInventory, new SimpleInventory(2));
}
@Override
public ItemStack quickMove(PlayerEntity player, int slot) {
return player.getInventory().getStack(slot);
}
@Override
public boolean canUse(PlayerEntity player) {
return true;
}
public int getHeight() {
int progressArrowSize = 63; // This is the width in pixels of your arrow
if (amountjija != 0 && this.vape.getItem() instanceof Vape pasito) {
return amountjija * progressArrowSize / pasito.mlbak;
}
return 0;
}
public int getAmount() {
return this.amountjija;
}
@Override
public void onClosed(PlayerEntity player) {
super.onClosed(player);
this.dropInventory(player, this.inventory);
}
}