hooolyyyy shiiiiiiiit

i finally fixed the bug!!!!!!!!!!
This commit is contained in:
BallOfEnergy 2024-08-24 00:10:20 -05:00
parent fce0b08056
commit 05cc217bfe
5 changed files with 142 additions and 30 deletions

View File

@ -0,0 +1,55 @@
package com.hbm.handler.rbmkmk2;
import com.hbm.items.machine.ItemRBMKPellet;
import com.hbm.items.machine.ItemRBMKRod;
import net.minecraft.util.MathHelper;
import java.util.function.BiFunction;
import java.util.function.Function;
public class ItemRBMKRodFluxCurve extends ItemRBMKRod {
/** Double 1: Flux ratio in.
* Double 2: Depletion value.
* Return double: Output flux ratio.
**/
BiFunction<Double, Double, Double> ratioCurve;
/** Double 1: Flux quantity in. <br>
* Double 2: Flux ratio in. <br>
* Return double: Output flux quantity.
**/
BiFunction<Double, Double, Double> fluxCurve;
public ItemRBMKRodFluxCurve(ItemRBMKPellet pellet) {
super(pellet);
}
public ItemRBMKRodFluxCurve(String fullName) {
super(fullName);
}
public ItemRBMKRodFluxCurve setOutputRatioCurve(Function<Double, Double> func) {
this.ratioCurve = (fluxRatioIn, depletion) -> func.apply(fluxRatioIn) * 1.0D;
return this;
}
public ItemRBMKRodFluxCurve setDepletionOutputRatioCurve(BiFunction<Double, Double, Double> func) {
this.ratioCurve = func;
return this;
}
public ItemRBMKRodFluxCurve setOutputFluxCurve(BiFunction<Double, Double, Double> func) {
this.fluxCurve = func;
return this;
}
public double fluxRatioOut(double fluxRatioIn, double depletion) {
return MathHelper.clamp_double(ratioCurve.apply(fluxRatioIn, depletion), 0, 1);
}
public double fluxFromRatio(double quantity, double ratio) {
return fluxCurve.apply(quantity, ratio);
}
}

View File

@ -49,6 +49,12 @@ public class RBMKHandler {
this.hasLid = tile.hasLid();
}
public RBMKNode(TileEntityRBMKBase tile, RBMKType type, boolean hasLid) {
this.type = type;
this.tile = tile;
this.hasLid = hasLid;
}
public void addLid() {
this.hasLid = true;
}
@ -57,13 +63,19 @@ public class RBMKHandler {
this.hasLid = false;
}
public void checkNode(BlockPos pos) {
public List<BlockPos> checkNode(BlockPos pos) {
if (tile == null)
removeNode(pos); // what the fuck???
List<BlockPos> list = new ArrayList<>();
if (tile.isInvalid())
removeNode(pos);
if (tile == null) {
list.add(pos); // what the fuck???
return list;
}
if (tile.isInvalid()) {
list.add(pos);
return list;
}
if (tile instanceof TileEntityRBMKRod && !(tile instanceof TileEntityRBMKRodReaSim)) {
TileEntityRBMKRod rod = (TileEntityRBMKRod) tile;
@ -76,11 +88,13 @@ public class RBMKHandler {
List<RBMKNode> nodes = stream.getNodes(false);
for (RBMKNode nodeToRemove : nodes)
removeNode(new BlockPos(nodeToRemove.tile));
list.add(new BlockPos(nodeToRemove.tile));
}
return list;
}
}
return list;
// TODO: Implement `hasRodInRange` for non-rod tile uncaching.
}
}
@ -89,6 +103,8 @@ public class RBMKHandler {
BlockPos pos = new BlockPos(tile);
if (nodeCache.containsKey(pos))
return getNode(pos);
if (!tile.hasWorldObj())
return new RBMKNode(tile, tile.getRBMKType(), true);
return new RBMKNode(tile, tile.getRBMKType());
}
@ -326,7 +342,7 @@ public class RBMKHandler {
// 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: 10
// total count of bugs fixed attributed to this function: 11
if (origin.tile.getWorldObj().getBlock(pos.getX(), pos.getY() + h, pos.getZ()).isOpaqueCube())
hits += 1;
}
@ -373,8 +389,7 @@ public class RBMKHandler {
nodeCache.clear();
}
static int cacheTime = 40;
static int ticks = 0;
private static int ticks = 0;
// The big one!! Runs all interactions for neutrons.
public static void runAllInteractions() {
@ -400,11 +415,15 @@ public class RBMKHandler {
}
// Freshen the node cache every `cacheTime` ticks to prevent huge RAM usage.
int cacheTime = 40;
if (ticks >= cacheTime) {
ticks = 0;
for(Entry<BlockPos, RBMKNode> cachedNode : nodeCache.entrySet()) {
cachedNode.getValue().checkNode(cachedNode.getKey());
}
List<BlockPos> toRemove = new ArrayList<>();
for(Entry<BlockPos, RBMKNode> cachedNode : nodeCache.entrySet())
toRemove.addAll(cachedNode.getValue().checkNode(cachedNode.getKey()));
for(BlockPos pos : toRemove)
removeNode(pos);
}
ticks++;
}

