From 0c05593a0837b4cab92154c171248fbd7a13db80 Mon Sep 17 00:00:00 2001 From: Alexmaster75 Date: Mon, 8 Jun 2026 01:16:20 +0200 Subject: [PATCH] watz up with conneczions added OC & RoR support for the watz --- .../tileentity/machine/TileEntityWatz.java | 255 +++++++++++++----- 1 file changed, 182 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityWatz.java b/src/main/java/com/hbm/tileentity/machine/TileEntityWatz.java index e012bbe80..37f3b3b41 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityWatz.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityWatz.java @@ -7,6 +7,7 @@ import java.util.Random; import com.hbm.blocks.ModBlocks; import com.hbm.entity.projectile.EntityShrapnel; import com.hbm.handler.radiation.ChunkRadiationManager; +import com.hbm.handler.CompatHandler; // ADD import com.hbm.interfaces.IControlReceiver; import com.hbm.inventory.container.ContainerWatz; import com.hbm.inventory.fluid.Fluids; @@ -29,10 +30,17 @@ import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.function.Function; import api.hbm.fluid.IFluidStandardTransceiver; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; +import api.hbm.redstoneoverradio.IRORInteractive; +import api.hbm.redstoneoverradio.IRORValueProvider; +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.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -45,7 +53,8 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityWatz extends TileEntityMachineBase implements IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IFluidCopiable { +@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")}) +public class TileEntityWatz extends TileEntityMachineBase implements IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IFluidCopiable, CompatHandler.OCComponent, IRORValueProvider, IRORInteractive { public FluidTank[] tanks; public FluidTank[] sharedTanks; @@ -54,11 +63,11 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand public double fluxLastReaction; //flux created by the previous reaction, used for the next reaction public double fluxDisplay; public boolean isOn; - + /* lock types for item IO */ public boolean isLocked = false; public ItemStack[] locks; - + public TileEntityWatz() { super(24); this.locks = new ItemStack[slots.length]; @@ -73,7 +82,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand public String getName() { return "container.watz"; } - + protected void resetSharedTanks() { this.sharedTanks = new FluidTank[3]; this.sharedTanks[0] = new FluidTank(Fluids.COOLANT, 64_000); @@ -86,16 +95,16 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand @Override public void updateEntity() { - + if(!worldObj.isRemote) resetSharedTanks(); - + if(!worldObj.isRemote && !updateLock()) { - + boolean turnedOn = worldObj.getBlock(xCoord, yCoord + 3, zCoord) == ModBlocks.watz_pump && worldObj.getIndirectPowerLevelTo(xCoord, yCoord + 5, zCoord, 0) > 0; List segments = new ArrayList(); segments.add(this); this.subscribeToTop(); - + /* accumulate all segments */ for(int y = yCoord - 3; y >= 0; y -= 3) { TileEntity tile = Compat.getTileStandard(worldObj, xCoord, y, zCoord); @@ -105,11 +114,11 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand break; } } - + /* set up shared tanks */ FluidTank[] sharedTanks = new FluidTank[3]; for(int i = 0; i < 3; i++) sharedTanks[i] = new FluidTank(tanks[i].getTankType(), 0); - + for(TileEntityWatz segment : segments) { segment.setupCoolant(); for(int i = 0; i < 3; i++) { @@ -117,13 +126,13 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand sharedTanks[i].setFill(sharedTanks[i].getFill() + segment.tanks[i].getFill()); } } - + //update coolant, bottom to top for(int i = segments.size() - 1; i >= 0; i--) { TileEntityWatz segment = segments.get(i); segment.updateCoolant(sharedTanks); } - + /* update reaction, top to bottom */ this.updateReaction(null, sharedTanks, turnedOn); for(int i = 1; i < segments.size(); i++) { @@ -131,7 +140,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand TileEntityWatz above = segments.get(i - 1); segment.updateReaction(above, sharedTanks, turnedOn); } - + /* send sync packets (order doesn't matter) */ for(TileEntityWatz segment : segments) { segment.sharedTanks[0] = sharedTanks[0]; @@ -141,7 +150,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand segment.networkPackNT(25); segment.heat *= 0.99; //cool 1% per tick } - + /* re-distribute fluid from shared tanks back into actual tanks, bottom to top */ for(int i = segments.size() - 1; i >= 0; i--) { TileEntityWatz segment = segments.get(i); @@ -151,9 +160,9 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand segment.tanks[j].setFill(min); } } - + segments.get(segments.size() - 1).sendOutBottom(); - + /* explode on mud overflow */ if(sharedTanks[2].getFill() > 0) { for(int x = -3; x <= 3; x++) { @@ -164,39 +173,39 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand } } this.disassemble(); - + ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord + 1, zCoord, 1_000F); - + worldObj.playSoundEffect(xCoord + 0.5, yCoord + 2, zCoord + 0.5, "hbm:block.rbmk_explosion", 50.0F, 1.0F); NBTTagCompound data = new NBTTagCompound(); data.setString("type", "rbmkmush"); data.setFloat("scale", 5); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5, yCoord + 2, zCoord + 0.5), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 250)); MainRegistry.proxy.effectNT(data); - + return; } } } - + /** basic sanity checking, usually wouldn't do anything except when NBT loading borks */ public void setupCoolant() { tanks[0].setTankType(Fluids.COOLANT); tanks[1].setTankType(tanks[0].getTankType().getTrait(FT_Heatable.class).getFirstStep().typeProduced); } - + public void updateCoolant(FluidTank[] tanks) { - + double coolingFactor = 0.2D; //20% per tick double heatToUse = this.heat * coolingFactor; - + FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class); HeatingStep step = trait.getFirstStep(); - + int heatCycles = (int) (heatToUse / step.heatReq); int coolCycles = tanks[0].getFill() / step.amountReq; int hotCycles = (tanks[1].getMaxFill() - tanks[1].getFill()) / step.amountProduced; - + int cycles = Math.min(heatCycles, Math.min(hotCycles, coolCycles)); this.heat -= cycles * step.heatReq; tanks[0].setFill(tanks[0].getFill() - cycles * step.amountReq); @@ -205,34 +214,34 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand /** enforces strict top to bottom update order (instead of semi-random based on placement) */ public void updateReaction(TileEntityWatz above, FluidTank[] tanks, boolean turnedOn) { - + if(turnedOn) { List pellets = new ArrayList(); - + for(int i = 0; i < 24; i++) { ItemStack stack = slots[i]; if(stack != null && stack.getItem() == ModItems.watz_pellet) { pellets.add(stack); } } - + double baseFlux = 0D; - + /* init base flux */ for(ItemStack stack : pellets) { EnumWatzType type = EnumUtil.grabEnumSafely(EnumWatzType.class, stack.getItemDamage()); baseFlux += type.passive; } - + double inputFlux = baseFlux + fluxLastReaction; double addedFlux = 0D; double addedHeat = 0D; - + for(ItemStack stack : pellets) { EnumWatzType type = EnumUtil.grabEnumSafely(EnumWatzType.class, stack.getItemDamage()); Function burnFunc = type.burnFunc; Function heatDiv = type.heatDiv; - + if(burnFunc != null) { double div = heatDiv != null ? heatDiv.effonix(heat) : 1D; double burn = burnFunc.effonix(inputFlux) / div; @@ -242,11 +251,11 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand tanks[2].setFill(tanks[2].getFill() + (int) Math.round(type.mudContent * burn)); } } - + for(ItemStack stack : pellets) { EnumWatzType type = EnumUtil.grabEnumSafely(EnumWatzType.class, stack.getItemDamage()); Function absorbFunc = type.absorbFunc; - + if(absorbFunc != null) { double absorb = absorbFunc.effonix(baseFlux + fluxLastReaction); addedHeat += absorb; @@ -254,38 +263,38 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand tanks[2].setFill(tanks[2].getFill() + (int) Math.round(type.mudContent * absorb)); } } - + this.heat += addedHeat; this.fluxLastBase = baseFlux; this.fluxLastReaction = addedFlux; - + } else { this.fluxLastBase = 0; this.fluxLastReaction = 0; - + } - + for(int i = 0; i < 24; i++) { ItemStack stack = slots[i]; - + /* deplete */ if(stack != null && stack.getItem() == ModItems.watz_pellet && ItemWatzPellet.getEnrichment(stack) <= 0) { slots[i] = new ItemStack(ModItems.watz_pellet_depleted, 1, stack.getItemDamage()); continue; // depleted pellets may persist for one tick } } - + if(above != null) { for(int i = 0; i < 24; i++) { ItemStack stackBottom = slots[i]; ItemStack stackTop = above.slots[i]; - + /* items fall down if the bottom slot is empty */ if(stackBottom == null && stackTop != null) { slots[i] = stackTop.copy(); above.decrStackSize(i, stackTop.stackSize); } - + /* items switch places if the top slot is depleted */ if(stackBottom != null && stackBottom.getItem() == ModItems.watz_pellet && stackTop != null && stackTop.getItem() == ModItems.watz_pellet_depleted) { ItemStack buf = stackTop.copy(); @@ -319,12 +328,12 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand tank.deserialize(buf); } } - + /** Prevent manual updates when another segment is above this one */ public boolean updateLock() { return Compat.getTileStandard(worldObj, xCoord, yCoord + 3, zCoord) instanceof TileEntityWatz; } - + protected void subscribeToTop() { this.trySubscribe(tanks[0].getTankType(), worldObj, xCoord, yCoord + 3, zCoord, ForgeDirection.UP); this.trySubscribe(tanks[0].getTankType(), worldObj, xCoord + 2, yCoord + 3, zCoord, ForgeDirection.UP); @@ -332,15 +341,15 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand this.trySubscribe(tanks[0].getTankType(), worldObj, xCoord, yCoord + 3, zCoord + 2, ForgeDirection.UP); this.trySubscribe(tanks[0].getTankType(), worldObj, xCoord, yCoord + 3, zCoord - 2, ForgeDirection.UP); } - + protected void sendOutBottom() { - + for(DirPos pos : getSendingPos()) { if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } } - + protected DirPos[] getSendingPos() { return new DirPos[] { new DirPos(xCoord, yCoord - 1, zCoord, ForgeDirection.DOWN), @@ -350,13 +359,13 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand new DirPos(xCoord, yCoord - 1, zCoord - 2, ForgeDirection.DOWN) }; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("locks", 10); - + for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound nbt1 = list.getCompoundTagAt(i); byte b0 = nbt1.getByte("slot"); @@ -364,21 +373,21 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand locks[b0] = ItemStack.loadItemStackFromNBT(nbt1); } } - + for(int i = 0; i < tanks.length; i++) tanks[i].readFromNBT(nbt, "t" + i); this.heat = nbt.getInteger("heat"); this.fluxLastBase = nbt.getDouble("lastFluxB"); this.fluxLastReaction = nbt.getDouble("lastFluxR"); - + this.isLocked = nbt.getBoolean("isLocked"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - + NBTTagList list = new NBTTagList(); - + for(int i = 0; i < locks.length; i++) { if(locks[i] != null) { NBTTagCompound nbt1 = new NBTTagCompound(); @@ -388,12 +397,12 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand } } nbt.setTag("locks", list); - + for(int i = 0; i < tanks.length; i++) tanks[i].writeToNBT(nbt, "t" + i); nbt.setInteger("heat", this.heat); nbt.setDouble("lastFluxB", fluxLastBase); nbt.setDouble("lastFluxR", fluxLastReaction); - + nbt.setBoolean("isLocked", isLocked); } @@ -404,9 +413,9 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand @Override public void receiveControl(NBTTagCompound data) { - + if(data.hasKey("lock")) { - + if(this.isLocked) { this.locks = new ItemStack[slots.length]; } else { @@ -414,7 +423,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand this.locks[i] = slots[i]; } } - + this.isLocked = !this.isLocked; this.markChanged(); } @@ -426,7 +435,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand if(!this.isLocked) return true; return this.locks[i] != null && this.locks[i].getItem() == stack.getItem() && locks[i].getItemDamage() == stack.getItemDamage(); } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; @@ -443,10 +452,10 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand } AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 3, @@ -457,16 +466,16 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand zCoord + 4 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { return 65536.0D; } - + private void disassemble() { int count = 20; @@ -486,7 +495,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.mud_block); worldObj.setBlock(xCoord, yCoord + 1, zCoord, ModBlocks.mud_block); worldObj.setBlock(xCoord, yCoord + 2, zCoord, ModBlocks.mud_block); - + setBrokenColumn(0, ModBlocks.watz_element, 0, 1, 0); setBrokenColumn(0, ModBlocks.watz_element, 0, 2, 0); setBrokenColumn(0, ModBlocks.watz_element, 0, 0, 1); @@ -507,7 +516,7 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand setBrokenColumn(0, ModBlocks.watz_cooler, 0, -2, -1); setBrokenColumn(0, ModBlocks.watz_cooler, 0, 1, -2); setBrokenColumn(0, ModBlocks.watz_cooler, 0, -1, -2); - + for(int j = -1; j < 2; j++) { setBrokenColumn(1, ModBlocks.watz_end, 1, 3, j); setBrokenColumn(1, ModBlocks.watz_end, 1, j, 3); @@ -518,20 +527,20 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand setBrokenColumn(1, ModBlocks.watz_end, 1, 2, -2); setBrokenColumn(1, ModBlocks.watz_end, 1, -2, 2); setBrokenColumn(1, ModBlocks.watz_end, 1, -2, -2); - + List players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5).expand(50, 50, 50)); - + for(EntityPlayer player : players) { player.triggerAchievement(MainRegistry.achWatzBoom); } } - + private void setBrokenColumn(int minHeight, Block b, int meta, int x, int z) { - + int height = minHeight + worldObj.rand.nextInt(3 - minHeight); - + for(int i = 0; i < 3; i++) { - + if(i <= height) { worldObj.setBlock(xCoord + x, yCoord + i, zCoord + z, b, meta, 3); } else { @@ -570,4 +579,104 @@ public class TileEntityWatz extends TileEntityMachineBase implements IFluidStand public FluidTank getTankToPaste() { return null; } + + // opencomputers stuff + @Override + @Optional.Method(modid = "OpenComputers") + public String getComponentName() { + return "watz_reactor"; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getHeat(Context context, Arguments args) { + return new Object[] {heat}; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getFlux(Context context, Arguments args) { + return new Object[] {fluxLastBase + fluxLastReaction}; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getCoolantInfo(Context context, Arguments args) { + return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()}; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getWasteInfo(Context context, Arguments args) { + return new Object[] {tanks[2].getFill(), tanks[2].getMaxFill()}; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] isOn(Context context, Arguments args) { + return new Object[] {isOn}; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getInfo(Context context, Arguments args) { + return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), tanks[2].getFill(), tanks[2].getMaxFill(), heat, fluxLastBase + fluxLastReaction, isOn}; + } + + @Override + @Optional.Method(modid = "OpenComputers") + public String[] methods() { + return new String[] { + "getComponentName", + "getHeat", + "getFlux", + "getCoolantInfo", + "getWasteInfo", + "isOn", + "getInfo" + }; + } + + @Override + @Optional.Method(modid = "OpenComputers") + public Object[] invoke(String method, Context context, Arguments args) throws Exception { + switch (method) { + case "getHeat": return getHeat(context, args); + case "getFlux": return getFlux(context, args); + case "getCoolantInfo": return getCoolantInfo(context, args); + case "getWasteInfo": return getWasteInfo(context, args); + case "isOn": return isOn(context, args); + case "getInfo": return getInfo(context, args); + } + throw new NoSuchMethodException(); + } + + public static final String[] ROR = new String[] { // not to be confused with RUR + PREFIX_VALUE + "heat", + PREFIX_VALUE + "flux", + PREFIX_VALUE + "mud", + PREFIX_VALUE + "coolant_hot", + PREFIX_VALUE + "coolant_cold", + }; + + @Override + public String[] getFunctionInfo() { + return ROR; + } + + @Override + public String runRORFunction(String name, String[] params) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String provideRORValue(String name) { + if((PREFIX_VALUE + "heat").equals(name)) return "" + this.heat; + if((PREFIX_VALUE + "flux").equals(name)) return "" + (int) (this.fluxLastBase + this.fluxLastReaction); + if((PREFIX_VALUE + "mud").equals(name)) return "" + this.tanks[2].getFill(); + if((PREFIX_VALUE + "coolant_hot").equals(name)) return "" + this.tanks[1].getFill(); + if((PREFIX_VALUE + "coolant_cold").equals(name)) return "" + this.tanks[0].getFill(); + return null; + } }