Valves redstone connection adaptions, valves remove pressurized flag when not inserting to fluid pipes, fluid accumulator refilling changed.

This commit is contained in:
stfwi 2019-05-02 00:04:04 +02:00
parent 16ddb6b84f
commit 6822334299
14 changed files with 172 additions and 93 deletions

View file

@ -4,4 +4,4 @@ org.gradle.jvmargs=-Xmx8G
version_minecraft=1.12.2
version_forge=14.23.5.2768
version_jei=4.10.0.198
version_engineersdecor=1.0.4-b8
version_engineersdecor=1.0.4-b9

View file

@ -1,6 +1,7 @@
{
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
"1.12.2": {
"1.0.4-b9": "[F] Inserting fluids with pressurized tag only into IE piping.\n[F] Valve redstone connector rendering does not check for \"can connect redstone\" but only for \"can provide power\".\n[M] Valves are adpted to be detected as pipe by IE.",
"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).",
@ -32,6 +33,6 @@
},
"promos": {
"1.12.2-recommended": "1.0.3",
"1.12.2-latest": "1.0.4-b8"
"1.12.2-latest": "1.0.4-b9"
}
}

View file

@ -10,6 +10,11 @@ Mod sources for Minecraft version 1.12.2.
----
## Revision history
- v1.0.4-b9 [F] Inserting fluids with pressurized tag only into IE piping.
[F] Valve redstone connector rendering does not check for
"can connect redstone" but only for "can provide power".
[M] Valves are adpted to be detected as pipe by IE.
- v1.0.4-b8 [F] Fixed stairs rendering without smooth light (thanks rastot9).
[E] Added passive fluid accumulator (experimental feature, see config).

View file

@ -0,0 +1,18 @@
/*
* BluSunrize
* Copyright (c) 2017
*
* This code is licensed under "Blu's License of Common Sense"
* Details can be found in the license file in the root folder of this project
*/
package blusunrize.immersiveengineering.api.fluid;
import net.minecraft.util.EnumFacing;
public interface IFluidPipe
{
boolean canOutputPressurized(boolean consumePower);
boolean hasOutputConnection(EnumFacing side);
}

View file

@ -4,11 +4,19 @@
* @copyright (C) 2019 Stefan Wilhelm
* @license MIT (see https://opensource.org/licenses/MIT)
*
* Basically a piece of pipe that does not connect to
* pipes on the side, and conducts fluids only in one way.
* A device that collects fluids from adjacent tank outputs
* when a pump drains on the (only) output side. Shall support
* high flow rates, and a vavuum suction delay. Shall not drain
* high amounts of fluid from the adjacent tanks when no fluid
* is requested at the output port. Shall drain balanced from
* the adjacent input sides.
*/
package wile.engineersdecor.blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import wile.engineersdecor.ModEngineersDecor;
import wile.engineersdecor.detail.ModAuxiliaries;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
@ -46,6 +54,15 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
public TileEntity createTileEntity(World world, IBlockState state)
{ return new BlockDecorPassiveFluidAccumulator.BTileEntity(); }
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(world.isRemote) return true;
TileEntity te = world.getTileEntity(pos);
if(!(te instanceof BTileEntity)) return true;
((BTileEntity)te).debug_info_dump(player);
return true;
}
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(); }
@ -57,18 +74,26 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
{
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_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;
private int total_volume_filled_ = 0;
private int total_volume_drained_ = 0;
@Deprecated
public void debug_info_dump(EntityPlayer player)
{
int t_vol = (tank_==null) ? 0 : (tank_.amount);
ModAuxiliaries.playerChatMessage(player,"pfacc I:" + total_volume_filled_ + " O:" + total_volume_drained_ + " B:" + t_vol);
}
public void block_changed()
{ initialized_ = false; tick_timer_ = MathHelper.clamp(tick_timer_ , 0, tick_idle_interval); }
@ -79,39 +104,16 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
private final BTileEntity parent_;
private final IFluidTankProperties[] props_ = {this};
InputFillHandler(BTileEntity parent) { parent_ = parent; }
@Override public int fill(FluidStack resource, boolean doFill) { return 0; }
@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 null; }
@Override public IFluidTankProperties[] getTankProperties() { return props_; }
@Override public int getCapacity() { return tank_capacity_mb; }
@Override public int getCapacity() { return max_flowrate; }
@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 ------------------------------------------------------------------------------
@ -170,8 +172,8 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
@Nullable
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if(doDrain) last_drain_request_fluid_ = resource.copy();
return ((tank_==null) || (!tank_.isFluidEqual(resource))) ? (null) : drain(resource.amount, doDrain);
if((resource==null) || (tank_==null)) return null;
return (!(tank_.isFluidEqual(resource))) ? (null) : drain(resource.amount, doDrain);
}
@Override
@ -179,18 +181,15 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
public FluidStack drain(int maxDrain, boolean doDrain)
{
if(!initialized_) return null;
if(doDrain) last_drain_request_amount_ = maxDrain;
if(doDrain && (maxDrain > 0)) last_drain_request_amount_ = maxDrain;
if(tank_==null) return null;
FluidStack res;
if(maxDrain >= tank_.amount) {
if(!doDrain) return tank_.copy();
res = tank_;
tank_ = null;
} else {
res = tank_.copy();
res.amount = maxDrain;
if(doDrain) tank_.amount -= maxDrain;
}
maxDrain = MathHelper.clamp(maxDrain ,0 , tank_.amount);
if(!doDrain) return tank_.copy();
FluidStack res = tank_.copy();
res.amount = maxDrain;
tank_.amount -= maxDrain;
if(tank_.amount <= 0) tank_= null;
total_volume_drained_ += res.amount;
return res;
}
@ -216,46 +215,53 @@ public class BlockDecorPassiveFluidAccumulator extends BlockDecorDirected implem
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.
if(n_requested > 0) {
vacuum_ += 2;
if(vacuum_ > 5) vacuum_ = 5;
} else {
n_requested = 10; // drip in
if((--vacuum_) <= 0) {
vacuum_ = 0;
if(tank_!=null) {
return; // nothing to do, noone's draining.
} 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_);
boolean has_refilled = false;
n_requested += (vacuum_ * 50);
int tank_buffer_needed = n_requested;
if(tank_buffer_needed > max_flowrate) tank_buffer_needed = max_flowrate;
for(int i=0; i<6; ++i) {
if(++round_robin_ > 5) round_robin_ = 0;
if(n_requested <= 0) break;
if(((tank_!=null) && (tank_.amount >= tank_buffer_needed))) break;
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;
if((te==null) || (te instanceof BTileEntity) || (!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 {
match.amount = refill;
res = fh.drain(match.copy(), true);
}
if(res == null) continue;
if(tank_==null) {
tank_ = res;
FluidStack res = fh.drain(n_requested, true);
if((res == null) || (res.amount==0)) continue;
total_volume_filled_ += res.amount;
tank_ = res.copy();
has_refilled = true;
} else {
if((tank_.amount + n_requested) > max_flowrate) n_requested = (max_flowrate - tank_.amount);
FluidStack rq = tank_.copy();
rq.amount = n_requested;
FluidStack res = fh.drain(rq, true);
if(res == null) continue;
tank_.amount += res.amount;
total_volume_filled_ += res.amount;
has_refilled = true;
if(tank_.amount >= max_flowrate) break;
}
if(tank_.amount >= tank_capacity_mb) break;
}
if(has_refilled) tick_timer_ = 0;
}
}
}

