diff --git a/src/main/java/com/hbm/handler/rbmkmk2/RBMKHandler.java b/src/main/java/com/hbm/handler/rbmkmk2/RBMKHandler.java new file mode 100644 index 000000000..03d369ae6 --- /dev/null +++ b/src/main/java/com/hbm/handler/rbmkmk2/RBMKHandler.java @@ -0,0 +1,339 @@ +package com.hbm.handler.rbmkmk2; + +import com.hbm.blocks.machine.rbmk.RBMKBase; +import com.hbm.handler.radiation.ChunkRadiationManager; +import com.hbm.tileentity.machine.rbmk.*; +import com.hbm.util.fauxpointtwelve.BlockPos; +import net.minecraft.block.Block; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import java.util.*; + +public class RBMKHandler { + + static double moderatorEfficiency; + static double reflectorEfficiency; + static double absorberEfficiency; + static int columnHeight; + static int fluxRange; + + public enum RBMKType { + ROD, + MODERATOR, + CONTROL_ROD, + REFLECTOR, + ABSORBER, + OUTGASSER, + OTHER // why do neutron calculations on them if they won't change anything? + } + + public static class RBMKNode { + + protected RBMKType type; + protected TileEntityRBMKBase tile; + protected boolean hasLid; + + public RBMKNode(TileEntityRBMKBase tile, RBMKType type) { + this.type = type; + this.tile = tile; + this.hasLid = tile.hasLid(); + addNode(this); + } + } + + private static TileEntity blockPosToTE(World worldObj, BlockPos pos) { + return worldObj.getTileEntity(pos.getX(), pos.getY(), pos.getZ()); + } + + public static RBMKNode makeNode(TileEntityRBMKBase tile) { + return new RBMKNode(tile, tile.getRBMKType()); + } + + public static class NeutronStream { + + public RBMKNode origin; + + // doubles!! + public double fluxQuantity; + // Hey, new implementation! Basically a ratio for slow flux to fast flux + // 0 = all slow flux + // 1 = all fast flux + public double fluxRatio; + + // Vector for direction of neutron flow. + public Vec3 vector; + + public NeutronStream(RBMKNode origin, Vec3 vector, double flux, double ratio) { + this.origin = origin; + this.vector = vector; + this.fluxQuantity = flux; + this.fluxRatio = ratio; + streams.put(this, origin.tile.getWorldObj()); + } + + public List getBlocks() { + List positions = new ArrayList<>(); + + for (int i = 1; i <= fluxRange; i++) { + int x = (int) Math.floor(0.5 + vector.xCoord * i); + int z = (int) Math.floor(0.5 + vector.zCoord * i); + + BlockPos pos = new BlockPos(origin.tile).add(x, 0, z); + positions.add(pos); + } + return positions; + } + + // This, however, is used for actual RBMK flux calculations. + // Does NOT include the origin node + // USES THE CACHE!!! + public List getNodes() { + List positions = new ArrayList<>(); + + for (int i = 1; i <= fluxRange; i++) { + int x = (int) Math.floor(0.5 + vector.xCoord * i); + int z = (int) Math.floor(0.5 + vector.zCoord * i); + + BlockPos pos = new BlockPos(origin.tile).add(x, 0, z); + + if (nodeCache.containsKey(pos)) { + positions.add(nodeCache.get(pos)); + continue; + } + + // If it isn't an RBMK block then don't do anything with it + if(!(origin.tile.getBlockType() instanceof RBMKBase)) + continue; + + TileEntity te = blockPosToTE(origin.tile.getWorldObj(), pos); + + if (te instanceof TileEntityRBMKBase) { + TileEntityRBMKBase rbmkBase = (TileEntityRBMKBase) te; + RBMKType type = rbmkBase.getRBMKType(); + // they should ALL be RBMKBase TEs + RBMKNode node = new RBMKNode(rbmkBase, type); + positions.add(node); + addNode(node); + } + } + return positions; + } + + // The... small one? whatever it's still pretty big, runs the interaction for the stream. + public void runStreamInteraction(World worldObj) { + + // do nothing if there's nothing to do lmao + if(fluxQuantity == 0D) + return; + + BlockPos pos = new BlockPos(origin.tile); + + TileEntityRBMKBase originTE; + + if (nodeCache.containsKey(pos)) + originTE = nodeCache.get(pos).tile; + else { + originTE = (TileEntityRBMKBase) blockPosToTE(worldObj, pos); + if(originTE == null) + return; // Doesn't exist anymore! + addNode(new RBMKNode(originTE, originTE.getRBMKType())); + } + + int moderatedCount = 0; + + for(BlockPos nodePos : getBlocks()) { + + if(fluxQuantity == 0D) // Whoops, used it all up! + return; + + RBMKNode node = nodeCache.get(nodePos); + + if(node == null) { + TileEntity te = blockPosToTE(worldObj, nodePos); // ok, maybe it didn't get added to the list somehow? + if (te instanceof TileEntityRBMKBase) { + node = makeNode((TileEntityRBMKBase) te); + addNode(node); // whoops! + } else + return; // TE no longer exists, die!! + } + + if(node.type == RBMKType.OTHER) // pass right on by! + continue; + + Block block = node.tile.getBlockType(); + + if (!(block instanceof RBMKBase)) { + int hits = getHits(nodePos); // Get the amount of hits on blocks. + if (hits == columnHeight) // If stream is fully blocked. + return; + else if (hits > 0) { // If stream is partially blocked. + irradiateFromFlux(pos, hits); + fluxQuantity *= 1 - ((double) hits / columnHeight); // Inverse to get partial blocking by blocks. + continue; + } else { // Nothing hit! + irradiateFromFlux(pos, 0); + continue; + } + } + + // we established earlier during `getNodes()` that they should all be RBMKBase TEs + // no issue with casting here! + TileEntityRBMKBase nodeTE = node.tile; + + if(!node.hasLid) + ChunkRadiationManager.proxy.incrementRad(worldObj, nodePos.getX(), nodePos.getY(), nodePos.getZ(), (float) (this.fluxQuantity * 0.05F)); + + if(node.type == RBMKType.MODERATOR) { + moderatedCount += 1; + moderateStream(); + } + + if(node.tile instanceof IRBMKFluxReceiver) { + IRBMKFluxReceiver column = ((IRBMKFluxReceiver) nodeTE); + if(node.type == RBMKType.ROD) { + TileEntityRBMKRod rod = ((TileEntityRBMKRod) column); + if(rod.hasRod) { + if(rod.isModerated()) + moderateStream(); + rod.receiveFlux(this); + return; + } + } else if(node.type == RBMKType.OUTGASSER) { + TileEntityRBMKOutgasser outgasser = ((TileEntityRBMKOutgasser) column); + if(outgasser.canProcess()) { + column.receiveFlux(this); + return; + } + } + } + + else if(node.type == RBMKType.CONTROL_ROD) { + TileEntityRBMKControl rod = ((TileEntityRBMKControl) nodeTE); + if (rod.level > 0D) + fluxQuantity *= ((TileEntityRBMKControl) nodeTE).getMult(); + else + return; + } + + else if(node.type == RBMKType.REFLECTOR) { + if((origin.tile).isModerated()) + moderatedCount += 1; + if (fluxRatio > 0D && moderatedCount > 0) { + for (int i = 0; i < moderatedCount; i++) { + moderateStream(); // Moderate streams on the way back! + } + } + if(reflectorEfficiency != 1) { + fluxQuantity *= reflectorEfficiency; + } else { + ((TileEntityRBMKRod) originTE).receiveFlux(this); + // this one missing return line was baffling me for half an hour + // "why is this rod jumping to double the flux randomly????" + // because you aren't fucking returning from the function, and it's hitting the reflector after it, you idiot + return; + } + } + + else if(node.type == RBMKType.ABSORBER) { + if (absorberEfficiency == 1) + return; // Instantly stop stream processing. + else + fluxQuantity *= absorberEfficiency; + } + } + + // Called *after* most streams have returned. + List nodes = getNodes(); + + if(nodes.isEmpty()) // how tf did we get here if its empty + return; + + // Get the last node in the stream. + RBMKNode lastNode = nodes.get(nodes.size() - 1); + + // Block hits don't have to be considered here, since if it's fully blocked it'll return the function before getting here. + if(lastNode.type != RBMKType.REFLECTOR && lastNode.type != RBMKType.ABSORBER && lastNode.type != RBMKType.CONTROL_ROD) { + // Neutrons must not have been caught then! + irradiateFromFlux(new BlockPos(lastNode.tile).add(vector.xCoord, 0, vector.zCoord)); + } + + // but oh wait, control rods exist + if(lastNode.type == RBMKType.CONTROL_ROD) { + TileEntityRBMKControl rod = ((TileEntityRBMKControl) lastNode.tile); + // just get level and irradiate based on that + if(rod.getMult() > 0D) { + fluxQuantity = fluxQuantity * rod.getMult(); + irradiateFromFlux(new BlockPos(lastNode.tile).add(vector.xCoord, 0, vector.zCoord)); + } + + } + } + + public int getHits(BlockPos pos) { + int hits = 0; + + for(int h = 0; h < columnHeight; h++) { + // holy fucking shit + // I have had this one line cause me like tens of problems + // I FUCKING HATE THIS + // total count of bugs fixed attributed to this function: 6 + if (!origin.tile.getWorldObj().getBlock(pos.getX(), pos.getY() + h, pos.getZ()).isOpaqueCube()) + hits += 1; + } + + return hits; + } + + public void irradiateFromFlux(BlockPos pos) { + ChunkRadiationManager.proxy.incrementRad(origin.tile.getWorldObj(), pos.getX(), pos.getY(), pos.getZ(), (float) (fluxQuantity * 0.05F * (1 - (double) getHits(pos) / columnHeight))); + } + + public void irradiateFromFlux(BlockPos pos, int hits) { + ChunkRadiationManager.proxy.incrementRad(origin.tile.getWorldObj(), pos.getX(), pos.getY(), pos.getZ(), (float) (fluxQuantity * 0.05F * (1 - (double) hits / columnHeight))); + } + + public void moderateStream() { + fluxRatio = fluxRatio * (1 - moderatorEfficiency); + } + } + + // HashMap of all RBMK nodes and their positions. + protected static HashMap nodeCache = new HashMap<>(); + + // List of all active neutron streams. + public static HashMap streams = new HashMap<>(); + + public static void addNode(RBMKNode node) { + nodeCache.put(new BlockPos(node.tile), node); + } + + public static void removeNode(BlockPos position) { + nodeCache.remove(position); + } + + // The big one!! Runs all interactions for neutrons. + public static void runAllInteractions() { + + for (World worldObj : MinecraftServer.getServer().worldServers) { + // Gamerule caching because this apparently is kinda slow? + // meh, good enough + reflectorEfficiency = 1; //RBMKDials.getReflectorEfficiency(); + absorberEfficiency = 1; //RBMKDials.getAbsorberEfficiency(); + moderatorEfficiency = RBMKDials.getModeratorEfficiency(worldObj); + // I hate this. + // this broke everything because it was ONE OFF + // IT'S NOT THE TOTAL HEIGHT IT'S THE AMOUNT OF BLOCKS ABOVE AAAAAAAAAAAAA + columnHeight = RBMKDials.getColumnHeight(worldObj) + 1; + fluxRange = RBMKDials.getFluxRange(worldObj); + streams.forEach((stream, world) -> { + if (world == worldObj) + // WOO!! + stream.runStreamInteraction(world); + }); + } + streams.clear(); + } +} diff --git a/src/main/java/com/hbm/main/ModEventHandler.java b/src/main/java/com/hbm/main/ModEventHandler.java index 2141b15e3..2f3b4ff4c 100644 --- a/src/main/java/com/hbm/main/ModEventHandler.java +++ b/src/main/java/com/hbm/main/ModEventHandler.java @@ -9,6 +9,8 @@ import java.util.Map; import java.util.Random; import java.util.UUID; +import com.hbm.handler.rbmkmk2.RBMKHandler; +import net.minecraft.server.MinecraftServer; import org.apache.commons.lang3.math.NumberUtils; import org.apache.logging.log4j.Level; @@ -1143,6 +1145,10 @@ public class ModEventHandler { RequestNetwork.updateEntries(); TileEntityMachineRadarNT.updateSystem(); Nodespace.updateNodespace(); + // RBMK!!!! + MinecraftServer.getServer().theProfiler.startSection("rbmkHandler_flux_interaction"); + RBMKHandler.runAllInteractions(); + MinecraftServer.getServer().theProfiler.endSection(); } } diff --git a/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java b/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java index 2783e8508..47fd69ef9 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java +++ b/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java @@ -35,7 +35,7 @@ public class RenderRBMKLid extends TileEntitySpecialRenderer { if(rod.hasRod) hasRod = true; - if(rod.fluxFast + rod.fluxSlow > 5) + if(rod.fluxQuantity > 5) cherenkov = true; } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/IRBMKFluxReceiver.java b/src/main/java/com/hbm/tileentity/machine/rbmk/IRBMKFluxReceiver.java index 91824df0a..655c234ae 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/IRBMKFluxReceiver.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/IRBMKFluxReceiver.java @@ -1,5 +1,7 @@ package com.hbm.tileentity.machine.rbmk; +import com.hbm.handler.rbmkmk2.RBMKHandler; + public interface IRBMKFluxReceiver { public enum NType { @@ -14,5 +16,5 @@ public interface IRBMKFluxReceiver { } } - public void receiveFlux(NType type, double flux); + public void receiveFlux(RBMKHandler.NeutronStream stream); } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/RBMKDials.java b/src/main/java/com/hbm/tileentity/machine/rbmk/RBMKDials.java index a93498b6f..e8f2867bb 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/RBMKDials.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/RBMKDials.java @@ -30,6 +30,8 @@ public class RBMKDials { public static final String KEY_REASIM_BOILER_SPEED = "dialReasimBoilerSpeed"; public static final String KEY_DISABLE_MELTDOWNS = "dialDisableMeltdowns"; public static final String KEY_ENABLE_MELTDOWN_OVERPRESSURE = "dialEnableMeltdownOverpressure"; + + public static final String KEY_MODERATOR_EFFICIENCY = "dialModeratorEfficiency"; public static void createDials(World world) { GameRules rules = world.getGameRules(); @@ -55,6 +57,7 @@ public class RBMKDials { rules.setOrCreateGameRule(KEY_REASIM_BOILER_SPEED, "0.05"); rules.setOrCreateGameRule(KEY_DISABLE_MELTDOWNS, "false"); rules.setOrCreateGameRule(KEY_ENABLE_MELTDOWN_OVERPRESSURE, "false"); + rules.setOrCreateGameRule(KEY_MODERATOR_EFFICIENCY, "1"); } } @@ -229,4 +232,13 @@ public class RBMKDials { public static boolean getOverpressure(World world) { return world.getGameRules().getGameRuleBooleanValue(KEY_ENABLE_MELTDOWN_OVERPRESSURE); } + + /** + * The percentage of neutron to moderate from fast to slow when they pass through a moderator. + * @param world + * @return + */ + public static double getModeratorEfficiency(World world) { + return MathHelper.clamp_double(GameRuleHelper.parseDouble(world.getGameRules().getGameRuleStringValue(KEY_MODERATOR_EFFICIENCY), 1D), 0.0D, 1.0D); + } } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityCraneConsole.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityCraneConsole.java index cf1d2d8bf..1d3ea4d8d 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityCraneConsole.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityCraneConsole.java @@ -7,8 +7,6 @@ import com.hbm.handler.CompatHandler; import com.hbm.handler.HbmKeybinds.EnumKeybind; import com.hbm.items.machine.ItemRBMKRod; import com.hbm.packet.PacketDispatcher; -import com.hbm.packet.toclient.NBTPacket; -import com.hbm.tileentity.INBTPacketReceiver; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import cpw.mods.fml.relauncher.Side; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKAbsorber.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKAbsorber.java index 20512c206..abbb5ceb1 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKAbsorber.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKAbsorber.java @@ -1,10 +1,11 @@ package com.hbm.tileentity.machine.rbmk; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; public class TileEntityRBMKAbsorber extends TileEntityRBMKBase { - + @Override public void onMelt(int reduce) { @@ -17,6 +18,11 @@ public class TileEntityRBMKAbsorber extends TileEntityRBMKBase { super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.ABSORBER; + } + @Override public ColumnType getConsoleType() { return ColumnType.ABSORBER; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java index 9adb5b1a8..4c85c3aff 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBase.java @@ -8,20 +8,23 @@ import com.hbm.blocks.machine.rbmk.RBMKBase; import com.hbm.entity.effect.EntitySpear; import com.hbm.entity.projectile.EntityRBMKDebris; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; +import com.hbm.handler.neutron.NeutronNodeWorld; +import com.hbm.handler.neutron.RBMKNeutronHandler; import com.hbm.main.MainRegistry; import com.hbm.packet.PacketDispatcher; import com.hbm.packet.toclient.AuxParticlePacketNT; -import com.hbm.packet.toclient.NBTPacket; import com.hbm.saveddata.TomSaveData; -import com.hbm.tileentity.INBTPacketReceiver; +import com.hbm.tileentity.IBufPacketReceiver; import com.hbm.tileentity.IOverpressurable; import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; import com.hbm.util.Compat; import com.hbm.util.I18nUtil; +import com.hbm.util.fauxpointtwelve.BlockPos; 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 net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -45,7 +48,7 @@ import java.util.*; * @author hbm * */ -public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements INBTPacketReceiver { +public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements IBufPacketReceiver { public double heat; @@ -108,10 +111,8 @@ public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements this.worldObj.theProfiler.endStartSection("rbmkBase_rpassive_cooling"); coolPassively(); this.worldObj.theProfiler.endSection(); - - NBTTagCompound data = new NBTTagCompound(); - this.writeToNBT(data); - this.networkPack(data, trackingRange()); + + this.networkPackNT(trackingRange()); } } @@ -211,6 +212,13 @@ public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements this.markDirty(); } } + + @Override + public void invalidate() { + super.invalidate(); + + NeutronNodeWorld.removeNode(new BlockPos(this)); // woo-fucking-hoo!!! + } @Override public void markDirty() { @@ -234,6 +242,8 @@ public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements if(heat < 20) heat = 20D; } + + public abstract RBMKNeutronHandler.RBMKType getRBMKType(); protected static boolean diag = false; @@ -260,22 +270,27 @@ public abstract class TileEntityRBMKBase extends TileEntityLoadedBase implements nbt.setInteger("water", this.water); nbt.setInteger("steam", this.steam); } - - public void networkPack(NBTTagCompound nbt, int range) { - diag = true; - if(!worldObj.isRemote) - PacketDispatcher.wrapper.sendToAllAround(new NBTPacket(nbt, xCoord, yCoord, zCoord), new TargetPoint(this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, range)); - diag = false; + public void networkPackNT(int range) { + if(!worldObj.isRemote) PacketDispatcher.wrapper.sendToAllAround(new BufPacket(xCoord, yCoord, zCoord, this), new TargetPoint(this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, range)); } - - public void networkUnpack(NBTTagCompound nbt) { - - diag = true; - this.readFromNBT(nbt); - diag = false; + + @Override + public void serialize(ByteBuf buf) { + buf.writeBoolean(this.muffled); + buf.writeDouble(this.heat); + buf.writeInt(this.water); + buf.writeInt(this.steam); } - + + @Override + public void deserialize(ByteBuf buf) { + this.muffled = buf.readBoolean(); + this.heat = buf.readDouble(); + this.water = buf.readInt(); + this.steam = buf.readInt(); + } + public void getDiagData(NBTTagCompound nbt) { diag = true; this.writeToNBT(nbt); diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBlank.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBlank.java index 82a7137a9..08611e1b1 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBlank.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBlank.java @@ -1,6 +1,7 @@ package com.hbm.tileentity.machine.rbmk; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; public class TileEntityRBMKBlank extends TileEntityRBMKBase { @@ -17,6 +18,11 @@ public class TileEntityRBMKBlank extends TileEntityRBMKBase { super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OTHER; + } + @Override public ColumnType getConsoleType() { return ColumnType.BLANK; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBoiler.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBoiler.java index 7a1a6ec0b..2a1ea6801 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBoiler.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKBoiler.java @@ -8,6 +8,7 @@ import api.hbm.tile.IInfoProviderEC; import com.hbm.blocks.ModBlocks; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; import com.hbm.handler.CompatHandler; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.interfaces.IControlReceiver; import com.hbm.inventory.container.ContainerRBMKGeneric; import com.hbm.inventory.fluid.FluidType; @@ -21,6 +22,7 @@ import com.hbm.util.fauxpointtwelve.DirPos; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -163,6 +165,20 @@ public class TileEntityRBMKBoiler extends TileEntityRBMKSlottedBase implements I steam.writeToNBT(nbt, "steam"); } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + steam.serialize(buf); + feed.serialize(buf); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.steam.deserialize(buf); + this.feed.deserialize(buf); + } + @Override public boolean hasPermission(EntityPlayer player) { return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20; @@ -208,6 +224,11 @@ public class TileEntityRBMKBoiler extends TileEntityRBMKSlottedBase implements I super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OTHER; + } + @Override public ColumnType getConsoleType() { return ColumnType.BOILER; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKConsole.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKConsole.java index ffbaea36f..02b224c7a 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKConsole.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKConsole.java @@ -103,7 +103,7 @@ public class TileEntityRBMKConsole extends TileEntityMachineBase implements ICon if(te instanceof TileEntityRBMKRod) { TileEntityRBMKRod fuel = (TileEntityRBMKRod) te; - flux += fuel.fluxFast + fuel.fluxSlow; + flux += fuel.fluxQuantity; } } else { @@ -556,8 +556,8 @@ public class TileEntityRBMKConsole extends TileEntityMachineBase implements ICon if(te instanceof TileEntityRBMKRod){ TileEntityRBMKRod fuelChannel = (TileEntityRBMKRod)te; - data_table.put("fluxSlow", fuelChannel.fluxSlow); - data_table.put("fluxFast", fuelChannel.fluxFast); + data_table.put("fluxQuantity", fuelChannel.fluxQuantity); + data_table.put("fluxRatio", fuelChannel.fluxRatio); } if(te instanceof TileEntityRBMKBoiler){ diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControl.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControl.java index 4b3f79c15..edb73195c 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControl.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControl.java @@ -2,9 +2,11 @@ package com.hbm.tileentity.machine.rbmk; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; import com.hbm.handler.CompatHandler; +import com.hbm.handler.rbmkmk2.RBMKHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -87,6 +89,20 @@ public abstract class TileEntityRBMKControl extends TileEntityRBMKSlottedBase im nbt.setDouble("level", this.level); nbt.setDouble("targetLevel", this.targetLevel); } + + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeDouble(this.level); + buf.writeDouble(this.targetLevel); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.level = buf.readDouble(); + this.targetLevel = buf.readDouble(); + } @Override @SideOnly(Side.CLIENT) @@ -115,6 +131,11 @@ public abstract class TileEntityRBMKControl extends TileEntityRBMKSlottedBase im this.standardMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.CONTROL_ROD; + } + @Override public NBTTagCompound getNBTForConsole() { NBTTagCompound data = new NBTTagCompound(); diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlAuto.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlAuto.java index dc4159964..158c85083 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlAuto.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlAuto.java @@ -8,6 +8,7 @@ import com.hbm.tileentity.machine.rbmk.TileEntityRBMKControlManual.RBMKColor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; @@ -105,6 +106,24 @@ public class TileEntityRBMKControlAuto extends TileEntityRBMKControl implements nbt.setInteger("function", function.ordinal()); } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeDouble(this.levelLower); + buf.writeDouble(this.levelUpper); + buf.writeDouble(this.heatLower); + buf.writeDouble(this.heatUpper); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.levelLower = buf.readDouble(); + this.levelUpper = buf.readDouble(); + this.heatLower = buf.readDouble(); + this.heatUpper = buf.readDouble(); + } + @Override public void receiveControl(NBTTagCompound data) { diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlManual.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlManual.java index 92ec4377e..d01438c7e 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlManual.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKControlManual.java @@ -9,6 +9,7 @@ import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -91,7 +92,7 @@ public class TileEntityRBMKControlManual extends TileEntityRBMKControl implement if(nbt.hasKey("startingLevel")) this.startingLevel = nbt.getDouble("startingLevel"); - + if(nbt.hasKey("color")) this.color = RBMKColor.values()[nbt.getInteger("color")]; else @@ -108,6 +109,24 @@ public class TileEntityRBMKControlManual extends TileEntityRBMKControl implement if(color != null) nbt.setInteger("color", color.ordinal()); } + + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeDouble(this.startingLevel); + if(this.color != null) + buf.writeInt(this.color.ordinal()); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.startingLevel = buf.readDouble(); + if(buf.isReadable(1)) { + int color = buf.readInt(); + this.color = RBMKColor.values()[MathHelper.clamp_int(color, 0, RBMKColor.values().length)]; + } + } public static enum RBMKColor { RED, diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKCooler.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKCooler.java index bd7250cf7..e4134ab0c 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKCooler.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKCooler.java @@ -2,11 +2,13 @@ package com.hbm.tileentity.machine.rbmk; import api.hbm.fluid.IFluidStandardReceiver; import com.hbm.handler.CompatHandler; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.lib.Library; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; 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; @@ -15,6 +17,7 @@ import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; import java.util.List; @@ -101,6 +104,25 @@ public class TileEntityRBMKCooler extends TileEntityRBMKBase implements IFluidSt nbt.setInteger("cooled", this.lastCooled); } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + this.tank.serialize(buf); + buf.writeInt(this.lastCooled); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.tank.deserialize(buf); + this.lastCooled = buf.readInt(); + } + + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OTHER; + } + @Override public ColumnType getConsoleType() { return ColumnType.COOLER; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKHeater.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKHeater.java index 941fb9637..e54a5acbd 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKHeater.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKHeater.java @@ -4,6 +4,7 @@ import api.hbm.fluid.IFluidStandardTransceiver; import com.hbm.blocks.ModBlocks; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; import com.hbm.handler.CompatHandler; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.inventory.container.ContainerRBMKHeater; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; @@ -17,6 +18,7 @@ import com.hbm.util.fauxpointtwelve.DirPos; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -50,7 +52,7 @@ public class TileEntityRBMKHeater extends TileEntityRBMKSlottedBase implements I if(!worldObj.isRemote) { feed.setType(0, slots); - + if(feed.getTankType().hasTrait(FT_Heatable.class)) { FT_Heatable trait = feed.getTankType().getTrait(FT_Heatable.class); HeatingStep step = trait.getFirstStep(); @@ -82,7 +84,7 @@ public class TileEntityRBMKHeater extends TileEntityRBMKSlottedBase implements I super.updateEntity(); } - + protected DirPos[] getOutputPos() { if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) == ModBlocks.rbmk_loader) { @@ -125,7 +127,21 @@ public class TileEntityRBMKHeater extends TileEntityRBMKSlottedBase implements I feed.writeToNBT(nbt, "feed"); steam.writeToNBT(nbt, "steam"); } - + + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + this.feed.serialize(buf); + this.steam.serialize(buf); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.feed.deserialize(buf); + this.steam.deserialize(buf); + } + @Override public void onMelt(int reduce) { @@ -138,6 +154,11 @@ public class TileEntityRBMKHeater extends TileEntityRBMKSlottedBase implements I super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OTHER; + } + @Override public ColumnType getConsoleType() { return ColumnType.HEATEX; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java index be66e767d..301f5bb1c 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKInlet.java @@ -4,14 +4,16 @@ import api.hbm.fluid.IFluidStandardReceiver; import com.hbm.blocks.machine.rbmk.RBMKBase; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; +import com.hbm.tileentity.IBufPacketReceiver; import com.hbm.tileentity.TileEntityLoadedBase; +import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityRBMKInlet extends TileEntityLoadedBase implements IFluidStandardReceiver { +public class TileEntityRBMKInlet extends TileEntityLoadedBase implements IFluidStandardReceiver, IBufPacketReceiver { public FluidTank water; @@ -61,6 +63,14 @@ public class TileEntityRBMKInlet extends TileEntityLoadedBase implements IFluidS this.water.writeToNBT(nbt, "tank"); } + public void serialize(ByteBuf buf) { + this.water.serialize(buf); + } + + public void deserialize(ByteBuf buf) { + this.water.deserialize(buf); + } + @Override public FluidTank[] getAllTanks() { return new FluidTank[] {water}; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKModerator.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKModerator.java index 7abb95b12..7ce7c1e67 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKModerator.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKModerator.java @@ -1,10 +1,11 @@ package com.hbm.tileentity.machine.rbmk; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; public class TileEntityRBMKModerator extends TileEntityRBMKBase { - + @Override public void onMelt(int reduce) { @@ -17,6 +18,11 @@ public class TileEntityRBMKModerator extends TileEntityRBMKBase { super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.MODERATOR; + } + @Override public ColumnType getConsoleType() { return ColumnType.MODERATOR; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutgasser.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutgasser.java index 81c74e75d..95a851736 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutgasser.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutgasser.java @@ -4,6 +4,7 @@ import api.hbm.fluid.IFluidStandardSender; import com.hbm.blocks.ModBlocks; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; import com.hbm.handler.CompatHandler; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.inventory.FluidStack; import com.hbm.inventory.container.ContainerRBMKOutgasser; import com.hbm.inventory.fluid.Fluids; @@ -17,6 +18,7 @@ import com.hbm.util.fauxpointtwelve.DirPos; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -90,14 +92,13 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement } @Override - public void receiveFlux(NType type, double flux) { + public void receiveFlux(RBMKHandler.NeutronStream stream) { if(canProcess()) { - - if(type == NType.FAST) - flux *= 0.2D; - - progress += flux * RBMKDials.getOutgasserMod(worldObj); + + double efficiency = Math.min((1 - stream.fluxRatio) * 0.8, 1); + + progress += stream.fluxQuantity * efficiency * RBMKDials.getOutgasserMod(worldObj); if(progress > duration) { process(); @@ -165,6 +166,11 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OUTGASSER; + } + @Override public ColumnType getConsoleType() { return ColumnType.OUTGASSER; @@ -196,6 +202,20 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement this.gas.writeToNBT(nbt, "gas"); } + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + this.gas.serialize(buf); + buf.writeDouble(this.progress); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.gas.deserialize(buf); + this.progress = buf.readDouble(); + } + @Override public boolean isItemValidForSlot(int i, ItemStack itemStack) { return OutgasserRecipes.getOutput(itemStack) != null && i == 0; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java index 259ac0b4c..0dc4cd89b 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKOutlet.java @@ -4,14 +4,16 @@ import api.hbm.fluid.IFluidStandardSender; import com.hbm.blocks.machine.rbmk.RBMKBase; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; +import com.hbm.tileentity.IBufPacketReceiver; import com.hbm.tileentity.TileEntityLoadedBase; +import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityRBMKOutlet extends TileEntityLoadedBase implements IFluidStandardSender { +public class TileEntityRBMKOutlet extends TileEntityLoadedBase implements IFluidStandardSender, IBufPacketReceiver { public FluidTank steam; @@ -61,6 +63,16 @@ public class TileEntityRBMKOutlet extends TileEntityLoadedBase implements IFluid this.steam.writeToNBT(nbt, "tank"); } + @Override + public void serialize(ByteBuf buf) { + this.steam.serialize(buf); + } + + @Override + public void deserialize(ByteBuf buf) { + this.steam.deserialize(buf); + } + public void fillFluidInit() { for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.sendFluid(steam, worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKReflector.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKReflector.java index ed5b1afc0..79e40867b 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKReflector.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKReflector.java @@ -1,6 +1,7 @@ package com.hbm.tileentity.machine.rbmk; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; public class TileEntityRBMKReflector extends TileEntityRBMKBase { @@ -17,6 +18,11 @@ public class TileEntityRBMKReflector extends TileEntityRBMKBase { super.onMelt(reduce); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.REFLECTOR; + } + @Override public ColumnType getConsoleType() { return ColumnType.REFLECTOR; diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRod.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRod.java index 70750e00a..e62ee4379 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRod.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRod.java @@ -5,13 +5,14 @@ import com.hbm.blocks.machine.rbmk.RBMKBase; import com.hbm.blocks.machine.rbmk.RBMKRod; import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType; import com.hbm.handler.CompatHandler; +import com.hbm.handler.neutron.NeutronStream; +import com.hbm.handler.neutron.RBMKNeutronHandler; import com.hbm.handler.radiation.ChunkRadiationManager; import com.hbm.inventory.container.ContainerRBMKRod; import com.hbm.inventory.gui.GUIRBMKRod; import com.hbm.items.ModItems; import com.hbm.items.machine.ItemRBMKRod; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; -import com.hbm.util.Compat; import com.hbm.util.CompatEnergyControl; import com.hbm.util.ParticleUtil; @@ -19,6 +20,7 @@ import api.hbm.tile.IInfoProviderEC; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +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; @@ -28,8 +30,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -38,10 +40,12 @@ import java.util.List; @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")}) public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBMKFluxReceiver, IRBMKLoadable, SimpleComponent, IInfoProviderEC, CompatHandler.OCComponent { - - //amount of "neutron energy" buffered for the next tick to use for the reaction - public double fluxFast; - public double fluxSlow; + + // New system!! + // Used for receiving flux (calculating outbound flux/burning rods) + public double fluxRatio; + public double fluxQuantity; + public boolean hasRod; public TileEntityRBMKRod() { @@ -52,243 +56,167 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM public String getName() { return "container.rbmkRod"; } - + @Override public boolean isModerated() { return ((RBMKRod)this.getBlockType()).moderated; } - + @Override public int trackingRange() { return 25; } - @SuppressWarnings("incomplete-switch") //shut the fuck up @Override - public void receiveFlux(NType type, double flux) { - - switch(type) { - case FAST: this.fluxFast += flux; break; - case SLOW: this.fluxSlow += flux; break; - } + public void receiveFlux(NeutronStream stream) { + double fastFlux = this.fluxQuantity * this.fluxRatio; + double fastFluxIn = stream.fluxQuantity * stream.fluxRatio; + + this.fluxQuantity += stream.fluxQuantity; + fluxRatio = (fastFlux + fastFluxIn) / fluxQuantity; } - + @Override public void updateEntity() { if(!worldObj.isRemote) { - + if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) { - + ItemRBMKRod rod = ((ItemRBMKRod)slots[0].getItem()); - + double fluxIn = fluxFromType(rod.nType); - double fluxOut = rod.burn(worldObj, slots[0], fluxIn); + double fluxQuantityOut = rod.burn(worldObj, slots[0], fluxIn); + double fluxRatioOut; NType rType = rod.rType; - + if(rType == NType.SLOW) + fluxRatioOut = 0; + else + fluxRatioOut = 1; + rod.updateHeat(worldObj, slots[0], 1.0D); this.heat += rod.provideHeat(worldObj, slots[0], heat, 1.0D); - + if(!this.hasLid()) { - ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord, zCoord, (float) ((this.fluxFast + this.fluxSlow) * 0.05F)); + ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord, zCoord, (float) (this.fluxQuantity * 0.05F)); } - + super.updateEntity(); - + if(this.heat > this.maxHeat()) { - + if(RBMKDials.getMeltdownsDisabled(worldObj)) { ParticleUtil.spawnGasFlame(worldObj, xCoord + 0.5, yCoord + RBMKDials.getColumnHeight(worldObj) + 0.5, zCoord + 0.5, 0, 0.2, 0); } else { this.meltdown(); } - this.fluxFast = 0; - this.fluxSlow = 0; + this.fluxQuantity = 0; return; } - - if(this.heat > 10_000) this.heat = 10_000; - - //for spreading, we want the buffered flux to be 0 because we want to know exactly how much gets reflected back - this.fluxFast = 0; - this.fluxSlow = 0; - this.worldObj.theProfiler.startSection("rbmkRod_flux_spread"); - spreadFlux(rType, fluxOut); - this.worldObj.theProfiler.endSection(); - + if(this.heat > 10_000) this.heat = 10_000; + + //for spreading, we want the buffered flux to be 0 because we want to know exactly how much gets reflected back + this.fluxQuantity = 0; + spreadFlux(fluxQuantityOut, fluxRatioOut); + hasRod = true; - + } else { - this.fluxFast = 0; - this.fluxSlow = 0; - + this.fluxQuantity = 0; + this.fluxRatio = 0; + hasRod = false; - + super.updateEntity(); } } } - - /** - * SLOW: full efficiency for slow neutrons, fast neutrons have half efficiency - * FAST: fast neutrons have 100% efficiency, slow only 30% - * ANY: just add together whatever we have because who cares - * @param type - * @return - */ - + private double fluxFromType(NType type) { - + + switch(type) { - case SLOW: return this.fluxFast * 0.5D + this.fluxSlow; - case FAST: return this.fluxFast + this.fluxSlow * 0.3D; - case ANY: return this.fluxFast + this.fluxSlow; + case SLOW: return (this.fluxQuantity * (1 - this.fluxRatio) + Math.min(this.fluxRatio * 0.5, 1)); + case FAST: return (this.fluxQuantity * this.fluxRatio + Math.min((1 - this.fluxRatio) * 0.3, 1)); + case ANY: return this.fluxQuantity; } - + return 0.0D; } - + public static final ForgeDirection[] fluxDirs = new ForgeDirection[] { ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.SOUTH, ForgeDirection.WEST }; - - protected static NType stream; - - protected void spreadFlux(NType type, double fluxOut) { - - int range = RBMKDials.getFluxRange(worldObj); - - for(ForgeDirection dir : fluxDirs) { - - stream = type; - double flux = fluxOut; - - for(int i = 1; i <= range; i++) { - - flux = runInteraction(xCoord + dir.offsetX * i, yCoord, zCoord + dir.offsetZ * i, flux); - - if(flux <= 0) - break; - } - } - } - - protected double runInteraction(int x, int y, int z, double flux) { - - TileEntity te = Compat.getTileStandard(worldObj, x, y, z); - - if(te instanceof TileEntityRBMKBase) { - TileEntityRBMKBase base = (TileEntityRBMKBase) te; - - if(!base.hasLid()) - ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord, zCoord, (float) (flux * 0.05F)); - - if(base.isModerated()) { - this.stream = NType.SLOW; - } - } - //burn baby burn - if(te instanceof TileEntityRBMKRod) { - TileEntityRBMKRod rod = (TileEntityRBMKRod)te; - - if(rod.getStackInSlot(0) != null && rod.getStackInSlot(0).getItem() instanceof ItemRBMKRod) { - rod.receiveFlux(stream, flux); - return 0; - } else { - return flux; - } + protected static NType stream; + + public void spreadFlux(double flux, double ratio) { + + for(ForgeDirection dir : fluxDirs) { + + Vec3 neutronVector = Vec3.createVectorHelper(dir.offsetX, dir.offsetY, dir.offsetZ); + + new NeutronStream(RBMKNeutronHandler.makeNode(this), neutronVector, flux, ratio); + // Create new neutron streams } - - if(te instanceof TileEntityRBMKOutgasser) { - TileEntityRBMKOutgasser rod = (TileEntityRBMKOutgasser)te; - - if(!rod.canProcess()) { - return flux; - } - } - - if(te instanceof IRBMKFluxReceiver) { - IRBMKFluxReceiver rod = (IRBMKFluxReceiver)te; - rod.receiveFlux(stream, flux); - return 0; - } - - //multiply neutron count with rod setting - if(te instanceof TileEntityRBMKControl) { - TileEntityRBMKControl control = (TileEntityRBMKControl)te; - - if(control.getMult() == 0.0D) - return 0; - - flux *= control.getMult(); - - return flux; - } - - //set neutrons to slow - if(te instanceof TileEntityRBMKModerator) { - stream = NType.SLOW; - return flux; - } - - //return the neutrons back to this with no further action required - if(te instanceof TileEntityRBMKReflector) { - this.receiveFlux(this.isModerated() ? NType.SLOW : stream, flux); - return 0; - } - - //break the neutron flow and nothign else - if(te instanceof TileEntityRBMKAbsorber) { - return 0; - } - - if(te instanceof TileEntityRBMKBase) { - return flux; - } - - int limit = RBMKDials.getColumnHeight(worldObj); - int hits = 0; - for(int h = 0; h <= limit; h++) { - - if(!worldObj.getBlock(x, y + h, z).isOpaqueCube()) - hits++; - } - - if(hits > 0) - ChunkRadiationManager.proxy.incrementRad(worldObj, xCoord, yCoord, zCoord, (float) (flux * 0.05F * hits / (float)limit)); - - return 0; } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - this.fluxFast = nbt.getDouble("fluxFast"); - this.fluxSlow = nbt.getDouble("fluxSlow"); + if(nbt.hasKey("fluxFast") || nbt.hasKey("fluxSlow")) { + // recalculate new values to keep stable operations + this.fluxQuantity = nbt.getDouble("fluxFast") + nbt.getDouble("fluxSlow"); + if(this.fluxQuantity > 0) + this.fluxRatio = nbt.getDouble("fluxFast") / fluxQuantity; + else + this.fluxRatio = 0; + nbt.removeTag("fluxSlow"); + nbt.removeTag("fluxFast"); + writeToNBT(nbt); + } else { + this.fluxQuantity = nbt.getDouble("fluxQuantity"); + this.fluxRatio = nbt.getDouble("fluxRatio"); + } this.hasRod = nbt.getBoolean("hasRod"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setDouble("fluxFast", this.fluxFast); - nbt.setDouble("fluxSlow", this.fluxSlow); + nbt.setDouble("fluxQuantity", this.fluxQuantity); + nbt.setDouble("fluxRatio", this.fluxRatio); nbt.setBoolean("hasRod", this.hasRod); } - + + @Override + public void serialize(ByteBuf buf) { + super.serialize(buf); + buf.writeDouble(this.fluxQuantity); + buf.writeDouble(this.fluxRatio); + buf.writeBoolean(this.hasRod); + } + + @Override + public void deserialize(ByteBuf buf) { + super.deserialize(buf); + this.fluxQuantity = buf.readDouble(); + this.fluxRatio = buf.readDouble(); + this.hasRod = buf.readBoolean(); + } + public void getDiagData(NBTTagCompound nbt) { this.writeToNBT(nbt); - + if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) { - + ItemRBMKRod rod = ((ItemRBMKRod)slots[0].getItem()); nbt.setString("f_yield", rod.getYield(slots[0]) + " / " + rod.yield + " (" + (rod.getEnrichment(slots[0]) * 100) + "%)"); @@ -296,55 +224,60 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM nbt.setString("f_heat", rod.getCoreHeat(slots[0]) + " / " + rod.getHullHeat(slots[0]) + " / " + rod.meltingPoint); } } - + @Override public void onMelt(int reduce) { boolean moderated = this.isModerated(); int h = RBMKDials.getColumnHeight(worldObj); reduce = MathHelper.clamp_int(reduce, 1, h); - + if(worldObj.rand.nextInt(3) == 0) reduce++; - + boolean corium = slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod; - - if(corium && slots[0].getItem() == ModItems.rbmk_fuel_drx) + + if(corium && slots[0].getItem() == ModItems.rbmk_fuel_drx) RBMKBase.digamma = true; - + slots[0] = null; if(corium) { - + for(int i = h; i >= 0; i--) { worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.corium_block, 5, 3); worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord); } - + int count = 1 + worldObj.rand.nextInt(RBMKDials.getColumnHeight(worldObj)); - + for(int i = 0; i < count; i++) { spawnDebris(DebrisType.FUEL); } } else { this.standardMelt(reduce); } - + if(moderated) { - + int count = 2 + worldObj.rand.nextInt(2); - + for(int i = 0; i < count; i++) { spawnDebris(DebrisType.GRAPHITE); } } - + spawnDebris(DebrisType.ELEMENT); - + if(this.getBlockMetadata() == RBMKBase.DIR_NORMAL_LID.ordinal() + RBMKBase.offset) spawnDebris(DebrisType.LID); } + @Override + public RBMKNeutronHandler.RBMKType getRBMKType() { + return RBMKNeutronHandler.RBMKType.ROD; + } + @Override public ColumnType getConsoleType() { return ColumnType.FUEL; @@ -353,9 +286,9 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM @Override public NBTTagCompound getNBTForConsole() { NBTTagCompound data = new NBTTagCompound(); - + if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) { - + ItemRBMKRod rod = ((ItemRBMKRod)slots[0].getItem()); data.setDouble("enrichment", rod.getEnrichment(slots[0])); data.setDouble("xenon", rod.getPoison(slots[0])); @@ -363,7 +296,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM data.setDouble("c_coreHeat", rod.getCoreHeat(slots[0])); data.setDouble("c_maxHeat", rod.meltingPoint); } - + return data; } @@ -393,7 +326,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM slots[0] = null; this.markDirty(); } - + // do some opencomputer stuff @Override @Optional.Method(modid = "OpenComputers") @@ -409,16 +342,16 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM @Callback(direct = true) @Optional.Method(modid = "OpenComputers") - public Object[] getFluxSlow(Context context, Arguments args) { - return new Object[] {fluxSlow}; + public Object[] getFluxQuantity(Context context, Arguments args) { + return new Object[] {fluxQuantity}; } @Callback(direct = true) @Optional.Method(modid = "OpenComputers") - public Object[] getFluxFast(Context context, Arguments args) { - return new Object[] {fluxFast}; + public Object[] getFluxRatio(Context context, Arguments args) { + return new Object[] {fluxRatio}; } - + @Callback(direct = true) @Optional.Method(modid = "OpenComputers") public Object[] getDepletion(Context context, Arguments args) { @@ -480,7 +413,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM return new Object[] { heat, returnValues.get(0), returnValues.get(1), - fluxSlow, fluxFast, returnValues.get(2), returnValues.get(3), returnValues.get(4), + fluxQuantity, fluxRatio, returnValues.get(2), returnValues.get(3), returnValues.get(4), ((RBMKRod)this.getBlockType()).moderated, xCoord, yCoord, zCoord}; } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRodReaSim.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRodReaSim.java index e8e284a07..7114db0c7 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRodReaSim.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKRodReaSim.java @@ -1,7 +1,9 @@ package com.hbm.tileentity.machine.rbmk; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.tileentity.machine.rbmk.TileEntityRBMKConsole.ColumnType; +import com.hbm.util.fauxpointtwelve.BlockPos; import net.minecraft.util.Vec3; public class TileEntityRBMKRodReaSim extends TileEntityRBMKRod { @@ -16,40 +18,17 @@ public class TileEntityRBMKRodReaSim extends TileEntityRBMKRod { } @Override - protected void spreadFlux(NType type, double fluxOut) { + public void spreadFlux(double flux, double ratio) { - int range = RBMKDials.getReaSimRange(worldObj); int count = RBMKDials.getReaSimCount(worldObj); - - Vec3 dir = Vec3.createVectorHelper(1, 0, 0); - - for(int i = 0; i < count; i++) { - - stream = type; - double flux = fluxOut * RBMKDials.getReaSimOutputMod(worldObj); - - dir.rotateAroundY((float)(Math.PI * 2D * worldObj.rand.nextDouble())); - - for(int j = 1; j <= range; j++) { - int x = (int)Math.floor(0.5 + dir.xCoord * j); - int z = (int)Math.floor(0.5 + dir.zCoord * j); - int lastX = (int)Math.floor(0.5 + dir.xCoord * (j - 1)); - int lastZ = (int)Math.floor(0.5 + dir.zCoord * (j - 1)); - - //skip if the position is on the rod itself - if(x == 0 && z == 0) - continue; - - //skip if the current position is equal to the last position - if(x == lastX && z == lastZ) - continue; - - flux = runInteraction(xCoord + x, yCoord, zCoord + z, flux); - - if(flux <= 0) - break; - } + for (int i = 0; i < count; i++) { + Vec3 neutronVector = Vec3.createVectorHelper(1, 0, 0); + + neutronVector.rotateAroundY((float)(Math.PI * 2D * worldObj.rand.nextDouble())); + + new RBMKHandler.NeutronStream(RBMKHandler.makeNode(this), neutronVector, flux, ratio); + // Create new neutron streams } } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKStorage.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKStorage.java index a670b6c09..ac8621882 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKStorage.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKStorage.java @@ -1,5 +1,6 @@ package com.hbm.tileentity.machine.rbmk; +import com.hbm.handler.rbmkmk2.RBMKHandler; import com.hbm.inventory.container.ContainerRBMKStorage; import com.hbm.inventory.gui.GUIRBMKStorage; import com.hbm.items.machine.ItemRBMKRod; @@ -40,6 +41,11 @@ public class TileEntityRBMKStorage extends TileEntityRBMKSlottedBase implements super.updateEntity(); } + @Override + public RBMKHandler.RBMKType getRBMKType() { + return RBMKHandler.RBMKType.OTHER; + } + @Override public ColumnType getConsoleType() { return ColumnType.STORAGE;