Skip to content

Commit

Permalink
Rename GT Classes; Correct show Meta Keys (#525)
Browse files Browse the repository at this point in the history
Co-authored-by: slprime <[email protected]>
  • Loading branch information
slprime and slprime authored Sep 7, 2024
1 parent 65652e5 commit d9143c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 37 deletions.
22 changes: 17 additions & 5 deletions src/main/java/codechicken/nei/NEIClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,26 @@ public class NEIClientUtils extends NEIServerUtils {

/** Formats a number with group separator and at most 2 fraction digits. */
private static final Map<Locale, DecimalFormat> decimalFormatters = new HashMap<>();
private static final Map<Integer, Integer> keyHashMap = new HashMap<>();

public static final int ALT_HASH = 1 << 27;
public static final int SHIFT_HASH = 1 << 26;
public static final int CTRL_HASH = 1 << 25;

static {
keyHashMap.put(Keyboard.KEY_LSHIFT, SHIFT_HASH);
keyHashMap.put(Keyboard.KEY_RSHIFT, SHIFT_HASH);

keyHashMap.put(Keyboard.KEY_LCONTROL, CTRL_HASH);
keyHashMap.put(Keyboard.KEY_LCONTROL, CTRL_HASH);

keyHashMap.put(Keyboard.KEY_LMETA, CTRL_HASH);
keyHashMap.put(Keyboard.KEY_RMETA, CTRL_HASH);

keyHashMap.put(Keyboard.KEY_LMENU, ALT_HASH);
keyHashMap.put(Keyboard.KEY_LMENU, ALT_HASH);
}

public static Minecraft mc() {
return Minecraft.getMinecraft();
}
Expand Down Expand Up @@ -439,11 +454,7 @@ public static int getKeyHash() {
if (Keyboard.getEventKeyState()) {
final int keycode = Keyboard.getEventKey();

if (keycode != Keyboard.KEY_LSHIFT && keycode != Keyboard.KEY_RSHIFT
&& keycode != Keyboard.KEY_LCONTROL
&& keycode != Keyboard.KEY_RCONTROL
&& keycode != Keyboard.KEY_LMENU
&& keycode != Keyboard.KEY_RMENU) {
if (!keyHashMap.containsKey(keycode)) {
return getMetaHash() + keycode;
}
}
Expand All @@ -470,6 +481,7 @@ public static String getKeyHashName(int keyBind) {
}

public static String getKeyName(int keyBind) {
keyBind = keyHashMap.getOrDefault(keyBind, keyBind);
StringJoiner keyText = new StringJoiner(" + ");
String hashText = getKeyHashName(keyBind);
int keyID = unHashKey(keyBind);
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/codechicken/nei/WorldOverlayRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import codechicken.lib.math.MathHelper;
import codechicken.nei.KeyManager.IKeyStateTracker;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class WorldOverlayRenderer implements IKeyStateTracker {

Expand All @@ -26,12 +27,11 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
private static byte[] mobSpawnCache;
private static long mobOverlayUpdateTime;
private static String oregenPatternName;
private static boolean hasOregenPatternBeenSet = false;

public static void reset() {
mobOverlay = 0;
chunkOverlay = 0;
hasOregenPatternBeenSet = false;
oregenPatternName = null;
}

@Override
Expand Down Expand Up @@ -288,18 +288,9 @@ private static void renderChunkBounds(Entity entity, int intOffsetX, int intOffs
GL11.glVertex3d(x2, y2, z1 + h);
}
} else if (chunkOverlay == 3) {
if (!hasOregenPatternBeenSet) {
try {
oregenPatternName = ((Enum<?>) Class.forName("gregtech.common.GT_Worldgenerator")
.getDeclaredField("oregenPattern").get(null)).name();
} catch (Exception ignored) {
oregenPatternName = "AXISSYMMETRICAL";
}
hasOregenPatternBeenSet = true;
}
int gx1;
int gz1;
if (oregenPatternName.equals("EQUAL_SPACING")) {
if (getOregenPatternName().equals("EQUAL_SPACING")) {
// gt oregen uses new regular pattern
gx1 = ((Math.floorDiv(entity.chunkCoordX, 3) * 3) << 4) - intOffsetX;
gz1 = ((Math.floorDiv(entity.chunkCoordZ, 3) * 3) << 4) - intOffsetZ;
Expand Down Expand Up @@ -368,6 +359,22 @@ private static void renderChunkBounds(Entity entity, int intOffsetX, int intOffs
GL11.glDisable(GL11.GL_BLEND);
}

private static String getOregenPatternName() {

if (oregenPatternName == null) {
try {
final ClassLoader loader = WorldOverlayRenderer.class.getClassLoader();
final Class<?> gtWorldGenerator = ReflectionHelper
.getClass(loader, "gregtech.common.GTWorldgenerator", "gregtech.common.GT_Worldgenerator");
oregenPatternName = ((Enum<?>) gtWorldGenerator.getDeclaredField("oregenPattern").get(null)).name();
} catch (Exception ignored) {
oregenPatternName = "AXISSYMMETRICAL";
}
}

return oregenPatternName;
}

public static void load() {
KeyManager.trackers.add(new WorldOverlayRenderer());
}
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/codechicken/nei/recipe/DefaultOverlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
import codechicken.nei.FastTransferManager;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class DefaultOverlayHandler implements IOverlayHandler {

public static Class<?> gtItem;
private static Class<?> gtItem;

static {
try {
gtItem = Class.forName("gregtech.api.items.GT_MetaBase_Item");
} catch (ClassNotFoundException ignored) {
gtItem = null;
final ClassLoader loader = DefaultOverlayHandler.class.getClassLoader();
gtItem = ReflectionHelper
.getClass(loader, "gregtech.api.items.MetaBaseItem", "gregtech.api.items.GT_MetaBase_Item");
} catch (Exception ignored) {
/* Do nothing */
}
}

Expand Down Expand Up @@ -85,13 +88,16 @@ public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeInd
}

private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
for (PositionedStack pstack : ingreds) for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
if (!slot.getHasStack()) continue;
for (PositionedStack pstack : ingreds) {
for (Slot slot : gui.inventorySlots.inventorySlots) {
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
if (!slot.getHasStack()) continue;

FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
if (slot.getHasStack()) return false;
FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
if (slot.getHasStack()) return false;
}
}
}

return true;
}
Expand All @@ -109,7 +115,7 @@ private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assi
int slotTransferred = 0;
int slotTransferCap = pstack.getMaxStackSize();

for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
for (Slot slot : gui.inventorySlots.inventorySlots) {
if (!slot.getHasStack() || !canMoveFrom(slot, gui)) continue;

ItemStack stack = slot.getStack();
Expand Down Expand Up @@ -178,7 +184,7 @@ private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingre
assignedSlots.add(new LinkedList<>());
}

while (avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
while (!avaliableSlots.isEmpty() && !remainingIngreds.isEmpty()) {
for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext();) {
int i = iterator.next();
boolean assigned = false;
Expand All @@ -196,8 +202,9 @@ private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingre
}
}

if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount)
if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount) {
iterator.remove();
}
}
}

Expand Down Expand Up @@ -243,7 +250,7 @@ private List<IngredientDistribution> assignIngredients(List<PositionedStack> ing
}

private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) /* work out how much we have to go round */ {
for (Slot slot : gui.inventorySlots.inventorySlots) /* work out how much we have to go round */ {
if (slot.getHasStack() && canMoveFrom(slot, gui)) {
ItemStack pstack = slot.getStack();
DistributedIngred istack = findIngred(ingredStacks, pstack);
Expand Down Expand Up @@ -273,7 +280,7 @@ public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredien
for (int i = 0; i < ingredients.size(); i++) /* identify slots */ {
LinkedList<Slot> recipeSlots = new LinkedList<>();
PositionedStack pstack = ingredients.get(i);
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
for (Slot slot : gui.inventorySlots.inventorySlots) {
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
recipeSlots.add(slot);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@

import codechicken.nei.api.IStackStringifyHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.ReflectionHelper;

public class GTFluidStackStringifyHandler implements IStackStringifyHandler {

protected static Class<?> GTDisplayFluid = null;
protected static Class<?> itemFluidDisplay = null;
protected static Method getFluidDisplayStack = null;
protected static Method getFluidFromDisplayStack = null;
public static boolean replaceAE2FCFluidDrop = false;

static {
try {
final Class<?> gtUtility = Class.forName("gregtech.api.util.GT_Utility");

GTDisplayFluid = Class.forName("gregtech.common.items.GT_FluidDisplayItem");
final ClassLoader loader = GTFluidStackStringifyHandler.class.getClassLoader();
final Class<?> gtUtility = ReflectionHelper
.getClass(loader, "gregtech.api.util.GTUtility", "gregtech.api.util.GT_Utility");

itemFluidDisplay = ReflectionHelper.getClass(
loader,
"gregtech.common.items.ItemFluidDisplay",
"gregtech.common.items.GT_FluidDisplayItem");
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class);

} catch (Exception ignored) {
/* Do nothing */
}
Expand Down Expand Up @@ -72,7 +77,7 @@ public FluidStack getFluid(ItemStack stack) {
final Item item = stack.getItem();

try {
if (getFluidFromDisplayStack != null && GTDisplayFluid != null && GTDisplayFluid.isInstance(item)) {
if (getFluidFromDisplayStack != null && itemFluidDisplay != null && itemFluidDisplay.isInstance(item)) {
final Object obj = getFluidFromDisplayStack.invoke(null, stack);

if (obj != null) {
Expand Down

0 comments on commit d9143c5

Please sign in to comment.