Some how broke tanks really bad
Not sure what i did in the last few commits, and in this one but the tanks don't work much at all now. They have rendering, saving, loading, merging, and other issues now. Not much has really changed to cause this bad of a reaction from the code.
This commit is contained in:
parent
ca73318c78
commit
fb3a235abe
8 changed files with 75 additions and 191 deletions
|
@ -101,7 +101,27 @@ public class FluidCraftingHandler
|
|||
receivedVolume = ((ItemStack) input).stackSize;
|
||||
((ItemStack) input).stackSize = 1;
|
||||
}
|
||||
|
||||
//Get result
|
||||
Object result = fluidMergeResults.containsKey(new Pair<Object, Object>(crafter.getReceivingObjectStack(), crafter.getInputObjectStack()));
|
||||
|
||||
//reset stack sized
|
||||
if (received instanceof FluidStack)
|
||||
{
|
||||
((FluidStack) received).amount = receivedVolume;
|
||||
}
|
||||
if (received instanceof ItemStack)
|
||||
{
|
||||
((ItemStack) received).stackSize = receivedVolume;
|
||||
}
|
||||
if (input instanceof FluidStack)
|
||||
{
|
||||
((FluidStack) input).amount = inputVolume;
|
||||
}
|
||||
if (input instanceof ItemStack)
|
||||
{
|
||||
((ItemStack) input).stackSize = inputVolume;
|
||||
}
|
||||
if (result != null)
|
||||
{
|
||||
if (result instanceof SimpleFluidRecipe)
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
import dark.api.fluid.INetworkFluidPart;
|
||||
import dark.api.parts.INetworkPart;
|
||||
import dark.core.interfaces.ColorCode;
|
||||
import dark.core.prefab.helpers.FluidHelper;
|
||||
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
||||
|
||||
/** Side note: the network should act like this when done {@link http
|
||||
|
@ -34,18 +35,15 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
@Override
|
||||
public void writeDataToTiles()
|
||||
{
|
||||
this.cleanUpMembers();
|
||||
|
||||
if (this.combinedStorage() == null || this.combinedStorage().getFluid() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int fluid = this.combinedStorage().getFluid().fluidID;
|
||||
int volume = Math.abs(this.combinedStorage().getFluid().amount);
|
||||
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
|
||||
FluidStack fillStack = this.combinedStorage().getFluid().copy();
|
||||
|
||||
int lowestY = 255;
|
||||
int highestY = 0;
|
||||
|
||||
this.cleanUpMembers();
|
||||
int lowestY = 255, highestY = 0;
|
||||
|
||||
if (this.combinedStorage().getFluid() != null && this.getNetworkMemebers().size() > 0)
|
||||
{
|
||||
|
@ -82,32 +80,21 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
if (!parts.isEmpty())
|
||||
{
|
||||
/* Div out the volume for this level. TODO change this to use a percent system for even filling */
|
||||
int fillvolume = Math.abs(volume / parts.size());
|
||||
int fillvolume = Math.abs(fillStack.amount / parts.size());
|
||||
|
||||
/* Fill all tanks on this level */
|
||||
for (INetworkFluidPart part : parts)
|
||||
{
|
||||
int fill = Math.min(fillvolume, part.getTank(0).getCapacity());
|
||||
volume -= part.fillTankContent(0, new FluidStack(fluid, fill, tag), true);
|
||||
fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (volume <= 0)
|
||||
if (fillStack == null || fillStack.amount <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int storeFluidInSystem(FluidStack stack, boolean doFill)
|
||||
{
|
||||
int vol = this.combinedStorage().getFluid() != null ? this.combinedStorage().getFluid().amount : 0;
|
||||
int filled = super.storeFluidInSystem(stack, doFill);
|
||||
if (vol != filled)
|
||||
{
|
||||
for (INetworkPart part : this.getNetworkMemebers())
|
||||
{
|
||||
if (part instanceof TileEntity)
|
||||
|
@ -117,38 +104,6 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
}
|
||||
}
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drainFluidFromSystem(int maxDrain, boolean doDrain)
|
||||
{
|
||||
FluidStack vol = this.combinedStorage().getFluid();
|
||||
FluidStack stack = super.drainFluidFromSystem(maxDrain, doDrain);
|
||||
boolean flag = false;
|
||||
if (vol != null)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else if (stack.amount != vol.amount)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
for (INetworkPart part : this.getNetworkMemebers())
|
||||
{
|
||||
if (part instanceof TileEntity)
|
||||
{
|
||||
TileEntity ent = ((TileEntity) part);
|
||||
ent.worldObj.markBlockForUpdate(ent.xCoord, ent.yCoord, ent.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +1,26 @@
|
|||
package dark.core.prefab.tilenetwork.fluid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.fluid.AdvancedFluidEvent;
|
||||
import dark.api.fluid.AdvancedFluidEvent.FluidMergeEvent;
|
||||
import dark.api.fluid.INetworkFluidPart;
|
||||
import dark.api.parts.INetworkPart;
|
||||
import dark.core.interfaces.ColorCode;
|
||||
import dark.core.prefab.helpers.FluidHelper;
|
||||
import dark.core.prefab.helpers.Pair;
|
||||
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
||||
import dark.fluid.common.machines.TileEntityTank;
|
||||
import dark.fluid.common.pipes.TileEntityPipe;
|
||||
|
||||
public class NetworkFluidTiles extends NetworkTileEntities
|
||||
{
|
||||
/** Fluid Tanks that are connected to the network but not part of it ** */
|
||||
public final List<IFluidHandler> connectedTanks = new ArrayList<IFluidHandler>();
|
||||
public final Set<IFluidHandler> connectedTanks = new HashSet<IFluidHandler>();
|
||||
/** Collective storage of all fluid tiles */
|
||||
public FluidTank sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
|
||||
|
@ -41,7 +29,6 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
/** Has the collective tank been loaded yet */
|
||||
protected boolean loadedLiquids = false;
|
||||
|
||||
|
||||
public NetworkFluidTiles(ColorCode color, INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
|
@ -68,21 +55,22 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
/** Stores Fluid in this network's collective tank */
|
||||
public int storeFluidInSystem(FluidStack stack, boolean doFill)
|
||||
{
|
||||
if (stack == null || this.combinedStorage() != null && (this.combinedStorage().getFluid() != null && !this.combinedStorage().getFluid().isFluidEqual(stack)))
|
||||
if (stack == null || this.combinedStorage() == null)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
int prevVolume = this.combinedStorage().getFluidAmount();
|
||||
|
||||
if (!loadedLiquids)
|
||||
{
|
||||
this.readDataFromTiles();
|
||||
}
|
||||
if (this.combinedStorage().getFluid() == null || this.combinedStorage().getFluid().amount < this.combinedStorage().getCapacity())
|
||||
|
||||
int filled = this.combinedStorage().fill(stack, doFill);
|
||||
if (doFill)
|
||||
{
|
||||
int filled = this.combinedStorage().fill(stack, doFill);
|
||||
if (doFill)
|
||||
{
|
||||
this.writeDataToTiles();
|
||||
}
|
||||
this.writeDataToTiles();
|
||||
return filled;
|
||||
}
|
||||
return 0;
|
||||
|
@ -91,6 +79,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
/** Drains the network's collective tank */
|
||||
public FluidStack drainFluidFromSystem(int maxDrain, boolean doDrain)
|
||||
{
|
||||
int prevVolume = this.combinedStorage().getFluidAmount();
|
||||
if (!loadedLiquids)
|
||||
{
|
||||
this.readDataFromTiles();
|
||||
|
@ -127,22 +116,25 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
super.writeDataToTiles();
|
||||
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
||||
{
|
||||
FluidStack stack = this.combinedStorage().getFluid().copy();
|
||||
FluidStack stack = this.combinedStorage().getFluid() == null ? null : this.combinedStorage().getFluid().copy();
|
||||
int membersFilled = 0;
|
||||
|
||||
for (INetworkPart par : this.networkMember)
|
||||
{
|
||||
//UPDATE FILL VOLUME
|
||||
int fillVol = stack.amount / (this.networkMember.size() - membersFilled);
|
||||
int fillVol = stack == null ? 0 : (stack.amount / (this.networkMember.size() - membersFilled));
|
||||
|
||||
if (par instanceof INetworkFluidPart)
|
||||
{
|
||||
//EMPTY TANK
|
||||
((INetworkFluidPart) par).drainTankContent(0, fillVol, true);
|
||||
((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true);
|
||||
|
||||
//FILL TANK
|
||||
stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true);
|
||||
membersFilled++;
|
||||
if (stack != null)
|
||||
{
|
||||
stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true);
|
||||
membersFilled++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +144,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
public void readDataFromTiles()
|
||||
{
|
||||
super.readDataFromTiles();
|
||||
|
||||
System.out.println("Debug>>FluidTiles>>Reading fluid stack from tiles");
|
||||
FluidStack stack = null;
|
||||
|
||||
for (INetworkPart par : this.networkMember)
|
||||
|
@ -163,7 +155,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
if (stack == null)
|
||||
{
|
||||
stack = ((INetworkFluidPart) par).getTank(0).getFluid();
|
||||
stack = ((INetworkFluidPart) par).getTank(0).getFluid().copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -206,8 +198,6 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
return this.connectedTanks.contains(tileEntity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
|
@ -220,75 +210,13 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
if (mergingNetwork instanceof NetworkFluidTiles && ((NetworkFluidTiles) mergingNetwork).color == this.color)
|
||||
{
|
||||
NetworkFluidTiles network = (NetworkFluidTiles) mergingNetwork;
|
||||
|
||||
this.readDataFromTiles();
|
||||
network.readDataFromTiles();
|
||||
Object result = FluidCraftingHandler.getMergeResult(this.combinedStorage().getFluid(), network.combinedStorage().getFluid());
|
||||
if (mergePoint instanceof TileEntity)
|
||||
if (!((NetworkFluidTiles) mergingNetwork).loadedLiquids)
|
||||
{
|
||||
World world = ((TileEntity) mergePoint).worldObj;
|
||||
int x = ((TileEntity) mergePoint).xCoord;
|
||||
int y = ((TileEntity) mergePoint).xCoord;
|
||||
int z = ((TileEntity) mergePoint).xCoord;
|
||||
try
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
if (result instanceof Block)
|
||||
{
|
||||
if (mergePoint instanceof TileEntityPipe)
|
||||
{
|
||||
//TODO in-case pipe in the block
|
||||
}
|
||||
else if (mergePoint instanceof TileEntityTank)
|
||||
{
|
||||
//TODO in-case tank in the block
|
||||
//for tank set the render Entity to the block at full size
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlock(x, y, z, 0);
|
||||
world.setBlock(x, y, z, ((Block) result).blockID);
|
||||
}
|
||||
}
|
||||
else if (result instanceof ItemStack)
|
||||
{
|
||||
world.setBlock(x, y, z, 0);
|
||||
|
||||
if (((ItemStack) result).itemID >= Block.blocksList.length)
|
||||
{
|
||||
EntityItem item = new EntityItem(world, x, y, z, (ItemStack) result);
|
||||
//TODO add some effect to this
|
||||
world.spawnEntityInWorld(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.setBlock(x, y, z, ((ItemStack) result).itemID, ((ItemStack) result).getItemDamage(), 3);
|
||||
}
|
||||
}
|
||||
else if (result instanceof String)
|
||||
{
|
||||
|
||||
String string = (String) result;
|
||||
if (string.startsWith("explosion:"))
|
||||
{
|
||||
int size = Integer.parseInt(string.replace("explosion:", ""));
|
||||
world.setBlock(x, y, z, 0);
|
||||
world.createExplosion(null, x, y, z, size, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
AdvancedFluidEvent.fireEvent(new FluidMergeEvent(this.combinedStorage().getFluid(), network.combinedStorage().getFluid(), world, new Vector3(x, y, z)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
((NetworkFluidTiles) mergingNetwork).readDataFromTiles();
|
||||
}
|
||||
if (!this.loadedLiquids)
|
||||
{
|
||||
this.readDataFromTiles();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -308,18 +236,16 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
||||
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
|
||||
|
||||
newNetwork.cleanUpMembers();
|
||||
newNetwork.refresh();
|
||||
newNetwork.combinedStorage().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
|
||||
newNetwork.writeDataToTiles();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUpMembers()
|
||||
{
|
||||
if (!loadedLiquids)
|
||||
{
|
||||
this.readDataFromTiles();
|
||||
}
|
||||
Iterator<INetworkPart> it = this.networkMember.iterator();
|
||||
int capacity = 0;
|
||||
while (it.hasNext())
|
||||
|
|
|
@ -19,7 +19,7 @@ import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
|||
/** Side note: the network should act like this when done {@link http
|
||||
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
|
||||
* Liquids
|
||||
*
|
||||
*
|
||||
* @author Rseifert */
|
||||
public class NetworkPipes extends NetworkFluidTiles
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ public class NetworkPipes extends NetworkFluidTiles
|
|||
}
|
||||
|
||||
/** Adds FLuid to this network from one of the connected Pipes
|
||||
*
|
||||
*
|
||||
* @param source - Were this liquid came from
|
||||
* @param stack - LiquidStack to be sent
|
||||
* @param doFill - actually fill the tank or just check numbers
|
||||
|
@ -174,7 +174,7 @@ public class NetworkPipes extends NetworkFluidTiles
|
|||
}
|
||||
|
||||
/** Adds FLuid to this network from one of the connected Pipes
|
||||
*
|
||||
*
|
||||
* @param source - Were this liquid came from
|
||||
* @param stack - LiquidStack to be sent
|
||||
* @param doFill - actually fill the tank or just check numbers
|
||||
|
@ -320,20 +320,6 @@ public class NetworkPipes extends NetworkFluidTiles
|
|||
public void onPresureChange()
|
||||
{
|
||||
this.cleanUpMembers();
|
||||
|
||||
for (int i = 0; i < networkMember.size(); i++)
|
||||
{
|
||||
if (networkMember.get(i) instanceof INetworkPipe)
|
||||
{
|
||||
INetworkPipe part = (INetworkPipe) networkMember.get(i);
|
||||
if (part.getMaxPressure(ForgeDirection.UNKNOWN) < this.pressureProduced && part.onOverPressure(true))
|
||||
{
|
||||
this.networkMember.remove(part);
|
||||
this.cleanUpMembers();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class RenderSink extends RenderMachine
|
|||
break;
|
||||
}
|
||||
model.render(0.0625F);
|
||||
renderWater(te.getStoredLiquid());
|
||||
renderWater(te.getTank().getFluid());
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
|
|
|
@ -37,11 +37,9 @@ public class RenderTank extends RenderMachine
|
|||
public void renderTank(TileEntity tileEntity, double x, double y, double z, int meta, FluidStack liquid)
|
||||
{
|
||||
int[] render = new int[6];
|
||||
ColorCode color = ColorCode.get(meta >= 0 && meta < ColorCode.values().length ? meta : 0);
|
||||
if (tileEntity instanceof TileEntityTank)
|
||||
{
|
||||
render = ((TileEntityTank) tileEntity).renderConnection;
|
||||
color = ((TileEntityTank) tileEntity).getColor();
|
||||
}
|
||||
if (liquid != null && liquid.amount > 100)
|
||||
{
|
||||
|
@ -126,6 +124,6 @@ public class RenderTank extends RenderMachine
|
|||
{
|
||||
texture = "textures/blocks/iron_block.png";
|
||||
}
|
||||
return new ResourceLocation(FluidMech.instance.getDomain(), texture);
|
||||
return new ResourceLocation(texture);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
@ -122,7 +123,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
|||
public Packet getDescriptionPacket()
|
||||
{
|
||||
FluidStack stack = null;
|
||||
if (this.getTank().getFluid() != null && this.getTank().getFluid().getFluid() != null)
|
||||
if (this.getTank().getFluid() != null)
|
||||
{
|
||||
stack = this.getTank().getFluid();
|
||||
}
|
||||
|
@ -296,9 +297,9 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
|||
@Override
|
||||
public int fillTankContent(int index, FluidStack stack, boolean doFill)
|
||||
{
|
||||
if (this.getTank() != null)
|
||||
if (this.getTank(index) != null)
|
||||
{
|
||||
return this.getTank().fill(stack, doFill);
|
||||
return this.getTank(index).fill(stack, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -356,6 +357,10 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
|
|||
@Override
|
||||
public IFluidTank getTank(int index)
|
||||
{
|
||||
return this.getTank();
|
||||
if (index == 0)
|
||||
{
|
||||
return this.getTank();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import dark.core.prefab.helpers.FluidHelper;
|
|||
public abstract class TileEntityFluidStorage extends TileEntityFluidDevice implements IFluidHandler, IColorCoded
|
||||
{
|
||||
|
||||
public FluidTank fluidTank = new FluidTank(this.getTankSize());
|
||||
public FluidTank fluidTank;
|
||||
|
||||
@Override
|
||||
public String getMeterReading(EntityPlayer user, ForgeDirection side, EnumTools tool)
|
||||
|
@ -120,13 +120,7 @@ public abstract class TileEntityFluidStorage extends TileEntityFluidDevice imple
|
|||
/** Is the internal tank full */
|
||||
public boolean isFull()
|
||||
{
|
||||
return this.getTank().getFluid() != null && this.getTank().getFluid().amount >= this.getTank().getCapacity();
|
||||
}
|
||||
|
||||
/** gets the liquidStack stored in the internal tank */
|
||||
public FluidStack getStoredLiquid()
|
||||
{
|
||||
return this.getTank().getFluid();
|
||||
return this.getTank().getFluidAmount() >= this.getTank().getCapacity();
|
||||
}
|
||||
|
||||
public FluidTank getTank()
|
||||
|
|
Loading…
Reference in a new issue