Skip to content

Commit

Permalink
Thermal Dynamics NASE Prevention
Browse files Browse the repository at this point in the history
Adds checks to prevent crash with Thermal Dynamics from Negative Array Exceptions upon transferring items
  • Loading branch information
DrParadox7 committed Jan 15, 2024
1 parent b2607e6 commit 18e032c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
transformedMod(deobfCurse("extratic-72728:2299292"))
transformedMod(deobfCurse("journeymap-32274:4500658"))
transformedMod("curse.maven:travellers-gear-224440:2262113")
transformedMod("curse.maven:thermal-dynamics-227443:2388756")
transformedMod(deobfCurse("witchery-69673:2234410"))
transformedMod(deobfCurse("ztones-224369:2223720"))
transformedMod("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class LoadingConfig {
public boolean fixVoxelMapYCoord;
public boolean fixVoxelMapChunkNPE;
public boolean fixRedstoneTorchWorldLeak;
public boolean preventThermalDynamicsNASE;

// render debug
public boolean renderDebug;
Expand Down Expand Up @@ -368,7 +369,7 @@ public LoadingConfig(File file) {
fixVoxelMapYCoord = config.get(Category.FIXES.toString(), "fixVoxelMapYCoord", true, "Fix Y coordinate being off by one").getBoolean();
fixVoxelMapChunkNPE = config.get(Category.FIXES.toString(), "fixVoxelMapChunkNPE", true, "Fix some NullPointerExceptions").getBoolean();
fixRedstoneTorchWorldLeak = config.get(Category.FIXES.toString(), "fixRedstoneTorchWorldLeak", true, "Fix redstone torch leaking world").getBoolean();

preventThermalDynamicsNASE = config.get(Category.FIXES.toString(), "preventThermalDynamicsNASE", true, "Prevent crash with Thermal Dynamics from Negative Array Exceptions from item duct transfers").getBoolean();

// Pollution :nauseous:
pollutionBlockRecolor = config.get(Category.POLLUTION_RECOLOR.toString(), "pollutionRecolor", true, "Changes colors of certain blocks based on pollution levels").getBoolean();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,11 @@ public enum Mixins {
.addTargetedMod(TargetedMod.GALACTICRAFT_CORE)),
IC2_CELL(new Builder("No IC2 Cell Consumption in tanks").addMixinClasses("ic2.MixinIC2ItemCell")
.setPhase(Phase.LATE).setSide(Side.BOTH).setApplyIf(() -> Common.config.ic2CellWithContainer)
.addTargetedMod(TargetedMod.IC2));
.addTargetedMod(TargetedMod.IC2)),
TD_NC_FIX(new Builder("Fix Thermal Dynamics Crash with Nuclearcraft")
.addMixinClasses("thermaldynamics.MixinSimulatedInv").setSide(Side.BOTH)
.setApplyIf(() -> Common.config.preventThermalDynamicsNASE).addTargetedMod(TargetedMod.THERMALDYNAMICS)
.setPhase(Phase.LATE));

private final List<String> mixinClasses;
private final List<TargetedMod> targetedMods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum TargetedMod {
PROJECTE("ProjectE", null, "ProjectE"),
RAILCRAFT("Railcraft", null, "Railcraft"),
THAUMCRAFT("Thaumcraft", null, "Thaumcraft"), // "thaumcraft.codechicken.core.launch.DepLoader"
THERMALDYNAMICS("Thermal Dynamics", null, "ThermalDynamics"),
TINKERSCONSTRUCT("TConstruct", null, "TConstruct"),
EXTRATIC("ExtraTiC", null, "ExtraTiC"),
TRAVELLERSGEAR("TravellersGear", null, "TravellersGear"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mitchej123.hodgepodge.mixins.late.thermaldynamics;

import net.minecraft.item.ItemStack;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import cofh.thermaldynamics.duct.item.SimulatedInv;

@Mixin(SimulatedInv.class)
public class MixinSimulatedInv {

@Shadow(remap = false)
ItemStack[] items;

@Inject(method = "func_70301_a", at = @At("HEAD"), remap = false, cancellable = true)
public void func_70301_a(int par1, CallbackInfoReturnable<ItemStack> cir) {
if (this.items.length <= par1) {
cir.setReturnValue(null);
}
}

@Inject(method = "func_70304_b", at = @At("HEAD"), remap = false, cancellable = true)
public void func_70304_b(int par1, CallbackInfoReturnable<ItemStack> cir) {
if (this.items.length <= par1) {
cir.setReturnValue(null);
}
}
}

0 comments on commit 18e032c

Please sign in to comment.