Err too much.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
|
||||
public interface AEMultiTile extends IGridHost, IPartHost
|
||||
@Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet", modid = "MineFactoryReloaded")
|
||||
public interface AEMultiTile extends IGridHost, IPartHost, IConnectableRedNet
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.implementations.IAEItemPowerStorage;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.MEMonitorHandler;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.me.storage.CellInventory;
|
||||
|
||||
public class CellItemViewer extends MEMonitorHandler<IAEItemStack> implements ICellItemViewer
|
||||
{
|
||||
|
||||
private ItemStack target;
|
||||
private IAEItemPowerStorage ips;
|
||||
|
||||
public CellItemViewer(ItemStack is) {
|
||||
super( CellInventory.getCell( is ) );
|
||||
ips = (IAEItemPowerStorage) is.getItem();
|
||||
target = is;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier)
|
||||
{
|
||||
amt = usePowerMultiplier.multiply( amt );
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
return usePowerMultiplier.divide( Math.min( amt, ips.getAECurrentPower( getItemStack() ) ) );
|
||||
|
||||
return usePowerMultiplier.divide( ips.extractAEPower( getItemStack(), amt ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+447
-447
@@ -1,447 +1,447 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.ISegmentedInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.storage.MEMonitorIInventory;
|
||||
import appeng.me.storage.MEMonitorPassthu;
|
||||
import appeng.me.storage.NullInventory;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorIInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.WrapperInvSlot;
|
||||
|
||||
public class DualityInterface implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory
|
||||
{
|
||||
|
||||
final int sides[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
final IAEItemStack requireWork[] = new IAEItemStack[] { null, null, null, null, null, null, null, null };
|
||||
|
||||
boolean hasConfig = false;
|
||||
AENetworkProxy gridProxy;
|
||||
IInterfaceHost iHost;
|
||||
BaseActionSource mySrc;
|
||||
|
||||
public DualityInterface(AENetworkProxy prox, IInterfaceHost ih) {
|
||||
gridProxy = prox;
|
||||
iHost = ih;
|
||||
mySrc = fluids.changeSource = items.changeSource = new MachineSource( iHost );
|
||||
}
|
||||
|
||||
private void readConfig()
|
||||
{
|
||||
boolean hadConfig = hasConfig;
|
||||
|
||||
hasConfig = false;
|
||||
|
||||
for (ItemStack p : config)
|
||||
{
|
||||
if ( p != null )
|
||||
{
|
||||
hasConfig = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean had = hasWorkToDo();
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
updatePlan( x );
|
||||
|
||||
boolean has = hasWorkToDo();
|
||||
|
||||
if ( had != has )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( has )
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
else
|
||||
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity te = iHost.getTileEntity();
|
||||
if ( hadConfig != hasConfig && te != null && te.worldObj != null )
|
||||
{
|
||||
te.worldObj.notifyBlocksOfNeighborChange( te.xCoord, te.yCoord, te.zCoord, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
config.writeToNBT( data, "config" );
|
||||
patterns.writeToNBT( data, "patterns" );
|
||||
storage.writeToNBT( data, "storage" );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
config.readFromNBT( data, "config" );
|
||||
patterns.readFromNBT( data, "patterns" );
|
||||
storage.readFromNBT( data, "storage" );
|
||||
readConfig();
|
||||
}
|
||||
|
||||
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 8 );
|
||||
AppEngInternalInventory storage = new AppEngInternalInventory( this, 8 );
|
||||
AppEngInternalInventory patterns = new AppEngInternalInventory( this, 9 );
|
||||
|
||||
WrapperInvSlot slotInv = new WrapperInvSlot( storage );
|
||||
InventoryAdaptor adaptor = new AdaptorIInventory( slotInv );
|
||||
|
||||
IMEInventory<IAEItemStack> destination;
|
||||
private boolean isWorking = false;
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
IAEItemStack out = destination.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE );
|
||||
if ( out == null )
|
||||
return true;
|
||||
return out.getStackSize() != stack.stackSize;
|
||||
// ItemStack after = adaptor.simulateAdd( stack );
|
||||
// if ( after == null )
|
||||
// return true;
|
||||
// return after.stackSize != stack.stackSize;
|
||||
}
|
||||
|
||||
private void updatePlan(int slot)
|
||||
{
|
||||
IAEItemStack req = config.getAEStackInSlot( slot );
|
||||
ItemStack Stored = storage.getStackInSlot( slot );
|
||||
|
||||
if ( req == null && Stored != null )
|
||||
{
|
||||
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
||||
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
||||
return;
|
||||
}
|
||||
else if ( req != null )
|
||||
{
|
||||
if ( Stored == null ) // need to add stuff!
|
||||
{
|
||||
requireWork[slot] = req.copy();
|
||||
return;
|
||||
}
|
||||
else if ( req.isSameType( Stored ) ) // same type ( qty diffrent? )!
|
||||
{
|
||||
if ( req.getStackSize() != Stored.stackSize )
|
||||
{
|
||||
requireWork[slot] = req.copy();
|
||||
requireWork[slot].setStackSize( req.getStackSize() - Stored.stackSize );
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ( Stored != null ) // dispose!
|
||||
{
|
||||
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
||||
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// else
|
||||
|
||||
requireWork[slot] = null;
|
||||
}
|
||||
|
||||
static private boolean interfaceRequest = false;
|
||||
|
||||
class InterfaceInventory extends MEMonitorIInventory
|
||||
{
|
||||
|
||||
public InterfaceInventory(DualityInterface tileInterface) {
|
||||
super( tileInterface.storage, ForgeDirection.UP );
|
||||
mySource = new MachineSource( iHost );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type)
|
||||
{
|
||||
if ( interfaceRequest )
|
||||
return input;
|
||||
|
||||
return super.injectItems( input, type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable type)
|
||||
{
|
||||
if ( interfaceRequest )
|
||||
return null;
|
||||
|
||||
return super.extractItems( request, type );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private boolean usePlan(int x, IAEItemStack itemStack)
|
||||
{
|
||||
boolean changed = false;
|
||||
slotInv.setSlot( x );
|
||||
interfaceRequest = isWorking = true;
|
||||
|
||||
try
|
||||
{
|
||||
destination = gridProxy.getStorage().getItemInventory();
|
||||
IEnergySource src = gridProxy.getEnergy();
|
||||
|
||||
if ( itemStack.getStackSize() > 0 )
|
||||
{
|
||||
IAEItemStack aquired = Platform.poweredExtraction( src, destination, itemStack, mySrc );
|
||||
if ( aquired != null )
|
||||
{
|
||||
changed = true;
|
||||
ItemStack issue = adaptor.addItems( aquired.getItemStack() );
|
||||
if ( issue != null )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
}
|
||||
}
|
||||
else if ( itemStack.getStackSize() < 0 )
|
||||
{
|
||||
IAEItemStack toStore = itemStack.copy();
|
||||
toStore.setStackSize( -toStore.getStackSize() );
|
||||
|
||||
long diff = toStore.getStackSize();
|
||||
|
||||
toStore = Platform.poweredInsert( src, destination, toStore, mySrc );
|
||||
|
||||
if ( toStore != null )
|
||||
diff -= toStore.getStackSize();
|
||||
|
||||
if ( diff != 0 )
|
||||
{
|
||||
// extract items!
|
||||
changed = true;
|
||||
ItemStack removed = adaptor.removeItems( (int) diff, null, null );
|
||||
if ( removed == null )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
else if ( removed.stackSize != diff )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
}
|
||||
}
|
||||
// else wtf?
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
if ( changed )
|
||||
updatePlan( x );
|
||||
|
||||
interfaceRequest = isWorking = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
public IInventory getConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
public IInventory getPatterns()
|
||||
{
|
||||
return patterns;
|
||||
}
|
||||
|
||||
MEMonitorPassthu<IAEItemStack> items = new MEMonitorPassthu<IAEItemStack>( new NullInventory() );
|
||||
MEMonitorPassthu<IAEFluidStack> fluids = new MEMonitorPassthu<IAEFluidStack>( new NullInventory() );
|
||||
|
||||
public void gridChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
items.setInternal( gridProxy.getStorage().getItemInventory() );
|
||||
fluids.setInternal( gridProxy.getStorage().getFluidInventory() );
|
||||
}
|
||||
catch (GridAccessException gae)
|
||||
{
|
||||
items.setInternal( new NullInventory() );
|
||||
fluids.setInternal( new NullInventory() );
|
||||
}
|
||||
|
||||
TileEntity te = iHost.getTileEntity();
|
||||
te.worldObj.notifyBlocksOfNeighborChange( te.xCoord, te.yCoord, te.zCoord, 0 );
|
||||
}
|
||||
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( iHost.getTileEntity() );
|
||||
}
|
||||
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
if ( isWorking )
|
||||
return;
|
||||
|
||||
if ( inv == config )
|
||||
readConfig();
|
||||
else if ( inv == patterns )
|
||||
{
|
||||
|
||||
}
|
||||
else if ( inv == storage && slot >= 0 )
|
||||
{
|
||||
boolean had = hasWorkToDo();
|
||||
|
||||
updatePlan( slot );
|
||||
|
||||
boolean now = hasWorkToDo();
|
||||
|
||||
if ( had != now )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( now )
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
else
|
||||
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasWorkToDo()
|
||||
{
|
||||
return requireWork[0] != null || requireWork[1] != null || requireWork[2] != null || requireWork[3] != null || requireWork[4] != null
|
||||
|| requireWork[5] != null || requireWork[6] != null || requireWork[7] != null;
|
||||
}
|
||||
|
||||
private boolean updateStorage()
|
||||
{
|
||||
boolean didSomething = false;
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
{
|
||||
if ( requireWork[x] != null )
|
||||
{
|
||||
didSomething = usePlan( x, requireWork[x] ) || didSomething;
|
||||
}
|
||||
}
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
public boolean hasConfig()
|
||||
{
|
||||
return hasConfig;
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( 5, 120, !hasWorkToDo(), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
boolean couldDoWork = updateStorage();
|
||||
return hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER) : TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
if ( hasConfig() )
|
||||
return new InterfaceInventory( this );
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
if ( hasConfig() )
|
||||
return null;
|
||||
|
||||
return fluids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "storage" ) )
|
||||
return storage;
|
||||
|
||||
if ( name.equals( "patterns" ) )
|
||||
return patterns;
|
||||
|
||||
if ( name.equals( "config" ) )
|
||||
return config;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IInventory getStorage()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
public TileEntity getTile()
|
||||
{
|
||||
return (TileEntity) (iHost instanceof TileEntity ? iHost : null);
|
||||
}
|
||||
|
||||
public IPart getPart()
|
||||
{
|
||||
return (IPart) (iHost instanceof IPart ? iHost : null);
|
||||
}
|
||||
|
||||
}
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.ISegmentedInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.storage.MEMonitorIInventory;
|
||||
import appeng.me.storage.MEMonitorPassthu;
|
||||
import appeng.me.storage.NullInventory;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorIInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.WrapperInvSlot;
|
||||
|
||||
public class DualityInterface implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory
|
||||
{
|
||||
|
||||
final int sides[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
final IAEItemStack requireWork[] = new IAEItemStack[] { null, null, null, null, null, null, null, null };
|
||||
|
||||
boolean hasConfig = false;
|
||||
AENetworkProxy gridProxy;
|
||||
IInterfaceHost iHost;
|
||||
BaseActionSource mySrc;
|
||||
|
||||
public DualityInterface(AENetworkProxy prox, IInterfaceHost ih) {
|
||||
gridProxy = prox;
|
||||
iHost = ih;
|
||||
mySrc = fluids.changeSource = items.changeSource = new MachineSource( iHost );
|
||||
}
|
||||
|
||||
private void readConfig()
|
||||
{
|
||||
boolean hadConfig = hasConfig;
|
||||
|
||||
hasConfig = false;
|
||||
|
||||
for (ItemStack p : config)
|
||||
{
|
||||
if ( p != null )
|
||||
{
|
||||
hasConfig = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean had = hasWorkToDo();
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
updatePlan( x );
|
||||
|
||||
boolean has = hasWorkToDo();
|
||||
|
||||
if ( had != has )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( has )
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
else
|
||||
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity te = iHost.getTileEntity();
|
||||
if ( hadConfig != hasConfig && te != null && te.worldObj != null )
|
||||
{
|
||||
te.worldObj.notifyBlocksOfNeighborChange( te.xCoord, te.yCoord, te.zCoord, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
config.writeToNBT( data, "config" );
|
||||
patterns.writeToNBT( data, "patterns" );
|
||||
storage.writeToNBT( data, "storage" );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
config.readFromNBT( data, "config" );
|
||||
patterns.readFromNBT( data, "patterns" );
|
||||
storage.readFromNBT( data, "storage" );
|
||||
readConfig();
|
||||
}
|
||||
|
||||
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 8 );
|
||||
AppEngInternalInventory storage = new AppEngInternalInventory( this, 8 );
|
||||
AppEngInternalInventory patterns = new AppEngInternalInventory( this, 9 );
|
||||
|
||||
WrapperInvSlot slotInv = new WrapperInvSlot( storage );
|
||||
InventoryAdaptor adaptor = new AdaptorIInventory( slotInv );
|
||||
|
||||
IMEInventory<IAEItemStack> destination;
|
||||
private boolean isWorking = false;
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
IAEItemStack out = destination.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, null );
|
||||
if ( out == null )
|
||||
return true;
|
||||
return out.getStackSize() != stack.stackSize;
|
||||
// ItemStack after = adaptor.simulateAdd( stack );
|
||||
// if ( after == null )
|
||||
// return true;
|
||||
// return after.stackSize != stack.stackSize;
|
||||
}
|
||||
|
||||
private void updatePlan(int slot)
|
||||
{
|
||||
IAEItemStack req = config.getAEStackInSlot( slot );
|
||||
ItemStack Stored = storage.getStackInSlot( slot );
|
||||
|
||||
if ( req == null && Stored != null )
|
||||
{
|
||||
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
||||
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
||||
return;
|
||||
}
|
||||
else if ( req != null )
|
||||
{
|
||||
if ( Stored == null ) // need to add stuff!
|
||||
{
|
||||
requireWork[slot] = req.copy();
|
||||
return;
|
||||
}
|
||||
else if ( req.isSameType( Stored ) ) // same type ( qty diffrent? )!
|
||||
{
|
||||
if ( req.getStackSize() != Stored.stackSize )
|
||||
{
|
||||
requireWork[slot] = req.copy();
|
||||
requireWork[slot].setStackSize( req.getStackSize() - Stored.stackSize );
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ( Stored != null ) // dispose!
|
||||
{
|
||||
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
||||
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// else
|
||||
|
||||
requireWork[slot] = null;
|
||||
}
|
||||
|
||||
static private boolean interfaceRequest = false;
|
||||
|
||||
class InterfaceInventory extends MEMonitorIInventory
|
||||
{
|
||||
|
||||
public InterfaceInventory(DualityInterface tileInterface) {
|
||||
super( tileInterface.storage, ForgeDirection.UP );
|
||||
mySource = new MachineSource( iHost );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
||||
{
|
||||
if ( interfaceRequest )
|
||||
return input;
|
||||
|
||||
return super.injectItems( input, type, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src)
|
||||
{
|
||||
if ( interfaceRequest )
|
||||
return null;
|
||||
|
||||
return super.extractItems( request, type, src );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private boolean usePlan(int x, IAEItemStack itemStack)
|
||||
{
|
||||
boolean changed = false;
|
||||
slotInv.setSlot( x );
|
||||
interfaceRequest = isWorking = true;
|
||||
|
||||
try
|
||||
{
|
||||
destination = gridProxy.getStorage().getItemInventory();
|
||||
IEnergySource src = gridProxy.getEnergy();
|
||||
|
||||
if ( itemStack.getStackSize() > 0 )
|
||||
{
|
||||
IAEItemStack aquired = Platform.poweredExtraction( src, destination, itemStack, mySrc );
|
||||
if ( aquired != null )
|
||||
{
|
||||
changed = true;
|
||||
ItemStack issue = adaptor.addItems( aquired.getItemStack() );
|
||||
if ( issue != null )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
}
|
||||
}
|
||||
else if ( itemStack.getStackSize() < 0 )
|
||||
{
|
||||
IAEItemStack toStore = itemStack.copy();
|
||||
toStore.setStackSize( -toStore.getStackSize() );
|
||||
|
||||
long diff = toStore.getStackSize();
|
||||
|
||||
toStore = Platform.poweredInsert( src, destination, toStore, mySrc );
|
||||
|
||||
if ( toStore != null )
|
||||
diff -= toStore.getStackSize();
|
||||
|
||||
if ( diff != 0 )
|
||||
{
|
||||
// extract items!
|
||||
changed = true;
|
||||
ItemStack removed = adaptor.removeItems( (int) diff, null, null );
|
||||
if ( removed == null )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
else if ( removed.stackSize != diff )
|
||||
throw new RuntimeException( "bad attempt at managining inventory. ( addItems )" );
|
||||
}
|
||||
}
|
||||
// else wtf?
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
if ( changed )
|
||||
updatePlan( x );
|
||||
|
||||
interfaceRequest = isWorking = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
public IInventory getConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
public IInventory getPatterns()
|
||||
{
|
||||
return patterns;
|
||||
}
|
||||
|
||||
MEMonitorPassthu<IAEItemStack> items = new MEMonitorPassthu<IAEItemStack>( new NullInventory() );
|
||||
MEMonitorPassthu<IAEFluidStack> fluids = new MEMonitorPassthu<IAEFluidStack>( new NullInventory() );
|
||||
|
||||
public void gridChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
items.setInternal( gridProxy.getStorage().getItemInventory() );
|
||||
fluids.setInternal( gridProxy.getStorage().getFluidInventory() );
|
||||
}
|
||||
catch (GridAccessException gae)
|
||||
{
|
||||
items.setInternal( new NullInventory() );
|
||||
fluids.setInternal( new NullInventory() );
|
||||
}
|
||||
|
||||
TileEntity te = iHost.getTileEntity();
|
||||
te.worldObj.notifyBlocksOfNeighborChange( te.xCoord, te.yCoord, te.zCoord, 0 );
|
||||
}
|
||||
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( iHost.getTileEntity() );
|
||||
}
|
||||
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
if ( isWorking )
|
||||
return;
|
||||
|
||||
if ( inv == config )
|
||||
readConfig();
|
||||
else if ( inv == patterns )
|
||||
{
|
||||
|
||||
}
|
||||
else if ( inv == storage && slot >= 0 )
|
||||
{
|
||||
boolean had = hasWorkToDo();
|
||||
|
||||
updatePlan( slot );
|
||||
|
||||
boolean now = hasWorkToDo();
|
||||
|
||||
if ( had != now )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( now )
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
else
|
||||
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasWorkToDo()
|
||||
{
|
||||
return requireWork[0] != null || requireWork[1] != null || requireWork[2] != null || requireWork[3] != null || requireWork[4] != null
|
||||
|| requireWork[5] != null || requireWork[6] != null || requireWork[7] != null;
|
||||
}
|
||||
|
||||
private boolean updateStorage()
|
||||
{
|
||||
boolean didSomething = false;
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
{
|
||||
if ( requireWork[x] != null )
|
||||
{
|
||||
didSomething = usePlan( x, requireWork[x] ) || didSomething;
|
||||
}
|
||||
}
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
public boolean hasConfig()
|
||||
{
|
||||
return hasConfig;
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( 5, 120, !hasWorkToDo(), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
boolean couldDoWork = updateStorage();
|
||||
return hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER) : TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
if ( hasConfig() )
|
||||
return new InterfaceInventory( this );
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
if ( hasConfig() )
|
||||
return null;
|
||||
|
||||
return fluids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "storage" ) )
|
||||
return storage;
|
||||
|
||||
if ( name.equals( "patterns" ) )
|
||||
return patterns;
|
||||
|
||||
if ( name.equals( "config" ) )
|
||||
return config;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IInventory getStorage()
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
public TileEntity getTile()
|
||||
{
|
||||
return (TileEntity) (iHost instanceof TileEntity ? iHost : null);
|
||||
}
|
||||
|
||||
public IPart getPart()
|
||||
{
|
||||
return (IPart) (iHost instanceof IPart ? iHost : null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public interface ICellItemViewer extends IStorageMonitorable, IMEMonitor<IAEItemStack>, IEnergySource
|
||||
{
|
||||
|
||||
public ItemStack getItemStack();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IGuiItem
|
||||
{
|
||||
|
||||
Object getGuiObject(ItemStack is);
|
||||
|
||||
}
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import appeng.api.networking.IGridHost;
|
||||
|
||||
public interface IInterfaceHost extends IGridHost
|
||||
{
|
||||
|
||||
DualityInterface getInterfaceDuality();
|
||||
|
||||
TileEntity getTileEntity();
|
||||
}
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import appeng.api.networking.IGridHost;
|
||||
|
||||
public interface IInterfaceHost extends IGridHost
|
||||
{
|
||||
|
||||
DualityInterface getInterfaceDuality();
|
||||
|
||||
TileEntity getTileEntity();
|
||||
}
|
||||
|
||||
+78
-37
@@ -20,8 +20,10 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
@@ -67,10 +69,7 @@ public class PartPlacement
|
||||
|
||||
ForgeDirection side = ForgeDirection.getOrientation( face );
|
||||
|
||||
if ( held == null )
|
||||
return false;
|
||||
|
||||
if ( Platform.isWrench( player, held, x, y, z ) )
|
||||
if ( held != null && Platform.isWrench( player, held, x, y, z ) && player.isSneaking() )
|
||||
{
|
||||
int block = world.getBlockId( x, y, z );
|
||||
TileEntity tile = world.getBlockTileEntity( x, y, z );
|
||||
@@ -92,7 +91,7 @@ public class PartPlacement
|
||||
|
||||
if ( sp.part != null )
|
||||
{
|
||||
is.add( sp.part.getItemStack( true ) );
|
||||
is.add( sp.part.getItemStack( PartItemStack.Wrench ) );
|
||||
sp.part.getDrops( is, true );
|
||||
host.removePart( sp.side );
|
||||
}
|
||||
@@ -132,51 +131,86 @@ public class PartPlacement
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
IFacadePart fp = isFacade( held, side );
|
||||
if ( fp != null )
|
||||
if ( held != null )
|
||||
{
|
||||
if ( host != null )
|
||||
IFacadePart fp = isFacade( held, side );
|
||||
if ( fp != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
if ( host != null )
|
||||
{
|
||||
if ( host.getPart( ForgeDirection.UNKNOWN ) == null )
|
||||
return false;
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.getPart( ForgeDirection.UNKNOWN ) == null )
|
||||
return false;
|
||||
|
||||
if ( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
host.markForUpdate();
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
if ( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
host.markForUpdate();
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( !(held.getItem() instanceof IPartItem) )
|
||||
// if ( held == null )
|
||||
{
|
||||
int block = world.getBlockId( x, y, z );
|
||||
if ( host != null && player.isSneaking() && Block.blocksList[block] != null )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player );
|
||||
MovingObjectPosition mop = Block.blocksList[block].collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
mop.hitVec = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ );
|
||||
SelectedPart sPart = host.selectPart( mop.hitVec );
|
||||
if ( sPart != null && sPart.part != null )
|
||||
if ( sPart.part.onShiftActivate( player, mop.hitVec ) )
|
||||
{
|
||||
if ( world.isRemote )
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( held == null || !(held.getItem() instanceof IPartItem) )
|
||||
return false;
|
||||
|
||||
int te_x = x;
|
||||
@@ -234,6 +268,8 @@ public class PartPlacement
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( host == null )
|
||||
@@ -256,16 +292,21 @@ public class PartPlacement
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( (blkID == 0 || Block.blocksList[blkID].isBlockReplaceable( world, te_x, te_y, te_z ) || host != null) && offset != ForgeDirection.UNKNOWN )
|
||||
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world, pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS
|
||||
: PlaceType.PLACE_ITEM, depth + 1 );
|
||||
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world,
|
||||
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.addPart( held, side ) != null )
|
||||
ForgeDirection mySide = host.addPart( held, side );
|
||||
if ( mySide != null )
|
||||
{
|
||||
IPart newlyPlacedPart = host.getPart( mySide );
|
||||
if ( newlyPlacedPart != null )
|
||||
newlyPlacedPart.onPlacement( player, held, side );
|
||||
|
||||
StepSound ss = AEApi.instance().blocks().blockMultiPart.block().stepSound;
|
||||
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.getPlaceSound(), (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F );
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class TickHandler implements ITickHandler
|
||||
@Override
|
||||
public EnumSet<TickType> ticks()
|
||||
{
|
||||
return EnumSet.of( TickType.WORLD );
|
||||
return EnumSet.of( TickType.SERVER );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user