Fixes #743 crash with plugs, fixes #942 builder integration, closes #319 BC 6 prep

This commit is contained in:
thatsIch
2014-12-21 19:08:05 +01:00
parent cdf949a557
commit e300bf93fd
31 changed files with 261 additions and 1692 deletions
@@ -27,14 +27,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.inventory.ISpecialInventory;
import appeng.api.config.FuzzyMode;
import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IBetterStorage;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorISpecialInventory;
import appeng.util.inv.AdaptorList;
import appeng.util.inv.AdaptorPlayerInventory;
import appeng.util.inv.IInventoryDestination;
@@ -45,19 +42,19 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
{
// return what was extracted.
public abstract ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination);
public abstract ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination);
public abstract ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination destination);
public abstract ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination);
// return what was extracted.
public abstract ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
public abstract ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
public abstract ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
// return what isn't used...
public abstract ItemStack addItems(ItemStack A);
public abstract ItemStack addItems(ItemStack toBeAdded);
public abstract ItemStack simulateAdd(ItemStack A);
public abstract ItemStack simulateAdd(ItemStack toBeSimulated);
public abstract boolean containsItems();
@@ -75,7 +72,10 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
}
else if ( te instanceof ArrayList )
{
return new AdaptorList( (ArrayList<ItemStack>) te );
@SuppressWarnings( "unchecked" )
final ArrayList<ItemStack> list = ( ArrayList<ItemStack> ) te;
return new AdaptorList( list );
}
else if ( bs != null && bs.isStorageCrate( te ) )
{
@@ -85,10 +85,6 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
{
return new AdaptorIInventory( Platform.GetChestInv( te ) );
}
else if ( isSpecialInventory( te ) )
{
return new AdaptorISpecialInventory( (ISpecialInventory) te, d );
}
else if ( te instanceof ISidedInventory )
{
ISidedInventory si =(ISidedInventory)te;
@@ -105,22 +101,4 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
return null;
}
private static boolean canBeSpecial = true;
private static boolean isSpecialInventory(Object a)
{
if ( canBeSpecial )
{
try
{
return a instanceof ISpecialInventory;
}
catch (Throwable e)
{
canBeSpecial = false;
}
}
return false;
}
}
@@ -60,43 +60,43 @@ public class AdaptorBCPipe extends InventoryAdaptor
}
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
return null;
}
@Override
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
{
return null;
}
@Override
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
{
return null;
}
@Override
public ItemStack addItems(ItemStack A)
public ItemStack addItems(ItemStack toBeAdded )
{
if ( this.i == null )
return A;
if ( A == null )
return toBeAdded;
if ( toBeAdded == null )
return null;
if ( A.stackSize == 0 )
if ( toBeAdded.stackSize == 0 )
return null;
if ( this.bc.addItemsToPipe( this.i, A, this.d ) )
if ( this.bc.addItemsToPipe( this.i, toBeAdded, this.d ) )
return null;
return A;
return toBeAdded;
}
@Override
public ItemStack simulateAdd(ItemStack A)
public ItemStack simulateAdd(ItemStack toBeSimulated )
{
if ( this.i == null )
return A;
return toBeSimulated;
return null;
}
@@ -224,15 +224,15 @@ public class AdaptorIInventory extends InventoryAdaptor
}
@Override
public ItemStack addItems( ItemStack itemsToAdd )
public ItemStack addItems( ItemStack toBeAdded )
{
return this.addItems( itemsToAdd, true );
return this.addItems( toBeAdded, true );
}
@Override
public ItemStack simulateAdd( ItemStack itemsToAdd )
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
return this.addItems( itemsToAdd, false );
return this.addItems( toBeSimulated, false );
}
/**
@@ -1,136 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.inv;
import java.util.Iterator;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.inventory.ISpecialInventory;
import appeng.api.config.FuzzyMode;
import appeng.util.InventoryAdaptor;
public class AdaptorISpecialInventory extends InventoryAdaptor
{
private final AdaptorIInventory remover;
private final ISpecialInventory i;
private final ForgeDirection d;
public AdaptorISpecialInventory(ISpecialInventory s, ForgeDirection dd) {
this.i = s;
this.d = dd;
if ( s instanceof ISidedInventory )
this.remover = new AdaptorIInventory( new WrapperMCISidedInventory( (ISidedInventory) s, this.d ) );
else
this.remover = new AdaptorIInventory( s );
}
@Override
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
return this.remover.removeSimilarItems( how_many, filter, fuzzyMode, destination );
}
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
return this.remover.simulateSimilarRemove( how_many, filter, fuzzyMode, destination );
}
@Override
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
{
return this.remover.removeItems( how_many, filter, destination );
}
@Override
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
{
return this.remover.simulateRemove( how_many, filter, destination );
}
@Override
public ItemStack addItems(ItemStack A)
{
if ( A == null )
return null;
if ( A.stackSize == 0 )
return null;
int used = this.i.addItem( A, true, this.d );
ItemStack out = A.copy();
out.stackSize -= used;
if ( out.stackSize > 0 )
return out;
return null;
}
@Override
public ItemStack simulateAdd(ItemStack A)
{
int used = this.i.addItem( A, false, this.d );
ItemStack out = A.copy();
out.stackSize -= used;
if ( out.stackSize > 0 )
return out;
return null;
}
@Override
public boolean containsItems()
{
if ( this.i instanceof ISidedInventory )
{
ISidedInventory sided = (ISidedInventory) this.i;
int[] slots = sided.getAccessibleSlotsFromSide( this.d.ordinal() );
if ( slots == null )
return false;
for (int slot : slots)
{
if ( this.i.getStackInSlot( slot ) != null )
{
return true;
}
}
return false;
}
int s = this.i.getSizeInventory();
for (int x = 0; x < s; x++)
if ( this.i.getStackInSlot( x ) != null )
return true;
return false;
}
@Override
public Iterator<ItemSlot> iterator()
{
return this.remover.iterator();
}
}
+24 -24
View File
@@ -69,25 +69,25 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
for (ItemStack is : this.i)
{
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
{
if ( how_many > is.stackSize )
if ( amount > is.stackSize )
{
how_many = is.stackSize;
amount = is.stackSize;
}
if ( destination != null && !destination.canInsert( is ) )
{
how_many = 0;
amount = 0;
}
if ( how_many > 0 )
if ( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = how_many;
rv.stackSize = amount;
return rv;
}
}
@@ -97,7 +97,7 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
{
int s = this.i.size();
for (int x = 0; x < s; x++)
@@ -105,16 +105,16 @@ public class AdaptorList extends InventoryAdaptor
ItemStack is = this.i.get( x );
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
{
if ( how_many > is.stackSize )
how_many = is.stackSize;
if ( amount > is.stackSize )
amount = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
how_many = 0;
amount = 0;
if ( how_many > 0 )
if ( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = how_many;
is.stackSize -= how_many;
rv.stackSize = amount;
is.stackSize -= amount;
// remove it..
if ( is.stackSize <= 0 )
@@ -128,25 +128,25 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
{
for (ItemStack is : this.i)
{
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
{
if ( how_many > is.stackSize )
if ( amount > is.stackSize )
{
how_many = is.stackSize;
amount = is.stackSize;
}
if ( destination != null && !destination.canInsert( is ) )
{
how_many = 0;
amount = 0;
}
if ( how_many > 0 )
if ( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = how_many;
rv.stackSize = amount;
return rv;
}
}
@@ -156,14 +156,14 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack addItems(ItemStack A)
public ItemStack addItems(ItemStack toBeAdded )
{
if ( A == null )
if ( toBeAdded == null )
return null;
if ( A.stackSize == 0 )
if ( toBeAdded.stackSize == 0 )
return null;
ItemStack left = A.copy();
ItemStack left = toBeAdded.copy();
for (ItemStack is : this.i)
{
@@ -179,7 +179,7 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack simulateAdd(ItemStack A)
public ItemStack simulateAdd(ItemStack toBeSimulated )
{
return null;
}
@@ -65,7 +65,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
}
@Override
public ItemStack simulateSimilarRemove( int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
public ItemStack simulateSimilarRemove( int amount, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
@@ -75,7 +75,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
if ( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
return result;
}
@@ -83,17 +83,17 @@ public class AdaptorPlayerHand extends InventoryAdaptor
}
@Override
public ItemStack removeItems( int how_many, ItemStack Filter, IInventoryDestination destination )
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
return null;
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
hand.stackSize -= how_many;
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
hand.stackSize -= amount;
if ( hand.stackSize <= 0 )
this.p.inventory.setItemStack( null );
return result;
@@ -103,17 +103,17 @@ public class AdaptorPlayerHand extends InventoryAdaptor
}
@Override
public ItemStack simulateRemove( int how_many, ItemStack Filter, IInventoryDestination destination )
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
return null;
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
return result;
}
@@ -121,38 +121,38 @@ public class AdaptorPlayerHand extends InventoryAdaptor
}
@Override
public ItemStack addItems( ItemStack A )
public ItemStack addItems( ItemStack toBeAdded )
{
if ( A == null )
if ( toBeAdded == null )
return null;
if ( A.stackSize == 0 )
if ( toBeAdded.stackSize == 0 )
return null;
if ( this.p == null )
return A;
return toBeAdded;
if ( this.p.inventory == null )
return A;
return toBeAdded;
ItemStack hand = this.p.inventory.getItemStack();
if ( hand != null && !Platform.isSameItemPrecise( A, hand ) )
return A;
if ( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) )
return toBeAdded;
int original = 0;
ItemStack newHand = null;
if ( hand == null )
newHand = A.copy();
newHand = toBeAdded.copy();
else
{
newHand = hand;
original = hand.stackSize;
newHand.stackSize += A.stackSize;
newHand.stackSize += toBeAdded.stackSize;
}
if ( newHand.stackSize > newHand.getMaxStackSize() )
{
newHand.stackSize = newHand.getMaxStackSize();
ItemStack B = A.copy();
ItemStack B = toBeAdded.copy();
B.stackSize -= newHand.stackSize - original;
this.p.inventory.setItemStack( newHand );
return B;
@@ -163,30 +163,30 @@ public class AdaptorPlayerHand extends InventoryAdaptor
}
@Override
public ItemStack simulateAdd( ItemStack A )
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( A == null )
if ( toBeSimulated == null )
return null;
if ( hand != null && !Platform.isSameItem( A, hand ) )
return A;
if ( hand != null && !Platform.isSameItem( toBeSimulated, hand ) )
return toBeSimulated;
int original = 0;
ItemStack newHand = null;
if ( hand == null )
newHand = A.copy();
newHand = toBeSimulated.copy();
else
{
newHand = hand.copy();
original = hand.stackSize;
newHand.stackSize += A.stackSize;
newHand.stackSize += toBeSimulated.stackSize;
}
if ( newHand.stackSize > newHand.getMaxStackSize() )
{
newHand.stackSize = newHand.getMaxStackSize();
ItemStack B = A.copy();
ItemStack B = toBeSimulated.copy();
B.stackSize -= newHand.stackSize - original;
return B;
}
+11 -11
View File
@@ -107,15 +107,15 @@ public class IMEAdaptor extends InventoryAdaptor
}
@Override
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination)
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
{
return this.doRemoveItems( how_many, Filter, destination, Actionable.MODULATE );
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
}
@Override
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination destination)
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
{
return this.doRemoveItems( how_many, Filter, destination, Actionable.SIMULATE );
return this.doRemoveItems( amount, filter, destination, Actionable.SIMULATE );
}
@Override
@@ -127,17 +127,17 @@ public class IMEAdaptor extends InventoryAdaptor
}
@Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
if ( filter == null )
return this.doRemoveItems( how_many, null, destination, Actionable.SIMULATE );
return this.doRemoveItemsFuzzy( how_many, filter, destination, Actionable.SIMULATE, fuzzyMode );
return this.doRemoveItems( amount, null, destination, Actionable.SIMULATE );
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.SIMULATE, fuzzyMode );
}
@Override
public ItemStack addItems(ItemStack A)
public ItemStack addItems(ItemStack toBeAdded )
{
IAEItemStack in = AEItemStack.create( A );
IAEItemStack in = AEItemStack.create( toBeAdded );
if ( in != null )
{
IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src );
@@ -148,9 +148,9 @@ public class IMEAdaptor extends InventoryAdaptor
}
@Override
public ItemStack simulateAdd(ItemStack A)
public ItemStack simulateAdd(ItemStack toBeSimulated )
{
IAEItemStack in = AEItemStack.create( A );
IAEItemStack in = AEItemStack.create( toBeSimulated );
if ( in != null )
{
IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src );