diff options
author | Martin Robertz <dream-master@gmx.net> | 2020-04-24 21:24:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 21:24:39 +0200 |
commit | af7f38ca83f43e6093af0505f55f95bfb9b070f0 (patch) | |
tree | 3cca26d252baeebb061cdf4d986c7af9681b9e22 /src | |
parent | 4b97e5c6f598b3bf2674b7bec4ad295b27338126 (diff) | |
parent | 369f15dd6b12446a7c8a15320b8c59d2fb59e336 (diff) | |
download | GT5-Unofficial-af7f38ca83f43e6093af0505f55f95bfb9b070f0.tar.gz GT5-Unofficial-af7f38ca83f43e6093af0505f55f95bfb9b070f0.tar.bz2 GT5-Unofficial-af7f38ca83f43e6093af0505f55f95bfb9b070f0.zip |
Merge pull request #272 from GTNewHorizons/cls
Cls
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/GT_Mod.java | 36 | ||||
-rw-r--r-- | src/main/java/gregtech/api/enums/GT_Values.java | 1 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_CLS_Compat.java | 145 | ||||
-rw-r--r-- | src/main/java/gregtech/common/GT_Proxy.java | 85 |
4 files changed, 217 insertions, 50 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 22b677337e..de199ac057 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -60,6 +60,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.*; +import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -799,17 +800,19 @@ public class GT_Mod implements IGT_Mod { GT_FML_LOGGER.info("Replacing Vanilla Materials in recipes, please wait."); ProgressManager.ProgressBar progressBar = ProgressManager.push("Register materials", replaceVanillaItemsSet.size()); - for (Materials m : replaceVanillaItemsSet) { - progressBar.step(m.mDefaultLocalName); - //GT_FML_LOGGER.info("Replacing Vanilla Recipes for: " + m.mDefaultLocalName); - String platename = OrePrefixes.plate.get(m).toString(); - boolean noSmash = !m.contains(SubTag.NO_SMASHING); - if ((m.mTypes & 2) != 0) - GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getIngots(1)); - if ((m.mTypes & 4) != 0) - GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getGems(1)); - if (m.getBlocks(1) != null) - GT_RecipeRegistrator.registerUsagesForMaterials(null, noSmash, m.getBlocks(1)); + if (GT_Values.cls_enabled){ + try { + GT_CLS_Compat.doActualRegistrationCLS(progressBar,replaceVanillaItemsSet); + GT_CLS_Compat.pushToDisplayProgress(); + } catch (InvocationTargetException | IllegalAccessException e) { + GT_Mod.GT_FML_LOGGER.catching(e); + } + } + else { + replaceVanillaItemsSet.forEach(m -> { + progressBar.step(m.mDefaultLocalName); + doActualRegistration(m); + }); } ProgressManager.pop(progressBar); GT_FML_LOGGER.info("Congratulations, you have been waiting long enough (" + (System.currentTimeMillis() - ms) / 1000 + "s / " + (System.currentTimeMillis() - ms) + "ms). Have a Cake."); @@ -1058,6 +1061,17 @@ public class GT_Mod implements IGT_Mod { }; } + public static void doActualRegistration(Materials m){ + String platename = OrePrefixes.plate.get(m).toString(); + boolean noSmash = !m.contains(SubTag.NO_SMASHING); + if ((m.mTypes & 2) != 0) + GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getIngots(1)); + if ((m.mTypes & 4) != 0) + GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getGems(1)); + if (m.getBlocks(1) != null) + GT_RecipeRegistrator.registerUsagesForMaterials(null, noSmash, m.getBlocks(1)); + } + @Mod.EventHandler public void onServerStarted(FMLServerStartedEvent aEvent) { gregtechproxy.onServerStarted(); diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index a0576e6a15..66b2e8a08f 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -286,4 +286,5 @@ public class GT_Values { public static boolean alwaysReloadChunkloaders = false; public static boolean debugChunkloaders = false; + public static boolean cls_enabled; } diff --git a/src/main/java/gregtech/api/util/GT_CLS_Compat.java b/src/main/java/gregtech/api/util/GT_CLS_Compat.java new file mode 100644 index 0000000000..738b04a3b3 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CLS_Compat.java @@ -0,0 +1,145 @@ +package gregtech.api.util; + +import cpw.mods.fml.common.ProgressManager; +import gregtech.GT_Mod; +import gregtech.api.enums.Materials; +import gregtech.common.GT_Proxy; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Optional; +import java.util.Set; + +@SuppressWarnings("rawtypes, unchecked, deprecation") +public class GT_CLS_Compat { + + private static Class alexiilMinecraftDisplayer; + private static Class alexiilProgressDisplayer; + + private static Method getLastPercent; + private static Method displayProgress; + + private static Field isReplacingVanillaMaterials; + private static Field isRegisteringGTmaterials; + + static { + //CLS + try { + alexiilMinecraftDisplayer = Class.forName("alexiil.mods.load.MinecraftDisplayer"); + alexiilProgressDisplayer = Class.forName("alexiil.mods.load.ProgressDisplayer"); + } catch (ClassNotFoundException ex) { + GT_Mod.GT_FML_LOGGER.catching(ex); + } + + Optional.ofNullable(alexiilMinecraftDisplayer).ifPresent(e -> { + try { + getLastPercent = e.getMethod("getLastPercent"); + isReplacingVanillaMaterials = e.getField("isReplacingVanillaMaterials"); + isRegisteringGTmaterials = e.getField("isRegisteringGTmaterials"); + } catch (NoSuchMethodException | NoSuchFieldException ex) { + GT_Mod.GT_FML_LOGGER.catching(ex); + } + + }); + + Optional.ofNullable(alexiilProgressDisplayer).ifPresent(e -> { + try { + displayProgress = e.getMethod("displayProgress", String.class, float.class); + } catch (NoSuchMethodException ex) { + GT_Mod.GT_FML_LOGGER.catching(ex); + } + }); + } + + public static void stepMaterialsCLS(Collection<GT_Proxy.OreDictEventContainer> mEvents, ProgressManager.ProgressBar progressBar) throws IllegalAccessException, InvocationTargetException { + int sizeStep = GT_CLS_Compat.setStepSize(mEvents); + int size = 0; + for (GT_Proxy.OreDictEventContainer tEvent : mEvents) { + sizeStep--; + + String materialName = tEvent.mMaterial == null ? "" : tEvent.mMaterial.toString(); + + displayProgress.invoke(null, materialName, ((float) size) / 100); + + if (sizeStep == 0) { + if (size % 5 == 0) + GT_Mod.GT_FML_LOGGER.info("Baking: " + size + "%"); + sizeStep = mEvents.size() / 100 - 1; + size++; + } + + progressBar.step(materialName); + GT_Proxy.registerRecipes(tEvent); + } + ProgressManager.pop(progressBar); + isRegisteringGTmaterials.set(null, false); + } + + + public static int setStepSize(Collection mEvents) { + try { + isRegisteringGTmaterials.set(null, true); + } catch (IllegalArgumentException | IllegalAccessException e) { + GT_Mod.GT_FML_LOGGER.catching(e); + } + + return mEvents.size() / 100 - 1; + } + + private GT_CLS_Compat() { + } + + private static int[] setSizeSteps(Set<Materials> replaceVanillaItemsSet){ + int sizeStep; + int sizeStep2; + if (replaceVanillaItemsSet.size() >= 100) { + sizeStep = replaceVanillaItemsSet.size() / 100 - 1; + sizeStep2 = 1; + } else { + sizeStep = 100 / replaceVanillaItemsSet.size(); + sizeStep2 = sizeStep; + } + return new int[]{sizeStep, sizeStep2}; + } + + private static void displayMethodAdapter(int counter, String mDefaultLocalName, int size) throws InvocationTargetException, IllegalAccessException { + if (counter == 1) { + displayProgress.invoke(null, mDefaultLocalName, ((float) 95) / 100); + } else if (counter == 0) { + displayProgress.invoke(null, mDefaultLocalName, (float) 1); + } else { + displayProgress.invoke(null, mDefaultLocalName, ((float) size) / 100); + } + } + + public static void doActualRegistrationCLS(ProgressManager.ProgressBar progressBar, Set<Materials> replaceVanillaItemsSet) throws InvocationTargetException, IllegalAccessException { + int size = 0; + int counter = replaceVanillaItemsSet.size(); + try { + isReplacingVanillaMaterials.set(null, true); + } catch (IllegalArgumentException | IllegalAccessException e) { + GT_Mod.GT_FML_LOGGER.catching(e); + } + + int[] sizeSteps = setSizeSteps(replaceVanillaItemsSet); + + for (Materials m : replaceVanillaItemsSet) { + counter--; + sizeSteps[0]--; + + displayMethodAdapter(counter,m.mDefaultLocalName,size); + GT_Mod.doActualRegistration(m); + + size += sizeSteps[1]; + progressBar.step(m.mDefaultLocalName); + } + } + + public static void pushToDisplayProgress() throws InvocationTargetException, IllegalAccessException { + isReplacingVanillaMaterials.set(null, false); + displayProgress.invoke(null, "Post Initialization: loading GregTech", getLastPercent.invoke(null)); + } + +} diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 3b668d805d..d21491adea 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.genetics.AlleleManager; +import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.*; import gregtech.api.enums.TC_Aspects.TC_AspectStack; @@ -21,11 +22,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Item; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.net.GT_Packet_Pollution; -import gregtech.api.objects.GT_Fluid; -import gregtech.api.objects.GT_FluidStack; -import gregtech.api.objects.GT_UO_DimensionList; -import gregtech.api.objects.ItemData; -import gregtech.api.objects.GT_ChunkManager; +import gregtech.api.objects.*; import gregtech.api.util.*; import gregtech.common.entities.GT_Entity_Arrow; import gregtech.common.gui.GT_ContainerVolumetricFlask; @@ -81,10 +78,9 @@ import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; import org.apache.commons.lang3.text.WordUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.text.DateFormat; import java.util.*; @@ -244,22 +240,6 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { } catch (Throwable e) {e.printStackTrace(GT_Log.err);} } - private static final void registerRecipes(OreDictEventContainer aOre) { - if ((aOre.mEvent.Ore == null) || (aOre.mEvent.Ore.getItem() == null)) { - return; - } - if (aOre.mEvent.Ore.stackSize != 1) { - aOre.mEvent.Ore.stackSize = 1; - } - if (aOre.mPrefix != null) { - if (!aOre.mPrefix.isIgnored(aOre.mMaterial)) { - aOre.mPrefix.processOre(aOre.mMaterial == null ? Materials._NULL : aOre.mMaterial, aOre.mEvent.Name, aOre.mModID, - GT_Utility.copyAmount(1L, aOre.mEvent.Ore)); - } - } else { -// GT_FML_LOGGER.info("Thingy Name: "+ aOre.mEvent.Name+ " !!!Unknown 'Thingy' detected!!! This Object seems to probably not follow a valid OreDictionary Convention, or I missed a Convention. Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me."); - } - } public void onPreLoad() { GT_Log.out.println("GT_Mod: Preload-Phase started!"); @@ -1221,6 +1201,23 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { e.printStackTrace(GT_Log.err); } } + + public static void stepMaterialsVanilla(Collection<GT_Proxy.OreDictEventContainer> mEvents, ProgressManager.ProgressBar progressBar){ + int size = 5; + int sizeStep = mEvents.size() / 20 - 1; + GT_Proxy.OreDictEventContainer tEvent; + for (Iterator<GT_Proxy.OreDictEventContainer> i$ = mEvents.iterator(); i$.hasNext(); GT_Proxy.registerRecipes(tEvent)) { + tEvent = i$.next(); + sizeStep--; + if(sizeStep == 0) { + GT_Mod.GT_FML_LOGGER.info("Baking : " + size + "%", new Object[0]); + sizeStep = mEvents.size()/20-1; + size += 5; + } + progressBar.step(tEvent.mMaterial == null ? "" : tEvent.mMaterial.toString()); + } + ProgressManager.pop(progressBar); + } @SubscribeEvent public void onLivingUpdate(LivingUpdateEvent aEvent) { @@ -1317,6 +1314,22 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { } } + public static void registerRecipes(GT_Proxy.OreDictEventContainer aOre) { + if ((aOre.mEvent.Ore == null) || (aOre.mEvent.Ore.getItem() == null)) { + return; + } + if (aOre.mEvent.Ore.stackSize != 1) { + aOre.mEvent.Ore.stackSize = 1; + } + if (aOre.mPrefix != null) { + if (!aOre.mPrefix.isIgnored(aOre.mMaterial)) { + aOre.mPrefix.processOre(aOre.mMaterial == null ? Materials._NULL : aOre.mMaterial, aOre.mEvent.Name, aOre.mModID, GT_Utility.copyAmount(1L, aOre.mEvent.Ore)); + } + } else { +// GT_FML_LOGGER.info("Thingy Name: "+ aOre.mEvent.Name+ " !!!Unknown 'Thingy' detected!!! This Object seems to probably not follow a valid OreDictionary Convention, or I missed a Convention. Please report to GregTech Intergalactical for additional compatiblity. This is not an Error, an Issue nor a Lag Source, it is just an Information, which you should pass to me."); + } + } + @SubscribeEvent public void onPlayerTickEventServer(TickEvent.PlayerTickEvent aEvent) { if ((aEvent.side.isServer()) && (aEvent.phase == TickEvent.Phase.END) && (!aEvent.player.isDead)) { @@ -1926,26 +1939,20 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { GT_Recipe.reInit(); } + @SuppressWarnings("deprecation") public void activateOreDictHandler() { - final Logger GT_FML_LOGGER = LogManager.getLogger("GregTech GTNH"); - this.mOreDictActivated = true; ProgressManager.ProgressBar progressBar = ProgressManager.push("Register materials", mEvents.size()); - int sizeStep = mEvents.size()/20-1; - int size = 5; - OreDictEventContainer tEvent; - for (Iterator i$ = this.mEvents.iterator(); i$.hasNext(); registerRecipes(tEvent)) { - tEvent = (OreDictEventContainer) i$.next(); - sizeStep--; - progressBar.step(tEvent.mMaterial == null ? "" : tEvent.mMaterial.toString()); - if( sizeStep == 0 ) - { - GT_FML_LOGGER.info("Baking : " + size + "%", new Object[0]); - sizeStep = mEvents.size()/20-1; - size += 5; - } + if (Loader.isModLoaded("betterloadingscreen")){ + GT_Values.cls_enabled = true; + try { + GT_CLS_Compat.stepMaterialsCLS(mEvents, progressBar); + } catch (IllegalAccessException | InvocationTargetException e) { + GT_Mod.GT_FML_LOGGER.catching(e); + } } - ProgressManager.pop(progressBar); + else + GT_Proxy.stepMaterialsVanilla(this.mEvents,progressBar); } public static final HashMap<Integer,HashMap<ChunkCoordIntPair,int []>> dimensionWiseChunkData = new HashMap<>(16);//stores chunk data that is loaded/saved |