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

@@ -14,11 +14,9 @@ import tconstruct.TConstruct;
/**
* @author BluSunrize
*/
public class CastingChannelLogic extends TileEntity implements IFluidHandler
{
public final static int fillMax = TConstruct.ingotLiquidValue * 3;
public final static int outputMax = TConstruct.ingotLiquidValue;
public class CastingChannelLogic extends TileEntity implements IFluidHandler {
public static final int fillMax = TConstruct.ingotLiquidValue * 3;
public static final int outputMax = TConstruct.ingotLiquidValue;
FluidTank internalTank = new FluidTank(fillMax);
HashMap<ForgeDirection, FluidTank> subTanks = new HashMap();
public ForgeDirection lastProvider;
@@ -30,8 +28,7 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
public CastingChannelMode mode = CastingChannelMode.SINGLEDRAIN;
*/
public CastingChannelLogic()
{
public CastingChannelLogic() {
lastProvider = ForgeDirection.UNKNOWN;
validOutputs.add(ForgeDirection.DOWN);
validOutputs.add(ForgeDirection.NORTH);
@@ -46,8 +43,7 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
}
@Override
public void updateEntity ()
{
public void updateEntity() {
ticks++;
boolean flagActiveFaucet = false;
@@ -56,21 +52,18 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
if (possibleFaucet != null && possibleFaucet instanceof FaucetLogic)
flagActiveFaucet = ((FaucetLogic) possibleFaucet).active;
if (ticks == 6)// && !flagActiveFaucet)
this.distributeFluids();
if (ticks >= 12)// && !flagActiveFaucet)
if (ticks == 6) // && !flagActiveFaucet)
this.distributeFluids();
if (ticks >= 12) // && !flagActiveFaucet)
{
if (recentlyFilledDelay != 0)
recentlyFilledDelay--;
if (recentlyFilledDelay == 0 || lastProvider == ForgeDirection.UP)
this.outputFluids();
if (recentlyFilledDelay != 0) recentlyFilledDelay--;
if (recentlyFilledDelay == 0 || lastProvider == ForgeDirection.UP) this.outputFluids();
ticks = 0;
}
}
public void changeOutputs (EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
public void changeOutputs(EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
/*
* UNUSED
if(player.isSneaking())
@@ -88,104 +81,69 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
*/
ForgeDirection toggle = ForgeDirection.UNKNOWN;
if (side == 0 || side == 1)
{
if (hitX > 0.3125 && hitX < 0.6875)
if (hitZ > 0 && hitZ < 0.3125)
toggle = ForgeDirection.NORTH;
if (hitX > 0.3125 && hitX < 0.6875)
if (hitZ > 0.6875 && hitZ < 1)
toggle = ForgeDirection.SOUTH;
if (hitZ > 0.3125 && hitZ < 0.6875)
if (hitX > 0 && hitX < 0.3125)
toggle = ForgeDirection.WEST;
if (hitZ > 0.3125 && hitZ < 0.6875)
if (hitX > 0.6875 && hitX < 1)
toggle = ForgeDirection.EAST;
if (side == 0 || side == 1) {
if (hitX > 0.3125 && hitX < 0.6875) if (hitZ > 0 && hitZ < 0.3125) toggle = ForgeDirection.NORTH;
if (hitX > 0.3125 && hitX < 0.6875) if (hitZ > 0.6875 && hitZ < 1) toggle = ForgeDirection.SOUTH;
if (hitZ > 0.3125 && hitZ < 0.6875) if (hitX > 0 && hitX < 0.3125) toggle = ForgeDirection.WEST;
if (hitZ > 0.3125 && hitZ < 0.6875) if (hitX > 0.6875 && hitX < 1) toggle = ForgeDirection.EAST;
if (side == 0)
if (hitX > 0.3125 && hitX < 0.6875)
if (hitZ > 0.3125 && hitZ < 0.6875)
toggle = ForgeDirection.DOWN;
}
else
{
if (side == 2)
{
if (hitX > 0 && hitX < 0.3125)
toggle = ForgeDirection.WEST;
if (hitX > 0.6875 && hitX < 1)
toggle = ForgeDirection.EAST;
if (hitX > 0.3125 && hitX < 0.6875) if (hitZ > 0.3125 && hitZ < 0.6875) toggle = ForgeDirection.DOWN;
} else {
if (side == 2) {
if (hitX > 0 && hitX < 0.3125) toggle = ForgeDirection.WEST;
if (hitX > 0.6875 && hitX < 1) toggle = ForgeDirection.EAST;
}
if (side == 3)
{
if (hitX > 0 && hitX < 0.3125)
toggle = ForgeDirection.WEST;
if (hitX > 0.6875 && hitX < 1)
toggle = ForgeDirection.EAST;
if (side == 3) {
if (hitX > 0 && hitX < 0.3125) toggle = ForgeDirection.WEST;
if (hitX > 0.6875 && hitX < 1) toggle = ForgeDirection.EAST;
}
if (side == 4)
{
if (hitZ > 0 && hitZ < 0.3125)
toggle = ForgeDirection.NORTH;
if (hitZ > 0.6875 && hitZ < 1)
toggle = ForgeDirection.SOUTH;
if (side == 4) {
if (hitZ > 0 && hitZ < 0.3125) toggle = ForgeDirection.NORTH;
if (hitZ > 0.6875 && hitZ < 1) toggle = ForgeDirection.SOUTH;
}
if (side == 5)
{
if (hitZ > 0 && hitZ < 0.3125)
toggle = ForgeDirection.NORTH;
if (hitZ > 0.6875 && hitZ < 1)
toggle = ForgeDirection.SOUTH;
if (side == 5) {
if (hitZ > 0 && hitZ < 0.3125) toggle = ForgeDirection.NORTH;
if (hitZ > 0.6875 && hitZ < 1) toggle = ForgeDirection.SOUTH;
}
}
if (toggle != ForgeDirection.UNKNOWN && toggle != ForgeDirection.UP)
{
TileEntity tile = worldObj.getTileEntity(xCoord + toggle.offsetX, yCoord + toggle.offsetY, zCoord + toggle.offsetZ);
if (toggle != ForgeDirection.UNKNOWN && toggle != ForgeDirection.UP) {
TileEntity tile =
worldObj.getTileEntity(xCoord + toggle.offsetX, yCoord + toggle.offsetY, zCoord + toggle.offsetZ);
if (tile instanceof IFluidHandler)
if (validOutputs.contains(toggle))
{
if (validOutputs.contains(toggle)) {
validOutputs.remove(toggle);
if (tile instanceof CastingChannelLogic && toggle != ForgeDirection.DOWN)
((CastingChannelLogic) tile).validOutputs.remove(toggle.getOpposite());
}
else
{
} else {
validOutputs.add(toggle);
if (tile instanceof CastingChannelLogic && toggle != ForgeDirection.DOWN)
if (!((CastingChannelLogic) tile).validOutputs.contains(toggle.getOpposite()))
((CastingChannelLogic) tile).validOutputs.add(toggle.getOpposite());
}
}
markDirtyForRendering();
}
private void distributeFluids ()
{
private void distributeFluids() {
/* DEBUG
boolean printDebugLog = false;
ArrayList<String> debugLog = new ArrayList();
*/
//Move Fluid to Output Tanks
// Move Fluid to Output Tanks
Set<ForgeDirection> connected = this.getOutputs().keySet();
if (connected.contains(ForgeDirection.DOWN))
connected.remove(ForgeDirection.DOWN);
if (connected.contains(lastProvider))
connected.remove(lastProvider);
if (connected.contains(ForgeDirection.DOWN)) connected.remove(ForgeDirection.DOWN);
if (connected.contains(lastProvider)) connected.remove(lastProvider);
int output = Math.min(internalTank.getFluidAmount(), outputMax);
int connectedAmount = connected.size();
if (connectedAmount < 1)
connectedAmount = 1;
if (connectedAmount < 1) connectedAmount = 1;
int scaledAmount = output / connectedAmount;
for (ForgeDirection dirOut : connected)
{
if (this.internalTank.getFluid() == null)
break;
for (ForgeDirection dirOut : connected) {
if (this.internalTank.getFluid() == null) break;
/* DEBUG
debugLog.add("Moving to "+dirOut+"ern SubTank");
@@ -195,8 +153,7 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
/* DEBUG
debugLog.add("SubTank will accept "+fit+"mb");
*/
if (fit > 0)
fit = internalTank.drain(fit, true).amount;
if (fit > 0) fit = internalTank.drain(fit, true).amount;
/* DEBUG
debugLog.add("Internal Tank was drained by "+fit+"mb");
*/
@@ -221,20 +178,20 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
printDebugLog = false;
*/
//Get Fluid from most recent InputTank
// Get Fluid from most recent InputTank
FluidTank inputTank = subTanks.get(lastProvider);
if (inputTank != null && inputTank.getFluid() != null) //Tank can be null if input was received from top
if (inputTank != null && inputTank.getFluid() != null) // Tank can be null if input was received from top
{
/* DEBUG
debugLog.add("Importing from "+lastProvider+"ern SubTank");
*/
FluidStack tempFS = new FluidStack(inputTank.getFluid().getFluid(), Math.min(inputTank.getFluidAmount(), outputMax));
FluidStack tempFS =
new FluidStack(inputTank.getFluid().getFluid(), Math.min(inputTank.getFluidAmount(), outputMax));
int fit = internalTank.fill(tempFS, false);
/* DEBUG
debugLog.add("Internal Tank will accept "+fit+"mb");
*/
if (fit > 0)
fit = inputTank.drain(fit, true).amount;
if (fit > 0) fit = inputTank.drain(fit, true).amount;
/* DEBUG
debugLog.add("Import Tank was drained by "+fit+"mb");
*/
@@ -259,44 +216,42 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
*/
}
private void outputFluids ()
{
private void outputFluids() {
/* DEBUG
boolean printDebugLog = false;
ArrayList<String> debugLog = new ArrayList();
*/
HashMap<ForgeDirection, TileEntity> connected = this.getOutputs();
if (connected.containsKey(lastProvider))
connected.remove(lastProvider);
if (connected.containsKey(ForgeDirection.DOWN) && this.internalTank.getFluid() != null) // Prioritizes FluidHandlers below
if (connected.containsKey(lastProvider)) connected.remove(lastProvider);
if (connected.containsKey(ForgeDirection.DOWN)
&& this.internalTank.getFluid() != null) // Prioritizes FluidHandlers below
{
int output = Math.min(internalTank.getFluid().amount, outputMax);
FluidStack tempFS = new FluidStack(internalTank.getFluid().getFluid(), output);
int fittingBelow = ((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, false);
if (fittingBelow > 0)
fittingBelow = this.drain(ForgeDirection.DOWN, fittingBelow, true).amount;
int fittingBelow =
((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, false);
if (fittingBelow > 0) fittingBelow = this.drain(ForgeDirection.DOWN, fittingBelow, true).amount;
tempFS.amount = fittingBelow;
fittingBelow = ((IFluidHandler) connected.get(ForgeDirection.DOWN)).fill(ForgeDirection.UP, tempFS, true);
connected.remove(ForgeDirection.DOWN);
}
if (connected.size() != 0)
{
for (ForgeDirection dir : connected.keySet()) //Iterates to connected FluidHandlers
if (connected.size() != 0) {
for (ForgeDirection dir : connected.keySet()) // Iterates to connected FluidHandlers
{
if (subTanks.get(dir) != null && subTanks.get(dir).getFluid() != null)
{
if (subTanks.get(dir) != null && subTanks.get(dir).getFluid() != null) {
/* DEBUG
debugLog.add("Exporting from "+dir+"ern SubTank");
*/
FluidStack tempFS = new FluidStack(subTanks.get(dir).getFluid().getFluid(), Math.min(subTanks.get(dir).getFluidAmount(), outputMax));
FluidStack tempFS = new FluidStack(
subTanks.get(dir).getFluid().getFluid(),
Math.min(subTanks.get(dir).getFluidAmount(), outputMax));
int fit = ((IFluidHandler) connected.get(dir)).fill(dir.getOpposite(), tempFS, false);
/* DEBUG
debugLog.add("New Channel will accept "+fit+"mb");
*/
if (fit > 0)
fit = this.drain(dir, fit, true).amount;
if (fit > 0) fit = this.drain(dir, fit, true).amount;
/* DEBUG
debugLog.add("OldSubTank was drained by "+fit+"mb");
*/
@@ -320,92 +275,77 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
}
@SideOnly(Side.CLIENT)
public float tankBelow ()
{
public float tankBelow() {
TileEntity te = this.worldObj.getTileEntity(this.xCoord, this.yCoord - 1, this.zCoord);
if (te instanceof CastingChannelLogic)
return -0.5f;
if (te instanceof LavaTankLogic)
return -1.0f;
if (te instanceof CastingBasinLogic)
return -0.75f;
if (te instanceof CastingTableLogic)
return -0.125f;
if (te instanceof IFluidHandler)
return 0f;
if (te instanceof CastingChannelLogic) return -0.5f;
if (te instanceof LavaTankLogic) return -1.0f;
if (te instanceof CastingBasinLogic) return -0.75f;
if (te instanceof CastingTableLogic) return -0.125f;
if (te instanceof IFluidHandler) return 0f;
return 0.5f;
}
private void markDirtyForRendering ()
{
private void markDirtyForRendering() {
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public HashMap<ForgeDirection, TileEntity> getOutputs ()
{
public HashMap<ForgeDirection, TileEntity> getOutputs() {
HashMap<ForgeDirection, TileEntity> map = new HashMap();
for (ForgeDirection fd : this.validOutputs)
{
for (ForgeDirection fd : this.validOutputs) {
int tX = this.xCoord + fd.offsetX;
int tY = this.yCoord + fd.offsetY;
int tZ = this.zCoord + fd.offsetZ;
TileEntity tile = this.worldObj.getTileEntity(tX, tY, tZ);
if (tile != null && tile instanceof IFluidHandler)
map.put(fd, tile);
if (tile != null && tile instanceof IFluidHandler) map.put(fd, tile);
}
return map;
}
@Override
public int fill (ForgeDirection from, FluidStack resource, boolean doFill)
{
if (doFill)
{
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (doFill) {
markDirtyForRendering();
this.lastProvider = from;
//if (this.internalTank.getFluid() == null)
//this.recentlyFilledDelay = 2;
// if (this.internalTank.getFluid() == null)
// this.recentlyFilledDelay = 2;
}
if (from == ForgeDirection.UP)
{
if (from == ForgeDirection.UP) {
return this.internalTank.fill(resource, doFill);
}
else if (from == ForgeDirection.NORTH || from == ForgeDirection.SOUTH || from == ForgeDirection.WEST || from == ForgeDirection.EAST)
{
} else if (from == ForgeDirection.NORTH
|| from == ForgeDirection.SOUTH
|| from == ForgeDirection.WEST
|| from == ForgeDirection.EAST) {
return this.subTanks.get(from).fill(resource, doFill);
}
return 0;
}
@Override
public FluidStack drain (ForgeDirection from, FluidStack resource, boolean doDrain)
{
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
FluidStack fluidStack = null;
if (from == ForgeDirection.DOWN)
if(this.internalTank.getFluid() != null)
fluidStack = this.internalTank.getFluid();
else if(validOutputs.contains(from))
if (this.internalTank.getFluid() != null) fluidStack = this.internalTank.getFluid();
else if (validOutputs.contains(from))
fluidStack = this.subTanks.get(from).getFluid();
// wrong fluid
if(fluidStack != null && fluidStack.getFluid() != resource.getFluid())
return null;
if (fluidStack != null && fluidStack.getFluid() != resource.getFluid()) return null;
return drain(from, resource.amount, doDrain);
}
@Override
public FluidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
{
//if(doDrain)
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
// if(doDrain)
// this.worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
if (from == ForgeDirection.DOWN)
return this.internalTank.drain(maxDrain, doDrain);
else if (from == ForgeDirection.NORTH || from == ForgeDirection.SOUTH || from == ForgeDirection.WEST || from == ForgeDirection.EAST)
{
if (from == ForgeDirection.DOWN) return this.internalTank.drain(maxDrain, doDrain);
else if (from == ForgeDirection.NORTH
|| from == ForgeDirection.SOUTH
|| from == ForgeDirection.WEST
|| from == ForgeDirection.EAST) {
return this.subTanks.get(from).drain(maxDrain, doDrain);
}
@@ -413,59 +353,45 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
}
@Override
public boolean canFill (ForgeDirection from, Fluid fluid)
{
if (from == ForgeDirection.DOWN)
return false;
if (from == ForgeDirection.UP)
return true;
public boolean canFill(ForgeDirection from, Fluid fluid) {
if (from == ForgeDirection.DOWN) return false;
if (from == ForgeDirection.UP) return true;
return validOutputs.contains(from);
}
@Override
public boolean canDrain (ForgeDirection from, Fluid fluid)
{
if (from == ForgeDirection.UP)
return false;
public boolean canDrain(ForgeDirection from, Fluid fluid) {
if (from == ForgeDirection.UP) return false;
return validOutputs.contains(from);
}
@Override
public FluidTankInfo[] getTankInfo (ForgeDirection from)
{
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
if (from == null || from == ForgeDirection.UP || from == ForgeDirection.DOWN || from == ForgeDirection.UNKNOWN)
return new FluidTankInfo[] { new FluidTankInfo(internalTank) };
else
return new FluidTankInfo[] { new FluidTankInfo(subTanks.get(from)) };
return new FluidTankInfo[] {new FluidTankInfo(internalTank)};
else return new FluidTankInfo[] {new FluidTankInfo(subTanks.get(from))};
}
@Override
public void readFromNBT (NBTTagCompound tags)
{
public void readFromNBT(NBTTagCompound tags) {
super.readFromNBT(tags);
readCustomNBT(tags);
}
public void readCustomNBT (NBTTagCompound tags)
{
public void readCustomNBT(NBTTagCompound tags) {
NBTTagCompound nbtTank = tags.getCompoundTag("internalTank");
if (nbtTank != null)
internalTank.readFromNBT(nbtTank);
if (nbtTank != null) internalTank.readFromNBT(nbtTank);
for (ForgeDirection fdSub : subTanks.keySet())
{
for (ForgeDirection fdSub : subTanks.keySet()) {
NBTTagCompound nbtSubTank = tags.getCompoundTag("subTank_" + fdSub.name());
if (nbtSubTank != null)
subTanks.get(fdSub).readFromNBT(nbtSubTank);
if (nbtSubTank != null) subTanks.get(fdSub).readFromNBT(nbtSubTank);
}
int[] validFDs = tags.getIntArray("validOutputs");
if (validFDs != null)
{
if (validFDs != null) {
validOutputs = new ArrayList();
for (int i : validFDs)
validOutputs.add(convertIntToFD(i));
for (int i : validFDs) validOutputs.add(convertIntToFD(i));
}
/* UNUSED
this.mode = CastingChannelMode.readFromNBT(tags);
@@ -474,19 +400,16 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
}
@Override
public void writeToNBT (NBTTagCompound tags)
{
public void writeToNBT(NBTTagCompound tags) {
super.writeToNBT(tags);
writeCustomNBT(tags);
}
public void writeCustomNBT (NBTTagCompound tags)
{
public void writeCustomNBT(NBTTagCompound tags) {
NBTTagCompound nbtTank = new NBTTagCompound();
internalTank.writeToNBT(nbtTank);
tags.setTag("internalTank", nbtTank);
for (ForgeDirection fdSub : subTanks.keySet())
{
for (ForgeDirection fdSub : subTanks.keySet()) {
NBTTagCompound nbtSubTank = new NBTTagCompound();
subTanks.get(fdSub).writeToNBT(nbtSubTank);
tags.setTag("subTank_" + fdSub.name(), nbtSubTank);
@@ -494,10 +417,8 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
int[] validFDs = new int[validOutputs.size()];
int it = 0;
for (ForgeDirection fd : validOutputs)
{
if (fd != null)
validFDs[it] = convertFDToInt(fd);
for (ForgeDirection fd : validOutputs) {
if (fd != null) validFDs[it] = convertFDToInt(fd);
it++;
}
tags.setIntArray("validOutputs", validFDs);
@@ -508,59 +429,53 @@ public class CastingChannelLogic extends TileEntity implements IFluidHandler
}
@Override
public Packet getDescriptionPacket ()
{
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
writeCustomNBT(tag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag);
}
@Override
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
{
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readCustomNBT(packet.func_148857_g());
this.worldObj.func_147479_m(this.xCoord, this.yCoord, this.zCoord);
}
public int convertFDToInt (ForgeDirection dir)
{
switch (dir)
{
case DOWN:
return 0;
case UP:
return 1;
case NORTH:
return 2;
case SOUTH:
return 3;
case WEST:
return 4;
case EAST:
return 5;
default:
return -1;
public int convertFDToInt(ForgeDirection dir) {
switch (dir) {
case DOWN:
return 0;
case UP:
return 1;
case NORTH:
return 2;
case SOUTH:
return 3;
case WEST:
return 4;
case EAST:
return 5;
default:
return -1;
}
}
public ForgeDirection convertIntToFD (int i)
{
switch (i)
{
case 0:
return ForgeDirection.DOWN;
case 1:
return ForgeDirection.UP;
case 2:
return ForgeDirection.NORTH;
case 3:
return ForgeDirection.SOUTH;
case 4:
return ForgeDirection.WEST;
case 5:
return ForgeDirection.EAST;
default:
return ForgeDirection.UNKNOWN;
public ForgeDirection convertIntToFD(int i) {
switch (i) {
case 0:
return ForgeDirection.DOWN;
case 1:
return ForgeDirection.UP;
case 2:
return ForgeDirection.NORTH;
case 3:
return ForgeDirection.SOUTH;
case 4:
return ForgeDirection.WEST;
case 5:
return ForgeDirection.EAST;
default:
return ForgeDirection.UNKNOWN;
}
}
/* UNUSED