mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-02-24 15:00:48 +00:00
fluid tank handling updated to match energy storage blocks, allowing for more consistent tank leveling behaviour
This commit is contained in:
parent
f00f2c7ca3
commit
62485c6854
@ -0,0 +1,5 @@
|
|||||||
|
package api.hbm.fluidmk2;
|
||||||
|
|
||||||
|
public interface IFluidBufferTransceiverMK2 extends IFluidStandardTransceiverMK2 {
|
||||||
|
|
||||||
|
}
|
||||||
@ -46,7 +46,7 @@ public interface IFluidStandardSenderMK2 extends IFluidProviderMK2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(te instanceof IFluidReceiverMK2 && te != this) {
|
if(te != this && te instanceof IFluidReceiverMK2 && !(te instanceof IFluidBufferTransceiverMK2)) {
|
||||||
IFluidReceiverMK2 rec = (IFluidReceiverMK2) te;
|
IFluidReceiverMK2 rec = (IFluidReceiverMK2) te;
|
||||||
if(rec.canConnect(type, dir.getOpposite())) {
|
if(rec.canConnect(type, dir.getOpposite())) {
|
||||||
long provides = Math.min(this.getFluidAvailable(type, pressure), this.getProviderSpeed(type, pressure));
|
long provides = Math.min(this.getFluidAvailable(type, pressure), this.getProviderSpeed(type, pressure));
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package com.hbm.tileentity.machine.storage;
|
package com.hbm.tileentity.machine.storage;
|
||||||
|
|
||||||
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
|
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
|
||||||
import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
|
import api.hbm.fluidmk2.FluidNode;
|
||||||
|
import api.hbm.fluidmk2.IFluidBufferTransceiverMK2;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
import com.hbm.handler.CompatHandler;
|
import com.hbm.handler.CompatHandler;
|
||||||
@ -20,6 +23,8 @@ import com.hbm.tileentity.IFluidCopiable;
|
|||||||
import com.hbm.tileentity.IGUIProvider;
|
import com.hbm.tileentity.IGUIProvider;
|
||||||
import com.hbm.tileentity.IPersistentNBT;
|
import com.hbm.tileentity.IPersistentNBT;
|
||||||
import com.hbm.tileentity.TileEntityMachineBase;
|
import com.hbm.tileentity.TileEntityMachineBase;
|
||||||
|
import com.hbm.uninos.UniNodespace;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
import cpw.mods.fml.common.Optional;
|
import cpw.mods.fml.common.Optional;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
@ -37,9 +42,13 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.EnumSkyBlock;
|
import net.minecraft.world.EnumSkyBlock;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
||||||
public class TileEntityBarrel extends TileEntityMachineBase implements SimpleComponent, IFluidStandardTransceiverMK2, IPersistentNBT, IGUIProvider, CompatHandler.OCComponent, IFluidCopiable {
|
public class TileEntityBarrel extends TileEntityMachineBase implements SimpleComponent, IFluidBufferTransceiverMK2, IPersistentNBT, IGUIProvider, CompatHandler.OCComponent, IFluidCopiable {
|
||||||
|
|
||||||
|
protected FluidNode node;
|
||||||
|
protected FluidType lastType;
|
||||||
|
|
||||||
public FluidTank tank;
|
public FluidTank tank;
|
||||||
public short mode = 0;
|
public short mode = 0;
|
||||||
@ -91,9 +100,27 @@ public class TileEntityBarrel extends TileEntityMachineBase implements SimpleCom
|
|||||||
tank.loadTank(2, 3, slots);
|
tank.loadTank(2, 3, slots);
|
||||||
tank.unloadTank(4, 5, slots);
|
tank.unloadTank(4, 5, slots);
|
||||||
|
|
||||||
for(DirPos pos : getConPos()) {
|
if(this.node == null || this.node.expired || tank.getTankType() != lastType) {
|
||||||
if(mode == 0 || mode == 1) this.trySubscribe(tank.getTankType(), worldObj, pos);
|
|
||||||
if(mode == 1 || mode == 2) this.tryProvide(tank, worldObj, pos);
|
this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
|
||||||
|
|
||||||
|
if(this.node == null || this.node.expired || tank.getTankType() != lastType) {
|
||||||
|
this.node = this.createNode(tank.getTankType());
|
||||||
|
UniNodespace.createNode(worldObj, this.node);
|
||||||
|
lastType = tank.getTankType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 2 || mode == 1) {
|
||||||
|
this.tryProvide(tank, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||||
|
} else {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.removeProvider(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 0 || mode == 1) {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.addReceiver(this);
|
||||||
|
} else {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tank.getFill() > 0) {
|
if(tank.getFill() > 0) {
|
||||||
@ -104,6 +131,30 @@ public class TileEntityBarrel extends TileEntityMachineBase implements SimpleCom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected FluidNode createNode(FluidType type) {
|
||||||
|
DirPos[] conPos = getConPos();
|
||||||
|
|
||||||
|
HashSet<BlockPos> posSet = new HashSet<>();
|
||||||
|
posSet.add(new BlockPos(this));
|
||||||
|
for(DirPos pos : conPos) {
|
||||||
|
ForgeDirection dir = pos.getDir();
|
||||||
|
posSet.add(new BlockPos(pos.getX() - dir.offsetX, pos.getY() - dir.offsetY, pos.getZ() - dir.offsetZ));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FluidNode(type.getNetworkProvider(), posSet.toArray(new BlockPos[posSet.size()])).setConnections(conPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate() {
|
||||||
|
super.invalidate();
|
||||||
|
|
||||||
|
if(!worldObj.isRemote) {
|
||||||
|
if(this.node != null) {
|
||||||
|
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf buf) {
|
public void serialize(ByteBuf buf) {
|
||||||
super.serialize(buf);
|
super.serialize(buf);
|
||||||
@ -220,6 +271,8 @@ public class TileEntityBarrel extends TileEntityMachineBase implements SimpleCom
|
|||||||
tank.writeToNBT(nbt, "tank");
|
tank.writeToNBT(nbt, "tank");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean canConnect(FluidType fluid, ForgeDirection dir) { return true; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank[] getSendingTanks() {
|
public FluidTank[] getSendingTanks() {
|
||||||
return (mode == 1 || mode == 2) ? new FluidTank[] {tank} : new FluidTank[0];
|
return (mode == 1 || mode == 2) ? new FluidTank[] {tank} : new FluidTank[0];
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.hbm.tileentity.machine.storage;
|
package com.hbm.tileentity.machine.storage;
|
||||||
|
|
||||||
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
|
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
|
||||||
import api.hbm.fluid.IFluidStandardTransceiver;
|
import api.hbm.fluidmk2.FluidNode;
|
||||||
|
import api.hbm.fluidmk2.IFluidBufferTransceiverMK2;
|
||||||
|
|
||||||
import com.hbm.blocks.BlockDummyable;
|
import com.hbm.blocks.BlockDummyable;
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
import com.hbm.explosion.vanillant.ExplosionVNT;
|
import com.hbm.explosion.vanillant.ExplosionVNT;
|
||||||
@ -22,8 +24,10 @@ import com.hbm.inventory.fluid.tank.FluidTank;
|
|||||||
import com.hbm.lib.Library;
|
import com.hbm.lib.Library;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
import com.hbm.packet.PacketDispatcher;
|
||||||
import com.hbm.tileentity.*;
|
import com.hbm.tileentity.*;
|
||||||
|
import com.hbm.uninos.UniNodespace;
|
||||||
import com.hbm.packet.toclient.AuxParticlePacketNT;
|
import com.hbm.packet.toclient.AuxParticlePacketNT;
|
||||||
import com.hbm.util.ParticleUtil;
|
import com.hbm.util.ParticleUtil;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||||
import cpw.mods.fml.common.Optional;
|
import cpw.mods.fml.common.Optional;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||||
@ -45,17 +49,20 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "opencomputers")})
|
||||||
public class TileEntityMachineFluidTank extends TileEntityMachineBase implements SimpleComponent, OCComponent, IFluidStandardTransceiver, IPersistentNBT, IOverpressurable, IGUIProvider, IRepairable, IFluidCopiable {
|
public class TileEntityMachineFluidTank extends TileEntityMachineBase implements SimpleComponent, OCComponent, IFluidBufferTransceiverMK2, IPersistentNBT, IOverpressurable, IGUIProvider, IRepairable, IFluidCopiable {
|
||||||
|
|
||||||
|
protected FluidNode node;
|
||||||
|
protected FluidType lastType;
|
||||||
|
|
||||||
public FluidTank tank;
|
public FluidTank tank;
|
||||||
public short mode = 0;
|
public short mode = 0;
|
||||||
public static final short modes = 4;
|
public static final short modes = 4;
|
||||||
public boolean hasExploded = false;
|
public boolean hasExploded = false;
|
||||||
protected boolean sendingBrake = false;
|
|
||||||
public boolean onFire = false;
|
public boolean onFire = false;
|
||||||
public byte lastRedstone = 0;
|
public byte lastRedstone = 0;
|
||||||
public Explosion lastExplosion = null;
|
public Explosion lastExplosion = null;
|
||||||
@ -107,15 +114,34 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
|
|||||||
this.markChanged();
|
this.markChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(DirPos pos : getConPos()) {
|
if(this.node == null || this.node.expired || tank.getTankType() != lastType) {
|
||||||
if(mode == 0 || mode == 1) this.trySubscribe(tank.getTankType(), worldObj, pos);
|
|
||||||
if(mode == 1 || mode == 2) this.tryProvide(tank, worldObj, pos);
|
this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
|
||||||
|
|
||||||
|
if(this.node == null || this.node.expired || tank.getTankType() != lastType) {
|
||||||
|
this.node = this.createNode(tank.getTankType());
|
||||||
|
UniNodespace.createNode(worldObj, this.node);
|
||||||
|
lastType = tank.getTankType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 2 || mode == 1) {
|
||||||
|
this.tryProvide(tank, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
|
||||||
|
} else {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.removeProvider(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 0 || mode == 1) {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.addReceiver(this);
|
||||||
|
} else {
|
||||||
|
if(node != null && node.hasValidNet()) node.net.removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
tank.loadTank(2, 3, slots);
|
tank.loadTank(2, 3, slots);
|
||||||
tank.setType(0, 1, slots);
|
tank.setType(0, 1, slots);
|
||||||
} else {
|
} else if(this.node != null) {
|
||||||
for(DirPos pos : getConPos()) this.tryUnsubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ());
|
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
|
||||||
|
this.node = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte comp = this.getComparatorPower(); //comparator shit
|
byte comp = this.getComparatorPower(); //comparator shit
|
||||||
@ -166,6 +192,30 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected FluidNode createNode(FluidType type) {
|
||||||
|
DirPos[] conPos = getConPos();
|
||||||
|
|
||||||
|
HashSet<BlockPos> posSet = new HashSet<>();
|
||||||
|
posSet.add(new BlockPos(this));
|
||||||
|
for(DirPos pos : conPos) {
|
||||||
|
ForgeDirection dir = pos.getDir();
|
||||||
|
posSet.add(new BlockPos(pos.getX() - dir.offsetX, pos.getY() - dir.offsetY, pos.getZ() - dir.offsetZ));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FluidNode(type.getNetworkProvider(), posSet.toArray(new BlockPos[posSet.size()])).setConnections(conPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate() {
|
||||||
|
super.invalidate();
|
||||||
|
|
||||||
|
if(!worldObj.isRemote) {
|
||||||
|
if(this.node != null) {
|
||||||
|
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf buf) {
|
public void serialize(ByteBuf buf) {
|
||||||
super.serialize(buf);
|
super.serialize(buf);
|
||||||
@ -362,6 +412,8 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
|
|||||||
this.onFire = data.getBoolean("onFire");
|
this.onFire = data.getBoolean("onFire");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean canConnect(FluidType fluid, ForgeDirection dir) { return true; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank[] getSendingTanks() {
|
public FluidTank[] getSendingTanks() {
|
||||||
if(this.hasExploded) return new FluidTank[0];
|
if(this.hasExploded) return new FluidTank[0];
|
||||||
@ -370,7 +422,7 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FluidTank[] getReceivingTanks() {
|
public FluidTank[] getReceivingTanks() {
|
||||||
if(this.hasExploded || this.sendingBrake) return new FluidTank[0];
|
if(this.hasExploded) return new FluidTank[0];
|
||||||
return (mode == 0 || mode == 1) ? new FluidTank[] {tank} : new FluidTank[0];
|
return (mode == 0 || mode == 1) ? new FluidTank[] {tank} : new FluidTank[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user