some more fluid IO work

This commit is contained in:
Boblet 2022-04-19 16:16:04 +02:00
parent 68efe9f28e
commit 2387cc13e7
9 changed files with 93 additions and 21 deletions

View File

@ -7,8 +7,8 @@ import com.hbm.inventory.fluid.FluidType;
* transceiver [trăn-vər], noun * transceiver [trăn-vər], noun
* *
* 1. A transmitter and receiver housed together in a single unit and having some circuits in common, often for portable or mobile use. * 1. A transmitter and receiver housed together in a single unit and having some circuits in common, often for portable or mobile use.
* 2. A combinedradiotransmitter and receiver. * 2. A combined radio transmitter and receiver.
* 3. A device that performs transmitting and receivingfunctions, especially if using commoncomponents. * 3. A device that performs transmitting and receiving functions, especially if using common components.
* *
* The American Heritage® Dictionary of the English Language, 5th Edition. * The American Heritage® Dictionary of the English Language, 5th Edition.
* *

View File

@ -64,12 +64,20 @@ public interface IFluidUser extends IFluidConnector {
public default long getTotalFluidForSend(FluidType type) { return 0; } public default long getTotalFluidForSend(FluidType type) { return 0; }
public default void removeFluidForTransfer(FluidType type, long amount) { } public default void removeFluidForTransfer(FluidType type, long amount) { }
public default void subscribeToAllAround(FluidType type, TileEntity te) {
subscribeToAllAround(type, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
public default void subscribeToAllAround(FluidType type, World world, int x, int y, int z) { public default void subscribeToAllAround(FluidType type, World world, int x, int y, int z) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
this.trySubscribe(type, world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir); this.trySubscribe(type, world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir);
} }
public default void unsubscribeToAllAround(FluidType type, TileEntity te) {
unsubscribeToAllAround(type, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
public default void unsubscribeToAllAround(FluidType type, World world, int x, int y, int z) { public default void unsubscribeToAllAround(FluidType type, World world, int x, int y, int z) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)

View File

@ -233,12 +233,18 @@ public class FluidTank {
} }
} }
public void setType(int in, ItemStack[] slots) { public boolean setType(int in, ItemStack[] slots) {
setType(in, in, slots); return setType(in, in, slots);
} }
//Changes tank type /**
public void setType(int in, int out, ItemStack[] slots) { * Changes the tank type and returns true if successful
* @param in
* @param out
* @param slots
* @return
*/
public boolean setType(int in, int out, ItemStack[] slots) {
if(slots[in] != null && slots[in].getItem() instanceof ItemFluidIdentifier) { if(slots[in] != null && slots[in].getItem() instanceof ItemFluidIdentifier) {
@ -248,6 +254,7 @@ public class FluidTank {
if(type != newType) { if(type != newType) {
type = newType; type = newType;
fluid = 0; fluid = 0;
return true;
} }
} else if(slots[out] == null) { } else if(slots[out] == null) {
@ -257,9 +264,12 @@ public class FluidTank {
slots[out] = slots[in].copy(); slots[out] = slots[in].copy();
slots[in] = null; slots[in] = null;
fluid = 0; fluid = 0;
return true;
} }
} }
} }
return false;
} }
/** /**

View File

@ -11,12 +11,13 @@ import com.hbm.inventory.fluid.Fluids;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.main.ModEventHandler; import com.hbm.main.ModEventHandler;
import api.hbm.fluid.IFluidStandardTransceiver;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.EnumSkyBlock;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityCondenser extends TileEntity implements IFluidAcceptor, IFluidSource { public class TileEntityCondenser extends TileEntity implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver {
public int age = 0; public int age = 0;
public FluidTank[] tanks; public FluidTank[] tanks;
@ -53,6 +54,9 @@ public class TileEntityCondenser extends TileEntity implements IFluidAcceptor, I
tanks[1].setFill(tanks[1].getFill() + convert); tanks[1].setFill(tanks[1].getFill() + convert);
} }
this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1].getTankType(), this);
fillFluidInit(tanks[1].getTankType()); fillFluidInit(tanks[1].getTankType());
} else { } else {
@ -148,4 +152,14 @@ public class TileEntityCondenser extends TileEntity implements IFluidAcceptor, I
public void clearFluidList(FluidType type) { public void clearFluidList(FluidType type) {
list.clear(); list.clear();
} }
@Override
public FluidTank[] getSendingTanks() {
return new FluidTank[] {tanks [1]};
}
@Override
public FluidTank[] getReceivingTanks() {
return new FluidTank[] {tanks [0]};
}
} }

View File

@ -14,11 +14,13 @@ import com.hbm.packet.PacketDispatcher;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IEnergyUser; import api.hbm.energy.IEnergyUser;
import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implements IFluidAcceptor, IFluidSource, IEnergyUser { public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implements IFluidAcceptor, IFluidSource, IEnergyUser, IFluidStandardTransceiver {
public int age = 0; public int age = 0;
public long power = 0; public long power = 0;
@ -61,8 +63,9 @@ public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implemen
data.setLong("power", power); data.setLong("power", power);
this.networkPack(data, 25); this.networkPack(data, 25);
} }
this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1].getTankType(), this);
if(power < 0) if(power < 0)
power = 0; power = 0;
@ -196,4 +199,14 @@ public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implemen
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
@Override
public FluidTank[] getSendingTanks() {
return new FluidTank[] {tanks [1]};
}
@Override
public FluidTank[] getReceivingTanks() {
return new FluidTank[] {tanks [0]};
}
} }

View File

@ -4,10 +4,13 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.inventory.FluidTank; import com.hbm.inventory.FluidTank;
import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.util.fauxpointtwelve.BlockPos;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor { public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor {
@ -71,6 +74,27 @@ public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor {
} }
protected void updateConnections() { protected void updateConnections() {
for(BlockPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), ForgeDirection.UNKNOWN);
}
}
public void subscribeToAllAround(FluidType type, World world, int x, int y, int z) {
for(BlockPos pos : getConPos()) {
this.trySubscribe(type, world, pos.getX(), pos.getY(), pos.getZ(), ForgeDirection.UNKNOWN);
}
}
public void sendFluidToAll(FluidType type, TileEntity te) {
for(BlockPos pos : getConPos()) {
this.sendFluid(type, worldObj, pos.getX(), pos.getY(), pos.getZ(), ForgeDirection.UNKNOWN);
}
}
private BlockPos[] getConPos() {
int offsetX = 0; int offsetX = 0;
int offsetZ = 0; int offsetZ = 0;
@ -85,14 +109,16 @@ public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor {
offsetZ = dir.offsetZ; offsetZ = dir.offsetZ;
} }
this.trySubscribe(worldObj, this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 1, ForgeDirection.UNKNOWN); //TODO: figure this one out without dying return new BlockPos[] {
this.trySubscribe(worldObj, this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 0, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 1),
this.trySubscribe(worldObj, this.xCoord + offsetX * 1, this.yCoord, this.zCoord - offsetZ * 2, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 0),
this.trySubscribe(worldObj, this.xCoord + offsetX * 0, this.yCoord, this.zCoord - offsetZ * 2, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 1, this.yCoord, this.zCoord - offsetZ * 2),
this.trySubscribe(worldObj, this.xCoord + offsetX * 1, this.yCoord, this.zCoord + offsetZ * 1, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 0, this.yCoord, this.zCoord - offsetZ * 2),
this.trySubscribe(worldObj, this.xCoord + offsetX * 0, this.yCoord, this.zCoord + offsetZ * 1, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 1, this.yCoord, this.zCoord + offsetZ * 1),
this.trySubscribe(worldObj, this.xCoord - offsetX * 1, this.yCoord, this.zCoord + offsetZ * 0, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord + offsetX * 0, this.yCoord, this.zCoord + offsetZ * 1),
this.trySubscribe(worldObj, this.xCoord - offsetX * 1, this.yCoord, this.zCoord - offsetZ * 1, ForgeDirection.UNKNOWN); new BlockPos(this.xCoord - offsetX * 1, this.yCoord, this.zCoord + offsetZ * 0),
new BlockPos(this.xCoord - offsetX * 1, this.yCoord, this.zCoord - offsetZ * 1)
};
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;

View File

@ -101,13 +101,14 @@ public class TileEntityMachineDiesel extends TileEntityMachineBase implements IE
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
this.sendPower(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); this.sendPower(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
this.subscribeToAllAround(Fluids.WATER, worldObj, xCoord, yCoord, zCoord);
//Tank Management //Tank Management
tank.setType(3, 4, slots); FluidType last = tank.getTankType();
if(tank.setType(3, 4, slots)) this.unsubscribeToAllAround(last, this);
tank.loadTank(0, 1, slots); tank.loadTank(0, 1, slots);
tank.updateTank(xCoord, yCoord, zCoord, worldObj.provider.dimensionId); tank.updateTank(xCoord, yCoord, zCoord, worldObj.provider.dimensionId);
this.subscribeToAllAround(tank.getTankType(), this);
FluidType type = tank.getTankType(); FluidType type = tank.getTankType();
if(type == Fluids.NITAN) if(type == Fluids.NITAN)

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B