Skip to content

Commit

Permalink
Merge branch '1.19' into 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Dec 17, 2023
2 parents 207b735 + ac1ba8e commit 2b04214
Show file tree
Hide file tree
Showing 24 changed files with 705 additions and 240 deletions.
139 changes: 139 additions & 0 deletions docs/ADDING_NUCLEAR_COMPONENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Adding nuclear reactor components
MI allows you to add new nuclear reactor components using KubeJS.
Currently, fuel rods, control rods and fluid-neutron interactions can be registered.

To add fission fuel rods and control rods, you will need to use a startup script and the events in `MIMaterialEvents`
Fuel rods and control rods are parts that can be added to a new or preexisting material.

Isotopes are used in the registration of rods.
They can be added using the `MIRegistrationEvents.registerNuclearIsotopes` event.

## Add a fuel rod
Read the [material system documentation](`ADDING_MATERIALS.md`) first for an explanation of the material system.

To register fuel rods for a material, you must first register the material as a fission fuel.
This can be done using `.nuclearFuel(...)` on the material builder with a number of parameters:
```js
MIMaterialEvents.addMaterials(event => {
event.createMaterial('LE Americium MOX', 'le_americium_mox', 0x83867B,
builder => {
builder
.nuclearFuel(
0.6, // Thermal absorption probabilty
0.35, // Thermal scattering
2400, // Max temperature
900, // Low temperature limit (neutron production starts to decrease)
2300, // High temperature limit (neutron production completely stops)
8, // Neutron multiplication
0.5) // Direct energy factor
});
});
```

You can also combine the parameters of two existing materials using the `.nuclearFuelMix(materialA, materialB, mix)` method.
This can be used to simulate MOX and MOX-type fuels.
The resulting parameters will be `(1 - r) * a + r * b`, where `r` is the factor, `a` is the first set of parameters and `b` is the second.
The example below illustrates how a fuel rod can be created from the uranium 238 and plutonium parameters.
This generates the same parameters as LE MOX fuel.
```js
MIMaterialEvents.addMaterials(event => {
event.createMaterial('LE Americium MOX', 'le_americium_mox', 0x83867B,
builder => {
builder
.nuclearFuelMix("uranium_238", "plutonium", 1/9)
});
});
```

You then need to call the `.fuelRods()` method on the material builder to register the rods.
Here is a complete example:
```js
MIMaterialEvents.addMaterials(event => {
event.createMaterial('LE Americium MOX', 'le_americium_mox', 0x83867B,
builder => {
builder
.nuclearFuelMix("uranium_238", "plutonium", 1/9)
// Every material with a fuel rod needs at least the ingot and rod parts
.addParts('ingot', 'rod')
.fuelRods()
});
});
```

## Add a control rod
To add a control rod, use the `.controlRod(...)` material builder method.

Here is an example script that adds a new `Boron` material that has a control rod:
```js
MIMaterialEvents.addMaterials(event => {
event.createMaterial('Boron', 'boron', 0x493D35,
builder => {
// Every material that has a control rod needs at least the ingot and rod parts
builder.addParts('ingot', 'rod')
.controlRod(
1900, // Max temperature
0.5, // Heat conduction
0.95, // Thermal absorption probability
0.9, // Fast absorption probability
0.05, // Thermal scattering probability
0.1, // Fast scattering probability
'HEAVY', // Scattering type, can be ULTRA_LIGHT (0.05), LIGHT (0.2), MEDIUM (0.5) or HEAVY (0.85)
1) // Size
.defaultRecipes();
});
});
```

## Add a fluid-neutron interaction
These types of fluids are the ones that can absorb neutrons inside a Nuclear Reactor (think water producing deuterium).
You can add your own using a startup script and the `MIRegistrationEvents.registerFluidNeutronInteractions` event.

To create the fluid in the first place, refer to the [fluid creation tutorial](`ADDING_FLUIDS.md`).

Here's an example script that adds tritium turning into hydrogen-4:

