Fixed NBT reference losses

This commit is contained in:
aidancbrady 2016-06-10 11:30:03 -04:00
parent e1a5bf13c7
commit 6340bb3cdc
9 changed files with 28 additions and 14 deletions

View file

@ -12,6 +12,7 @@ import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.IGridTransmitter;
import mekanism.common.util.LangUtils; import mekanism.common.util.LangUtils;
import mekanism.common.util.PipeUtils;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -164,7 +165,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(acceptor != null && fluidToSend != null) if(acceptor != null && fluidToSend != null)
{ {
fluidSent += acceptor.fill(side, new FluidStack(fluidToSend.getFluidID(), currentSending), doTransfer); fluidSent += acceptor.fill(side, PipeUtils.copy(fluidToSend, currentSending), doTransfer);
} }
if(fluidSent > prev) if(fluidSent > prev)

View file

@ -84,6 +84,7 @@ import mekanism.common.tile.TileEntitySolarNeutronActivator;
import mekanism.common.tile.TileEntityTeleporter; import mekanism.common.tile.TileEntityTeleporter;
import mekanism.common.util.LangUtils; import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
import mekanism.common.util.SecurityUtils; import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
@ -899,7 +900,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IBlo
if(itemFluid.amount-toFill > 0) if(itemFluid.amount-toFill > 0)
{ {
tileEntity.pushUp(new FluidStack(itemFluid.getFluid(), itemFluid.amount-toFill), true); tileEntity.pushUp(PipeUtils.copy(itemFluid, itemFluid.amount-toFill), true);
} }
return true; return true;

View file

@ -36,6 +36,7 @@ import mekanism.common.tile.TileEntityFactory;
import mekanism.common.tile.TileEntityFluidTank; import mekanism.common.tile.TileEntityFluidTank;
import mekanism.common.util.LangUtils; import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
import mekanism.common.util.SecurityUtils; import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -852,7 +853,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
if(doFill) if(doFill)
{ {
int fillAmount = toFill + (stored == null ? 0 : stored.amount); int fillAmount = toFill + (stored == null ? 0 : stored.amount);
setFluidStack(new FluidStack(resource.getFluid(), (stored != null ? stored.amount : 0)+toFill), container); setFluidStack(PipeUtils.copy(resource, (stored != null ? stored.amount : 0)+toFill), container);
} }
return toFill; return toFill;
@ -870,7 +871,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
if(stored != null) if(stored != null)
{ {
FluidStack toDrain = new FluidStack(stored.getFluid(), Math.min(stored.amount, maxDrain)); FluidStack toDrain = PipeUtils.copy(stored, Math.min(stored.amount, maxDrain));
if(doDrain) if(doDrain)
{ {

View file

@ -7,6 +7,7 @@ import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem; import mekanism.api.gas.IGasItem;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.util.LangUtils; import mekanism.common.util.LangUtils;
import mekanism.common.util.PipeUtils;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -164,7 +165,7 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
if(doFill) if(doFill)
{ {
int fillAmount = toFill + (stored == null ? 0 : stored.amount); int fillAmount = toFill + (stored == null ? 0 : stored.amount);
setFluid(container, new FluidStack(resource.getFluid(), (stored != null ? stored.amount : 0)+toFill)); setFluid(container, PipeUtils.copy(resource, (stored != null ? stored.amount : 0)+toFill));
} }
return toFill; return toFill;
@ -177,7 +178,7 @@ public class ItemGaugeDropper extends ItemMekanism implements IGasItem, IFluidCo
if(stored != null) if(stored != null)
{ {
FluidStack toDrain = new FluidStack(stored.getFluid(), Math.min(stored.amount, maxDrain)); FluidStack toDrain = PipeUtils.copy(stored, Math.min(stored.amount, maxDrain));
if(doDrain) if(doDrain)
{ {

View file

@ -104,7 +104,7 @@ public class PartMechanicalPipe extends PartTransmitter<IFluidHandler, FluidNetw
toSave += remain; toSave += remain;
} }
return new FluidStack(getTransmitter().getTransmitterNetwork().buffer.getFluid(), toSave); return PipeUtils.copy(getTransmitter().getTransmitterNetwork().buffer, toSave);
} }
return null; return null;

View file

@ -22,6 +22,7 @@ import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
import mekanism.common.util.InventoryUtils; import mekanism.common.util.InventoryUtils;
import mekanism.common.util.LangUtils; import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -183,13 +184,13 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
if(ret != null) if(ret != null)
{ {
fluidTank.setFluid(new FluidStack(ret.getFluid(), Math.min(fluidTank.getCapacity(), ret.amount))); fluidTank.setFluid(PipeUtils.copy(ret, Math.min(fluidTank.getCapacity(), ret.amount)));
int rejects = Math.max(0, ret.amount - fluidTank.getCapacity()); int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());
if(rejects > 0) if(rejects > 0)
{ {
pushUp(new FluidStack(ret.getFluid(), rejects), true); pushUp(PipeUtils.copy(ret, rejects), true);
} }
} }
} }
@ -204,13 +205,13 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
if(ret != null) if(ret != null)
{ {
fluidTank.setFluid(new FluidStack(ret.getFluid(), Math.min(fluidTank.getCapacity(), ret.amount))); fluidTank.setFluid(PipeUtils.copy(ret, Math.min(fluidTank.getCapacity(), ret.amount)));
int rejects = Math.max(0, ret.amount - fluidTank.getCapacity()); int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());
if(rejects > 0) if(rejects > 0)
{ {
pushUp(new FluidStack(ret.getFluid(), rejects), true); pushUp(PipeUtils.copy(ret, rejects), true);
} }
} }
} }
@ -464,7 +465,7 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
if(filled < resource.amount && !isActive) if(filled < resource.amount && !isActive)
{ {
filled += pushUp(new FluidStack(resource.getFluid(), resource.amount-filled), doFill); filled += pushUp(PipeUtils.copy(resource, resource.amount-filled), doFill);
} }
if(filled > 0 && from == ForgeDirection.UP) if(filled > 0 && from == ForgeDirection.UP)

View file

@ -703,6 +703,7 @@ public class TileEntityThermalEvaporationController extends TileEntityThermalEva
return side != 0 && side != 1; return side != 0 && side != 1;
} }
@Override
public TileEntityThermalEvaporationController getController() public TileEntityThermalEvaporationController getController()
{ {
return structured ? this : null; return structured ? this : null;

View file

@ -138,7 +138,7 @@ public class TileComponentEjector implements ITileComponent
if(tank.getFluidAmount() > 0) if(tank.getFluidAmount() > 0)
{ {
FluidStack toEmit = new FluidStack(tank.getFluid().getFluid(), Math.min(FLUID_OUTPUT, tank.getFluidAmount())); FluidStack toEmit = PipeUtils.copy(tank.getFluid(), Math.min(FLUID_OUTPUT, tank.getFluidAmount()));
int emit = PipeUtils.emit(outputSides, toEmit, tileEntity); int emit = PipeUtils.emit(outputSides, toEmit, tileEntity);
tank.drain(emit, true); tank.drain(emit, true);
} }

View file

@ -115,10 +115,18 @@ public final class PipeUtils
} }
ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
toSend -= acceptor.fill(dir, new FluidStack(stack.getFluid(), currentSending), true); toSend -= acceptor.fill(dir, copy(stack, currentSending), true);
} }
} }
return prevSending-toSend; return prevSending-toSend;
} }
public static FluidStack copy(FluidStack fluid, int amount)
{
FluidStack ret = fluid.copy();
ret.amount = amount;
return ret;
}
} }