Skip to content

Commit

Permalink
delete the gt++ "plugin" manager that uses reflection to load all cla…
Browse files Browse the repository at this point in the history
…sses in a package to end up registering 2 classes
  • Loading branch information
Alexdoru committed Sep 25, 2024
1 parent c4725b7 commit 9239f2a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 272 deletions.
50 changes: 44 additions & 6 deletions src/main/java/gtPlusPlus/GTplusplus.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
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 Down Expand Up @@ -41,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 @@ -146,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 @@ -159,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 @@ -168,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 @@ -181,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 @@ -371,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);
}
}
30 changes: 0 additions & 30 deletions src/main/java/gtPlusPlus/api/interfaces/IPlugin.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package gtPlusPlus.core.util.reflect;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

import com.google.common.reflect.ClassPath;
import com.gtnewhorizon.gtnhlib.reflect.Fields;

import gtPlusPlus.api.objects.Logger;
Expand Down Expand Up @@ -107,30 +105,6 @@ public static void makeFieldAccessible(final Field field) {
}
}

/**
*
* @param aPackageName - The full {@link Package} name in {@link String} form.
* @return - {@link Boolean} object. True if loaded > 0 classes.
*/
public static boolean dynamicallyLoadClassesInPackage(String aPackageName) {
ClassLoader classLoader = ReflectionUtils.class.getClassLoader();
int loaded = 0;
try {
ClassPath path = ClassPath.from(classLoader);
for (ClassPath.ClassInfo info : path.getTopLevelClassesRecursive(aPackageName)) {
Class<?> clazz = Class.forName(info.getName(), true, classLoader);
if (clazz != null) {
loaded++;
Logger.INFO("Found " + clazz.getCanonicalName() + ". [" + loaded + "]");
}
}
} catch (ClassNotFoundException | IOException e) {

}

return loaded > 0;
}

public static boolean setField(final Object object, final Field field, final Object fieldValue) {
if (field == null) return false;
Class<?> clazz;
Expand Down
46 changes: 0 additions & 46 deletions src/main/java/gtPlusPlus/plugin/agrichem/AgrichemCore.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AgrichemFluids {
public static Fluid mAcetone;
public static Fluid mButanol;

public static void init() {
public static void preInit() {
if (!FluidRegistry.isFluidRegistered("aceticacid")) {
mAceticAcid = FluidUtils
.generateFluidNoPrefix("aceticacid", "Acetic Acid", 200, new short[] { 97, 168, 96, 100 }, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gregtech.asm.GTCorePlugin;
import gtPlusPlus.api.interfaces.IPlugin;
import gtPlusPlus.api.objects.Logger;

// TODO move this as a mixin in hodgepodge
public class VanillaBedHeightFix {

private final Method mSleepInBedAt;

public VanillaBedHeightFix(IPlugin minstance) {
public VanillaBedHeightFix() {
Method m = null;
try {
m = EntityPlayer.class.getDeclaredMethod(
Expand All @@ -29,7 +28,7 @@ public VanillaBedHeightFix(IPlugin minstance) {
} catch (NoSuchMethodException ignored) {}
if (m != null) {
mSleepInBedAt = m;
minstance.log("Registering Bed Height Fix.");
Logger.INFO("Registering Bed Height Fix.");
MinecraftForge.EVENT_BUS.register(this);
} else {
mSleepInBedAt = null;
Expand Down

This file was deleted.

Loading

0 comments on commit 9239f2a

Please sign in to comment.