```js
MIRegistrationEvents.registerFluidNeutronInteractions(event => {
event.register(
'modern_industrialization:tritium', // The fluid being added as a nuclear component
5, // Heat conduction factor (later multiplied by the base heat conduction, 0.01)
1, // Density
'ultra_light', // Scattering type
0.02, // Thermal absorption probability
0.01, // Fast absorption probability
0.15, // Thermal scattering probability
0.65, // Fast scattering probability
'modern_industrialization:hydrogen_4', // The fluid product
1, // Amount of converted product fluid per consumed input fluid
1.0); // Probability of converting 1 of input fluid per received neutron
});
```
For a high-pressure fluid (with 8x the density), the last two parameters would be `8, 0.125`.

### Removing and modifying a fluid nuclear component
You can remove a fluid nuclear component:

```js
MIRegistrationEvents.registerFluidNeutronInteractions(event => {
event.remove('minecraft:water'); // Remove water as a fluid nuclear component
});
```

If, instead of removing the fluid nuclear component, you'd rather modify it, you can:
```js
MIRegistrationEvents.registerFluidNeutronInteractions(event => {
// Same parameters as `register(...)`, see above.
event.modify(
'minecraft:water',
5,
1,
'ultra_light',
0.02,
0.01,
0.15,
0.65,
'modern_industrialization:heavy_water',
1,
1.0);
});
```
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Refer to the page that interests you:
- [Fluids](ADDING_FLUIDS.md)
- [Machines](ADDING_MACHINES.md)
- [Materials](ADDING_MATERIALS.md)
- [Nuclear reactor components](ADDING_NUCLEAR_COMPONENTS.md)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import aztech.modern_industrialization.MIText;
import aztech.modern_industrialization.ModernIndustrialization;
import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory;
import aztech.modern_industrialization.nuclear.FluidNuclearComponents;
import aztech.modern_industrialization.nuclear.FluidNuclearComponent;
import aztech.modern_industrialization.nuclear.INeutronBehaviour;
import aztech.modern_industrialization.nuclear.INuclearComponent;
import aztech.modern_industrialization.nuclear.NeutronInteraction;
Expand Down Expand Up @@ -90,8 +90,7 @@ public void buildRecipes(RecipeManager recipeManager, RegistryAccess registryAcc

for (Fluid fluid : BuiltInRegistries.FLUID) {
if (fluid.isSource(fluid.defaultFluidState()) && fluid != Fluids.EMPTY) {
FluidVariant variant = FluidVariant.of(fluid);
INuclearComponent<?> component = FluidNuclearComponents.of(variant);
INuclearComponent<?> component = FluidNuclearComponent.get(fluid);
if (component != null) {
consumer.accept(new Recipe(component, CategoryType.FAST_NEUTRON_INTERACTION));
consumer.accept(new Recipe(component, CategoryType.THERMAL_NEUTRON_INTERACTION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import aztech.modern_industrialization.MIText;
import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory;
import aztech.modern_industrialization.machines.gui.MachineScreen;
import aztech.modern_industrialization.nuclear.FluidNuclearComponents;
import aztech.modern_industrialization.nuclear.FluidNuclearComponent;
import aztech.modern_industrialization.nuclear.INeutronBehaviour;
import aztech.modern_industrialization.nuclear.INuclearComponent;
import aztech.modern_industrialization.nuclear.NuclearComponentItem;
Expand All @@ -36,7 +36,6 @@
import aztech.modern_industrialization.util.Rectangle;
import aztech.modern_industrialization.util.TextHelper;
import java.util.function.Consumer;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.minecraft.client.Minecraft;
import net.minecraft.core.RegistryAccess;
Expand Down Expand Up @@ -77,8 +76,7 @@ public void buildRecipes(RecipeManager recipeManager, RegistryAccess registryAcc

for (Fluid fluid : BuiltInRegistries.FLUID) {
if (fluid.isSource(fluid.defaultFluidState()) && fluid != Fluids.EMPTY) {
FluidVariant variant = FluidVariant.of(fluid);
INuclearComponent<?> component = FluidNuclearComponents.of(variant);
INuclearComponent<?> component = FluidNuclearComponent.get(fluid);

if (component != null) {
consumer.accept(new Recipe(component, CategoryType.THERMAL_PROPERTIES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import aztech.modern_industrialization.materials.MIMaterials;
import aztech.modern_industrialization.misc.autotest.MIAutoTesting;
import aztech.modern_industrialization.misc.guidebook.GuidebookEvents;
import aztech.modern_industrialization.nuclear.FluidNuclearComponent;
import aztech.modern_industrialization.pipes.MIPipes;
import aztech.modern_industrialization.proxy.CommonProxy;
import aztech.modern_industrialization.stats.PlayerStatisticsData;
Expand Down Expand Up @@ -106,6 +107,7 @@ public static void initialize() {
setupBlocks();
MIBlockEntityTypes.init();
MIVillager.init();
FluidNuclearComponent.init();

// fields.
setupPackets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ public void fireCustomConditionEvent() {

public void fireCableTiersEvent() {
}

public void fireRegisterFluidNeutronInteractionsEvent() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
*/
package aztech.modern_industrialization.compat.kubejs;

import aztech.modern_industrialization.compat.kubejs.machine.AddEbfTiersEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.AddMultiblockSlotsEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.MIMachineKubeJSEvents;
import aztech.modern_industrialization.compat.kubejs.machine.RegisterCasingsEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.RegisterMachinesEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.RegisterRecipeTypesEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.RegisterUpgradesEventJS;
import aztech.modern_industrialization.compat.kubejs.machine.*;
import aztech.modern_industrialization.compat.kubejs.material.AddMaterialsEventJS;
import aztech.modern_industrialization.compat.kubejs.material.MIMaterialKubeJSEvents;
import aztech.modern_industrialization.compat.kubejs.material.ModifyMaterialEventJS;
Expand All @@ -38,6 +32,7 @@
import aztech.modern_industrialization.compat.kubejs.registration.MIRegistrationKubeJSEvents;
import aztech.modern_industrialization.compat.kubejs.registration.RegisterCableTiersEventJS;
import aztech.modern_industrialization.compat.kubejs.registration.RegisterFluidFuelsEventJS;
import aztech.modern_industrialization.compat.kubejs.registration.RegisterFluidNeutronInteractionsEventJS;
import aztech.modern_industrialization.compat.kubejs.registration.RegisterFluidsEventJS;
import aztech.modern_industrialization.inventory.SlotPositions;
import aztech.modern_industrialization.machines.blockentities.multiblocks.ElectricBlastFurnaceBlockEntity;
Expand Down Expand Up @@ -106,4 +101,10 @@ public void fireCustomConditionEvent() {
public void fireCableTiersEvent() {
MIRegistrationKubeJSEvents.REGISTER_CABLE_TIERS.post(new RegisterCableTiersEventJS());
}

@Override
public void fireRegisterFluidNeutronInteractionsEvent() {
MIRegistrationKubeJSEvents.REGISTER_FLUID_NEUTRON_INTERACTIONS.post(new RegisterFluidNeutronInteractionsEventJS());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
package aztech.modern_industrialization.compat.kubejs.material;

import aztech.modern_industrialization.materials.MaterialBuilder;
import aztech.modern_industrialization.materials.MaterialRegistry;
import aztech.modern_industrialization.materials.part.MaterialItemPart;
import aztech.modern_industrialization.materials.part.NuclearFuelPart;
import aztech.modern_industrialization.materials.part.PartKey;
import aztech.modern_industrialization.materials.property.MaterialHardness;
import aztech.modern_industrialization.materials.property.MaterialProperty;
import aztech.modern_industrialization.materials.recipe.ForgeHammerRecipes;
import aztech.modern_industrialization.materials.recipe.SmeltingRecipes;
import aztech.modern_industrialization.materials.recipe.StandardRecipes;
import aztech.modern_industrialization.materials.set.MaterialSet;
import aztech.modern_industrialization.nuclear.IsotopeFuelParams;
import aztech.modern_industrialization.nuclear.NuclearConstant;
import com.google.gson.JsonObject;

class MaterialBuilderJSWrapper {
Expand Down Expand Up @@ -186,4 +190,31 @@ public MaterialBuilderJSWrapper forgeHammerRecipes() {
materialBuilder.addRecipes(ForgeHammerRecipes::apply);
return this;
}

public MaterialBuilderJSWrapper nuclearFuel(double thermalAbsorbProba, double thermalScatterings, int maxTemp, int tempLimitLow,
int tempLimitHigh, double neutronsMultiplication, double directEnergyFactor) {
materialBuilder.set(MaterialProperty.ISOTOPE, new IsotopeFuelParams(thermalAbsorbProba, thermalScatterings, maxTemp, tempLimitLow,
tempLimitHigh, neutronsMultiplication, directEnergyFactor));
return this;
}

public MaterialBuilderJSWrapper nuclearFuelMix(String a, String b, double factor) {
materialBuilder.set(MaterialProperty.ISOTOPE, IsotopeFuelParams.mix(
IsotopeFuelParams.of(MaterialRegistry.getMaterial(a)),
IsotopeFuelParams.of(MaterialRegistry.getMaterial(b)),
factor));
return this;
}

public MaterialBuilderJSWrapper fuelRods() {
materialBuilder.addParts(NuclearFuelPart.ofAll());
return this;
}

public MaterialBuilderJSWrapper controlRod(int maxTemperature, double heatConduction, double thermalAbsorbProba, double fastAbsorbProba,
double thermalScatteringProba, double fastScatteringProba, NuclearConstant.ScatteringType scatteringType, double size) {
materialBuilder.addParts(creator.controlRodPart(maxTemperature, heatConduction, thermalAbsorbProba, fastAbsorbProba, thermalScatteringProba,
fastScatteringProba, scatteringType, size));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
package aztech.modern_industrialization.compat.kubejs.material;

import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.materials.part.*;
import aztech.modern_industrialization.materials.part.MIParts;
import aztech.modern_industrialization.materials.part.OrePart;
import aztech.modern_industrialization.materials.part.PartTemplate;
import aztech.modern_industrialization.materials.part.RawMetalPart;
import aztech.modern_industrialization.materials.set.MaterialBlockSet;
import aztech.modern_industrialization.materials.set.MaterialOreSet;
import aztech.modern_industrialization.materials.set.MaterialRawSet;
import aztech.modern_industrialization.nuclear.NuclearConstant;
import com.google.gson.JsonObject;
import net.minecraft.util.valueproviders.UniformInt;

Expand Down Expand Up @@ -151,4 +155,11 @@ public PartTemplate tankPart(int bucketCapacity) {
public PartTemplate tankPart(String englishName, String path, int bucketCapacity) {
return MIParts.TANK.of(englishName, path, bucketCapacity);
}

public PartTemplate controlRodPart(int maxTemperature, double heatConduction, double thermalAbsorbProba, double fastAbsorbProba,
double thermalScatteringProba, double fastScatteringProba, NuclearConstant.ScatteringType scatteringType, double size) {
return MIParts.CONTROL_ROD.of(maxTemperature, heatConduction, thermalAbsorbProba, fastAbsorbProba, thermalScatteringProba,
fastScatteringProba, scatteringType, size);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface MIRegistrationKubeJSEvents {
EventHandler REGISTER_CABLE_TIERS = EVENT_GROUP.startup("registerCableTiers", () -> RegisterCableTiersEventJS.class);
EventHandler REGISTER_FLUIDS = EVENT_GROUP.startup("registerFluids", () -> RegisterFluidsEventJS.class);
EventHandler REGISTER_FLUID_FUELS = EVENT_GROUP.startup("registerFluidFuels", () -> RegisterFluidFuelsEventJS.class);
EventHandler REGISTER_FLUID_NEUTRON_INTERACTIONS = EVENT_GROUP.startup("registerFluidNeutronInteractions",
() -> RegisterFluidNeutronInteractionsEventJS.class);
}
Loading

0 comments on commit 2b04214

Please sign in to comment.