Skip to content

Commit

Permalink
Bump GT and update API to new naming (#92)
Browse files Browse the repository at this point in the history
* bump gt and fix api usage

* use reflection to preserve compat

* remove unneeded import

* spotless

* Update src/main/java/com/kuba6000/mobsinfo/nei/MobHandler.java

Co-authored-by: Jakub <53441451+kuba6000@users.noreply.github.com>

---------

Co-authored-by: Jakub <53441451+kuba6000@users.noreply.github.com>
  • Loading branch information
NotAPenguin0 and kuba6000 authored Sep 3, 2024
1 parent 6f958fa commit 34e63f7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:Electro-Magic-Tools:1.5.5:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:WitchingGadgets:1.5.8-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTplusplus:1.12.11:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.64:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.49.56:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Hardcore-Ender-Expansion:1.10.1-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.7:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicBases:1.7.4:dev") { transitive = false }
Expand Down
65 changes: 48 additions & 17 deletions src/main/java/com/kuba6000/mobsinfo/nei/MobHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import java.awt.Point;
import java.awt.Rectangle;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -97,7 +99,6 @@
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.objects.ItemData;
import gregtech.api.util.GT_OreDictUnificator;

public class MobHandler extends TemplateRecipeHandler implements IScrollableGUI {

Expand Down Expand Up @@ -870,26 +871,56 @@ public List<PositionedStack> getOtherStacks() {

private static class GT5Helper {

public static List<ItemStack> getAssociated(ItemStack aResult) {
ItemData tPrefixMaterial = GT_OreDictUnificator.getAssociation(aResult);

ArrayList<ItemStack> tResults = new ArrayList<>();
tResults.add(aResult);
tResults.add(GT_OreDictUnificator.get(true, aResult));
if ((tPrefixMaterial != null) && (!tPrefixMaterial.mBlackListed)
&& (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) {
for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) {
tResults.add(GT_OreDictUnificator.get(tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L));
private static Class<?> oreDictUnificator = null;

private static Class<?> getUnificator() {
if (oreDictUnificator != null) return oreDictUnificator;
try {
// Try new API first
oreDictUnificator = Class.forName("gregtech.api.util.GTOreDictUnificator");
} catch (ClassNotFoundException ignored) {
try {
// Compat with old GT versions: use old name
oreDictUnificator = Class.forName("gregtech.api.GT_OreDictUnificator");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
if (aResult.getUnlocalizedName()
.startsWith("gt.blockores")) {
for (int i = 0; i < 8; i++) {
tResults.add(new ItemStack(aResult.getItem(), 1, aResult.getItemDamage() % 1000 + i * 1000));
return oreDictUnificator;
}

public static List<ItemStack> getAssociated(ItemStack aResult) {
try {
// Use reflection to lookup oredict unificator methods to keep compatibility with non-GTNH GT5
Class<?> unificator = getUnificator();
Method getAssociation = unificator.getMethod("getAssociation", ItemStack.class);
Method get = unificator.getMethod("get", boolean.class, ItemStack.class);
Method getWithMaterial = unificator.getMethod("get", OrePrefixes.class, Object.class, long.class);

ItemData tPrefixMaterial = (ItemData) getAssociation.invoke(null, aResult);

ArrayList<ItemStack> tResults = new ArrayList<>();
tResults.add(aResult);
tResults.add((ItemStack) get.invoke(null, true, aResult));
if ((tPrefixMaterial != null) && (!tPrefixMaterial.mBlackListed)
&& (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) {
for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) {
tResults.add(
(ItemStack) getWithMaterial.invoke(null, tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L));
}
}
if (aResult.getUnlocalizedName()
.startsWith("gt.blockores")) {
for (int i = 0; i < 8; i++) {
tResults.add(new ItemStack(aResult.getItem(), 1, aResult.getItemDamage() % 1000 + i * 1000));
}
}
}

return tResults;
return tResults;
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
}
}

0 comments on commit 34e63f7

Please sign in to comment.