aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIColorOverride.java69
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainer.java2
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIScreen.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaTileEntity.java3
-rw-r--r--src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java6
-rw-r--r--src/main/java/gregtech/common/GT_Client.java16
-rw-r--r--src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java2
-rw-r--r--src/main/java/gregtech/nei/RecipeMapHandler.java2
9 files changed, 84 insertions, 20 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java
index f934102eb9..2d6268dbec 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java
@@ -1,28 +1,69 @@
package gregtech.api.gui;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.util.concurrent.UncheckedExecutionException;
+import cpw.mods.fml.relauncher.FMLLaunchHandler;
+import cpw.mods.fml.relauncher.Side;
import gregtech.api.GregTech_API;
import gregtech.api.util.ColorsMetadataSection;
-import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.Nonnull;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
public class GT_GUIColorOverride {
-
+ private static final Object NOT_FOUND = new Object();
+ private static final LoadingCache<ResourceLocation, Object> cache = CacheBuilder.newBuilder()
+ .softValues()
+ .build(new CacheLoader<ResourceLocation, Object>() {
+ @Override
+ public Object load(@Nonnull ResourceLocation key) throws Exception {
+ IResource ir = Minecraft.getMinecraft().getResourceManager().getResource(key);
+ if (ir.hasMetadata()) return ir.getMetadata("colors");
+ // return a dummy object because LoadingCache doesn't like null
+ return NOT_FOUND;
+ }
+ });
+ private static final GT_GUIColorOverride FALLBACK = new GT_GUIColorOverride();
private ColorsMetadataSection cmSection;
+ public static GT_GUIColorOverride get(String fullLocation) {
+ // see other get for more info
+ if (FMLLaunchHandler.side() != Side.CLIENT) return FALLBACK;
+ return new GT_GUIColorOverride(new ResourceLocation(fullLocation));
+ }
+
+ public static GT_GUIColorOverride get(ResourceLocation path) {
+ // use dummy fallback if there isn't such thing as a resource pack.
+ // #side() usually has two possible return value, but since this might be called by test code, it might
+ // also return null when in test env. Using #isClient will cause a NPE. A plain inequality test won't.
+ // FMLCommonHandler's #getSide() might trigger a NPE when in test env, so no.
+ if (FMLLaunchHandler.side() != Side.CLIENT) return FALLBACK;
+ return new GT_GUIColorOverride(path);
+ }
+
+ private GT_GUIColorOverride() {
+ cmSection = null;
+ }
+
+ /**
+ * @deprecated use {@link #get(String)} instead.
+ */
+ @Deprecated
public GT_GUIColorOverride(String guiTexturePath) {
+ this(new ResourceLocation(guiTexturePath));
+ }
+
+ private GT_GUIColorOverride(ResourceLocation resourceLocation) {
try {
- // this is dumb, but CombTypeTest causes cascading class load
- // and leads to instantiation of GT_CoverBehaviorBase
- if (Minecraft.getMinecraft() == null) return;
- IResource ir =
- Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(guiTexturePath));
- if (ir.hasMetadata()) {
- cmSection = (ColorsMetadataSection) ir.getMetadata("colors");
- }
- } catch (IOException | NoClassDefFoundError ignore) {
- // this is also dumb, but FMLCommonHandler#getEffectiveSide doesn't work during test
+ Object metadata = cache.get(resourceLocation);
+ if (metadata != NOT_FOUND) cmSection = (ColorsMetadataSection) metadata;
+ } catch (ExecutionException | UncheckedExecutionException ignore) {
+ // make sure it doesn't cache a failing entry
+ cache.invalidate(resourceLocation);
}
}
@@ -41,4 +82,8 @@ public class GT_GUIColorOverride {
public boolean sLoaded() {
return cmSection != null;
}
+
+ public static void onResourceManagerReload() {
+ cache.invalidateAll();
+ }
}
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer.java b/src/main/java/gregtech/api/gui/GT_GUIContainer.java
index 281f910d8c..efed327b46 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainer.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainer.java
@@ -27,7 +27,7 @@ public class GT_GUIContainer extends GuiContainer {
public GT_GUIContainer(Container aContainer, String aGUIbackground) {
super(aContainer);
mGUIbackground = new ResourceLocation(mGUIbackgroundPath = aGUIbackground);
- colorOverride = new GT_GUIColorOverride(aGUIbackground);
+ colorOverride = GT_GUIColorOverride.get(aGUIbackground);
}
protected int getTextColorOrDefault(String textType, int defaultColor) {
diff --git a/src/main/java/gregtech/api/gui/GT_GUIScreen.java b/src/main/java/gregtech/api/gui/GT_GUIScreen.java
index 470c1045a4..141f51e7c7 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIScreen.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIScreen.java
@@ -48,7 +48,7 @@ public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRende
this.header = header;
this.headerIcon = new GT_GuiFakeItemButton(this, 5, 5, null);
this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath);
- this.colorOverride = new GT_GUIColorOverride(guiTexturePath);
+ this.colorOverride = GT_GUIColorOverride.get(guiTexturePath);
this.textColor = getTextColorOrDefault("title", 0xFF222222);
}
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index b5efdc8112..8c6076a56e 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -118,7 +118,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity
oTextureData = 0,
oUpdateData = 0,
oTexturePage = 0;
- private byte oLightValueClient = -1,
+ private byte oLightValueClient = 0,
oLightValue = -1,
mLightValue = 0,
mOtherUpgrades = 0,
diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
index 586b52fd99..21a93307e5 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
@@ -138,8 +138,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac
mInventory = new ItemStack[aInvSlotCount];
mName = aName;
inventoryHandler = new ItemStackHandler(mInventory);
- colorOverride = new GT_GUIColorOverride(
- getGUITextureSet().getMainBackground().location.getResourcePath());
+ colorOverride = GT_GUIColorOverride.get(getGUITextureSet().getMainBackground().location);
}
/**
diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
index cfa9b593fa..8991289a78 100644
--- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
+++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
@@ -45,7 +45,11 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> {
protected GT_CoverBehaviorBase(Class<T> typeToken, ITexture coverTexture) {
this.typeToken = typeToken;
this.coverFGTexture = coverTexture;
- this.colorOverride = new GT_GUIColorOverride(guiTexturePath);
+ reloadColorOverride();
+ }
+
+ public void reloadColorOverride() {
+ this.colorOverride = GT_GUIColorOverride.get(guiTexturePath);
}
public abstract T createDataObject(int aLegacyData);
diff --git a/src/main/java/gregtech/common/GT_Client.java b/src/main/java/gregtech/common/GT_Client.java
index 04d02cbbcb..8a0a9e921b 100644
--- a/src/main/java/gregtech/common/GT_Client.java
+++ b/src/main/java/gregtech/common/GT_Client.java
@@ -21,6 +21,7 @@ import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import gregtech.api.GregTech_API;
import gregtech.api.enums.*;
+import gregtech.api.gui.GT_GUIColorOverride;
import gregtech.api.interfaces.IHasFluidDisplayItem;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -31,6 +32,7 @@ import gregtech.api.objects.GT_ItemStack;
import gregtech.api.util.ColorsMetadataSection;
import gregtech.api.util.ColorsMetadataSectionSerializer;
import gregtech.api.util.GT_ClientPreference;
+import gregtech.api.util.GT_CoverBehaviorBase;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_PlayedSound;
@@ -58,6 +60,9 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.resources.IReloadableResourceManager;
+import net.minecraft.client.resources.IResourceManager;
+import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
@@ -598,6 +603,17 @@ public class GT_Client extends GT_Proxy implements Runnable {
// CosmicItemRendererGT.registerItemWithMeta(Item.getItemFromBlock(GregTech_API.sBlockCasings5), 14);
CosmicItemRendererGT.init();
}
+
+ // reobf doesn't work with lambda, so this must be a class
+ //noinspection Convert2Lambda
+ ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager())
+ .registerReloadListener(new IResourceManagerReloadListener() {
+ @Override
+ public void onResourceManagerReload(IResourceManager l) {
+ GT_GUIColorOverride.onResourceManagerReload();
+ GregTech_API.sCoverBehaviors.values().forEach(GT_CoverBehaviorBase::reloadColorOverride);
+ }
+ });
}
@Override
diff --git a/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java b/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java
index c3da5cb1b4..c3161b3f5e 100644
--- a/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java
+++ b/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java
@@ -46,7 +46,7 @@ public class SelectItemUIFactory {
private final ItemStackHandler currentDisplayItemHandler = new ItemStackHandler();
private Supplier<ItemStack> currentGetter;
- private final GT_GUIColorOverride colorOverride = new GT_GUIColorOverride("SelectItemUIFactory");
+ private final GT_GUIColorOverride colorOverride = GT_GUIColorOverride.get("SelectItemUIFactory");
private int getTextColorOrDefault(String textType, int defaultColor) {
return colorOverride.getTextColorOrDefault(textType, defaultColor);
diff --git a/src/main/java/gregtech/nei/RecipeMapHandler.java b/src/main/java/gregtech/nei/RecipeMapHandler.java
index 075433e1af..5449484471 100644
--- a/src/main/java/gregtech/nei/RecipeMapHandler.java
+++ b/src/main/java/gregtech/nei/RecipeMapHandler.java
@@ -17,7 +17,7 @@ abstract class RecipeMapHandler extends TemplateRecipeHandler {
RecipeMapHandler(GT_Recipe.GT_Recipe_Map mRecipeMap) {
this.mRecipeMap = mRecipeMap;
- colorOverride = new GT_GUIColorOverride(mRecipeMap.mNEIGUIPath);
+ colorOverride = GT_GUIColorOverride.get(mRecipeMap.mNEIGUIPath);
}
GT_Recipe.GT_Recipe_Map getRecipeMap() {