View file

@ -9,21 +9,23 @@
*/
package wile.engineersdecor.blocks;
import net.minecraft.util.EnumHand;
import wile.engineersdecor.ModEngineersDecor;
import blusunrize.immersiveengineering.api.fluid.IFluidPipe;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@ -81,9 +83,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
if(f.getAxis() == bfa) continue;
BlockPos nbp = pos.offset(f);
IBlockState nbs = world.getBlockState(nbp);
if(nbs.canProvidePower() && (nbs.getBlock().canConnectRedstone(nbs, world, nbp, f))) {
return state.withProperty(RS_CONNECTION_DIR, rsconnectors[state.getValue(FACING).getIndex()][f.getIndex()]);
}
if(nbs.canProvidePower()) return state.withProperty(RS_CONNECTION_DIR, rsconnectors[state.getValue(FACING).getIndex()][f.getIndex()]);
}
return state.withProperty(RS_CONNECTION_DIR, 0);
}
@ -102,6 +102,11 @@ public class BlockDecorPipeValve extends BlockDecorDirected
world.notifyNeighborsOfStateChange(pos, this, true);
}
@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{ return BlockFaceShape.SOLID; }
@Override
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side)
{ return (side!=null) && (side!=state.getValue(FACING)) && (side!=state.getValue(FACING).getOpposite()); }
@ -123,7 +128,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
// Tile entity
//--------------------------------------------------------------------------------------------------------------------
public static class BTileEntity extends TileEntity implements IFluidHandler, IFluidTankProperties, ICapabilityProvider
public static class BTileEntity extends TileEntity implements IFluidHandler, IFluidTankProperties, ICapabilityProvider, IFluidPipe
{
private static final BackFlowHandler back_flow_handler_ = new BackFlowHandler();
protected static int fluid_maxflow_mb = 1000;
@ -131,6 +136,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
private final IFluidTankProperties[] fluid_props_ = {this};
private EnumFacing block_facing_ = EnumFacing.NORTH;
private boolean filling_ = false;
private boolean getlocked_ = false;
private boolean filling_enabled_ = true;
private long block_config_ = 0;
@ -224,14 +230,17 @@ public class BlockDecorPipeValve extends BlockDecorDirected
}
FluidStack res = resource.copy();
if(res.amount > fluid_maxflow_mb) res.amount = fluid_maxflow_mb;
if(res.amount > 50) {
// forward pressureized tag
if(res.tag==null) res.tag = new NBTTagCompound();
res.tag.setBoolean("pressurized", true);
}
final IFluidHandler fh = forward_fluid_handler();
if(fh==null) return 0;
filling_ = true; // in case someone does not check the cap, but just "forwards back" what is beeing filled right now.
if(res.amount > 50) {
final TileEntity te = world.getTileEntity(pos.offset(block_facing_));
if(te instanceof IFluidPipe) {
// forward pressureized tag
if(res.tag == null) res.tag = new NBTTagCompound();
res.tag.setBoolean("pressurized", true);
}
}
int n_filled = forward_fluid_handler().fill(res, doFill);
filling_ = false;
//if(n_filled > 0) System.out.println("F:" + resource.amount + "->" + n_filled);
@ -260,7 +269,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
{ return null; }
public int getCapacity()
{ return 10000; }
{ return 1000; }
@Override
public boolean canFill()
@ -295,5 +304,23 @@ public class BlockDecorPipeValve extends BlockDecorDirected
@Override public boolean canDrainFluidType(FluidStack fluidStack) { return false; }
}
// IFluidPipe
@Override
public boolean hasOutputConnection(EnumFacing side)
{ return (side == block_facing_); }
@Override
public boolean canOutputPressurized(boolean consumePower)
{
if(getlocked_ || (!filling_enabled_)) return false;
final TileEntity te = world.getTileEntity(pos.offset(block_facing_));
if(!(te instanceof IFluidPipe)) return false;
getlocked_ = true; // not sure if IE explicitly pre-detects loops, so let's lock recurion here, too.
boolean r = ((IFluidPipe)te).canOutputPressurized(consumePower);
getlocked_ = false;
return r;
}
}
}

