Files
CustomNPC-Plus/src/main/java/noppes/npcs/containers/ContainerCustomGui.java
T

149 lines
5.5 KiB
Java
Raw Normal View History

2022-01-12 04:44:08 -06:00
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package noppes.npcs.containers;
import net.minecraft.entity.player.EntityPlayer;
2022-06-18 12:52:23 -05:00
import net.minecraft.entity.player.EntityPlayerMP;
2022-01-12 04:44:08 -06:00
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
2022-06-18 12:52:23 -05:00
import noppes.npcs.EventHooks;
2022-11-15 15:25:53 -05:00
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.gui.IItemSlot;
2022-01-12 04:44:08 -06:00
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
2023-01-12 21:33:06 -05:00
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.gui.ScriptGui;
import java.util.Iterator;
2022-01-12 04:44:08 -06:00
public class ContainerCustomGui extends Container {
public ScriptGui customGui;
public IInventory guiInventory;
int slotCount = 0;
public int playerInvX;
public int playerInvY;
public ContainerCustomGui(IInventory inventory) {
this.guiInventory = inventory;
}
public void setGui(ScriptGui gui, EntityPlayer player) {
this.customGui = gui;
if (this.customGui.getShowPlayerInv()) {
this.addPlayerInventory(player, this.customGui.getPlayerInvX(), this.customGui.getPlayerInvY());
}
Iterator var3 = this.customGui.getSlots().iterator();
while(var3.hasNext()) {
IItemSlot slot = (IItemSlot)var3.next();
if (slot.hasStack()) {
2023-03-18 15:52:50 -05:00
this.addSlot(player, slot.getPosX(), slot.getPosY(), slot, slot.getStack().getMCItemStack(), player.worldObj.isRemote);
2022-01-12 04:44:08 -06:00
} else {
2023-03-18 15:52:50 -05:00
this.addSlot(player, slot.getPosX(), slot.getPosY(), slot, player.worldObj.isRemote);
2022-01-12 04:44:08 -06:00
}
}
}
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index < this.guiInventory.getSizeInventory()) {
if (!this.mergeItemStack(itemstack1, this.guiInventory.getSizeInventory(), this.inventorySlots.size(), true)) {
return null;
}
} else if (!this.mergeItemStack(itemstack1, 0, this.guiInventory.getSizeInventory(), false)) {
return null;
}
if (itemstack1.stackSize <= 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return itemstack;
}
2023-03-18 15:52:50 -05:00
void addSlot(EntityPlayer player, int x, int y, IItemSlot slot, boolean clientSide) {
this.addSlotToContainer(new CustomGuiSlot(player, this.guiInventory, this.slotCount++, slot, x, y, clientSide));
2022-01-12 04:44:08 -06:00
}
2023-03-18 15:52:50 -05:00
void addSlot(EntityPlayer player, int x, int y, IItemSlot slot, ItemStack itemStack, boolean clientSide) {
2022-01-12 04:44:08 -06:00
this.guiInventory.setInventorySlotContents(this.slotCount, itemStack);
2023-03-18 15:52:50 -05:00
this.addSlotToContainer(new CustomGuiSlot(player, this.guiInventory, this.slotCount++, slot, x, y, clientSide));
2022-01-12 04:44:08 -06:00
}
void addPlayerInventory(EntityPlayer player, int x, int y) {
this.playerInvX = x;
this.playerInvY = y;
int row;
for(row = 0; row < 3; ++row) {
for(int col = 0; col < 9; ++col) {
this.addSlotToContainer(new Slot(player.inventory, col + row * 9 + 9, x + col * 18, y + row * 18));
}
}
for(row = 0; row < 9; ++row) {
this.addSlotToContainer(new Slot(player.inventory, row, x + row * 18, y + 58));
}
}
public boolean canInteractWith(EntityPlayer p_75145_1_) {
return true;
}
2022-06-18 12:52:23 -05:00
@Override
public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) {
if(slotId < 0)
return super.slotClick(slotId, dragType, clickTypeIn, player);
if (slotId >= this.inventorySlots.size()) {
return null;
}
2023-03-18 15:52:50 -05:00
Slot mcSlot = (Slot)this.inventorySlots.get(slotId);
if(!player.worldObj.isRemote && mcSlot != null) {
IItemSlot slot = null;
if (this.getSlot(slotId) instanceof CustomGuiSlot) {
2023-03-18 15:52:50 -05:00
slot = ((CustomGuiSlot)this.getSlot(slotId)).slot;
}
2023-03-18 15:52:50 -05:00
if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, slot, dragType, clickTypeIn)) {
ItemStack prevStack = mcSlot.getStack();
if (slot != null) {
prevStack = slot.getStack() == null ? null : slot.getStack().getMCItemStack();
}
2022-06-18 12:52:23 -05:00
ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player);
2023-03-18 15:52:50 -05:00
if (!ItemStack.areItemStacksEqual(prevStack,item)) {
if (slot != null) {
slot.setStack(NpcAPI.Instance().getIItemStack(mcSlot.getStack()));
}
if (player.openContainer instanceof ContainerCustomGui) {
EventHooks.onCustomGuiSlot((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui,
mcSlot.slotNumber, prevStack, slot);
}
}
2022-06-18 12:52:23 -05:00
EntityPlayerMP p = (EntityPlayerMP) player;
p.sendContainerToPlayer(this);
2022-06-18 12:52:23 -05:00
return item;
}
}
2023-03-18 15:52:50 -05:00
2022-06-18 12:52:23 -05:00
return null;
}
2022-01-12 04:44:08 -06:00
public boolean canDragIntoSlot(Slot p_94531_1_) { return true; }
}