Skip to content

Commit

Permalink
Rename and add ModHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
wohaopa committed May 20, 2024
1 parent 45b55c7 commit 39e7f14
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
name = "GTNHModify",
acceptedMinecraftVersions = "[1.7.10]",
acceptableRemoteVersions = "*",
dependencies = "required-after:gregtech;required-after:Thaumcraft")
dependencies = "after:gregtech;after:Thaumcraft")
public class GTNHModifyMod {

public static final String MODID = "GTNHModify";
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/com/github/wohaopa/GTNHModify/LateMixinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@ public String getMixinConfig() {

@Override
public List<String> getMixins(Set<String> loadedMods) {

for (String modId : loadedMods) {
if (modId.equals("gregtech")) {
ModHelper.hasGregtech = true;
} else if (modId.equals("Thaumcraft")) {
ModHelper.hasThaumcraft = true;
}
}

List<String> mixins = new ArrayList<>();
// GregTech
mixins.add("GT_MetaTileEntity_ScannerMixin");
mixins.add("GT_MetaTileEntity_MinerMixin");
mixins.add("GT_MetaTileEntity_MultiFurnaceMixin");
mixins.add("GT_MetaTileEntity_DrillerBaseMixin");

if (ModHelper.hasGregtech) {
// GregTech
mixins.add("gregtech.GT_MetaTileEntity_ScannerMixin");
mixins.add("gregtech.GT_MetaTileEntity_MinerMixin");
mixins.add("gregtech.GT_MetaTileEntity_MultiFurnaceMixin");
mixins.add("gregtech.GT_MetaTileEntity_DrillerBaseMixin");
}
if (ModHelper.hasThaumcraft) {

}

return mixins;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/github/wohaopa/GTNHModify/ModHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.wohaopa.GTNHModify;

public class ModHelper {

public static boolean hasGregtech;
public static boolean hasThaumcraft;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.github.wohaopa.GTNHModify.handler;

import com.github.wohaopa.GTNHModify.ModHelper;
import com.github.wohaopa.GTNHModify.strategies.Strategy;

import gregtech.api.recipe.RecipeMap;
import gregtech.api.util.GT_Recipe;

@IHandler("init")
public class GT_RecipesHandler {
public class GregTechHandler {

protected static void init() {
if (!ModHelper.hasGregtech) return;

RecipeMap.ALL_RECIPE_MAPS.forEach(
(s, recipeMap) -> recipeMap.getAllRecipes()
.forEach(recipe -> Strategy.strategy.handler_GT_Recipe(recipe)));
GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.forEach(
gtRecipeAssemblyLine -> { Strategy.strategy.handler_GT_Recipe_AssemblyLine(gtRecipeAssemblyLine); });
GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes
.forEach(gtRecipeAssemblyLine -> Strategy.strategy.handler_GT_Recipe_AssemblyLine(gtRecipeAssemblyLine));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

public class Handlers {

public static List<String> handlers = Arrays.asList("Furnace", "GT");
private static final String Suffix = "_RecipesHandler";
public static List<String> handlers = Arrays.asList("Minecraft", "GregTech", "Thaumcraft");
private static final String Suffix = "Handler";
private static final List<Method> methods = new ArrayList<>();

public static void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import com.github.wohaopa.GTNHModify.strategies.Strategy;

@IHandler("init")
public class Furnace_RecipesHandler {
public class MinecraftHandler {

public static void init() {
// todo recipe
FurnaceRecipes.smelting()
.getSmeltingList()
.forEach((itemStack, itemStack2) -> Strategy.strategy.handler_FurnaceRecipe(itemStack, itemStack2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import com.github.wohaopa.GTNHModify.handler.Furnace_RecipesHandler;
import com.github.wohaopa.GTNHModify.handler.MinecraftHandler;

@Mixin(TileEntityFurnace.class)
public abstract class TileEntityFurnaceMixin {

@ModifyConstant(method = "updateEntity", constant = @Constant(intValue = 200))
private int injected(int value) {
return Furnace_RecipesHandler.handle(this, value);
return MinecraftHandler.handle(this, value);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.wohaopa.GTNHModify.mixins.late;
package com.github.wohaopa.GTNHModify.mixins.late.gregtech;

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

import com.github.wohaopa.GTNHModify.handler.GT_RecipesHandler;
import com.github.wohaopa.GTNHModify.handler.GregTechHandler;

import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_DrillerBase;
Expand All @@ -21,7 +21,7 @@ public abstract class GT_MetaTileEntity_DrillerBaseMixin {
shift = At.Shift.AFTER))
private void injected(CallbackInfoReturnable<CheckRecipeResult> cir) {

((GT_MetaTileEntity_DrillerBase) ((Object) this)).mMaxProgresstime = GT_RecipesHandler
((GT_MetaTileEntity_DrillerBase) ((Object) this)).mMaxProgresstime = GregTechHandler
.handle(this, ((GT_MetaTileEntity_DrillerBase) ((Object) this)).mMaxProgresstime);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.wohaopa.GTNHModify.mixins.late;
package com.github.wohaopa.GTNHModify.mixins.late.gregtech;

import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -8,7 +8,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import com.github.wohaopa.GTNHModify.handler.GT_RecipesHandler;
import com.github.wohaopa.GTNHModify.handler.GregTechHandler;

import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Miner;

Expand All @@ -27,6 +27,6 @@ public class GT_MetaTileEntity_MinerMixin {
target = "Lgregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner;mSpeed:I",
opcode = Opcodes.GETFIELD))
private int injected(GT_MetaTileEntity_Miner miner) {
return GT_RecipesHandler.handle(miner, mSpeed);
return GregTechHandler.handle(miner, mSpeed);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.wohaopa.GTNHModify.mixins.late;
package com.github.wohaopa.GTNHModify.mixins.late.gregtech;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import com.github.wohaopa.GTNHModify.handler.GT_RecipesHandler;
import com.github.wohaopa.GTNHModify.handler.GregTechHandler;

import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_MultiFurnace;

Expand All @@ -13,6 +13,6 @@ public class GT_MetaTileEntity_MultiFurnaceMixin {

@ModifyConstant(method = "checkProcessing", constant = @Constant(intValue = 512))
private int injected(int value) {
return GT_RecipesHandler.handle(this, value);
return GregTechHandler.handle(this, value);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.wohaopa.GTNHModify.mixins.late;
package com.github.wohaopa.GTNHModify.mixins.late.gregtech;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import com.github.wohaopa.GTNHModify.handler.GT_RecipesHandler;
import com.github.wohaopa.GTNHModify.handler.GregTechHandler;

import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Scanner;

Expand All @@ -13,6 +13,6 @@ public abstract class GT_MetaTileEntity_ScannerMixin {

@ModifyArg(method = "checkRecipe", at = @At(value = "INVOKE", target = "calculateOverclockedNess"), index = 1)
private int injected(int x) {
return GT_RecipesHandler.handle(this, x);
return GregTechHandler.handle(this, x);
}
}

0 comments on commit 39e7f14

Please sign in to comment.