Added redstone controlled fluid valves. Check valve recipe adapted.
This commit is contained in:
parent
a6bdff4bde
commit
ff03a1b70d
22 changed files with 317 additions and 27 deletions
|
@ -51,7 +51,9 @@ public class BlockDecor extends Block
|
|||
public static final long CFG_TRANSLUCENT = 0x0000000000000040L; // indicates a block/pane is glass like (transparent, etc)
|
||||
public static final long CFG_LIGHT_VALUE_MASK = 0x0000000000000f00L; // fixed value for getLightValue()
|
||||
public static final long CFG_LIGHT_VALUE_SHIFT = 8L;
|
||||
public static final long CFG_LAB_FURNACE_CRUDE = 0x0000000000010000L; // For DecorFurnace, denotes that it is a crude furnace.
|
||||
public static final long CFG_ELECTRICAL = 0x0000000000010000L; // Denotes if a component is mainly flux driven.
|
||||
public static final long CFG_REDSTONE_CONTROLLED = 0x0000000000020000L; // Denotes if a component has somehow a redstone control input
|
||||
public static final long CFG_ANALOG = 0x0000000000040000L; // Denotes if a component has analog behaviour
|
||||
|
||||
protected final AxisAlignedBB aabb;
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
*/
|
||||
package wile.engineersdecor.blocks;
|
||||
|
||||
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;
|
||||
|
@ -16,6 +18,8 @@ import net.minecraft.block.material.Material;
|
|||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
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.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
@ -26,6 +30,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import wile.engineersdecor.ModEngineersDecor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -33,18 +38,59 @@ import javax.annotation.Nullable;
|
|||
|
||||
public class BlockDecorPipeValve extends BlockDecorDirected
|
||||
{
|
||||
public static final PropertyInteger RS_CONNECTION_DIR = PropertyInteger.create("rsdir", 0,4);
|
||||
|
||||
public static void on_config(int container_size_decl, int redstone_slope)
|
||||
{
|
||||
BTileEntity.fluid_capacity_mb = MathHelper.clamp(container_size_decl, 1, 10000);
|
||||
BTileEntity.redstone_flow_slope_mb = MathHelper.clamp(redstone_slope, 1, 10000);
|
||||
ModEngineersDecor.logger.info("Config pipe valve: maxflow:" + BTileEntity.fluid_capacity_mb + "mb, redstone amp:" + BTileEntity.redstone_flow_slope_mb + "mb/sig");
|
||||
}
|
||||
|
||||
public BlockDecorPipeValve(@Nonnull String registryName, long config, @Nullable Material material, float hardness, float resistance, @Nullable SoundType sound, @Nonnull AxisAlignedBB unrotatedAABB)
|
||||
{ super(registryName, config, material, hardness, resistance, sound, unrotatedAABB); }
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{ return new BlockStateContainer(this, FACING, RS_CONNECTION_DIR); }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
{
|
||||
IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
|
||||
if(!placer.isSneaking()) state = state.withProperty(FACING, state.getValue(FACING).getOpposite());
|
||||
if(!placer.isSneaking()) state = state.withProperty(FACING, state.getValue(FACING).getOpposite()).withProperty(RS_CONNECTION_DIR, 0);
|
||||
return state;
|
||||
}
|
||||
|
||||
// world to model index transformations. [Facing block][Facing neighbour] -> int 0=nothing, 1=top, 2=right, 3=down, 4=left.
|
||||
private static final int rsconnectors[][] = {
|
||||
//D U N S W E
|
||||
{0, 0, 1, 3, 4, 2}, // D
|
||||
{0, 0, 3, 1, 4, 2}, // U
|
||||
{3, 1, 0, 0, 4, 2}, // N
|
||||
{3, 1, 0, 0, 2, 4}, // S
|
||||
{3, 1, 2, 4, 0, 0}, // W
|
||||
{3, 1, 4, 2, 0, 0}, // E
|
||||
};
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
if((config & (CFG_REDSTONE_CONTROLLED))==0) return state;
|
||||
EnumFacing.Axis bfa = state.getValue(FACING).getAxis();
|
||||
int bfi = state.getValue(FACING).getIndex();
|
||||
for(EnumFacing f:EnumFacing.VALUES) {
|
||||
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()]);
|
||||
}
|
||||
}
|
||||
return state.withProperty(RS_CONNECTION_DIR, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos fromPos)
|
||||
|
@ -60,6 +106,9 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
world.notifyNeighborsOfStateChange(pos, this, true);
|
||||
}
|
||||
|
||||
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side)
|
||||
{ return (side!=null) && (side!=state.getValue(FACING)) && (side!=state.getValue(FACING).getOpposite()); }
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{ return true; }
|
||||
|
@ -71,7 +120,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
private void update_te(World world, IBlockState state, BlockPos pos)
|
||||
{
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if(te instanceof BlockDecorPipeValve.BTileEntity) ((BlockDecorPipeValve.BTileEntity)te).block_reconfigure(state.getValue(FACING));
|
||||
if(te instanceof BlockDecorPipeValve.BTileEntity) ((BlockDecorPipeValve.BTileEntity)te).block_reconfigure(state.getValue(FACING), config);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -80,17 +129,34 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
|
||||
public static class BTileEntity extends TileEntity implements IFluidHandler, IFluidTankProperties, ICapabilityProvider
|
||||
{
|
||||
public static final int FLUID_CAPACITY_MB = 1000; // likely also the max flow per tick
|
||||
private static final BackFlowHandler back_flow_handler_ = new BackFlowHandler();
|
||||
protected static int fluid_capacity_mb = 1000; // likely also the max flow per tick
|
||||
protected static int redstone_flow_slope_mb = 1000/15;
|
||||
private final IFluidTankProperties[] fluid_props_ = {this};
|
||||
private EnumFacing block_facing_ = EnumFacing.NORTH;
|
||||
private boolean filling = false;
|
||||
private boolean filling_ = false;
|
||||
private boolean filling_enabled_ = true;
|
||||
private long block_config_ = 0;
|
||||
|
||||
public BTileEntity()
|
||||
{}
|
||||
|
||||
public void block_reconfigure(EnumFacing facing)
|
||||
{ block_facing_ = facing; }
|
||||
public void block_reconfigure(EnumFacing facing, long block_config)
|
||||
{
|
||||
block_facing_ = facing;
|
||||
block_config_ = block_config;
|
||||
filling_enabled_ = false;
|
||||
IFluidHandler fh = forward_fluid_handler();
|
||||
if(fh!=null) {
|
||||
if(fh.getTankProperties().length==0) {
|
||||
filling_enabled_ = true; // we don't know, so in doubt try filling.
|
||||
} else {
|
||||
for(IFluidTankProperties fp:fh.getTankProperties()) {
|
||||
if((fp!=null) && (fp.canFill())) { filling_enabled_ = true; break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TileEntity ------------------------------------------------------------------------------
|
||||
|
||||
|
@ -104,7 +170,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
if(!hasWorld()) return;
|
||||
final IBlockState state = world.getBlockState(pos);
|
||||
if((!(state.getBlock() instanceof BlockDecorPipeValve))) return;
|
||||
block_reconfigure(state.getValue(FACING));
|
||||
block_reconfigure(state.getValue(FACING), block_config_);
|
||||
}
|
||||
|
||||
// ICapabilityProvider --------------------------------------------------------------------
|
||||
|
@ -124,17 +190,28 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
|
||||
// IFluidHandler/IFluidTankProperties ---------------------------------------------------------------
|
||||
|
||||
@Nullable
|
||||
private IFluidHandler forward_fluid_handler()
|
||||
{
|
||||
final TileEntity te = world.getTileEntity(pos.offset(block_facing_));
|
||||
if(te == null) return null;
|
||||
return te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, block_facing_.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if(filling) return 0;
|
||||
final TileEntity te = world.getTileEntity(pos.offset(block_facing_));
|
||||
if(te == null) return 0;
|
||||
final IFluidHandler fh = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, block_facing_.getOpposite());
|
||||
if((filling_) || (!filling_enabled_)) return 0;
|
||||
if((block_config_ & CFG_REDSTONE_CONTROLLED) != 0) {
|
||||
int rs = world.getRedstonePowerFromNeighbors(pos);
|
||||
if(rs <= 0) return 0;
|
||||
if(((block_config_ & CFG_ANALOG) != 0) && (rs < 15)) resource.amount = MathHelper.clamp(rs * redstone_flow_slope_mb, 1, resource.amount);
|
||||
}
|
||||
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.
|
||||
int n_filled = fh.fill(resource, doFill);
|
||||
filling = false;
|
||||
filling_ = true; // in case someone does not check the cap, but just "forwards back" what is beeing filled right now.
|
||||
int n_filled = forward_fluid_handler().fill(resource, doFill);
|
||||
filling_ = false;
|
||||
return n_filled;
|
||||
}
|
||||
|
||||
|
@ -160,7 +237,7 @@ public class BlockDecorPipeValve extends BlockDecorDirected
|
|||
{ return null; }
|
||||
|
||||
public int getCapacity()
|
||||
{ return FLUID_CAPACITY_MB; }
|
||||
{ return fluid_capacity_mb; }
|
||||
|
||||
@Override
|
||||
public boolean canFill()
|
||||
|
|
|
@ -181,13 +181,27 @@ public class ModBlocks
|
|||
ModAuxiliaries.getPixeledAABB(5,11,0, 11,16,16)
|
||||
);
|
||||
|
||||
public static final BlockDecorPipeValve STRAIGHT_PIPE_VALVE = new BlockDecorPipeValve(
|
||||
public static final BlockDecorPipeValve STRAIGHT_CHECK_VALVE = new BlockDecorPipeValve(
|
||||
"straight_pipe_valve",
|
||||
BlockDecor.CFG_CUTOUT|BlockDecor.CFG_FACING_PLACEMENT,
|
||||
Material.IRON, 1.0f, 15f, SoundType.METAL,
|
||||
ModAuxiliaries.getPixeledAABB(4,4,0, 12,12,16)
|
||||
);
|
||||
|
||||
public static final BlockDecorPipeValve STRAIGHT_REDSTONE_VALVE = new BlockDecorPipeValve(
|
||||
"straight_pipe_valve_redstone",
|
||||
BlockDecor.CFG_FACING_PLACEMENT|BlockDecor.CFG_REDSTONE_CONTROLLED,
|
||||
Material.IRON, 1.0f, 15f, SoundType.METAL,
|
||||
ModAuxiliaries.getPixeledAABB(4,4,0, 12,12,16)
|
||||
);
|
||||
|
||||
public static final BlockDecorPipeValve STRAIGHT_REDSTONE_ANALOG_VALVE = new BlockDecorPipeValve(
|
||||
"straight_pipe_valve_redstone_analog",
|
||||
BlockDecor.CFG_FACING_PLACEMENT|BlockDecor.CFG_REDSTONE_CONTROLLED|BlockDecor.CFG_ANALOG,
|
||||
Material.IRON, 1.0f, 15f, SoundType.METAL,
|
||||
ModAuxiliaries.getPixeledAABB(4,4,0, 12,12,16)
|
||||
);
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
//-- Tile entities
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -247,11 +261,10 @@ public class ModBlocks
|
|||
THIN_STEEL_POLE_HEAD,
|
||||
THICK_STEEL_POLE_HEAD,
|
||||
STEEL_DOUBLE_T_SUPPORT,
|
||||
STRAIGHT_PIPE_VALVE, STRAIGHT_PIPE_VALVE_TEI
|
||||
STRAIGHT_CHECK_VALVE, STRAIGHT_REDSTONE_VALVE, STRAIGHT_REDSTONE_ANALOG_VALVE, STRAIGHT_PIPE_VALVE_TEI
|
||||
};
|
||||
|
||||
private static final Object dev_content[] = {
|
||||
};
|
||||
private static final Object dev_content[] = {};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
//-- Init
|
||||
|
|
|
@ -201,6 +201,26 @@ public class ModConfig
|
|||
})
|
||||
@Config.Name("Crafting table: Move buttons")
|
||||
public boolean with_crafting_quickmove_buttons = false;
|
||||
|
||||
@Config.Comment({
|
||||
"Defines how many millibuckets can be transferred (per tick) through the valves. " +
|
||||
"That is technically the 'storage size' specified for blocks that want to fill " +
|
||||
"fluids into the valve (the valve has no container and forward that to the output " +
|
||||
"block), The value can be changed on-the-fly for tuning. "
|
||||
})
|
||||
@Config.Name("Valves: Max flow rate")
|
||||
@Config.RangeInt(min=1, max=10000)
|
||||
public int pipevalve_max_flowrate = 1000;
|
||||
|
||||
@Config.Comment({
|
||||
"Defines how many millibuckets per redstone signal strength can be transferred per tick " +
|
||||
"through the analog redstone controlled valves. Note: power 0 is always off, power 15 is always " +
|
||||
"the max flow rate. Between power 1 and 14 this scaler will result in a flow = 'redstone slope' * 'current redstone power'. " +
|
||||
"The value can be changed on-the-fly for tuning. "
|
||||
})
|
||||
@Config.Name("Valves: Redstone slope")
|
||||
@Config.RangeInt(min=1, max=10000)
|
||||
public int pipevalve_redstone_slope = 20;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -268,6 +288,7 @@ public class ModConfig
|
|||
BlockDecorChair.on_config(optout.without_chair_sitting, optout.without_mob_chair_sitting, tweaks.chair_mob_sitting_probability_percent, tweaks.chair_mob_standup_probability_percent);
|
||||
BlockDecorLadder.on_config(optout.without_ladder_speed_boost);
|
||||
BlockDecorCraftingTable.on_config(optout.without_crafting_table_history, false, tweaks.with_crafting_quickmove_buttons);
|
||||
BlockDecorPipeValve.on_config(tweaks.pipevalve_max_flowrate, tweaks.pipevalve_redstone_slope);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue