Add crafting recipes for RBMK fuel cooling, rod disassembly, and waste decaying

This commit is contained in:
George Paton 2025-03-25 16:42:00 +11:00
parent 20bd424cd4
commit a2f5eeada7
6 changed files with 251 additions and 99 deletions

View File

@ -0,0 +1,85 @@
package com.hbm.handler.nei;
import java.util.HashMap;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.items.machine.ItemRBMKRod;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class RBMKRodDisassemblyHandler extends NEIUniversalHandler {
public RBMKRodDisassemblyHandler() {
super("RBMK Rod Disassembly", Blocks.crafting_table, getRecipes());
}
@Override
public String getKey() {
return "ntmRBMKDisassembly";
}
public static HashMap<ComparableStack, ItemStack> getRecipes() {
HashMap<ComparableStack, ItemStack> map = new HashMap<>();
for(ItemRBMKRod rod : ItemRBMKRod.craftableRods) {
for(int enrichment = 0; enrichment <= 4; enrichment++) {
ItemStack result = new ItemStack(rod.pellet, 8, enrichment);
map.put(new ComparableStackHeat(rod, false, enrichment, false), result);
if(rod.pellet.isXenonEnabled()) {
ItemStack resultPoison = new ItemStack(rod.pellet, 8, enrichment + 5);
map.put(new ComparableStackHeat(rod, false, enrichment, true), resultPoison);
}
}
}
return map;
}
public static class ComparableStackHeat extends ComparableStack {
// I was going to filter by these, but found it is just best to show all possible recipes for everything but heat
// that and... I'm actually stumped on how to filter by NBT, seeing as both `isApplicable` and `matchesRecipe` don't seem to work
private final boolean matchHot;
private final int matchEnrichment;
private final boolean matchPoison;
public ComparableStackHeat(Item item, boolean matchHot) {
this(item, matchHot, -1, false);
}
public ComparableStackHeat(Item item, boolean matchHot, int matchEnrichment, boolean matchPoison) {
super(item);
this.matchHot = matchHot;
this.matchEnrichment = matchEnrichment;
this.matchPoison = matchPoison;
}
public ItemStack toStack() {
ItemStack stack = super.toStack();
ItemRBMKRod rod = (ItemRBMKRod) stack.getItem();
if(matchEnrichment >= 0) {
ItemRBMKRod.setYield(stack, Math.max(1 - ((double) matchEnrichment) / 5, 0.05) * rod.yield);
} else {
ItemRBMKRod.setYield(stack, 0.2 * rod.yield);
}
if(matchPoison) ItemRBMKRod.setPoison(stack, 50);
if(!matchHot) return stack;
ItemRBMKRod.setCoreHeat(stack, 100);
ItemRBMKRod.setHullHeat(stack, 50);
return stack;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + matchEnrichment;
result = prime * result + (matchPoison ? 1 : 0);
return result;
}
}
}

View File

@ -0,0 +1,40 @@
package com.hbm.handler.nei;
import java.util.HashMap;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.items.ModItems;
import com.hbm.items.special.ItemWasteLong;
import com.hbm.items.special.ItemWasteShort;
import net.minecraft.item.ItemStack;
public class RBMKWasteDecayHandler extends NEIUniversalHandler {
public RBMKWasteDecayHandler() {
super("Nuclear Waste Decay", ModBlocks.machine_storage_drum, getRecipes());
}
@Override
public String getKey() {
return "ntmRBMKWaste";
}
public static HashMap<ComparableStack, ItemStack> getRecipes() {
HashMap<ComparableStack, ItemStack> map = new HashMap<>();
for(ItemWasteShort.WasteClass waste : ItemWasteShort.WasteClass.values()) {
map.put(new ComparableStack(ModItems.nuclear_waste_short, 1, waste), new ItemStack(ModItems.nuclear_waste_short_depleted, 1, waste.ordinal()));
map.put(new ComparableStack(ModItems.nuclear_waste_short_tiny, 1, waste), new ItemStack(ModItems.nuclear_waste_short_depleted_tiny, 1, waste.ordinal()));
}
for(ItemWasteLong.WasteClass waste : ItemWasteLong.WasteClass.values()) {
map.put(new ComparableStack(ModItems.nuclear_waste_long, 1, waste), new ItemStack(ModItems.nuclear_waste_long_depleted, 1, waste.ordinal()));
map.put(new ComparableStack(ModItems.nuclear_waste_long_tiny, 1, waste), new ItemStack(ModItems.nuclear_waste_long_depleted_tiny, 1, waste.ordinal()));
}
return map;
}
}

View File

@ -8,15 +8,17 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import com.hbm.handler.nei.RBMKRodDisassemblyHandler;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.recipes.loader.SerializableRecipe;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemPWRFuel.EnumPWRFuel;
import com.hbm.items.machine.ItemRBMKRod;
import net.minecraft.item.ItemStack;
public class FuelPoolRecipes extends SerializableRecipe {
public static final HashMap<ComparableStack, ItemStack> recipes = new HashMap<ComparableStack, ItemStack>();
public static final FuelPoolRecipes instance = new FuelPoolRecipes();
@ -38,8 +40,14 @@ public class FuelPoolRecipes extends SerializableRecipe {
recipes.put(new ComparableStack(ModItems.waste_plate_sa326, 1, 1), new ItemStack(ModItems.waste_plate_sa326));
recipes.put(new ComparableStack(ModItems.waste_plate_ra226be, 1, 1), new ItemStack(ModItems.waste_plate_ra226be));
recipes.put(new ComparableStack(ModItems.waste_plate_pu238be, 1, 1), new ItemStack(ModItems.waste_plate_pu238be));
for(EnumPWRFuel pwr : EnumPWRFuel.values()) recipes.put(new ComparableStack(ModItems.pwr_fuel_hot, 1, pwr.ordinal()), new ItemStack(ModItems.pwr_fuel_depleted, 1, pwr.ordinal()));
for(ItemRBMKRod rod : ItemRBMKRod.craftableRods) {
ItemStack result = new ItemStack(rod);
ItemRBMKRod.setYield(result, 0.2 * rod.yield);
recipes.put(new RBMKRodDisassemblyHandler.ComparableStackHeat(rod, true), result);
}
}
@Override

View File

@ -16,7 +16,7 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
public class ItemRBMKPellet extends ItemNuclearWaste {
public String fullName = "";
protected boolean hasXenon = true;
@ -26,12 +26,16 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
this.setMaxDamage(0);
this.setCreativeTab(MainRegistry.controlTab);
}
public ItemRBMKPellet disableXenon() {
this.hasXenon = false;
return this;
}
public boolean isXenonEnabled() {
return hasXenon;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list) {
@ -39,10 +43,10 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
list.add(new ItemStack(item, 1, i));
}
}
@SideOnly(Side.CLIENT)
private IIcon[] enrichmentOverlays;
@SideOnly(Side.CLIENT)
private IIcon xenonOverlay;
@ -50,13 +54,13 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
super.registerIcons(iconRegister);
this.enrichmentOverlays = new IIcon[5];
for(int i = 0; i < enrichmentOverlays.length; i++) {
enrichmentOverlays[i] = iconRegister.registerIcon("hbm:rbmk_pellet_overlay_e" + i);
}
if(this.hasXenon)
xenonOverlay = iconRegister.registerIcon("hbm:rbmk_pellet_overlay_xenon");
}
@ -71,16 +75,16 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
public int getRenderPasses(int meta) {
return hasXenon(meta) ? 3 : 2;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
super.addInformation(stack, player, list, bool);
list.add(EnumChatFormatting.ITALIC + this.fullName);
list.add(EnumChatFormatting.DARK_GRAY + "" + EnumChatFormatting.ITALIC + "Pellet for recycling");
int meta = rectify(stack.getItemDamage());
switch(meta % 5) {
case 0: list.add(EnumChatFormatting.GOLD + "Brand New"); break;
case 1: list.add(EnumChatFormatting.YELLOW + "Barely Depleted"); break;
@ -88,7 +92,7 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
case 3: list.add(EnumChatFormatting.DARK_GREEN + "Highly Depleted"); break;
case 4: list.add(EnumChatFormatting.DARK_GRAY + "Fully Depleted"); break;
}
if(hasXenon(meta))
list.add(EnumChatFormatting.DARK_PURPLE + "High Xenon Poison");
}
@ -96,20 +100,20 @@ public class ItemRBMKPellet extends ItemNuclearWaste {
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
if(pass == 0)
return this.itemIcon;
if(pass == 2)
return this.xenonOverlay;
return this.enrichmentOverlays[rectify(meta) % 5];
}
public static boolean hasXenon(int meta) {
return rectify(meta) >= 5;
}
public static int rectify(int meta) {
return Math.abs(meta) % 10;
}

View File

@ -1,5 +1,6 @@
package com.hbm.items.machine;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.BiFunction;
@ -20,7 +21,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class ItemRBMKRod extends Item {
public ItemRBMKPellet pellet;
public String fullName = ""; //full name of the fuel rod
public double reactivity; //endpoint of the function
@ -35,7 +36,7 @@ public class ItemRBMKRod extends Item {
public double diffusion = 0.02D; //the speed at which the core heats the hull
public NType nType = NType.SLOW; //neutronType, the most efficient neutron type for fission
public NType rType = NType.FAST; //releaseType, the type of neutrons released by this fuel
/* _____
* ,I I I I,
* |'-----'|
@ -52,18 +53,22 @@ public class ItemRBMKRod extends Item {
* | |
* '-----'
* I I I I
*
*
* i drew a fuel rod yay
*/
public static List<ItemRBMKRod> craftableRods = new ArrayList<>();
public ItemRBMKRod(ItemRBMKPellet pellet) {
this(pellet.fullName);
this.pellet = pellet;
craftableRods.add(this);
}
public ItemRBMKRod(String fullName) {
this.fullName = fullName;
this.setContainerItem(ModItems.rbmk_fuel_empty);
this.setMaxStackSize(1);
this.setCreativeTab(MainRegistry.controlTab);
@ -93,7 +98,7 @@ public class ItemRBMKRod extends Item {
this.depFunc = func;
return this;
}
public ItemRBMKRod setXenon(double gen, double burn) {
this.xGen = gen;
this.xBurn = burn;
@ -120,7 +125,7 @@ public class ItemRBMKRod extends Item {
this.rType = rType;
return this;
}
/**
* Adjusts the input flux using the poison level
* Generates, then burns poison
@ -131,82 +136,82 @@ public class ItemRBMKRod extends Item {
* @return outFlux
*/
public double burn(World world, ItemStack stack, double inFlux) {
inFlux += selfRate;
//if xenon poison is enabled
if(RBMKDials.getXenon(world)) {
double xenon = getPoison(stack);
xenon -= xenonBurnFunc(inFlux);
inFlux *= (1D - getPoisonLevel(stack));
xenon += xenonGenFunc(inFlux);
if(xenon < 0D) xenon = 0D;
if(xenon > 100D) xenon = 100D;
setPoison(stack, xenon);
}
double outFlux = reactivityFunc(inFlux, getEnrichment(stack)) * RBMKDials.getReactivityMod(world);
//if depletion is enabled
if(RBMKDials.getDepletion(world)) {
double y = getYield(stack);
y -= inFlux;
if(y < 0D) y = 0D;
setYield(stack, y);
}
double coreHeat = this.getCoreHeat(stack);
coreHeat += outFlux * heat;
this.setCoreHeat(stack, rectify(coreHeat));
return outFlux;
}
private double rectify(double num) {
if(num > 1_000_000D) num = 1_000_000D;
if(num < 20D || Double.isNaN(num)) num = 20D;
return num;
}
/**
* Heat up the core based on the outFlux, then move some heat to the hull
* @param stack
*/
public void updateHeat(World world, ItemStack stack, double mod) {
double coreHeat = this.getCoreHeat(stack);
double hullHeat = this.getHullHeat(stack);
if(coreHeat > hullHeat) {
double mid = (coreHeat - hullHeat) / 2D;
coreHeat -= mid * this.diffusion * RBMKDials.getFuelDiffusionMod(world) * mod;
hullHeat += mid * this.diffusion * RBMKDials.getFuelDiffusionMod(world) * mod;
this.setCoreHeat(stack, rectify(coreHeat));
this.setHullHeat(stack, rectify(hullHeat));
}
}
/**
* return one tick's worth of heat and cool the hull of the fuel rod, this heat goes into the fuel rod assembly block
* @param stack
* @return
*/
public double provideHeat(World world, ItemStack stack, double heat, double mod) {
double hullHeat = this.getHullHeat(stack);
//metldown! the hull melts so the entire structure stops making sense
//hull and core heats are instantly equalized into 33% of their sum each,
//the rest is sent to the component which is always fatal
@ -217,20 +222,20 @@ public class ItemRBMKRod extends Item {
this.setHullHeat(stack, avg);
return avg - heat;
}
if(hullHeat <= heat)
return 0;
double ret = (hullHeat - heat) / 2;
ret *= RBMKDials.getFuelHeatProvision(world) * mod;
hullHeat -= ret;
this.setHullHeat(stack, hullHeat);
return ret;
}
public static enum EnumBurnFunc {
PASSIVE(EnumChatFormatting.DARK_GREEN + "SAFE / PASSIVE"), //const, no reactivity
LOG_TEN(EnumChatFormatting.YELLOW + "MEDIUM / LOGARITHMIC"), //log10(x + 1) * reactivity * 50
@ -241,22 +246,22 @@ public class ItemRBMKRod extends Item {
LINEAR(EnumChatFormatting.RED + "DANGEROUS / LINEAR"), //x * reactivity
QUADRATIC(EnumChatFormatting.RED + "DANGEROUS / QUADRATIC"), //x^2 / 100 * reactivity
EXPERIMENTAL(EnumChatFormatting.RED + "EXPERIMENTAL / SINE SLOPE"); //x * (sin(x) + 1)
public String title = "";
private EnumBurnFunc(String title) {
this.title = title;
}
}
/**
* @param enrichment [0;100] ...or at least those are sane levels
* @return the amount of reactivity yielded, unmodified by xenon
*/
public double reactivityFunc(double in, double enrichment) {
double flux = in * reactivityModByEnrichment(enrichment);
switch(this.function) {
case PASSIVE: return selfRate * enrichment;
case LOG_TEN: return Math.log10(flux + 1) * 0.5D * reactivity;
@ -268,14 +273,14 @@ public class ItemRBMKRod extends Item {
case QUADRATIC: return flux * flux / 10000D * reactivity;
case EXPERIMENTAL: return flux * (Math.sin(flux) + 1) * reactivity;
}
return 0;
}
public String getFuncDescription(ItemStack stack) {
String function;
switch(this.function) {
case PASSIVE: function = EnumChatFormatting.RED + "" + selfRate;
break;
@ -297,20 +302,20 @@ public class ItemRBMKRod extends Item {
break;
default: function = "ERROR";
}
double enrichment = getEnrichment(stack);
if(enrichment < 1) {
enrichment = reactivityModByEnrichment(enrichment);
String reactivity = EnumChatFormatting.YELLOW + "" + ((int)(this.reactivity * enrichment * 1000D) / 1000D) + EnumChatFormatting.WHITE;
String enrichmentPer = EnumChatFormatting.GOLD + " (" + ((int)(enrichment * 1000D) / 10D) + "%)";
return String.format(Locale.US, function, selfRate > 0 ? "(x" + EnumChatFormatting.RED + " + " + selfRate + "" + EnumChatFormatting.WHITE + ")" : "x", reactivity).concat(enrichmentPer);
}
return String.format(Locale.US, function, selfRate > 0 ? "(x" + EnumChatFormatting.RED + " + " + selfRate + "" + EnumChatFormatting.WHITE + ")" : "x", reactivity);
}
public static enum EnumDepleteFunc {
LINEAR, //old function
RAISING_SLOPE, //for breeding fuels such as MEU, maximum of 110% at 28% depletion
@ -318,9 +323,9 @@ public class ItemRBMKRod extends Item {
GENTLE_SLOPE, //recommended for most fuels, maximum barely over the start, near the beginning
STATIC; //for arcade-style neutron sources
}
public double reactivityModByEnrichment(double enrichment) {
switch(this.depFunc) {
default:
case LINEAR: return enrichment;
@ -330,7 +335,7 @@ public class ItemRBMKRod extends Item {
case GENTLE_SLOPE: return enrichment + (Math.sin(enrichment * Math.PI) / 3D); //x + (sin(x * pi) / 3) also works
}
}
/**
* Xenon generated per tick, linear function
* @param flux
@ -339,7 +344,7 @@ public class ItemRBMKRod extends Item {
public double xenonGenFunc(double flux) {
return flux * xGen;
}
/**
* Xenon burned away per tick, quadratic function
* @param flux
@ -348,7 +353,7 @@ public class ItemRBMKRod extends Item {
public double xenonBurnFunc(double flux) {
return (flux * flux) / xBurn;
}
/**
* @param stack
* @return enrichment [0;1]
@ -356,7 +361,7 @@ public class ItemRBMKRod extends Item {
public static double getEnrichment(ItemStack stack) {
return getYield(stack) / ((ItemRBMKRod) stack.getItem()).yield;
}
/**
* @param stack
* @return poison [0;1]
@ -415,15 +420,19 @@ public class ItemRBMKRod extends Item {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
list.add(EnumChatFormatting.ITALIC + this.fullName);
if(this == ModItems.rbmk_fuel_drx) {
if(ItemRBMKRod.getHullHeat(stack) >= 50 && ItemRBMKRod.getCoreHeat(stack) >= 50) {
list.add(EnumChatFormatting.GOLD + I18nUtil.resolveKey("desc.item.wasteCooling"));
}
if(selfRate > 0 || this.function == EnumBurnFunc.SIGMOID) {
list.add(EnumChatFormatting.RED + I18nUtil.resolveKey("trait.rbmx.source"));
}
list.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey("trait.rbmx.depletion", ((int)(((yield - getYield(stack)) / yield) * 100000)) / 1000D + "%"));
list.add(EnumChatFormatting.DARK_PURPLE + I18nUtil.resolveKey("trait.rbmx.xenon", ((int)(getPoison(stack) * 1000D) / 1000D) + "%"));
list.add(EnumChatFormatting.BLUE + I18nUtil.resolveKey("trait.rbmx.splitsWith", I18nUtil.resolveKey(nType.unlocalized + ".x")));
@ -437,13 +446,17 @@ public class ItemRBMKRod extends Item {
list.add(EnumChatFormatting.RED + I18nUtil.resolveKey("trait.rbmx.skinTemp", ((int)(getHullHeat(stack) * 10D) / 10D) + "m"));
list.add(EnumChatFormatting.RED + I18nUtil.resolveKey("trait.rbmx.coreTemp", ((int)(getCoreHeat(stack) * 10D) / 10D) + "m"));
list.add(EnumChatFormatting.DARK_RED + I18nUtil.resolveKey("trait.rbmx.melt", meltingPoint + "m"));
} else {
if(ItemRBMKRod.getHullHeat(stack) >= 50 && ItemRBMKRod.getCoreHeat(stack) >= 50) {
list.add(EnumChatFormatting.GOLD + I18nUtil.resolveKey("desc.item.wasteCooling"));
}
if(selfRate > 0 || this.function == EnumBurnFunc.SIGMOID) {
list.add(EnumChatFormatting.RED + I18nUtil.resolveKey("trait.rbmk.source"));
}
list.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey("trait.rbmk.depletion", ((int)(((yield - getYield(stack)) / yield) * 100000D)) / 1000D + "%"));
list.add(EnumChatFormatting.DARK_PURPLE + I18nUtil.resolveKey("trait.rbmk.xenon", ((int)(getPoison(stack) * 1000D) / 1000D) + "%"));
list.add(EnumChatFormatting.BLUE + I18nUtil.resolveKey("trait.rbmk.splitsWith", I18nUtil.resolveKey(nType.unlocalized)));
@ -471,10 +484,10 @@ public class ItemRBMKRod extends Item {
list.add(EnumChatFormatting.RED + "Skin temp: " + ((int)(getHullHeat(stack) * 10D) / 10D) + "°C");
list.add(EnumChatFormatting.RED + "Core temp: " + ((int)(getCoreHeat(stack) * 10D) / 10D) + "°C");
list.add(EnumChatFormatting.DARK_RED + "Melting point: " + meltingPoint + "°C");*/
super.addInformation(stack, player, list, bool);
}
/* __ __ ____ ________
* | \ | | | __ \ |__ __|
* | \ | | | |__| | | |
@ -482,40 +495,40 @@ public class ItemRBMKRod extends Item {
* | | \ | | |__| | | |
* |__| \__| |_____/ |__|
*/
public static void setYield(ItemStack stack, double yield) {
setDouble(stack, "yield", yield);
}
public static double getYield(ItemStack stack) {
if(stack.getItem() instanceof ItemRBMKRod) {
return getDouble(stack, "yield");
}
return 0;
}
public static void setPoison(ItemStack stack, double xenon) {
setDouble(stack, "xenon", xenon);
}
public static double getPoison(ItemStack stack) {
return getDouble(stack, "xenon");
}
public static void setCoreHeat(ItemStack stack, double heat) {
setDouble(stack, "core", heat);
}
public static double getCoreHeat(ItemStack stack) {
return getDouble(stack, "core");
}
public static void setHullHeat(ItemStack stack, double heat) {
setDouble(stack, "hull", heat);
}
public static double getHullHeat(ItemStack stack) {
return getDouble(stack, "hull");
}
@ -529,23 +542,23 @@ public class ItemRBMKRod extends Item {
public double getDurabilityForDisplay(ItemStack stack) {
return 1D - getEnrichment(stack);
}
public static void setDouble(ItemStack stack, String key, double yield) {
if(!stack.hasTagCompound())
setNBTDefaults(stack);
stack.stackTagCompound.setDouble(key, yield);
}
public static double getDouble(ItemStack stack, String key) {
if(!stack.hasTagCompound())
setNBTDefaults(stack);
return stack.stackTagCompound.getDouble(key);
}
/**
* Sets up the default values for all NBT data because doing it one-by-one will only correctly set the first called value and the rest stays 0 which is very not good
* @param stack
@ -557,7 +570,7 @@ public class ItemRBMKRod extends Item {
setCoreHeat(stack, 20.0D);
setHullHeat(stack, 20.0D);
}
@Override
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
setNBTDefaults(stack); //minimize the window where NBT screwups can happen

View File

@ -38,6 +38,8 @@ public class NEIRegistry {
handlers.add(new FusionRecipeHandler());
handlers.add(new SILEXRecipeHandler());
handlers.add(new FuelPoolHandler());
handlers.add(new RBMKRodDisassemblyHandler());
handlers.add(new RBMKWasteDecayHandler());
handlers.add(new CrucibleSmeltingHandler());
handlers.add(new CrucibleAlloyingHandler());
handlers.add(new CrucibleCastingHandler());