initial patch
This commit is contained in:
@@ -41,7 +41,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
|
||||
public class CraftingTreeNode {
|
||||
|
||||
// what slot!
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ToolClass {
|
||||
private static Class<?> GTToolClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
GTToolClass = Class.forName("gregtech.api.items.IToolItem", false, Launch.classLoader);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
try {
|
||||
GTToolClass = Class.forName("gregtech.api.items.toolitem.IGTTool", false, Launch.classLoader);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Enum<Interfaces> GTToolInterface = getGTToolInterface();
|
||||
private static final Method getMaxItemDamage = ReflectionHelper.findMethod(GTToolClass, "getMaxItemDamage", null, ItemStack.class);
|
||||
private static final Method getItemDamage = ReflectionHelper.findMethod(GTToolClass, "getItemDamage", null, ItemStack.class);
|
||||
|
||||
public static Class<?> getGTToolClass() {
|
||||
return GTToolClass;
|
||||
}
|
||||
|
||||
public static Enum<Interfaces> getGTToolInterface() {
|
||||
if (GTToolClass.getName().equals("IToolItem")) {
|
||||
return Interfaces.ITOOLITEM;
|
||||
} else {
|
||||
return Interfaces.IGTTOOL;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getGTMaxDamage(ItemStack itemStack) {
|
||||
if (GTToolInterface == Interfaces.ITOOLITEM) {
|
||||
try {
|
||||
return (int) getMaxItemDamage.invoke(itemStack.getItem(), itemStack);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return itemStack.getMaxDamage();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getGTitemDamage(ItemStack itemStack) {
|
||||
if (GTToolInterface == Interfaces.ITOOLITEM) {
|
||||
try {
|
||||
return (int) getItemDamage.invoke(itemStack.getItem(), itemStack);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
return itemStack.getMaxDamage();
|
||||
}
|
||||
}
|
||||
|
||||
enum Interfaces {
|
||||
ITOOLITEM,
|
||||
IGTTOOL
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.integration.Integrations;
|
||||
import appeng.integration.modules.bogosorter.InventoryBogoSortModule;
|
||||
import appeng.integration.modules.gregtech.ToolClass;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.GridNode;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
@@ -67,7 +68,6 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import gregtech.api.block.machines.BlockMachine;
|
||||
import gregtech.api.items.IToolItem;
|
||||
import gregtech.api.metatileentity.MetaTileEntity;
|
||||
import gregtech.api.util.GTUtility;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
@@ -126,7 +126,6 @@ import java.util.*;
|
||||
* @version rv2
|
||||
* @since rv0
|
||||
*/
|
||||
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
|
||||
@Optional.Interface(iface = "ic2.api.item.ICustomDamageItem", modid = "IC2")
|
||||
public class Platform {
|
||||
|
||||
@@ -1417,7 +1416,7 @@ public class Platform {
|
||||
|
||||
//consider methods below moving to a compability class
|
||||
public static boolean isGTDamageableItem(Item item) {
|
||||
return ((GTLoaded) && item instanceof IToolItem);
|
||||
return ((GTLoaded) && item.getClass().isInstance(ToolClass.getGTToolClass()));
|
||||
}
|
||||
|
||||
public static MetaTileEntity getMetaTileEntity(IBlockAccess world, BlockPos pos) {
|
||||
|
||||
@@ -23,9 +23,9 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.Api;
|
||||
import appeng.integration.modules.gregtech.ToolClass;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.primitives.Ints;
|
||||
import gregtech.api.items.IToolItem;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -326,7 +326,7 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
|
||||
} else if (a.getItem().isDamageable()) {
|
||||
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
|
||||
} else if (Platform.isGTDamageableItem(a.getItem())) {
|
||||
return ((IToolItem) a.getItem()).getItemDamage(a) > 1 == ((IToolItem) b.getItem()).getItemDamage(b) > 1;
|
||||
return (ToolClass.getGTitemDamage(a) > 1 == ToolClass.getGTitemDamage(b) > 1);
|
||||
}
|
||||
} else {
|
||||
float percentDamageOfA = 0;
|
||||
@@ -338,8 +338,8 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
|
||||
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
|
||||
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
|
||||
} else if (Platform.isGTDamageableItem(a.getItem())) {
|
||||
percentDamageOfA = (float) ((IToolItem) a.getItem()).getItemDamage(a) / ((IToolItem) a.getItem()).getMaxItemDamage(a);
|
||||
percentDamageOfB = (float) ((IToolItem) b.getItem()).getItemDamage(b) / ((IToolItem) b.getItem()).getMaxItemDamage(b);
|
||||
percentDamageOfA = (float) ToolClass.getGTitemDamage(a) / ToolClass.getGTMaxDamage(a);
|
||||
percentDamageOfB = (float) ToolClass.getGTitemDamage(b) / ToolClass.getGTMaxDamage(b);
|
||||
}
|
||||
|
||||
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
|
||||
|
||||
@@ -20,9 +20,9 @@ package appeng.util.item;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.integration.modules.gregtech.ToolClass;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Preconditions;
|
||||
import gregtech.api.items.IToolItem;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
||||
@@ -154,8 +154,8 @@ class FuzzyItemVariantList extends ItemVariantList {
|
||||
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
|
||||
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
|
||||
} else if (Platform.isGTDamageableItem(stack.getItem())) {
|
||||
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
|
||||
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
|
||||
maxDamage = ToolClass.getGTMaxDamage(stack);
|
||||
damage = ToolClass.getGTitemDamage(stack);
|
||||
} else {
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
@@ -189,8 +189,8 @@ class FuzzyItemVariantList extends ItemVariantList {
|
||||
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
|
||||
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
|
||||
} else if (Platform.isGTDamageableItem(stack.getItem())) {
|
||||
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
|
||||
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
|
||||
maxDamage = ToolClass.getGTMaxDamage(stack);
|
||||
damage = ToolClass.getGTitemDamage(stack);
|
||||
} else {
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
|
||||
Reference in New Issue
Block a user