View file

@ -8,6 +8,7 @@
*/
package wile.engineersdecor.detail;
import net.minecraft.entity.player.EntityPlayer;
import wile.engineersdecor.ModEngineersDecor;
import net.minecraft.world.World;
import net.minecraft.item.ItemStack;
@ -145,5 +146,13 @@ public class ModAuxiliaries
return bb;
}
@SuppressWarnings("unused")
public static void playerChatMessage(EntityPlayer player, final String message)
{
String s = message.trim();
if(!s.isEmpty()) player.sendMessage(new TextComponentTranslation(s));
}
@SuppressWarnings("unused")
public interface IExperimentalFeature{}
}

View file

@ -22,11 +22,11 @@
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#end"},
"east": {"uv": [0, 1, 16, 16], "rotation": 90, "texture": "#side"},
"east": {"uv": [0, 0, 15, 16], "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"}
"west": {"uv": [1, 0, 16, 16], "texture": "#side"},
"up": {"uv": [0, 0, 16, 15], "texture": "#side"},
"down": {"uv": [0, 0, 16, 15], "rotation": 180, "texture": "#side"}
}
}
],

View file

@ -6,14 +6,26 @@
},
"elements": [
{
"from": [5, 5, 0],
"from": [5, 5, 2],
"to": [11, 11, 3],
"faces": {
"north": {"uv": [5, 5, 11, 11], "rotation": 90, "texture": "#rsend"},
"east": {"uv": [13, 5, 16, 11], "texture": "#rsside"},
"west": {"uv": [13, 5, 16, 11], "rotation": 180, "texture": "#rsside"},
"up": {"uv": [13, 5, 16, 11], "rotation": 270, "texture": "#rsside"},
"down": {"uv": [13, 5, 16, 11], "rotation": 90, "texture": "#rsside"}
"east": {"uv": [13, 5, 14, 11], "texture": "#rsside"},
"west": {"uv": [13, 5, 14, 11], "rotation": 180, "texture": "#rsside"},
"up": {"uv": [13, 5, 14, 11], "rotation": 270, "texture": "#rsside"},
"down": {"uv": [13, 5, 14, 11], "rotation": 90, "texture": "#rsside"}
}
},
{
"from": [4, 4, 0],
"to": [12, 12, 2],
"faces": {
"north": {"uv": [4, 4, 12, 12], "rotation": 90, "texture": "#rsend"},
"east": {"uv": [13, 4, 16, 12], "texture": "#rsside"},
"south": {"uv": [4, 4, 12, 12], "texture": "#rsend"},
"west": {"uv": [13, 4, 16, 12], "rotation": 180, "texture": "#rsside"},
"up": {"uv": [13, 4, 16, 12], "rotation": 270, "texture": "#rsside"},
"down": {"uv": [13, 4, 16, 12], "rotation": 90, "texture": "#rsside"}
}
}
],

Binary file not shown.

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 639 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 693 B

After

Width:  |  Height:  |  Size: 680 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 682 B

After

Width:  |  Height:  |  Size: 618 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 B

After

Width:  |  Height:  |  Size: 324 B

Before After
Before After