Experimental passive fluid accumulator implemented.
This commit is contained in:
parent
7783cf94a6
commit
16ddb6b84f
8 changed files with 154 additions and 69 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
|
||||
"1.12.2": {
|
||||
"1.0.4-b8": "[F] Fixed stairs rendering without smooth light (thanks rastot9).\n[A] Added passive fluid accumulator.",
|
||||
"1.0.4-b8": "[F] Fixed stairs rendering without smooth light (thanks rastot9).\n[E] Added passive fluid accumulator (experimental feature, see config).",
|
||||
"1.0.4-b7": "[F] Fixed recipe loading issue if IE is not installed.\n[M] Valves support IE pressurized fluid transfer.",
|
||||
"1.0.4-b6": "[A] Added redstone controlled fluid valve.\n[A] Added redstone controlled analog fluid valve.\n[M] Check valve recipe adapted (thanks majijn).",
|
||||
"1.0.4-b5": "[A] Horizontal steel double-T support beam with pole connections.\n[A] Added fluid pipe check valve (straight, conducts only one way).\n[M] Internal registration block/te handling changed.",
|
||||
|
|
|
@ -11,7 +11,7 @@ Mod sources for Minecraft version 1.12.2.
|
|||
## Revision history
|
||||
|
||||
- v1.0.4-b8 [F] Fixed stairs rendering without smooth light (thanks rastot9).
|
||||
[A] Added passive fluid accumulator.
|
||||
[E] Added passive fluid accumulator (experimental feature, see config).
|
||||
|
||||
- v1.0.4-b7 [F] Fixed recipe loading issue if IE is not installed.
|
||||
[M] Valves support IE pressurized fluid transfer.
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
*/
|
||||
package wile.engineersdecor.blocks;
|
||||
|
||||
import wile.engineersdecor.ModEngineersDecor;
|
||||
import wile.engineersdecor.detail.ModAuxiliaries;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -45,31 +46,85 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
|
|||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
{ return new BlockDecorPassiveFluidAccumulator.BTileEntity(); }
|
||||
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos fromPos)
|
||||
{ TileEntity te = world.getTileEntity(pos); if(te instanceof BlockDecorPipeValve.BTileEntity) ((BTileEntity)te).block_changed(); }
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
// Tile entity
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static class BTileEntity extends TileEntity implements IFluidHandler, IFluidTankProperties, ICapabilityProvider
|
||||
, ModAuxiliaries.IExperimentalFeature
|
||||
public static class BTileEntity extends TileEntity implements IFluidHandler, IFluidTankProperties, ICapabilityProvider, ITickable, ModAuxiliaries.IExperimentalFeature
|
||||
{
|
||||
protected static int tank_fill_rate_mb = 1000;
|
||||
protected static int tank_capacity_mb = 2000;
|
||||
protected static int tick_idle_interval = 20; // ca 1000ms, simulates suction delay and saves CPU when not drained.
|
||||
protected static int max_flowrate = 1000;
|
||||
protected static int tank_capacity_mb = max_flowrate * 2;
|
||||
private final IFluidTankProperties[] fluid_props_ = {this};
|
||||
private final InputFillHandler fill_handler_ = new InputFillHandler(this);
|
||||
private EnumFacing block_facing_ = EnumFacing.NORTH;
|
||||
private FluidStack tank_ = null;
|
||||
private FluidStack last_filled_ = null;
|
||||
private FluidStack last_drain_request_fluid_ = null;
|
||||
private int last_drain_request_amount_ = 0;
|
||||
private int vacuum_ = 0;
|
||||
private int tick_timer_ = 0;
|
||||
private int round_robin_ = 0;
|
||||
private boolean initialized_ = false;
|
||||
|
||||
public void block_changed()
|
||||
{ initialized_ = false; tick_timer_ = MathHelper.clamp(tick_timer_ , 0, tick_idle_interval); }
|
||||
|
||||
// Output flow handler ---------------------------------------------------------------------
|
||||
|
||||
private static class InputFillHandler implements IFluidHandler, IFluidTankProperties
|
||||
{
|
||||
private final BTileEntity parent_;
|
||||
private final IFluidTankProperties[] props_ = {this};
|
||||
InputFillHandler(BTileEntity parent) { parent_ = parent; }
|
||||
@Override @Nullable public FluidStack drain(FluidStack resource, boolean doDrain) { return null; }
|
||||
@Override @Nullable public FluidStack drain(int maxDrain, boolean doDrain) { return null; }
|
||||
@Override public IFluidTankProperties[] getTankProperties() { return props_; }
|
||||
@Override public int getCapacity() { return tank_capacity_mb; }
|
||||
@Override public boolean canFill() { return true; }
|
||||
@Override public boolean canDrain() { return false; }
|
||||
@Override public boolean canFillFluidType(FluidStack fluidStack) { return true; }
|
||||
@Override public boolean canDrainFluidType(FluidStack fluidStack) { return false; }
|
||||
|
||||
@Nullable
|
||||
@Override public FluidStack getContents()
|
||||
{
|
||||
if(parent_.tank_==null) return null;
|
||||
FluidStack res = parent_.tank_.copy();
|
||||
if(res.amount > max_flowrate) res.amount = max_flowrate;
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if(!parent_.initialized_) return 0;
|
||||
FluidStack res = resource.copy();
|
||||
if(parent_.tank_ == null) {
|
||||
res.amount = MathHelper.clamp(res.amount, 0, max_flowrate*2);
|
||||
if(doFill) parent_.tank_ = res;
|
||||
return res.amount;
|
||||
} else {
|
||||
res.amount = MathHelper.clamp(res.amount, 0, Math.min(max_flowrate*2, tank_capacity_mb-parent_.tank_.amount));
|
||||
if((res.amount <= 0) || (!parent_.tank_.isFluidEqual(resource))) return 0;
|
||||
if(doFill) parent_.tank_.amount += res.amount;
|
||||
return res.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TileEntity ------------------------------------------------------------------------------
|
||||
|
||||
public BTileEntity()
|
||||
{}
|
||||
|
||||
// TileEntity ------------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState os, IBlockState ns)
|
||||
{ return (os.getBlock() != ns.getBlock()) || (!(ns.getBlock() instanceof BlockDecorPipeValve)); }
|
||||
{
|
||||
block_changed();
|
||||
return (os.getBlock() != ns.getBlock()) || (!(ns.getBlock() instanceof BlockDecorPipeValve));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
|
@ -90,27 +145,32 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
|
|||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
|
||||
{ return ((capability==CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)) || super.hasCapability(capability, facing); }
|
||||
{ return (initialized_ && (capability==CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)) || super.hasCapability(capability, facing); }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{ return (capability!=CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) ? (super.getCapability(capability, facing)) : (facing==block_facing_) ? (((T)this)) : ((T)fill_handler_); }
|
||||
{
|
||||
if(capability != CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return super.getCapability(capability, facing);
|
||||
return (facing==block_facing_) ? (((T)this)) : ((T)fill_handler_);
|
||||
}
|
||||
|
||||
// IFluidHandler/IFluidTankProperties of the output port -----------------------------------
|
||||
// IFluidHandler of the output port --------------------------------------------------------
|
||||
|
||||
@Override public IFluidTankProperties[] getTankProperties()
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties()
|
||||
{ return fluid_props_; }
|
||||
|
||||
@Override public int fill(FluidStack resource, boolean doFill)
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{ return 0; }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain)
|
||||
{
|
||||
last_drain_request_fluid_ = resource.copy();
|
||||
if(doDrain) last_drain_request_fluid_ = resource.copy();
|
||||
return ((tank_==null) || (!tank_.isFluidEqual(resource))) ? (null) : drain(resource.amount, doDrain);
|
||||
}
|
||||
|
||||
|
@ -118,58 +178,83 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
|
|||
@Nullable
|
||||
public FluidStack drain(int maxDrain, boolean doDrain)
|
||||
{
|
||||
last_drain_request_amount_ = maxDrain;
|
||||
if(!initialized_) return null;
|
||||
if(doDrain) last_drain_request_amount_ = maxDrain;
|
||||
if(tank_==null) return null;
|
||||
FluidStack res;
|
||||
if(maxDrain >= tank_.amount) {
|
||||
if(!doDrain) return tank_.copy();
|
||||
FluidStack res = tank_;
|
||||
res = tank_;
|
||||
tank_ = null;
|
||||
return res;
|
||||
} else {
|
||||
FluidStack res = tank_.copy();
|
||||
res = tank_.copy();
|
||||
res.amount = maxDrain;
|
||||
if(doDrain) tank_.amount -= maxDrain;
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// IFluidTankProperties --
|
||||
// IFluidTankProperties --------------------------------------------------------------------
|
||||
|
||||
@Override @Nullable public FluidStack getContents() { return (tank_==null) ? (null) : (tank_.copy()); }
|
||||
@Override public int getCapacity() { return tank_capacity_mb; }
|
||||
@Override public int getCapacity() { return max_flowrate; }
|
||||
@Override public boolean canFill() { return false; }
|
||||
@Override public boolean canDrain() { return true; }
|
||||
@Override public boolean canFillFluidType(FluidStack fluidStack) { return false; }
|
||||
@Override public boolean canDrainFluidType(FluidStack fluidStack) { return true; }
|
||||
|
||||
// Output flow handler --
|
||||
private static class InputFillHandler implements IFluidHandler, IFluidTankProperties
|
||||
{
|
||||
private final BTileEntity parent_;
|
||||
private final IFluidTankProperties[] props_ = {this};
|
||||
InputFillHandler(BTileEntity parent) { parent_ = parent; }
|
||||
@Override @Nullable public FluidStack drain(FluidStack resource, boolean doDrain) { return null; }
|
||||
@Override @Nullable public FluidStack drain(int maxDrain, boolean doDrain) { return null; }
|
||||
@Override @Nullable public FluidStack getContents() { return (parent_.tank_==null) ? (null) : (parent_.tank_.copy()); }
|
||||
@Override public IFluidTankProperties[] getTankProperties() { return props_; }
|
||||
@Override public int getCapacity() { return tank_capacity_mb; }
|
||||
@Override public boolean canFill() { return true; }
|
||||
@Override public boolean canDrain() { return false; }
|
||||
@Override public boolean canFillFluidType(FluidStack fluidStack) { return true; }
|
||||
@Override public boolean canDrainFluidType(FluidStack fluidStack) { return false; }
|
||||
// ITickable--------------------------------------------------------------------------------
|
||||
|
||||
@Override public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
FluidStack res = resource.copy();
|
||||
if(parent_.tank_ == null) {
|
||||
res.amount = MathHelper.clamp(res.amount, 0, tank_fill_rate_mb);
|
||||
if(doFill) parent_.tank_ = res;
|
||||
return res.amount;
|
||||
public void update()
|
||||
{
|
||||
if((world.isRemote) || (--tick_timer_ > 0)) return;
|
||||
tick_timer_ = tick_idle_interval;
|
||||
if(!initialized_) {
|
||||
initialized_ = true;
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if((state==null) || (!(state.getBlock() instanceof BlockDecorPassiveFluidAccumulator))) return;
|
||||
block_facing_ = state.getValue(FACING);
|
||||
}
|
||||
int n_requested = last_drain_request_amount_;
|
||||
final FluidStack req_res = last_drain_request_fluid_;
|
||||
last_drain_request_amount_ = 0;
|
||||
last_drain_request_fluid_ = null;
|
||||
if(tank_!=null) {
|
||||
if((n_requested > 0) && ((req_res == null) || (tank_.isFluidEqual(req_res)))) { vacuum_ += 2; } else { --vacuum_; }
|
||||
vacuum_ = MathHelper.clamp(vacuum_, 0, 5);
|
||||
if(vacuum_ <= 0) return; // nothing to do, noone's draining or can't because the fuild does not match.
|
||||
} else {
|
||||
n_requested = 10; // drip in
|
||||
}
|
||||
int tank_level = MathHelper.clamp( (tank_==null) ? 0 : tank_.amount, 0, tank_capacity_mb);
|
||||
if(tank_level >= Math.min(tank_capacity_mb, n_requested * 4)) return; // enough reserve
|
||||
tick_timer_ = 0; // pull next tick
|
||||
FluidStack match = (tank_==null) ? (req_res) : (tank_);
|
||||
for(int i=0; i<6; ++i) {
|
||||
if(++round_robin_ > 5) round_robin_ = 0;
|
||||
final EnumFacing f = EnumFacing.byIndex(round_robin_);
|
||||
if(f == block_facing_) continue;
|
||||
final TileEntity te = world.getTileEntity(pos.offset(f));
|
||||
if((te==null) || (!te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite()))) continue;
|
||||
final IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite());
|
||||
if(fh==null) continue;
|
||||
int refill = Math.min(Math.max(n_requested, 100), tank_capacity_mb-tank_level);
|
||||
if(refill <= 0) break;
|
||||
FluidStack res;
|
||||
if(match==null) {
|
||||
res = fh.drain(refill, true);
|
||||
if(res != null) match = res.copy();
|
||||
} else {
|
||||
res.amount = MathHelper.clamp(res.amount, 0, Math.min(tank_fill_rate_mb, tank_capacity_mb-parent_.tank_.amount));
|
||||
if((res.amount <= 0) || (!parent_.tank_.isFluidEqual(resource))) return 0;
|
||||
if(doFill) parent_.tank_.amount += res.amount;
|
||||
return res.amount;
|
||||
match.amount = refill;
|
||||
res = fh.drain(match.copy(), true);
|
||||
}
|
||||
if(res == null) continue;
|
||||
if(tank_==null) {
|
||||
tank_ = res;
|
||||
} else {
|
||||
tank_.amount += res.amount;
|
||||
}
|
||||
if(tank_.amount >= tank_capacity_mb) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
{
|
||||
"textures": {
|
||||
"end": "engineersdecor:blocks/pipe/straight_pipe_valve_end_texture",
|
||||
"particle": "engineersdecor:blocks/pipe/straight_pipe_valve_end_texture",
|
||||
"side": "engineersdecor:blocks/pipe/straight_pipe_valve_side_texture"
|
||||
"end": "engineersdecor:blocks/pipe/passive_fluid_accumulator_front_texture",
|
||||
"particle": "engineersdecor:blocks/pipe/passive_fluid_accumulator_front_texture",
|
||||
"side": "engineersdecor:blocks/pipe/passive_fluid_accumulator_side_texture",
|
||||
"back": "engineersdecor:blocks/pipe/passive_fluid_accumulator_back_texture"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [2, 2, 0],
|
||||
"to": [14, 14, 1],
|
||||
"from": [3, 3, 0],
|
||||
"to": [13, 13, 1],
|
||||
"faces": {
|
||||
"north": {"uv": [2, 2, 14, 14], "texture": "#end"},
|
||||
"east": {"uv": [2, 0, 14, 1], "rotation": 90, "texture": "#side"},
|
||||
"south": {"uv": [2, 2, 14, 14], "texture": "#end"},
|
||||
"west": {"uv": [2, 0, 14, 1], "rotation": 270, "texture": "#side"},
|
||||
"up": {"uv": [2, 0, 14, 1], "texture": "#side"},
|
||||
"down": {"uv": [2, 15, 14, 16], "texture": "#side"}
|
||||
"north": {"uv": [3, 3, 13, 13], "texture": "#end"},
|
||||
"east": {"uv": [15, 4, 16, 16], "texture": "#side"},
|
||||
"west": {"uv": [0, 4, 1, 16], "texture": "#side"},
|
||||
"up": {"uv": [4, 0, 16, 1], "texture": "#side"},
|
||||
"down": {"uv": [0, 15, 12, 16], "texture": "#side"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [0, 0, 1],
|
||||
"to": [16, 16, 16],
|
||||
"faces": {
|
||||
"north": {"uv": [4, 4, 12, 12], "texture": "#end"},
|
||||
"east": {"uv": [3, 5, 13, 11], "rotation": 90, "texture": "#side"},
|
||||
"south": {"uv": [4, 4, 12, 12], "texture": "#end"},
|
||||
"west": {"uv": [3, 5, 13, 11], "rotation": 270, "texture": "#side"},
|
||||
"up": {"uv": [3, 5, 13, 11], "texture": "#side"},
|
||||
"down": {"uv": [3, 5, 13, 11], "rotation": 180, "texture": "#side"}
|
||||
"north": {"uv": [0, 0, 16, 16], "texture": "#end"},
|
||||
"east": {"uv": [0, 1, 16, 16], "rotation": 90, "texture": "#side"},
|
||||
"south": {"uv": [0, 0, 16, 16], "texture": "#back"},
|
||||
"west": {"uv": [0, 1, 16, 16], "rotation": 270, "texture": "#side"},
|
||||
"up": {"uv": [0, 1, 16, 16], "texture": "#side"},
|
||||
"down": {"uv": [0, 1, 16, 16], "rotation": 180, "texture": "#side"}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 691 B |
Binary file not shown.
After Width: | Height: | Size: 693 B |
Binary file not shown.
After Width: | Height: | Size: 682 B |
Loading…
Add table
Add a link
Reference in a new issue