fix crash with GTCEu 2.2 and higher

This commit is contained in:
PrototypeTrousers
2022-04-06 14:34:37 -03:00
parent a4f50ea9ef
commit a289dec832
3 changed files with 43 additions and 8 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
extended=extended_life
extendedversion=v51j
extendedversion=v51k
#########################################################
# Versions #
#########################################################
@@ -98,9 +98,6 @@ import net.minecraftforge.items.wrapper.RangedWrapper;
import javax.annotation.Nullable;
import java.util.*;
import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
{
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
@@ -1477,8 +1474,11 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
if( Loader.isModLoaded( "gregtech" ) && directedBlock instanceof BlockMachine )
{
MetaTileEntity metaTileEntity = getMetaTileEntity( hostWorld, targ );
return metaTileEntity.getMetaFullName();
MetaTileEntity metaTileEntity = Platform.getMetaTileEntity( directedTile.getWorld(), directedTile.getPos() );
if( metaTileEntity != null )
{
return metaTileEntity.getMetaFullName();
}
}
try
@@ -1506,7 +1506,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
if( what.getItem() != Items.AIR )
{
return what.getUnlocalizedName();
return what.getItem().getItemStackDisplayName( what );
}
final Item item = Item.getItemFromBlock( directedBlock );
+36 -1
View File
@@ -19,6 +19,8 @@
package appeng.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.InvalidParameterException;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -36,8 +38,10 @@ 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 ic2.api.item.IC2Items;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.util.GTUtility;
import ic2.api.item.ICustomDamageItem;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -67,6 +71,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
@@ -77,6 +82,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
@@ -158,6 +164,7 @@ public class Platform
private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper();
private static final P2PHelper P2P_HELPER = new P2PHelper();
private static Method reflectGTgetMTE;
public static ItemComparisonHelper itemComparisons()
{
@@ -1681,11 +1688,39 @@ public class Platform
return isPurified;
}
//consider methods below moving to a compability class
public static boolean isGTDamageableItem( Item item )
{
return ( isModLoaded( "gregtech" ) && item instanceof IToolItem );
}
public static MetaTileEntity getMetaTileEntity( IBlockAccess world, BlockPos pos )
{
if( reflectGTgetMTE == null )
{
try
{
reflectGTgetMTE = ReflectionHelper.findMethod( BlockMachine.class, "getMetaTileEntity", null, IBlockAccess.class, BlockPos.class );
}
catch( ReflectionHelper.UnableToFindMethodException e )
{
reflectGTgetMTE = ReflectionHelper.findMethod( GTUtility.class, "getMetaTileEntity", null, IBlockAccess.class, BlockPos.class );
}
}
else
{
try
{
return (MetaTileEntity) reflectGTgetMTE.invoke( reflectGTgetMTE, world, pos );
}
catch( IllegalAccessException | InvocationTargetException e )
{
e.printStackTrace();
}
}
return null;
}
public static boolean isIC2DamageableItem( Item item )
{
return ( isModLoaded( "IC2" ) && item instanceof ICustomDamageItem );