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

@@ -27,55 +27,46 @@ import tconstruct.tools.inventory.FurnaceContainer;
* 3-16: Chest
*/
public class FurnaceLogic extends InventoryLogic implements IActiveLogic, IFacingLogic, ISidedInventory
{
public class FurnaceLogic extends InventoryLogic implements IActiveLogic, IFacingLogic, ISidedInventory {
boolean active = false;
public int fuel;
public int fuelGague;
public int progress;
public int fuelScale = 200;
byte direction;
private static final int[] slots_top = new int[] { 0 };
private static final int[] slots_bottom = new int[] { 2, 1 };
private static final int[] slots_sides = new int[] { 1 };
private static final int[] slots_top = new int[] {0};
private static final int[] slots_bottom = new int[] {2, 1};
private static final int[] slots_sides = new int[] {1};
public FurnaceLogic()
{
public FurnaceLogic() {
super(3);
}
@Override
public String getDefaultName ()
{
public String getDefaultName() {
return "container.furnace";
}
@Override
public boolean getActive ()
{
public boolean getActive() {
return active;
}
@Override
public void setActive (boolean flag)
{
public void setActive(boolean flag) {
active = flag;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
/* Fuel gauge */
public int gaugeProgressScaled (int scale)
{
public int gaugeProgressScaled(int scale) {
return (progress * scale) / fuelScale;
}
public int gaugeFuelScaled (int scale)
{
if (fuelGague == 0)
{
public int gaugeFuelScaled(int scale) {
if (fuelGague == 0) {
fuelGague = fuel;
if (fuelGague == 0)
{
if (fuelGague == 0) {
fuelGague = fuelScale;
}
}
@@ -84,175 +75,133 @@ public class FurnaceLogic extends InventoryLogic implements IActiveLogic, IFacin
/* Item cooking */
@Override
public void updateEntity ()
{
public void updateEntity() {
boolean burning = isBurning();
boolean updateInventory = false;
if (fuel <= 0 && canSmelt())
{
if (fuel <= 0 && canSmelt()) {
fuel = fuelGague = (int) (getItemBurnTime(inventory[1]));
if (fuel > 0)
{
if (fuel > 0) {
if (inventory[1].getItem().hasContainerItem()) // Fuel slot
{
inventory[1] = new ItemStack(inventory[1].getItem().getContainerItem());
}
else
{
} else {
inventory[1].stackSize--;
}
if (inventory[1].stackSize <= 0)
{
if (inventory[1].stackSize <= 0) {
inventory[1] = null;
}
updateInventory = true;
}
}
if (isBurning() && canSmelt())
{
if (isBurning() && canSmelt()) {
progress++;
if (progress >= fuelScale)
{
if (progress >= fuelScale) {
progress = 0;
cookItems();
updateInventory = true;
}
}
else
{
} else {
progress = 0;
}
if (fuel > 0)
{
if (fuel > 0) {
fuel--;
}
if (burning != isBurning())
{
if (burning != isBurning()) {
setActive(isBurning());
updateInventory = true;
}
if (updateInventory)
{
if (updateInventory) {
markDirty();
}
}
public void cookItems ()
{
if (this.canSmelt())
{
public void cookItems() {
if (this.canSmelt()) {
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]);
if (this.inventory[2] == null)
{
if (this.inventory[2] == null) {
this.inventory[2] = itemstack.copy();
}
else if (this.inventory[2].isItemEqual(itemstack))
{
} else if (this.inventory[2].isItemEqual(itemstack)) {
inventory[2].stackSize += itemstack.stackSize;
}
--this.inventory[0].stackSize;
if (this.inventory[0].stackSize <= 0)
{
if (this.inventory[0].stackSize <= 0) {
this.inventory[0] = null;
}
}
}
public boolean canSmelt ()
{
public boolean canSmelt() {
if (inventory[0] == null) // Nothing here!
return false;
else
{
return false;
else {
ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.inventory[0]);
if (itemstack == null)
return false;
if (this.inventory[2] == null)
return true;
if (!this.inventory[2].isItemEqual(itemstack))
return false;
if (itemstack == null) return false;
if (this.inventory[2] == null) return true;
if (!this.inventory[2].isItemEqual(itemstack)) return false;
int result = inventory[2].stackSize + itemstack.stackSize;
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
}
public boolean isBurning ()
{
public boolean isBurning() {
return fuel > 0;
}
public ItemStack getResultFor (ItemStack stack)
{
public ItemStack getResultFor(ItemStack stack) {
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack);
if (result != null) // Only valid for food
return result.copy();
return result.copy();
return null;
}
public static int getItemBurnTime (ItemStack stack)
{
if (stack == null)
{
public static int getItemBurnTime(ItemStack stack) {
if (stack == null) {
return 0;
}
else
{
} else {
Item item = stack.getItem();
if (stack.getItem() instanceof ItemBlock && BlockUtils.getBlockFromItem(item) != null)
{
if (stack.getItem() instanceof ItemBlock && BlockUtils.getBlockFromItem(item) != null) {
Block block = BlockUtils.getBlockFromItem(item);
if (block == Blocks.wooden_slab)
{
if (block == Blocks.wooden_slab) {
return 150;
}
if (block == Blocks.log)
{
if (block == Blocks.log) {
return 1200;
}
if (block.getMaterial() == Material.wood)
{
if (block.getMaterial() == Material.wood) {
return 300;
}
if (block == Blocks.coal_block)
{
if (block == Blocks.coal_block) {
return 16000;
}
}
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD"))
return 200;
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD"))
return 200;
if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD"))
return 200;
if (item == Items.stick)
return 100;
if (item == Items.coal)
return 1600;
if (item == Items.lava_bucket)
return 20000;
if (item == new ItemStack(Blocks.sapling).getItem())
return 100;
if (item == Items.blaze_rod)
return 2400;
if (item instanceof ItemTool
&& ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemSword
&& ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemHoe
&& ((ItemHoe) item).getToolMaterialName().equals("WOOD")) return 200;
if (item == Items.stick) return 100;
if (item == Items.coal) return 1600;
if (item == Items.lava_bucket) return 20000;
if (item == new ItemStack(Blocks.sapling).getItem()) return 100;
if (item == Items.blaze_rod) return 2400;
return GameRegistry.getFuelValue(stack);
}
}
/* NBT */
@Override
public void readFromNBT (NBTTagCompound tags)
{
public void readFromNBT(NBTTagCompound tags) {
super.readFromNBT(tags);
active = tags.getBoolean("Active");
fuel = tags.getInteger("Fuel");
@@ -261,140 +210,118 @@ public class FurnaceLogic extends InventoryLogic implements IActiveLogic, IFacin
}
@Override
public void writeToNBT (NBTTagCompound tags)
{
public void writeToNBT(NBTTagCompound tags) {
super.writeToNBT(tags);
tags.setInteger("Fuel", fuel);
tags.setInteger("FuelGague", fuelGague);
writeNetworkNBT(tags);
}
public void readNetworkNBT (NBTTagCompound tags)
{
public void readNetworkNBT(NBTTagCompound tags) {
active = tags.getBoolean("Active");
direction = tags.getByte("Direction");
}
public void writeNetworkNBT (NBTTagCompound tags)
{
public void writeNetworkNBT(NBTTagCompound tags) {
tags.setBoolean("Active", active);
tags.setByte("Direction", direction);
}
/* Packets */
@Override
public Packet getDescriptionPacket ()
{
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
writeNetworkNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
}
@Override
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
{
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readNetworkNBT(packet.func_148857_g());
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
@Override
public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z)
{
public Container getGuiContainer(InventoryPlayer inventoryplayer, World world, int x, int y, int z) {
return new FurnaceContainer(inventoryplayer, this);
}
@Override
public byte getRenderDirection ()
{
public byte getRenderDirection() {
return direction;
}
@Override
public ForgeDirection getForgeDirection ()
{
public ForgeDirection getForgeDirection() {
return ForgeDirection.VALID_DIRECTIONS[direction];
}
@Override
@Deprecated
public void setDirection (int side)
{
public void setDirection(int side) {
// Nope!
}
@Override
@Deprecated
public void setDirection (float yaw, float pitch, EntityLivingBase player)
{
public void setDirection(float yaw, float pitch, EntityLivingBase player) {
int facing = MathHelper.floor_double((double) (yaw / 360) + 0.5D) & 3;
switch (facing)
{
case 0:
direction = 2;
break;
switch (facing) {
case 0:
direction = 2;
break;
case 1:
direction = 5;
break;
case 1:
direction = 5;
break;
case 2:
direction = 3;
break;
case 2:
direction = 3;
break;
case 3:
direction = 4;
break;
case 3:
direction = 4;
break;
}
}
@Override
public String getInventoryName ()
{
public String getInventoryName() {
return getDefaultName();
}
@Override
public boolean hasCustomInventoryName ()
{
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void openInventory ()
{
}
public void openInventory() {}
@Override
public void closeInventory ()
{
}
public void closeInventory() {}
public static boolean isItemFuel (ItemStack par0ItemStack)
{
public static boolean isItemFuel(ItemStack par0ItemStack) {
return getItemBurnTime(par0ItemStack) > 0;
}
@Override
public boolean isItemValidForSlot (int par1, ItemStack par2ItemStack)
{
public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) {
return par1 == 2 ? false : (par1 == 1 ? isItemFuel(par2ItemStack) : true);
}
@Override
public int[] getAccessibleSlotsFromSide (int par1)
{
public int[] getAccessibleSlotsFromSide(int par1) {
return par1 == 0 ? slots_bottom : (par1 == 1 ? slots_top : slots_sides);
}
@Override
public boolean canInsertItem (int par1, ItemStack par2ItemStack, int par3)
{
public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3) {
return this.isItemValidForSlot(par1, par2ItemStack);
}
@Override
public boolean canExtractItem (int par1, ItemStack par2ItemStack, int par3)
{
public boolean canExtractItem(int par1, ItemStack par2ItemStack, int par3) {
return par3 != 0 || par1 != 1 || par2ItemStack.getItem() == Items.bucket;
}
}