View File

@ -394,6 +394,7 @@ public class HazardRegistry {
registerRBMKRod(rbmk_fuel_zfb_pu241, pu239 * rod_rbmk * 0.1F, wst * rod_rbmk * 7.5F);
registerRBMKRod(rbmk_fuel_zfb_am_mix, pu241 * rod_rbmk * 0.1F, wst * rod_rbmk * 10F);
registerRBMK(rbmk_fuel_drx, bf * rod_rbmk, bf * rod_rbmk * 100F, true, true, 0, 1F/3F);
registerRBMKRod(rbmk_fuel_curve, saf * rod_rbmk * np237 * rod_rbmk, wst * rod_rbmk * 35F);
registerRBMKPellet(rbmk_pellet_ueu, u * billet, wst * billet * 20F);
registerRBMKPellet(rbmk_pellet_meu, uf * billet, wst * billet * 21.5F);

View File

@ -7,6 +7,7 @@ import com.hbm.handler.ToolAbility;
import com.hbm.handler.ToolAbility.LuckAbility;
import com.hbm.handler.WeaponAbility;
import com.hbm.handler.guncfg.*;
import com.hbm.handler.rbmkmk2.ItemRBMKRodFluxCurve;
import com.hbm.interfaces.ICustomWarhead.SaltedFuel.HalfLifeType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
@ -64,6 +65,8 @@ import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import java.util.function.BiFunction;
public class ModItems {
public static void mainRegistry()
@ -1129,6 +1132,7 @@ public class ModItems {
public static ItemRBMKRod rbmk_fuel_zfb_am_mix;
public static ItemRBMKRod rbmk_fuel_drx;
public static ItemRBMKRod rbmk_fuel_test;
public static ItemRBMKRodFluxCurve rbmk_fuel_curve;
public static ItemRBMKPellet rbmk_pellet_ueu;
public static ItemRBMKPellet rbmk_pellet_meu;
public static ItemRBMKPellet rbmk_pellet_heu233;
@ -3753,6 +3757,15 @@ public class ModItems {
.setHeat(1.0D)
.setMeltingPoint(100000)
.setUnlocalizedName("rbmk_fuel_test").setTextureName(RefStrings.MODID + ":rbmk_fuel_test");
rbmk_fuel_curve = (ItemRBMKRodFluxCurve) new ItemRBMKRodFluxCurve("3D curve test")
.setOutputFluxCurve((fluxQuantity, fluxRatio) -> fluxQuantity * (1 - Math.pow(fluxRatio, 2)))
.setDepletionOutputRatioCurve((ratioIn, depletion) -> Math.pow(ratioIn, 2) * depletion)
.setYield(1000000D)
.setStats(100)
.setFunction(EnumBurnFunc.EXPERIMENTAL)
.setHeat(1.0D)
.setMeltingPoint(100000)
.setUnlocalizedName("rbmk_fuel_curve").setTextureName(RefStrings.MODID + ":rbmk_fuel_curve");
watz_pellet = new ItemWatzPellet().setUnlocalizedName("watz_pellet").setTextureName(RefStrings.MODID + ":watz_pellet");
watz_pellet_depleted = new ItemWatzPellet().setUnlocalizedName("watz_pellet_depleted").setTextureName(RefStrings.MODID + ":watz_pellet");
@ -6594,6 +6607,7 @@ public class ModItems {
GameRegistry.registerItem(rbmk_fuel_zfb_am_mix, rbmk_fuel_zfb_am_mix.getUnlocalizedName());
GameRegistry.registerItem(rbmk_fuel_drx, rbmk_fuel_drx.getUnlocalizedName());
GameRegistry.registerItem(rbmk_fuel_test, rbmk_fuel_test.getUnlocalizedName());
GameRegistry.registerItem(rbmk_fuel_curve, rbmk_fuel_curve.getUnlocalizedName());
GameRegistry.registerItem(rbmk_pellet_ueu, rbmk_pellet_ueu.getUnlocalizedName());
GameRegistry.registerItem(rbmk_pellet_meu, rbmk_pellet_meu.getUnlocalizedName());

View File

@ -8,6 +8,7 @@ import com.hbm.handler.CompatHandler;
import com.hbm.handler.radiation.ChunkRadiationManager;
import com.hbm.handler.rbmkmk2.RBMKHandler;
import com.hbm.handler.rbmkmk2.RBMKHandler.NeutronStream;
import com.hbm.handler.rbmkmk2.ItemRBMKRodFluxCurve;
import com.hbm.inventory.container.ContainerRBMKRod;
import com.hbm.inventory.gui.GUIRBMKRod;
import com.hbm.items.ModItems;
@ -39,8 +40,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.List;
import static com.hbm.handler.rbmkmk2.RBMKHandler.addNode;
import static com.hbm.handler.rbmkmk2.RBMKHandler.getNode;
import static com.hbm.handler.rbmkmk2.RBMKHandler.*;
@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 {
@ -49,6 +49,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
// Used for receiving flux (calculating outbound flux/burning rods)
public double fluxRatio;
public double fluxQuantity;
public double lastFluxQuantity;
public boolean hasRod;
@ -89,14 +90,29 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
ItemRBMKRod rod = ((ItemRBMKRod)slots[0].getItem());
double fluxIn = fluxFromType(rod.nType);
double fluxQuantityOut = rod.burn(worldObj, slots[0], fluxIn);
double fluxRatioOut;
NType rType = rod.rType;
if(rType == NType.SLOW)
fluxRatioOut = 0;
else
fluxRatioOut = 1;
double fluxQuantityOut;
if (rod instanceof ItemRBMKRodFluxCurve) { // Experimental flux ratio curve rods!
ItemRBMKRodFluxCurve rodCurve = (ItemRBMKRodFluxCurve) rod;
fluxRatioOut = rodCurve.fluxRatioOut(this.fluxRatio, ItemRBMKRod.getEnrichment(slots[0]));
double fluxIn;
fluxIn = rodCurve.fluxFromRatio(this.fluxQuantity, this.fluxRatio);
fluxQuantityOut = rod.burn(worldObj, slots[0], fluxIn);
} else {
NType rType = rod.rType;
if (rType == NType.SLOW)
fluxRatioOut = 0;
else
fluxRatioOut = 1;
double fluxIn = fluxFromType(rod.nType);
fluxQuantityOut = rod.burn(worldObj, slots[0], fluxIn);
}
rod.updateHeat(worldObj, slots[0], 1.0D);
this.heat += rod.provideHeat(worldObj, slots[0], heat, 1.0D);
@ -114,15 +130,14 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
} else {
this.meltdown();
}
this.lastFluxQuantity = 0;
this.fluxQuantity = 0;
return;
}
if(this.heat > 10_000) this.heat = 10_000;
this.markDirty();
//for spreading, we want the buffered flux to be 0 because we want to know exactly how much gets reflected back
this.lastFluxQuantity = this.fluxQuantity;
this.fluxQuantity = 0;
spreadFlux(fluxQuantityOut, fluxRatioOut);
@ -130,6 +145,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
} else {
this.lastFluxQuantity = 0;
this.fluxQuantity = 0;
this.fluxRatio = 0;
@ -142,10 +158,9 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
private double fluxFromType(NType type) {
switch(type) {
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 FAST: return (this.fluxQuantity * (1 - this.fluxRatio) + Math.min(this.fluxRatio * 0.3, 1));
case ANY: return this.fluxQuantity;
}
@ -184,10 +199,10 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
if(nbt.hasKey("fluxFast") || nbt.hasKey("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)
if (this.fluxQuantity > 0)
this.fluxRatio = nbt.getDouble("fluxFast") / fluxQuantity;
else
this.fluxRatio = 0;
@ -201,10 +216,18 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
this.hasRod = nbt.getBoolean("hasRod");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setDouble("fluxQuantity", this.lastFluxQuantity);
nbt.setDouble("fluxRatio", this.fluxRatio);
nbt.setBoolean("hasRod", this.hasRod);
}
// aaaaaaa
public void writeToNBTDiag(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setDouble("fluxQuantity", this.fluxQuantity);
nbt.setDouble("fluxRatio", this.fluxRatio);
nbt.setBoolean("hasRod", this.hasRod);
@ -227,7 +250,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
}
public void getDiagData(NBTTagCompound nbt) {
this.writeToNBT(nbt);
this.writeToNBTDiag(nbt);
if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) {