WIP API for adding new slots

Rendering needs reworked and shift-clicking needs some improvements.
This commit is contained in:
jss2a98aj committed 2021-11-03 05:13:32 -04:00
1 parent 36a332e597
commit e50c4de348
11 files changed
+393 -434

No files matched your search

@@ -8,126 +8,72 @@ import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.BaubleExpandedSlots;
import baubles.common.lib.PlayerHandler;
public class ContainerPlayerExpanded extends Container
{
/**
* The crafting matrix inventory.
*/
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
public class ContainerPlayerExpanded extends Container {
public IInventory craftResult = new InventoryCraftResult();
public InventoryBaubles baubles;
/**
* Determines if inventory manipulation should be handled.
*/
public boolean isLocalWorld;
private final EntityPlayer thePlayer;
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player)
{
this.isLocalWorld = par2;
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player) {
this.thePlayer = player;
baubles = new InventoryBaubles(player);
baubles.setEventHandler(this);
if (!player.worldObj.isRemote) {
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
}
this.addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 144, 27));//36 -> 27
int i;
int j;
for (i = 0; i < 2; ++i)
{
for (j = 0; j < 2; ++j)
{
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 106 + j * 18, 17 + i * 18));//26 -> 17
}
}
for (i = 0; i < 4; ++i)
{
//armor
for (i = 0; i < 4; ++i) {
final int k = i;
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18)
{
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
@Override
public int getSlotStackLimit() { return 1; }
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
if (par1ItemStack == null) return false;
return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, thePlayer);
public boolean isItemValid(ItemStack itemStack) {
if (itemStack == null) return false;
return itemStack.getItem().isValidArmor(itemStack, k, thePlayer);
}
});
}
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.AMULET, 0, 80, 8));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,1, 80, 8 + 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.RING,2, 80, 8 + 2 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.BELT,3, 80, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.HEAD,4, 80 + 18, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.BODY,5, 80 + 18 * 2, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.CHARM,6, 80 + 18 * 3, 8 + 3 * 18));
this.addSlotToContainer(new SlotBauble(baubles,BaubleType.GAUNTLET,7, 80 + 18 * 4, 8 + 3 * 18));
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
final int slotOffset = 18;
final int slotStartX = 80;
final int slotStartY = 8;
final int baubleSlots = BaubleExpandedSlots.getTotalSlots();
//bauble slots
for(i = 0; i < baubleSlots; i++) {
addSlotToContainer(new SlotBauble(baubles, BaubleExpandedSlots.getTypeInSlot(i), i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4))));
}
//inventory slots
for (i = 0; i < 3; ++i) {
for (j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142));
//hotbar slots
for (i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj));
}
/**
* Called when the container is closed.
*/
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
for (int i = 0; i < 4; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
player.dropPlayerItemWithRandomChoice(itemstack, false);
}
}
this.craftResult.setInventorySlotContents(0, (ItemStack)null);
if (!player.worldObj.isRemote) {
PlayerHandler.setPlayerBaubles(player, baubles);
}
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@@ -135,171 +81,82 @@ public class ContainerPlayerExpanded extends Container
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
Slot slot = (Slot)inventorySlots.get(slotIndex);
final int baubleSlots = BaubleExpandedSlots.getTotalSlots();
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, true))
{
Item item = itemstack.getItem();
if (slotIndex >= 5 && slotIndex < 4) {
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false)) {
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 >= 1 && par2 < 5)
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false))
{
} else if (item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) {
int j = ((ItemArmor)item).armorType;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (par2 >= 5 && par2 < 9)
//TODO: rewrite bauble shift clicking
} else if (item instanceof IBauble &&
((IBauble)item).getBaubleType(itemstack)==BaubleType.AMULET &&
((IBauble)item).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(4)).getHasStack())
{
if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false))
{
int j = 4;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof ItemArmor &&
!((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack())
{
int j = 5 + ((ItemArmor)itemstack.getItem()).armorType;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex>11 && item instanceof IBauble &&
((IBauble)item).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)item).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(5)).getHasStack()) {
int j = 5;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.AMULET &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(9)).getHasStack())
{
int j = 9;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex>11 && item instanceof IBauble &&
((IBauble)item).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)item).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(6)).getHasStack()) {
int j = 6;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (par2>11 && itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(10)).getHasStack())
{
int j = 10;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (item instanceof IBauble &&
((IBauble)item).getBaubleType(itemstack)==BaubleType.BELT &&
((IBauble)item).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(7)).getHasStack()) {
int j = 7;
if (!this.mergeItemStack(itemstack1, j, j + 1, false)) {
return null;
}
}
else if (par2>11 && itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(11)).getHasStack())
{
int j = 11;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex >= 4 + baubleSlots && slotIndex < 31 + baubleSlots) {
if (!this.mergeItemStack(itemstack1, 31 + baubleSlots, 40 + baubleSlots, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.BELT &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(12)).getHasStack())
{
int j = 12;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
} else if (slotIndex >= 31 + baubleSlots && slotIndex < 40 + baubleSlots) {
if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 31 + baubleSlots, false)) {
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.HEAD &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(13)).getHasStack())
{
int j = 13;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.BODY &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(14)).getHasStack())
{
int j = 14;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.CHARM &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(15)).getHasStack())
{
int j = 15;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (itemstack.getItem() instanceof IBauble &&
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.GAUNTLET &&
((IBauble)itemstack.getItem()).canEquip(itemstack, thePlayer) &&
!((Slot)this.inventorySlots.get(16)).getHasStack())
{
int j = 16;
if (!this.mergeItemStack(itemstack1, j, j + 1, false))
{
return null;
}
}
else if (par2 >= 9+4 && par2 < 36+4)
{
if (!this.mergeItemStack(itemstack1, 36+4, 45+4, false))
{
return null;
}
}
else if (par2 >= 36+4 && par2 < 45+4)
{
if (!this.mergeItemStack(itemstack1, 9+4, 36+4, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 9+4, 45+4, false, slot))
{
} else if (!this.mergeItemStack(itemstack1, 4 + baubleSlots, 40 + baubleSlots, false, slot)) {
return null;
}
if (itemstack1.stackSize == 0)
{
if (itemstack1.stackSize == 0) {
slot.putStack((ItemStack)null);
}
else
{
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
if (itemstack1.stackSize == itemstack.stackSize) {
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
@@ -310,102 +167,77 @@ public class ContainerPlayerExpanded extends Container
// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer);
// }
}
@Override
public void putStacksInSlots(ItemStack[] p_75131_1_) {
baubles.blockEvents=true;
super.putStacksInSlots(p_75131_1_);
}
protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4, Slot ss)
{
protected boolean mergeItemStack(ItemStack itemStack, int par2, int par3, boolean par4, Slot ss) {
boolean flag1 = false;
int k = par2;
if (par4)
{
if (par4) {
k = par3 - 1;
}
Slot slot;
ItemStack itemstack1;
if (par1ItemStack.isStackable())
{
while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2))
{
if (itemStack.isStackable()) {
while (itemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) {
slot = (Slot)this.inventorySlots.get(k);
itemstack1 = slot.getStack();
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))
{
int l = itemstack1.stackSize + par1ItemStack.stackSize;
if (l <= par1ItemStack.getMaxStackSize())
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
par1ItemStack.stackSize = 0;
if (itemstack1 != null && itemstack1.getItem() == itemStack.getItem() && (!itemStack.getHasSubtypes() || itemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemStack, itemstack1)) {
int l = itemstack1.stackSize + itemStack.stackSize;
if (l <= itemStack.getMaxStackSize()) {
if (ss instanceof SlotBauble) unequipBauble(itemStack);
itemStack.stackSize = 0;
itemstack1.stackSize = l;
slot.onSlotChanged();
flag1 = true;
}
else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize())
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = par1ItemStack.getMaxStackSize();
} else if (itemstack1.stackSize < itemStack.getMaxStackSize()) {
if (ss instanceof SlotBauble) unequipBauble(itemStack);
itemStack.stackSize -= itemStack.getMaxStackSize() - itemstack1.stackSize;
itemstack1.stackSize = itemStack.getMaxStackSize();
slot.onSlotChanged();
flag1 = true;
}
}
if (par4)
{
if (par4) {
--k;
}
else
{
} else {
++k;
}
}
}
if (par1ItemStack.stackSize > 0)
{
if (par4)
{
if (itemStack.stackSize > 0) {
if (par4) {
k = par3 - 1;
}
else
{
} else {
k = par2;
}
while (!par4 && k < par3 || par4 && k >= par2)
{
while (!par4 && k < par3 || par4 && k >= par2) {
slot = (Slot)this.inventorySlots.get(k);
itemstack1 = slot.getStack();
if (itemstack1 == null)
{
if (ss instanceof SlotBauble) unequipBauble(par1ItemStack);
slot.putStack(par1ItemStack.copy());
if (itemstack1 == null) {
if (ss instanceof SlotBauble) unequipBauble(itemStack);
slot.putStack(itemStack.copy());
slot.onSlotChanged();
par1ItemStack.stackSize = 0;
itemStack.stackSize = 0;
flag1 = true;
break;
}
if (par4)
{
if (par4) {
--k;
}
else
{
} else {
++k;
}
}
@@ -414,11 +246,8 @@ public class ContainerPlayerExpanded extends Container
}
@Override
public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot)
{
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
public boolean func_94530_a(ItemStack itemStack, Slot slot) {
return slot.inventory != this.craftResult && super.func_94530_a(itemStack, slot);
}
}