move gtce blocking code out of generic item adaptor
fixes crash with ae2 fluid crafting
This commit is contained in:
@@ -29,6 +29,8 @@ import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.integration.modules.gregtech.GTCEInventoryAdaptor;
|
||||
import appeng.util.*;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -46,7 +48,6 @@ import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
||||
@@ -102,10 +103,6 @@ import appeng.parts.automation.StackUpgradeInventory;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
@@ -146,6 +143,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
private IMEInventory<IAEItemStack> destination;
|
||||
private int isWorking = -1;
|
||||
private final Accessor accessor = new Accessor();
|
||||
private GTCEInventoryAdaptor GTad;
|
||||
|
||||
public DualityInterface( final AENetworkProxy networkProxy, final IInterfaceHost ih )
|
||||
{
|
||||
@@ -910,12 +908,16 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
|
||||
private static boolean invIsBlocked(InventoryAdaptor inv) {
|
||||
if (AEConfig.instance().isFeatureEnabled(AEFeature.INSANE_BLOCKING_MODE)) {
|
||||
if (Loader.isModLoaded("gregtech")) return !inv.canRemoveAllExceptCircuits();
|
||||
else return !inv.simulateRemove( 1, ItemStack.EMPTY, null ).isEmpty();
|
||||
if (AEConfig.instance().isFeatureEnabled(AEFeature.INSANE_BLOCKING_MODE))
|
||||
{
|
||||
return !inv.simulateRemove( 1, ItemStack.EMPTY, null ).isEmpty();
|
||||
}
|
||||
else
|
||||
return inv.containsItems();
|
||||
else return inv.containsItems();
|
||||
}
|
||||
|
||||
private static boolean invIsBlockedGTCE(GTCEInventoryAdaptor inv)
|
||||
{
|
||||
return (!inv.canRemoveAllExceptCircuits());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -962,13 +964,24 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( ad != null )
|
||||
if( ad != null )
|
||||
{
|
||||
if( this.isBlocking() )
|
||||
{
|
||||
if( invIsBlocked(ad) )
|
||||
if (te.getBlockType().getRegistryName().getResourceDomain().equals("gregtech"))
|
||||
{
|
||||
continue;
|
||||
GTad = GTCEInventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if (invIsBlockedGTCE(GTad))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (invIsBlocked(ad))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,17 +1030,28 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( ad != null )
|
||||
{
|
||||
if( !invIsBlocked(ad) )
|
||||
if (te.getBlockType().getRegistryName().getResourceDomain().equals("gregtech"))
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
GTad = GTCEInventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if ( !invIsBlockedGTCE(GTad) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !invIsBlocked(ad) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
busy = allAreBusy;
|
||||
}
|
||||
|
||||
return busy;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public abstract class GTCEInventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
public static GTCEInventoryAdaptor getAdaptor(final TileEntity te, final EnumFacing d)
|
||||
{
|
||||
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d))
|
||||
{
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
if (itemHandler != null)
|
||||
{
|
||||
return new GTCEItemHandler(itemHandler);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean canRemoveAllExceptCircuits();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GTCEItemHandler extends GTCEInventoryAdaptor {
|
||||
|
||||
final static ItemStack integratedCircuit = new ItemStack((Item.getByNameOrId("gregtech:meta_item_1")), 1, 32766); // Gregtech Community Edition Integrated Circuit
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
|
||||
public GTCEItemHandler( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if ( is.isEmpty() || is.isItemEqual(integratedCircuit)) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -69,8 +69,6 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
|
||||
public abstract ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination );
|
||||
|
||||
public abstract boolean canRemoveAllExceptCircuits();
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
||||
|
||||
@@ -84,4 +82,5 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
public abstract boolean containsItems();
|
||||
|
||||
public abstract boolean hasSlots();
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -32,7 +31,6 @@ import appeng.util.Platform;
|
||||
|
||||
public class AdaptorItemHandler extends InventoryAdaptor
|
||||
{
|
||||
final static ItemStack integratedCircuit = new ItemStack((Item.getByNameOrId("gregtech:meta_item_1")),1,32766); // Gregtech Community Edition Integrated Circuit
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
public AdaptorItemHandler( IItemHandler itemHandler )
|
||||
@@ -267,17 +265,4 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if ( is.isEmpty() || is.isItemEqual(integratedCircuit)) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -226,9 +226,4 @@ public class AdaptorList extends InventoryAdaptor
|
||||
return new StackToSlotIterator( this.i.iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -204,9 +204,4 @@ public class IMEAdaptor extends InventoryAdaptor
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user