Fix JABBA-related issues with crafting station slots (#54)

* Fix shift-merging tools voiding items

fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392>

* Change 0-sized ItemStacks into null stacks in crafting station attached slots

Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425>

* Update buildscript

* spotlessApply
This commit is contained in:
Raven Szewczyk authored and GitHub committed 2022-09-22 20:51:23 +02:00
1 parent 18bfeaff32
commit 39be06c23b
571 files changed
+25959 -28223

No files matched your search

@@ -1,10 +1,9 @@
package tconstruct.armor.player;
import java.io.IOException;
import java.lang.ref.WeakReference;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.lang.ref.WeakReference;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@@ -13,126 +12,99 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class KnapsackInventory implements IInventory
{
public class KnapsackInventory implements IInventory {
public ItemStack[] inventory = new ItemStack[27];
public WeakReference<EntityPlayer> parent;
public void init (EntityPlayer player)
{
public void init(EntityPlayer player) {
parent = new WeakReference<EntityPlayer>(player);
}
@Override
public ItemStack getStackInSlot (int slot)
{
public ItemStack getStackInSlot(int slot) {
return inventory[slot];
}
public boolean isStackInSlot (int slot)
{
public boolean isStackInSlot(int slot) {
return inventory[slot] != null;
}
@Override
public int getSizeInventory ()
{
public int getSizeInventory() {
return inventory.length;
}
@Override
public int getInventoryStackLimit ()
{
public int getInventoryStackLimit() {
return 64;
}
public boolean canDropInventorySlot (int slot)
{
public boolean canDropInventorySlot(int slot) {
return true;
}
@Override
public void setInventorySlotContents (int slot, ItemStack itemstack)
{
public void setInventorySlotContents(int slot, ItemStack itemstack) {
inventory[slot] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
itemstack.stackSize = getInventoryStackLimit();
}
}
@Override
public ItemStack decrStackSize (int slot, int quantity)
{
if (inventory[slot] != null)
{
if (inventory[slot].stackSize <= quantity)
{
public ItemStack decrStackSize(int slot, int quantity) {
if (inventory[slot] != null) {
if (inventory[slot].stackSize <= quantity) {
ItemStack stack = inventory[slot];
inventory[slot] = null;
return stack;
}
ItemStack split = inventory[slot].splitStack(quantity);
if (inventory[slot].stackSize == 0)
{
if (inventory[slot].stackSize == 0) {
inventory[slot] = null;
}
return split;
}
else
{
} else {
return null;
}
}
@Override
public String getInventoryName ()
{
public String getInventoryName() {
return "tconstruct.knapsack";
}
@Override
public boolean hasCustomInventoryName ()
{
public boolean hasCustomInventoryName() {
return false;
}
@Override
public ItemStack getStackInSlotOnClosing (int slot)
{
public ItemStack getStackInSlotOnClosing(int slot) {
return null;
}
public void openChest ()
{
}
public void openChest() {}
public void closeChest ()
{
}
public void closeChest() {}
@Override
public boolean isItemValidForSlot (int i, ItemStack itemstack)
{
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return true;
}
@Override
public boolean isUseableByPlayer (EntityPlayer entityplayer)
{
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
/* Save/Load */
public void saveToNBT (NBTTagCompound tagCompound)
{
public void saveToNBT(NBTTagCompound tagCompound) {
NBTTagList tagList = new NBTTagList();
NBTTagCompound invSlot;
for (int i = 0; i < this.inventory.length; ++i)
{
if (this.inventory[i] != null)
{
for (int i = 0; i < this.inventory.length; ++i) {
if (this.inventory[i] != null) {
invSlot = new NBTTagCompound();
invSlot.setByte("Slot", (byte) i);
this.inventory[i].writeToNBT(invSlot);
@@ -143,36 +115,28 @@ public class KnapsackInventory implements IInventory
tagCompound.setTag("Knapsack", tagList);
}
public void readFromNBT (NBTTagCompound tagCompound)
{
public void readFromNBT(NBTTagCompound tagCompound) {
// player doesn't have a knapsack saved, tcon probably wasn't present before. don't error out.
if(tagCompound == null || !tagCompound.hasKey("Knapsack"))
return;
if (tagCompound == null || !tagCompound.hasKey("Knapsack")) return;
NBTTagList tagList = tagCompound.getTagList("Knapsack", 10);
for (int i = 0; i < tagList.tagCount(); ++i)
{
for (int i = 0; i < tagList.tagCount(); ++i) {
NBTTagCompound nbttagcompound = (NBTTagCompound) tagList.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);
if (itemstack != null)
{
if (itemstack != null) {
this.inventory[j] = itemstack;
}
}
}
public void dropItems ()
{
public void dropItems() {
EntityPlayer player = parent.get();
if (player != null)
{
for (int i = 0; i < inventory.length; ++i)
{
if (this.inventory[i] != null)
{
if (player != null) {
for (int i = 0; i < inventory.length; ++i) {
if (this.inventory[i] != null) {
player.func_146097_a(this.inventory[i], true, false);
this.inventory[i] = null;
}
@@ -180,16 +144,12 @@ public class KnapsackInventory implements IInventory
}
}
public void unequipItems ()
{
public void unequipItems() {
EntityPlayer player = parent.get();
if (player != null)
{
for (int i = 0; i < inventory.length; ++i)
{
if (this.inventory[i] != null)
{
if (player != null) {
for (int i = 0; i < inventory.length; ++i) {
if (this.inventory[i] != null) {
dropItemEntity(player, inventory[i]);
this.inventory[i] = null;
}
@@ -197,37 +157,25 @@ public class KnapsackInventory implements IInventory
}
}
void dropItemEntity (Entity dropper, ItemStack dropStack)
{
void dropItemEntity(Entity dropper, ItemStack dropStack) {
EntityItem entityitem = new EntityItem(dropper.worldObj, dropper.posX, dropper.posY, dropper.posZ, dropStack);
dropper.worldObj.spawnEntityInWorld(entityitem);
}
@Override
public void markDirty ()
{
}
public void markDirty() {}
@Override
public void openInventory ()
{
}
public void openInventory() {}
@Override
public void closeInventory ()
{
public void closeInventory() {}
public void writeInventoryToStream(ByteBuf os) throws IOException {
for (int i = 0; i < 27; i++) ByteBufUtils.writeItemStack(os, inventory[i]);
}
public void writeInventoryToStream (ByteBuf os) throws IOException
{
for (int i = 0; i < 27; i++)
ByteBufUtils.writeItemStack(os, inventory[i]);
public void readInventoryFromStream(ByteBuf is) throws IOException {
for (int i = 0; i < 27; i++) inventory[i] = ByteBufUtils.readItemStack(is);
}
public void readInventoryFromStream (ByteBuf is) throws IOException
{
for (int i = 0; i < 27; i++)
inventory[i] = ByteBufUtils.readItemStack(is);
}
}
}