mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Added fluid valve with counter
This commit is contained in:
parent
de2a11389c
commit
a944c28dd4
@ -743,7 +743,7 @@ public class ModBlocks {
|
||||
public static Block machine_microwave;
|
||||
|
||||
public static Block machine_battery_socket;
|
||||
|
||||
|
||||
@Deprecated public static Block machine_battery_potato;
|
||||
@Deprecated public static Block machine_battery;
|
||||
@Deprecated public static Block machine_lithium_battery;
|
||||
@ -787,6 +787,7 @@ public class ModBlocks {
|
||||
public static Block pipe_anchor;
|
||||
public static Block fluid_valve;
|
||||
public static Block fluid_switch;
|
||||
public static Block fluid_counter_valve;
|
||||
public static Block fluid_pump;
|
||||
public static Block machine_drain;
|
||||
public static Block radio_torch_sender;
|
||||
@ -1920,6 +1921,7 @@ public class ModBlocks {
|
||||
fluid_duct_gauge = new FluidDuctGauge().setBlockName("fluid_duct_gauge").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
|
||||
fluid_valve = new FluidValve(Material.iron).setBlockName("fluid_valve").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
|
||||
fluid_switch = new FluidSwitch(Material.iron).setBlockName("fluid_switch").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
|
||||
fluid_counter_valve = new FluidCounterValve(Material.iron).setBlockName("fluid_counter_valve").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
|
||||
fluid_pump = new FluidPump(Material.iron).setBlockName("fluid_pump").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":block_steel");
|
||||
machine_drain = new MachineDrain(Material.iron).setBlockName("machine_drain").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":concrete");
|
||||
radio_torch_sender = new RadioTorchSender().setBlockName("radio_torch_sender").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
|
||||
@ -3205,6 +3207,7 @@ public class ModBlocks {
|
||||
register(pipe_anchor);
|
||||
register(fluid_duct_gauge);
|
||||
register(fluid_valve);
|
||||
register(fluid_counter_valve);
|
||||
register(fluid_switch);
|
||||
register(fluid_pump);
|
||||
register(machine_drain);
|
||||
|
||||
68
src/main/java/com/hbm/blocks/network/FluidCounterValve.java
Normal file
68
src/main/java/com/hbm/blocks/network/FluidCounterValve.java
Normal file
@ -0,0 +1,68 @@
|
||||
package com.hbm.blocks.network;
|
||||
|
||||
import com.hbm.blocks.ILookOverlay;
|
||||
import com.hbm.blocks.ITooltipProvider;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.tileentity.network.TileEntityFluidCounterValve;
|
||||
import com.hbm.util.i18n.I18nUtil;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FluidCounterValve extends FluidDuctBase implements ILookOverlay, ITooltipProvider {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon iconOn;
|
||||
|
||||
public FluidCounterValve(Material mat) {
|
||||
super(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
this.iconOn = iconRegister.registerIcon(RefStrings.MODID + ":fluid_counter_valve_on");
|
||||
this.blockIcon = iconRegister.registerIcon(RefStrings.MODID + ":fluid_counter_valve_off");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
return metadata == 1 ? iconOn : blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileEntityFluidCounterValve();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHook(Pre event, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
|
||||
if(!(te instanceof TileEntityFluidCounterValve))
|
||||
return;
|
||||
|
||||
TileEntityFluidCounterValve duct = (TileEntityFluidCounterValve) te;
|
||||
|
||||
List<String> text = new ArrayList<>();
|
||||
text.add("&[" + duct.getType().getColor() + "&]" + duct.getType().getLocalizedName());
|
||||
text.add("Counter: " + duct.getCounter());
|
||||
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
|
||||
this.addStandardInfo(stack, player, list, ext);
|
||||
}
|
||||
}
|
||||
@ -443,6 +443,7 @@ public class TileMappings {
|
||||
put(TileEntityPipeExhaust.class, "tileentity_pipe_exhaust");
|
||||
put(TileEntityPipeExhaustPaintable.class, "tileentity_pipe_exhaust_paintable");
|
||||
put(TileEntityFluidValve.class, "tileentity_pipe_valve");
|
||||
put(TileEntityFluidCounterValve.class, "tileentity_pipe_counter_valve");
|
||||
put(TileEntityFluidPump.class, "tileentity_pipe_pump");
|
||||
|
||||
put(TileEntityPipeAnchor.class, "tileentity_pioe_anchor");
|
||||
|
||||
@ -0,0 +1,157 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import api.hbm.redstoneoverradio.IRORInteractive;
|
||||
import api.hbm.redstoneoverradio.IRORValueProvider;
|
||||
import com.hbm.handler.CompatHandler;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
import com.hbm.uninos.UniNodespace;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.SimpleComponent;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
|
||||
public class TileEntityFluidCounterValve extends TileEntityPipeBaseNT implements SimpleComponent, CompatHandler.OCComponent, IRORValueProvider, IRORInteractive {
|
||||
private long counter;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
if(node != null && node.net != null && getType() != Fluids.NONE) {
|
||||
counter += node.net.fluidTracker;
|
||||
}
|
||||
|
||||
networkPackNT(25);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateNode() {
|
||||
return this.getBlockMetadata() == 1;
|
||||
}
|
||||
|
||||
public void updateState() {
|
||||
this.blockMetadata = -1; // delete cache
|
||||
|
||||
if(this.getBlockMetadata() == 0 && this.node != null) {
|
||||
UniNodespace.destroyNode(worldObj, xCoord, yCoord, zCoord, this.getType().getNetworkProvider());
|
||||
this.node = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z) {
|
||||
return oldBlock != newBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
counter = nbt.getLong("counter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setLong("counter", counter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
buf.writeLong(counter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
this.counter = Math.max(buf.readLong(), 0);
|
||||
}
|
||||
|
||||
private void setState(int state) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, state, 2);
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "hbm:block.reactorStart", 1.0F, 1.0F);
|
||||
updateState();
|
||||
}
|
||||
|
||||
public long getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public String getComponentName() {
|
||||
return "ntm_fluid_counter_valve";
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] getFluid(Context context, Arguments args) {
|
||||
return new Object[] {getType().getName()};
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] getCounter(Context context, Arguments args) {
|
||||
return new Object[] {counter};
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] resetCounter(Context context, Arguments args) {
|
||||
counter = 0;
|
||||
markDirty();
|
||||
return new Object[] {};
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] getState(Context context, Arguments args) {
|
||||
return new Object[] {getBlockMetadata() == 1 ? 1 : 0};
|
||||
}
|
||||
|
||||
@Callback(direct = true)
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] setState(Context context, Arguments args) {
|
||||
final int state = args.checkInteger(0);
|
||||
if(state != 0 && state != 1) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
setState(state);
|
||||
return new Object[] {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String provideRORValue(String name) {
|
||||
if((PREFIX_VALUE + "value").equals(name))
|
||||
return String.valueOf(counter);
|
||||
if((PREFIX_VALUE + "state").equals(name))
|
||||
return String.valueOf(getBlockMetadata() == 1 ? 1 : 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFunctionInfo() {
|
||||
return new String[] {
|
||||
PREFIX_VALUE + "value",
|
||||
PREFIX_VALUE + "state",
|
||||
PREFIX_FUNCTION + "reset",
|
||||
PREFIX_FUNCTION + "setState" + NAME_SEPARATOR + "state",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String runRORFunction(String name, String[] params) {
|
||||
if(name.equals(PREFIX_FUNCTION + "reset")) {
|
||||
counter = 0;
|
||||
markDirty();
|
||||
} else if(name.equals(PREFIX_FUNCTION + "setState")) {
|
||||
setState(IRORInteractive.parseInt(params[0], 0, 1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -5529,6 +5529,8 @@ tile.fluid_duct_neo.name=Universal Fluid Duct
|
||||
tile.fluid_duct_paintable.name=Paintable Coated Universal Fluid Duct
|
||||
tile.fluid_duct_solid.name=Coated Universal Fluid Duct (Deprecated)
|
||||
tile.fluid_pump.name=Flow Control Pump
|
||||
tile.fluid_counter_valve.name=Fluid Valve with Counter
|
||||
tile.fluid_counter_valve.desc=Beware of loops in your fluid network...
|
||||
tile.fluid_switch.name=Redstone Fluid Valve
|
||||
tile.fluid_valve.name=Fluid Valve
|
||||
tile.foam_layer.name=Foam layer
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Loading…
x
Reference in New Issue
Block a user