Skip to content

Commit

Permalink
added GTNHlib to the target mod to avoid a crash if it's not loaded (#…
Browse files Browse the repository at this point in the history
…109)

* added GTNHlib to certain mixin to avoid crash

* check once if env is obfuscated

* yeet the reflection in MixinFurnaceRecipes
  • Loading branch information
Alexdoru authored Sep 12, 2022
1 parent 1e7de59 commit a6a8866
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import ru.timeconqueror.spongemixins.MinecraftURLClassPath;

public class HodgepodgeMixinPlugin implements IMixinConfigPlugin {

public static boolean isEnvironmentDeobfuscated;

@Override
public void onLoad(String mixinPackage) {}

Expand All @@ -37,19 +40,19 @@ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
final boolean isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
isEnvironmentDeobfuscated = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");

List<TargetedMod> loadedMods = Arrays.stream(TargetedMod.values())
.filter(mod -> (mod == TargetedMod.VANILLA
|| (isDevelopmentEnvironment && MinecraftURLClassPath.findJarInClassPath(mod.devJarName))
|| (isEnvironmentDeobfuscated && MinecraftURLClassPath.findJarInClassPath(mod.devJarName))
|| loadModJar(mod)))
.collect(Collectors.toList());

for (TargetedMod mod : TargetedMod.values()) {
if (loadedMods.contains(mod)) {
Hodgepodge.log.info("Found Mod " + mod.modName + "!");
} else if (ArrayUtils.contains(Hodgepodge.config.requiredMods, mod.modName)
&& (!isDevelopmentEnvironment || Hodgepodge.config.requiredModsInDev)) {
&& (!isEnvironmentDeobfuscated || Hodgepodge.config.requiredModsInDev)) {
Hodgepodge.log.error(
"CRITICAL ERROR: Could not find required jar {}. If this mod is not required please remove it from the 'requiredMods' section of the config.",
mod.modName);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Mixins {
NORTHWEST_BIAS_FIX(
"minecraft.MixinRandomPositionGenerator", () -> Hodgepodge.config.fixNorthWestBias, TargetedMod.VANILLA),
SPEEDUP_VANILLA_FURNACE(
"minecraft.MixinFurnaceRecipes", () -> Hodgepodge.config.speedupVanillaFurnace, TargetedMod.VANILLA),
"minecraft.MixinFurnaceRecipes", () -> Hodgepodge.config.speedupVanillaFurnace, TargetedMod.GTNHLIB),
GAMEOVER_GUI_LOCKED_DISABLED(
"minecraft.MixinGuiGameOver", Side.CLIENT, () -> Hodgepodge.config.fixGuiGameOver, TargetedMod.VANILLA),
PREVENT_PICKUP_LOOT(
Expand Down Expand Up @@ -107,7 +107,7 @@ public enum Mixins {
"minecraft.MixinMinecraft_ToggleDebugMessage",
Side.CLIENT,
() -> Hodgepodge.config.addToggleDebugMessage,
TargetedMod.VANILLA),
TargetedMod.GTNHLIB),
SPEEDUP_VANILLA_ANIMATIONS(
() -> Hodgepodge.config.speedupAnimations,
Side.CLIENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap;
import com.mitchej123.hodgepodge.Hodgepodge;
import java.lang.reflect.Field;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.launchwrapper.Launch;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(FurnaceRecipes.class)
public abstract class MixinFurnaceRecipes {
Expand All @@ -22,51 +17,15 @@ public abstract class MixinFurnaceRecipes {
* 2) No longer looping over every. single. recipe. in the list and using the .get()
*/
@Shadow
private Map smeltingList;
private Map smeltingList = new ItemStackMap<ItemStack>(false);

@Shadow
private Map experienceList;
private Map experienceList = new ItemStackMap<Float>(false);

@Shadow
abstract boolean func_151397_a(ItemStack p_151397_1_, ItemStack p_151397_2_);

@Redirect(
at =
@At(
value = "INVOKE",
target =
"Lnet/minecraft/item/crafting/FurnaceRecipes;func_151393_a(Lnet/minecraft/block/Block;Lnet/minecraft/item/ItemStack;F)V",
ordinal = 0),
method = "Lnet/minecraft/item/crafting/FurnaceRecipes;<init>()V")
private void doStuff(FurnaceRecipes instance, Block p_151393_1_, ItemStack p_151393_2_, float p_151393_3_)
throws NoSuchFieldException, IllegalAccessException {
Hodgepodge.log.info("Swapping out smeltingList and experienceList in FurnaceRecipes");

// Hack into the first call in the constructor and replace the lists with a new hashmap that has an ItemStackMi
// hashing strategy
boolean devEnv = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
try {
Class<?> clazz = Class.forName("net.minecraft.item.crafting.FurnaceRecipes");

Field smeltingList = clazz.getDeclaredField(devEnv ? "smeltingList" : "field_77604_b");
smeltingList.setAccessible(true);
smeltingList.set(instance, new ItemStackMap<ItemStack>(false));

Field experienceList = clazz.getDeclaredField(devEnv ? "experienceList" : "field_77605_c");
experienceList.setAccessible(true);
experienceList.set(instance, new ItemStackMap<Float>(false));

Hodgepodge.log.info("Successfully swapped the lists in FurnaceRecipes");

} catch (ClassNotFoundException | IllegalAccessException e) {
e.printStackTrace();
}
instance.func_151393_a(p_151393_1_, p_151393_2_, p_151393_3_);
}
/**
* @author mitchej123
* @reason Significantly Faster
* Inspired by later versions of forge
* @reason Significantly faster
* Inspired by later versions of forge
*/
@SuppressWarnings("unchecked")
@Overwrite(remap = false)
Expand All @@ -84,7 +43,7 @@ private void doStuff(FurnaceRecipes instance, Block p_151393_1_, ItemStack p_151

/**
* @author mitchej123
* @reason Significantly Faster
* @reason Significantly faster
*/
@Overwrite
public ItemStack getSmeltingResult(ItemStack stack) {
Expand All @@ -93,12 +52,11 @@ public ItemStack getSmeltingResult(ItemStack stack) {

/**
* @author mitchej123
* @reason Significantly Faster
* @reason Significantly faster
*/
@Overwrite(remap = false)
public float func_151398_b /* getSmeltingExperience */(ItemStack stack) {
if (stack == null || stack.getItem() == null) return 0f;

float exp = stack.getItem().getSmeltingExperience(stack);
if (exp == -1) {
exp = (Float) (this.experienceList.getOrDefault(stack, 0f));
Expand Down

0 comments on commit a6a8866

Please sign in to comment.