batteries and fluid tanks now block propagation if not set to buffer mode (which the player can circumvent by cabling/piping around them, which gives them the choice of behaviour, and is more intuitive)

This commit is contained in:
George Paton 2025-03-24 16:09:56 +11:00
parent 62485c6854
commit 141e80bfcb
5 changed files with 139 additions and 99 deletions

View File

@ -1,5 +0,0 @@
package api.hbm.fluidmk2;
public interface IFluidBufferTransceiverMK2 extends IFluidStandardTransceiverMK2 {
}

View File

@ -46,7 +46,7 @@ public interface IFluidStandardSenderMK2 extends IFluidProviderMK2 {
} }
} }
if(te != this && te instanceof IFluidReceiverMK2 && !(te instanceof IFluidBufferTransceiverMK2)) { if(te != this && te instanceof IFluidReceiverMK2) {
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));

View File

@ -2,7 +2,7 @@ package com.hbm.tileentity.machine.storage;
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority; import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
import api.hbm.fluidmk2.FluidNode; import api.hbm.fluidmk2.FluidNode;
import api.hbm.fluidmk2.IFluidBufferTransceiverMK2; import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
import java.util.HashSet; import java.util.HashSet;
@ -45,10 +45,9 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; 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, IFluidBufferTransceiverMK2, IPersistentNBT, IGUIProvider, CompatHandler.OCComponent, IFluidCopiable { public class TileEntityBarrel extends TileEntityMachineBase implements SimpleComponent, IFluidStandardTransceiverMK2, IPersistentNBT, IGUIProvider, CompatHandler.OCComponent, IFluidCopiable {
protected FluidNode node; protected FluidNode node;
protected FluidType lastType;
public FluidTank tank; public FluidTank tank;
public short mode = 0; public short mode = 0;
@ -100,27 +99,42 @@ 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);
if(this.node == null || this.node.expired || tank.getTankType() != lastType) { // In buffer mode, acts like a pipe block, providing fluid to its own node
// otherwise, it is a regular providing/receiving machine, blocking further propagation
if(mode == 1) {
if(this.node == null || this.node.expired) {
this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider()); this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
if(this.node == null || this.node.expired || tank.getTankType() != lastType) { if(this.node == null || this.node.expired) {
this.node = this.createNode(tank.getTankType()); this.node = this.createNode(tank.getTankType());
UniNodespace.createNode(worldObj, this.node); UniNodespace.createNode(worldObj, this.node);
lastType = tank.getTankType(); }
} }
}
if(mode == 2 || mode == 1) {
this.tryProvide(tank, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN); 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); if(node != null && node.hasValidNet()) node.net.addReceiver(this);
} else { } else {
if(node != null && node.hasValidNet()) node.net.removeReceiver(this); if(this.node != null) {
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
this.node = null;
}
for(DirPos pos : getConPos()) {
FluidNode dirNode = (FluidNode) UniNodespace.getNode(worldObj, pos.getX(), pos.getY(), pos.getZ(), tank.getTankType().getNetworkProvider());
if(mode == 2) {
tryProvide(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeProvider(this);
}
if(mode == 0) {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.addReceiver(this);
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeReceiver(this);
}
}
} }
if(tank.getFill() > 0) { if(tank.getFill() > 0) {

View File

@ -16,6 +16,7 @@ import com.hbm.lib.Library;
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.CompatEnergyControl; import com.hbm.util.CompatEnergyControl;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
@ -170,24 +171,46 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
int mode = this.getRelevantMode(false); int mode = this.getRelevantMode(false);
if(this.node == null || this.node.expired) {
this.node = Nodespace.getNode(worldObj, xCoord, yCoord, zCoord);
if(this.node == null || this.node.expired) {
this.node = this.createNode();
Nodespace.createNode(worldObj, this.node);
}
}
long prevPower = this.power; long prevPower = this.power;
power = Library.chargeItemsFromTE(slots, 1, power, getMaxPower()); power = Library.chargeItemsFromTE(slots, 1, power, getMaxPower());
if(mode == mode_output || mode == mode_buffer) { // In buffer mode, becomes a cable block and provides power to itself
// otherwise, acts like a regular power providing/accepting machine
if(mode == mode_buffer) {
if(this.node == null || this.node.expired) {
this.node = (PowerNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, Nodespace.THE_POWER_PROVIDER);
if(this.node == null || this.node.expired) {
this.node = this.createNode();
UniNodespace.createNode(worldObj, this.node);
}
}
this.tryProvide(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN); this.tryProvide(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN);
if(node != null && node.hasValidNet()) node.net.addReceiver(this);
} else { } else {
if(node != null && node.hasValidNet()) node.net.removeProvider(this); if(this.node != null) {
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, Nodespace.THE_POWER_PROVIDER);
this.node = null;
}
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
PowerNode dirNode = (PowerNode) UniNodespace.getNode(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, Nodespace.THE_POWER_PROVIDER);
if(mode == mode_output) {
tryProvide(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeProvider(this);
}
if(mode == mode_input) {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.addReceiver(this);
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeReceiver(this);
}
}
} }
byte comp = this.getComparatorPower(); byte comp = this.getComparatorPower();
@ -195,12 +218,6 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
this.markDirty(); this.markDirty();
this.lastRedstone = comp; this.lastRedstone = comp;
if(mode == mode_input || mode == mode_buffer) {
if(node != null && node.hasValidNet()) node.net.addReceiver(this);
} else {
if(node != null && node.hasValidNet()) node.net.removeReceiver(this);
}
power = Library.chargeTEFromItems(slots, 0, power, getMaxPower()); power = Library.chargeTEFromItems(slots, 0, power, getMaxPower());
long avg = (power + prevPower) / 2; long avg = (power + prevPower) / 2;
@ -228,7 +245,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(this.node != null) { if(this.node != null) {
Nodespace.destroyNode(worldObj, xCoord, yCoord, zCoord); UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, Nodespace.THE_POWER_PROVIDER);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package com.hbm.tileentity.machine.storage;
import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority; import api.hbm.energymk2.IEnergyReceiverMK2.ConnectionPriority;
import api.hbm.fluidmk2.FluidNode; import api.hbm.fluidmk2.FluidNode;
import api.hbm.fluidmk2.IFluidBufferTransceiverMK2; import api.hbm.fluidmk2.IFluidStandardTransceiverMK2;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
@ -54,10 +54,9 @@ 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, IFluidBufferTransceiverMK2, IPersistentNBT, IOverpressurable, IGUIProvider, IRepairable, IFluidCopiable { public class TileEntityMachineFluidTank extends TileEntityMachineBase implements SimpleComponent, OCComponent, IFluidStandardTransceiverMK2, IPersistentNBT, IOverpressurable, IGUIProvider, IRepairable, IFluidCopiable {
protected FluidNode node; protected FluidNode node;
protected FluidType lastType;
public FluidTank tank; public FluidTank tank;
public short mode = 0; public short mode = 0;
@ -114,27 +113,42 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
this.markChanged(); this.markChanged();
} }
if(this.node == null || this.node.expired || tank.getTankType() != lastType) { // In buffer mode, acts like a pipe block, providing fluid to its own node
// otherwise, it is a regular providing/receiving machine, blocking further propagation
if(mode == 1) {
if(this.node == null || this.node.expired) {
this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider()); this.node = (FluidNode) UniNodespace.getNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
if(this.node == null || this.node.expired || tank.getTankType() != lastType) { if(this.node == null || this.node.expired) {
this.node = this.createNode(tank.getTankType()); this.node = this.createNode(tank.getTankType());
UniNodespace.createNode(worldObj, this.node); UniNodespace.createNode(worldObj, this.node);
lastType = tank.getTankType(); }
} }
}
if(mode == 2 || mode == 1) {
this.tryProvide(tank, worldObj, xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN); 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); if(node != null && node.hasValidNet()) node.net.addReceiver(this);
} else { } else {
if(node != null && node.hasValidNet()) node.net.removeReceiver(this); if(this.node != null) {
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, tank.getTankType().getNetworkProvider());
this.node = null;
}
for(DirPos pos : getConPos()) {
FluidNode dirNode = (FluidNode) UniNodespace.getNode(worldObj, pos.getX(), pos.getY(), pos.getZ(), tank.getTankType().getNetworkProvider());
if(mode == 2) {
tryProvide(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeProvider(this);
}
if(mode == 0) {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.addReceiver(this);
} else {
if(dirNode != null && dirNode.hasValidNet()) dirNode.net.removeReceiver(this);
}
}
} }
tank.loadTank(2, 3, slots); tank.loadTank(2, 3, slots);