Skip to content

Commit

Permalink
Remove more reflection + reorganize mixin accessors packages (#3260)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
  • Loading branch information
3 people authored Sep 28, 2024
1 parent 6b1f145 commit 86f1765
Show file tree
Hide file tree
Showing 67 changed files with 267 additions and 1,251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;

import bartworks.hooks.BWCoreStaticReplacementMethodes;
import gregtech.mixin.hooks.BWCoreStaticReplacementMethodes;

public class ClearCraftingCache extends CommandBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import bartworks.API.recipe.BWNBTDependantCraftingRecipe;
import bartworks.API.recipe.BartWorksRecipeMaps;
import bartworks.hooks.BWCoreStaticReplacementMethodes;
import bartworks.system.material.WerkstoffLoader;
import bartworks.util.BWUtil;
import bartworks.util.Pair;
Expand All @@ -48,6 +47,7 @@
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.mixin.hooks.BWCoreStaticReplacementMethodes;

public class CircuitImprintLoader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
import gregtech.api.interfaces.IRecipeMutableAccess;
import gregtech.api.interfaces.ISubTagContainer;
import gregtech.api.items.GTGenericBlock;
import gregtech.api.items.GTGenericItem;
Expand All @@ -123,6 +122,7 @@
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.common.blocks.BlockOresAbstract;
import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess;
import gtPlusPlus.core.block.base.BlockBaseModular;
import gtPlusPlus.core.item.base.BaseItemComponent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
import gregtech.api.enums.Mods;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
import gregtech.api.interfaces.IRecipeMutableAccess;
import gregtech.api.recipe.RecipeMaps;
import gregtech.api.util.GTLog;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTRecipe;
import gregtech.api.util.GTUtility;
import gregtech.common.items.CombType;
import gregtech.loaders.misc.GTBees;
import gregtech.mixin.interfaces.accessors.IRecipeMutableAccess;
import gtPlusPlus.api.recipe.GTPPRecipeMaps;
import gtPlusPlus.core.item.chemistry.GenericChem;

Expand Down
17 changes: 3 additions & 14 deletions src/main/java/gregtech/api/util/GTRecipeRegistrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static gregtech.api.util.GTUtility.calculateRecipeEU;
import static gregtech.api.util.GTUtility.getTier;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.IdentityHashMap;
Expand All @@ -53,7 +52,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;

import cpw.mods.fml.relauncher.ReflectionHelper;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.Materials;
Expand All @@ -63,6 +61,7 @@
import gregtech.api.objects.ItemData;
import gregtech.api.objects.MaterialStack;
import gregtech.api.recipe.RecipeCategories;
import gregtech.mixin.interfaces.accessors.ShapedOreRecipeAccessor;
import ic2.api.reactor.IReactorComponent;

/**
Expand Down Expand Up @@ -123,8 +122,6 @@ public class GTRecipeRegistrator {
new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null),
new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null),
new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2) };
public static final Field SHAPED_ORE_RECIPE_WIDTH = ReflectionHelper.findField(ShapedOreRecipe.class, "width");
public static final Field SHAPED_ORE_RECIPE_HEIGHT = ReflectionHelper.findField(ShapedOreRecipe.class, "height");
private static volatile Map<RecipeShape, List<IRecipe>> indexedRecipeListCache;
private static final String[][] sShapesA = new String[][] { null, null, null,
{ "Helmet", s_P + s_P + s_P, s_P + s_H + s_P },
Expand Down Expand Up @@ -791,19 +788,11 @@ public static boolean hasVanillaRecipes(Materials materials) {
}

private static int getRecipeWidth(ShapedOreRecipe r) {
try {
return (int) SHAPED_ORE_RECIPE_WIDTH.get(r);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return ((ShapedOreRecipeAccessor) r).gt5u$getWidth();
}

private static int getRecipeHeight(ShapedOreRecipe r) {
try {
return (int) SHAPED_ORE_RECIPE_HEIGHT.get(r);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
return ((ShapedOreRecipeAccessor) r).gt5u$getHeight();
}

private static int getRecipeHeight(ShapedRecipes r) {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/gregtech/loaders/preload/GTPreLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,9 @@ public static void adjustScrap() {
try {
Objects.requireNonNull(GTUtility.getField("ic2.core.item.ItemScrapbox$Drop", "topChance", true, true))
.set(null, 0);
((List<?>) Objects.requireNonNull(
GTUtility.getFieldContent(
GTUtility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true),
"drops",
true,
true))).clear();
((List<?>) Objects
.requireNonNull(GTUtility.getFieldContent(ic2.api.recipe.Recipes.scrapboxDrops, "drops", true, true)))
.clear();
} catch (Throwable e) {
if (GTValues.D1) {
e.printStackTrace(GTLog.err);
Expand Down Expand Up @@ -539,7 +536,7 @@ public static void loadConfig() {

/**
* Clamp value between 0 and 255
*
*
* @param value the value to clamp
* @return the clamped value
*/
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/gregtech/mixin/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ public enum Mixin {
.setSide(Side.BOTH)),
VanillaAccessors(new Builder("Adds various accessors")
.addMixinClasses(
"minecraft.VanillaShapedRecipeMixin",
"minecraft.VanillaShapelessRecipeMixin",
"minecraft.ForgeShapedRecipeMixin",
"minecraft.ForgeShapelessRecipeMixin",
"minecraft.PotionMixin")
.addTargetedMod(VANILLA)
.setApplyIf(() -> true)
.setPhase(Phase.EARLY)
.setSide(Side.BOTH)),
BlockStemMixin(new Builder("Stem Crop Block Accessor").addMixinClasses("minecraft.BlockStemMixin")
"minecraft.accessors.BlockStemMixin",
"minecraft.accessors.VanillaShapedRecipeMixin",
"minecraft.accessors.VanillaShapelessRecipeMixin",
"minecraft.accessors.ForgeShapedRecipeMixin",
"minecraft.accessors.ForgeShapelessRecipeMixin",
"minecraft.accessors.PotionMixin",
"minecraft.accessors.EntityPlayerMPMixin")
.addTargetedMod(VANILLA)
.setApplyIf(() -> true)
.setPhase(Phase.EARLY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* DEALINGS IN THE SOFTWARE.
*/

package bartworks.hooks;
package gregtech.mixin.hooks;

import java.util.HashSet;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gregtech.mixin;
package gregtech.mixin.hooks;

public class MixinsVariablesHelper {

Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/gregtech/mixin/interfaces/PotionExt.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gregtech.mixin.interfaces.accessors;

public interface EntityPlayerMPAccessor {

String gt5u$getTranslator();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gregtech.mixin.interfaces.accessors;

import net.minecraft.block.Block;

public interface IBlockStemAccessor {

Block gt5u$getCropBlock();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gregtech.api.interfaces;
package gregtech.mixin.interfaces.accessors;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gregtech.mixin.interfaces.accessors;

public interface PotionAccessor {

boolean gt5u$isBadEffect();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package gregtech.mixin.interfaces.accessors;

public interface ShapedOreRecipeAccessor {

int gt5u$getWidth();

int gt5u$getHeight();

}
64 changes: 45 additions & 19 deletions src/main/java/gtPlusPlus/GTplusplus.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import static gregtech.api.enums.Mods.Names;
import static gregtech.api.enums.Mods.Thaumcraft;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.launchwrapper.Launch;

import com.gtnewhorizon.gtnhlib.config.ConfigException;
Expand All @@ -25,7 +26,6 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand All @@ -44,7 +44,9 @@
import gtPlusPlus.core.lib.GTPPCore;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.util.data.LocaleUtils;
import gtPlusPlus.plugin.manager.CoreManager;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.plugin.agrichem.block.AgrichemFluids;
import gtPlusPlus.plugin.fixes.vanilla.VanillaBedHeightFix;
import gtPlusPlus.xmod.gregtech.common.MetaGTProxy;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools;
Expand Down Expand Up @@ -76,7 +78,7 @@
+ " after:TGregworks;"
+ " after:StevesCarts;"
+ " required-after:gtnhlib@[0.0.10,);")
public class GTplusplus implements ActionListener {
public class GTplusplus {

public enum INIT_PHASE {

Expand Down Expand Up @@ -149,8 +151,6 @@ public GTplusplus() {
@EventHandler
public void preInit(final FMLPreInitializationEvent event) {
INIT_PHASE.PRE_INIT.setPhaseActive(true);
// Load all class objects within the plugin package.
CoreManager.veryEarlyInit();
PacketHandler.init();

// Give this a go mate.
Expand All @@ -162,7 +162,9 @@ public void preInit(final FMLPreInitializationEvent event) {
proxy.preInit(event);
Logger.INFO("Setting up our own GTProxy.");
MetaGTProxy.preInit();
CoreManager.preInit();
AgrichemFluids.preInit();
fixVanillaOreDict();
new VanillaBedHeightFix();
}

@EventHandler
Expand All @@ -171,7 +173,6 @@ public void init(final FMLInitializationEvent event) {
proxy.init(event);
proxy.registerNetworkStuff();
MetaGTProxy.init();
CoreManager.init();
// Used by foreign players to generate .lang files for translation.
if (Configuration.debug.dumpItemAndBlockData) {
LocaleUtils.generateFakeLocaleFile();
Expand All @@ -184,7 +185,6 @@ public void postInit(final FMLPostInitializationEvent event) {
proxy.postInit(event);
BookHandler.runLater();
MetaGTProxy.postInit();
CoreManager.postInit();

Logger.INFO("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Logger.INFO(
Expand Down Expand Up @@ -218,18 +218,9 @@ public synchronized void serverStarting(final FMLServerStartingEvent event) {
if (Thaumcraft.isModLoaded()) {
event.registerServerCommand(new CommandDumpAspects());
}
CoreManager.serverStart();
INIT_PHASE.STARTED.setPhaseActive(true);
}

@EventHandler
public synchronized void serverStopping(final FMLServerStoppingEvent event) {
CoreManager.serverStop();
}

@Override
public void actionPerformed(final ActionEvent arg0) {}

/**
* This {@link EventHandler} is called after the {@link FMLPostInitializationEvent} stages of all loaded mods
* executes successfully. {@link #onLoadComplete(FMLLoadCompleteEvent)} exists to inject recipe generation after
Expand Down Expand Up @@ -383,4 +374,39 @@ private static void remap(Block block, FMLMissingMappingsEvent.MissingMapping ma
mapping.remap(block);
Logger.INFO("Remapping block " + mapping.name + " to " + GTPlusPlus.ID + ":" + block.getUnlocalizedName());
}

private static void fixVanillaOreDict() {
registerToOreDict(ItemUtils.getSimpleStack(Items.blaze_rod), "rodBlaze");
registerToOreDict(ItemUtils.getSimpleStack(Items.nether_wart), "cropNetherWart");
registerToOreDict(ItemUtils.getSimpleStack(Items.reeds), "sugarcane");
registerToOreDict(ItemUtils.getSimpleStack(Items.paper), "paper");
registerToOreDict(ItemUtils.getSimpleStack(Items.ender_pearl), "enderpearl");
registerToOreDict(ItemUtils.getSimpleStack(Items.bone), "bone");
registerToOreDict(ItemUtils.getSimpleStack(Items.gunpowder), "gunpowder");
registerToOreDict(ItemUtils.getSimpleStack(Items.string), "string");
registerToOreDict(ItemUtils.getSimpleStack(Items.nether_star), "netherStar");
registerToOreDict(ItemUtils.getSimpleStack(Items.leather), "leather");
registerToOreDict(ItemUtils.getSimpleStack(Items.feather), "feather");
registerToOreDict(ItemUtils.getSimpleStack(Items.egg), "egg");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.grass), "grass");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.obsidian), "obsidian");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.crafting_table), "workbench");
}

private static void registerToOreDict(ItemStack aStack, String aString) {
if (aStack.getItem() == Items.blaze_rod) {
Logger
.INFO("Registering " + aStack.getDisplayName() + " to OreDictionary under the tag '" + aString + "'.");
} else {
Logger.INFO(
"Registering " + aStack.getDisplayName()
+ " to OreDictionary under the tag '"
+ aString
+ "'. (Added to Forge in 1.8.9)");
}
ItemUtils.addItemToOreDictionary(aStack, aString);
}
}
Loading

0 comments on commit 86f1765

Please sign in to comment.