Relocate Source to proper directory.

This commit is contained in:
AlgorithmX2
2014-09-23 19:26:27 -05:00
parent fe927ce65d
commit 386d18a059
785 changed files with 35585 additions and 35580 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
package appeng.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
/*
* Totaly useless container that does nothing.
*/
public class ContainerNull extends Container
{
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return false;
}
}
@@ -0,0 +1,28 @@
package appeng.container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.parts.IPart;
public class ContainerOpenContext
{
public World w;
public int x, y, z;
public ForgeDirection side;
final public boolean isItem;
public ContainerOpenContext(Object myItem) {
boolean isWorld = myItem instanceof IPart || myItem instanceof TileEntity;
isItem = !isWorld;
}
public TileEntity getTile()
{
if ( isItem )
return null;
return w.getTileEntity( x, y, z );
}
}
@@ -0,0 +1,11 @@
package appeng.container.guisync;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface GuiSync {
int value();
}
@@ -0,0 +1,170 @@
package appeng.container.guisync;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.ICrafting;
import appeng.container.AEBaseContainer;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketProgressBar;
import appeng.core.sync.packets.PacketValueConfig;
public class SyncDat
{
private Object clientVersion;
private AEBaseContainer source;
private Field field;
private int channel;
public SyncDat(AEBaseContainer container, Field field, GuiSync anno) {
clientVersion = null;
this.source = container;
this.field = field;
channel = anno.value();
}
public int getChannel()
{
return channel;
}
public void tick(ICrafting c)
{
try
{
Object val = field.get( source );
if ( val == clientVersion )
return;
else if ( val != null && clientVersion == null )
send( c, val );
else if ( !val.equals( clientVersion ) )
send( c, val );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
catch (IOException e)
{
AELog.error( e );
}
}
public void update(Object val)
{
try
{
Object oldValue = field.get( source );
if ( val instanceof String )
updateString( oldValue, (String) val );
else
updateValue( oldValue, (Long) val );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
}
private void updateString(Object oldValue, String val)
{
try
{
field.set( source, val );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
}
private void updateValue(Object oldValue, long val)
{
try
{
if ( field.getType().isEnum() )
{
EnumSet<? extends Enum> valList = EnumSet.allOf( (Class<? extends Enum>) field.getType() );
for (Enum e : valList)
{
if ( e.ordinal() == val )
{
field.set( source, e );
break;
}
}
}
else
{
if ( field.getType().equals( int.class ) )
field.set( source, (int) val );
else if ( field.getType().equals( long.class ) )
field.set( source, (long) val );
else if ( field.getType().equals( boolean.class ) )
field.set( source, val == 1 );
else if ( field.getType().equals( Integer.class ) )
field.set( source, (Integer) (int) val );
else if ( field.getType().equals( Long.class ) )
field.set( source, (Long) val );
else if ( field.getType().equals( Boolean.class ) )
field.set( source, (Boolean) (val == 1) );
}
source.onUpdate( field.getName(), oldValue, field.get( source ) );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
}
private void send(ICrafting o, Object val) throws IOException
{
if ( val instanceof String )
{
if ( o instanceof EntityPlayerMP )
NetworkHandler.instance.sendTo( new PacketValueConfig( "SyncDat." + channel, (String) val ), (EntityPlayerMP) o );
}
else if ( field.getType().isEnum() )
{
o.sendProgressBarUpdate( source, channel, ((Enum) val).ordinal() );
}
else if ( val instanceof Long || val.getClass() == long.class )
{
NetworkHandler.instance.sendTo( new PacketProgressBar( channel, (Long) val ), (EntityPlayerMP) o );
}
else if ( val instanceof Boolean || val.getClass() == boolean.class )
{
o.sendProgressBarUpdate( source, channel, ((Boolean) val) ? 1 : 0 );
}
else
{
o.sendProgressBarUpdate( source, channel, (Integer) val );
}
clientVersion = val;
}
}
@@ -0,0 +1,309 @@
package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.CopyMode;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
import appeng.api.storage.ICellWorkbenchItem;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.OptionalSlotRestrictedInput;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngNullInventory;
import appeng.tile.misc.TileCellWorkbench;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
public class ContainerCellWorkbench extends ContainerUpgradeable
{
TileCellWorkbench workBench;
AppEngNullInventory ni = new AppEngNullInventory();
public IInventory getCellUpgradeInventory()
{
IInventory ri = workBench.getCellUpgradeInventory();
return ri == null ? ni : ri;
}
public void setFuzzy(FuzzyMode valueOf)
{
ICellWorkbenchItem cwi = workBench.getCell();
if ( cwi != null )
cwi.setFuzzyMode( workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ), valueOf );
}
private FuzzyMode getFuzzyMode()
{
ICellWorkbenchItem cwi = workBench.getCell();
if ( cwi != null )
return cwi.getFuzzyMode( workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ) );
return FuzzyMode.IGNORE_ALL;
}
public void nextCopyMode()
{
workBench.getConfigManager().putSetting( Settings.COPY_MODE, Platform.nextEnum( getCopyMode() ) );
}
public CopyMode getCopyMode()
{
return (CopyMode) workBench.getConfigManager().getSetting( Settings.COPY_MODE );
}
class Upgrades implements IInventory
{
@Override
public int getSizeInventory()
{
return getCellUpgradeInventory().getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i)
{
return getCellUpgradeInventory().getStackInSlot( i );
}
@Override
public ItemStack decrStackSize(int i, int j)
{
IInventory inv = getCellUpgradeInventory();
ItemStack is = inv.decrStackSize( i, j );
inv.markDirty();
return is;
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
{
IInventory inv = getCellUpgradeInventory();
ItemStack is = inv.getStackInSlotOnClosing( i );
inv.markDirty();
return is;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
IInventory inv = getCellUpgradeInventory();
inv.setInventorySlotContents( i, itemstack );
inv.markDirty();
}
@Override
public String getInventoryName()
{
return "Upgrades";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void markDirty()
{
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return false;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return getCellUpgradeInventory().isItemValidForSlot( i, itemstack );
}
};
IInventory UpgradeInventoryWrapper;
ItemStack prevStack = null;
int lastUpgrades = 0;
@GuiSync(2)
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
public ContainerCellWorkbench(InventoryPlayer ip, TileCellWorkbench te) {
super( ip, te );
workBench = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
public int availableUpgrades()
{
ItemStack is = workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if ( prevStack != is )
{
prevStack = is;
return lastUpgrades = getCellUpgradeInventory().getSizeInventory();
}
return lastUpgrades;
}
@Override
public boolean isSlotEnabled(int idx)
{
return idx < availableUpgrades();
}
@Override
protected void setupConfig()
{
int x = 8;
int y = 29;
int offset = 0;
IInventory cell = myte.getInventoryByName( "cell" );
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, invPlayer ) );
IInventory inv = myte.getInventoryByName( "config" );
UpgradeInventoryWrapper = new Upgrades();// Platform.isServer() ? new Upgrades() : new AppEngInternalInventory(
// null, 3 * 8 );
for (int w = 0; w < 7; w++)
for (int z = 0; z < 9; z++)
addSlotToContainer( new SlotFakeTypeOnly( inv, offset++, x + z * 18, y + w * 18 ) );
for (int zz = 0; zz < 3; zz++)
for (int z = 0; z < 8; z++)
{
int iSLot = zz * 8 + z;
addSlotToContainer( new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, UpgradeInventoryWrapper, this, iSLot, 187 + zz * 18,
8 + 18 * z, iSLot, invPlayer ) );
}
/*
* if ( supportCapacity() ) { for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new
* OptionalSlotFakeTypeOnly( inv, this, offset++, x, y, z, w, 1 ) );
*
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 2, 2 ) );
*
* for (int w = 0; w < 2; w++) for (int z = 0; z < 9; z++) addSlotToContainer( new OptionalSlotFakeTypeOnly(
* inv, this, offset++, x, y, z, w + 4, 3 ) ); }
*/
}
ItemStack LastCell;
@Override
public void onUpdate(String field, Object oldValue, Object newValue)
{
if ( field.equals( "copyMode" ) )
workBench.getConfigManager().putSetting( Settings.COPY_MODE, this.copyMode );
super.onUpdate( field, oldValue, newValue );
}
@Override
public void detectAndSendChanges()
{
ItemStack is = workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if ( Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
if ( prevStack != is )
{
// if the bars changed an item was probably made, so just send shit!
for (Object s : inventorySlots)
{
if ( s instanceof OptionalSlotRestrictedInput )
{
OptionalSlotRestrictedInput sri = (OptionalSlotRestrictedInput) s;
icrafting.sendSlotContents( this, sri.slotNumber, sri.getStack() );
}
}
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
}
this.copyMode = getCopyMode();
this.fzMode = (FuzzyMode) getFuzzyMode();
}
prevStack = is;
standardDetectAndSendChanges();
}
public void clear()
{
IInventory inv = myte.getInventoryByName( "config" );
for (int x = 0; x < inv.getSizeInventory(); x++)
inv.setInventorySlotContents( x, null );
detectAndSendChanges();
}
public void partition()
{
IInventory inv = myte.getInventoryByName( "config" );
IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell()
.getCellInventory( myte.getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
Iterator<IAEItemStack> i = new NullIterator<IAEItemStack>();
if ( cellInv != null )
{
IItemList<IAEItemStack> list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() );
i = list.iterator();
}
for (int x = 0; x < inv.getSizeInventory(); x++)
{
if ( i.hasNext() )
{
ItemStack g = i.next().getItemStack();
g.stackSize = 1;
inv.setInventorySlotContents( x, g );
}
else
inv.setInventorySlotContents( x, null );
}
detectAndSendChanges();
}
}
@@ -0,0 +1,22 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileChest;
public class ContainerChest extends AEBaseContainer
{
TileChest myte;
public ContainerChest(InventoryPlayer ip, TileChest te) {
super( ip, te, null );
myte = te;
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, myte, 1, 80, 37, invPlayer ) );
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
}
}
@@ -0,0 +1,55 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.config.CondenserOutput;
import appeng.api.config.Settings;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileCondenser;
import appeng.util.Platform;
public class ContainerCondenser extends AEBaseContainer
{
TileCondenser myte;
public ContainerCondenser(InventoryPlayer ip, TileCondenser te) {
super( ip, te, null );
myte = te;
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, te, 0, 51, 52, ip ) );
addSlotToContainer( new SlotOutput( te, 1, 105, 52, -1 ) );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, te.getInternalInventory(), 2, 101, 26, ip )).setStackLimit( 1 ) );
bindPlayerInventory( ip, 0, 197 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
if ( Platform.isServer() )
{
double maxStorage = this.myte.getStorage();
double requiredEnergy = this.myte.getRequiredPower();
int maxDisplay = requiredEnergy == 0 ? (int) maxStorage : (int) Math.min( requiredEnergy, maxStorage );
this.requiredEnergy = (int) maxDisplay;
this.storedPower = (int) this.myte.storedPower;
this.output = (CondenserOutput) this.myte.getConfigManager().getSetting( Settings.CONDENSER_OUTPUT );
}
super.detectAndSendChanges();
}
@GuiSync(0)
public long requiredEnergy = 0;
@GuiSync(1)
public long storedPower = 0;
@GuiSync(2)
public CondenserOutput output = CondenserOutput.TRASH;
}
@@ -0,0 +1,56 @@
package appeng.container.implementations;
import appeng.container.slot.SlotInaccessible;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.world.World;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.tile.inventory.AppEngInternalInventory;
public class ContainerCraftAmount extends AEBaseContainer
{
ITerminalHost priHost;
public IAEItemStack whatToMake;
public Slot craftingItem;
public ContainerCraftAmount(InventoryPlayer ip, ITerminalHost te) {
super( ip, te );
priHost = te;
craftingItem = new SlotInaccessible( new AppEngInternalInventory( null, 1 ), 0, 34, 53 );
addSlotToContainer( craftingItem );
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
verifyPermissions( SecurityPermissions.CRAFT, false );
}
public IGrid getGrid()
{
IActionHost h = ((IActionHost) this.getTarget());
return h.getActionableNode().getGrid();
}
public World getWorld()
{
return getPlayerInv().player.worldObj;
}
public BaseActionSource getActionSrc()
{
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
}
}
@@ -0,0 +1,352 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Future;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.AELog;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartTerminal;
import appeng.util.Platform;
import com.google.common.collect.ImmutableSet;
public class ContainerCraftConfirm extends AEBaseContainer
{
ITerminalHost priHost;
public Future<ICraftingJob> job;
public ICraftingJob result;
@GuiSync(0)
public long bytesUsed;
@GuiSync(1)
public long cpuBytesAvail;
@GuiSync(2)
public int cpuCoProcessors;
@GuiSync(3)
public boolean autoStart = false;
@GuiSync(4)
public boolean simulation = true;
@GuiSync(5)
public int selectedCpu = -1;
@GuiSync(6)
public boolean noCPU = true;
@GuiSync(7)
public String myName = "";
protected long cpuIdx = Long.MIN_VALUE;
public ArrayList<CraftingCPURecord> cpus = new ArrayList();
public ContainerCraftConfirm(InventoryPlayer ip, ITerminalHost te) {
super( ip, te );
priHost = te;
}
private void sendCPUs()
{
Collections.sort( cpus );
if ( selectedCpu >= cpus.size() )
{
selectedCpu = -1;
cpuBytesAvail = 0;
cpuCoProcessors = 0;
myName = "";
}
else if ( selectedCpu != -1 )
{
myName = cpus.get( selectedCpu ).myName;
cpuBytesAvail = cpus.get( selectedCpu ).size;
cpuCoProcessors = cpus.get( selectedCpu ).processors;
}
}
public void cycleCpu(boolean next)
{
if ( next )
selectedCpu++;
else
selectedCpu--;
if ( selectedCpu < -1 )
selectedCpu = cpus.size() - 1;
else if ( selectedCpu >= cpus.size() )
selectedCpu = -1;
if ( selectedCpu == -1 )
{
cpuBytesAvail = 0;
cpuCoProcessors = 0;
myName = "";
}
else
{
myName = cpus.get( selectedCpu ).myName;
cpuBytesAvail = cpus.get( selectedCpu ).size;
cpuCoProcessors = cpus.get( selectedCpu ).processors;
}
}
@Override
public void detectAndSendChanges()
{
if ( Platform.isClient() )
return;
ICraftingGrid cc = getGrid().getCache( ICraftingGrid.class );
ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for (ICraftingCPU c : cpuSet)
{
boolean found = false;
for (CraftingCPURecord ccr : cpus)
if ( ccr.cpu == c )
found = true;
boolean matched = cpuMatches( c );
if ( matched )
matches++;
if ( !found != matched )
changed = true;
}
if ( changed || cpus.size() != matches )
{
cpus.clear();
for (ICraftingCPU c : cpuSet)
{
if ( cpuMatches( c ) )
cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
}
sendCPUs();
}
noCPU = cpus.size() == 0;
super.detectAndSendChanges();
if ( job != null && job.isDone() )
{
try
{
result = job.get();
if ( !result.isSimulation() )
{
simulation = false;
if ( autoStart )
{
startJob();
return;
}
}
else
simulation = true;
try
{
PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
PacketMEInventoryUpdate c = result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
result.populatePlan( plan );
bytesUsed = result.getByteTotal();
for (IAEItemStack out : plan)
{
IAEItemStack m = null;
IAEItemStack o = out.copy();
o.reset();
o.setStackSize( out.getStackSize() );
IAEItemStack p = out.copy();
p.reset();
p.setStackSize( out.getCountRequestable() );
IStorageGrid sg = getGrid().getCache( IStorageGrid.class );
IMEInventory<IAEItemStack> items = sg.getItemInventory();
if ( c != null && result.isSimulation() )
{
m = o.copy();
o = items.extractItems( o, Actionable.SIMULATE, mySrc );
if ( o == null )
{
o = m.copy();
o.setStackSize( 0 );
}
m.setStackSize( m.getStackSize() - o.getStackSize() );
}
if ( o.getStackSize() > 0 )
a.appendItem( o );
if ( p.getStackSize() > 0 )
b.appendItem( p );
if ( c != null && m != null && m.getStackSize() > 0 )
c.appendItem( m );
}
for (Object g : this.crafters)
{
if ( g instanceof EntityPlayer )
{
NetworkHandler.instance.sendTo( a, (EntityPlayerMP) g );
NetworkHandler.instance.sendTo( b, (EntityPlayerMP) g );
if ( c != null )
NetworkHandler.instance.sendTo( c, (EntityPlayerMP) g );
}
}
}
catch (IOException e)
{
// :P
}
}
catch (Throwable e)
{
getPlayerInv().player.addChatMessage( new ChatComponentText( "Error: " + e.toString() ) );
AELog.error( e );
this.isContainerValid = false;
result = null;
}
job = null;
}
verifyPermissions( SecurityPermissions.CRAFT, false );
}
private boolean cpuMatches(ICraftingCPU c)
{
return c.getAvailableStorage() >= bytesUsed && !c.isBusy();
}
public void startJob()
{
GuiBridge OriginalGui = null;
IActionHost ah = getActionHost();
if ( ah instanceof WirelessTerminalGuiObject )
OriginalGui = GuiBridge.GUI_WIRELESS_TERM;
if ( ah instanceof PartTerminal )
OriginalGui = GuiBridge.GUI_ME;
if ( ah instanceof PartCraftingTerminal )
OriginalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
if ( ah instanceof PartPatternTerminal )
OriginalGui = GuiBridge.GUI_PATTERN_TERMINAL;
if ( result != null && simulation == false )
{
ICraftingGrid cc = getGrid().getCache( ICraftingGrid.class );
ICraftingLink g = cc.submitJob( result, null, selectedCpu == -1 ? null : cpus.get( selectedCpu ).cpu, true, getActionSrc() );
autoStart = false;
if ( g != null && OriginalGui != null && openContext != null )
{
try
{
NetworkHandler.instance.sendTo( new PacketSwitchGuis( OriginalGui ), (EntityPlayerMP) invPlayer.player );
}
catch (IOException e)
{
// :(
}
TileEntity te = openContext.getTile();
Platform.openGUI( invPlayer.player, te, openContext.side, OriginalGui );
}
}
}
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed( par1EntityPlayer );
if ( job != null )
{
job.cancel( true );
job = null;
}
}
@Override
public void removeCraftingFromCrafters(ICrafting c)
{
super.removeCraftingFromCrafters( c );
if ( job != null )
{
job.cancel( true );
job = null;
}
}
public IGrid getGrid()
{
IActionHost h = ((IActionHost) this.getTarget());
return h.getActionableNode().getGrid();
}
public World getWorld()
{
return getPlayerInv().player.worldObj;
}
public BaseActionSource getActionSrc()
{
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
}
}
@@ -0,0 +1,215 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.ICustomNameObject;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject
{
CraftingCPUCluster monitor = null;
String cpuName = null;
protected IGrid network;
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
public ContainerCraftingCPU(InventoryPlayer ip, Object te) {
super( ip, te );
IGridHost host = (IGridHost) (te instanceof IGridHost ? te : null);
if ( host != null )
{
findNode( host, ForgeDirection.UNKNOWN );
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
findNode( host, d );
}
if ( te instanceof TileCraftingTile )
setCPU( (ICraftingCPU) ((TileCraftingTile) te).getCluster() );
if ( network == null && Platform.isServer() )
isContainerValid = false;
}
protected void setCPU(ICraftingCPU c)
{
if ( c == monitor )
return;
if ( monitor != null )
monitor.removeListener( this );
for (Object g : this.crafters)
{
if ( g instanceof EntityPlayer )
{
try
{
NetworkHandler.instance.sendTo( new PacketValueConfig( "CraftingStatus", "Clear" ), (EntityPlayerMP) g );
}
catch (IOException e)
{
AELog.error( e );
}
}
}
if ( c instanceof CraftingCPUCluster )
{
cpuName = ((CraftingCPUCluster) c).getName();
monitor = (CraftingCPUCluster) c;
if ( monitor != null )
{
list.resetStatus();
monitor.getListOfItem( list, CraftingItemList.ALL );
monitor.addListener( this, null );
}
}
else
{
monitor = null;
cpuName = "";
}
}
public void cancelCrafting()
{
if ( monitor != null )
{
monitor.cancel();
}
}
private void findNode(IGridHost host, ForgeDirection d)
{
if ( network == null )
{
IGridNode node = host.getGridNode( d );
if ( node != null )
network = node.getGrid();
}
}
int delay = 40;
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed( player );
if ( monitor != null )
monitor.removeListener( this );
}
@Override
public void removeCraftingFromCrafters(ICrafting c)
{
super.removeCraftingFromCrafters( c );
if ( this.crafters.isEmpty() && monitor != null )
monitor.removeListener( this );
}
@Override
public void detectAndSendChanges()
{
if ( Platform.isServer() && monitor != null && !list.isEmpty() )
{
try
{
PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
for (IAEItemStack out : list)
{
a.appendItem( monitor.getItemStack( out, CraftingItemList.STORAGE ) );
b.appendItem( monitor.getItemStack( out, CraftingItemList.ACTIVE ) );
c.appendItem( monitor.getItemStack( out, CraftingItemList.PENDING ) );
}
list.resetStatus();
for (Object g : this.crafters)
{
if ( g instanceof EntityPlayer )
{
if ( !a.isEmpty() )
NetworkHandler.instance.sendTo( a, (EntityPlayerMP) g );
if ( !b.isEmpty() )
NetworkHandler.instance.sendTo( b, (EntityPlayerMP) g );
if ( !c.isEmpty() )
NetworkHandler.instance.sendTo( c, (EntityPlayerMP) g );
}
}
}
catch (IOException e)
{
// :P
}
}
super.detectAndSendChanges();
}
@Override
public boolean isValid(Object verificationToken)
{
return true;
}
@Override
public void postChange(IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource actionSource)
{
for (IAEItemStack is : change)
{
is = is.copy();
is.setStackSize( 1 );
list.add( is );
}
}
@Override
public void onListUpdate()
{
}
@Override
public String getCustomName()
{
return cpuName;
}
@Override
public boolean hasCustomName()
{
return cpuName != null && cpuName.length() > 0;
}
}
@@ -0,0 +1,131 @@
package appeng.container.implementations;
import java.util.ArrayList;
import java.util.Collections;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import com.google.common.collect.ImmutableSet;
public class ContainerCraftingStatus extends ContainerCraftingCPU
{
@GuiSync(5)
public int selectedCpu = -1;
@GuiSync(6)
public boolean noCPU = true;
@GuiSync(7)
public String myName = "";
public ArrayList<CraftingCPURecord> cpus = new ArrayList();
private void sendCPUs()
{
Collections.sort( cpus );
if ( selectedCpu >= cpus.size() )
{
selectedCpu = -1;
myName = "";
}
else if ( selectedCpu != -1 )
{
myName = cpus.get( selectedCpu ).myName;
}
if ( selectedCpu == -1 && cpus.size() > 0 )
selectedCpu = 0;
if ( selectedCpu != -1 )
{
if ( cpus.get( selectedCpu ).cpu != monitor )
setCPU( cpus.get( selectedCpu ).cpu );
}
else
setCPU( null );
}
@Override
public void detectAndSendChanges()
{
ICraftingGrid cc = network.getCache( ICraftingGrid.class );
ImmutableSet<ICraftingCPU> cpuSet = cc.getCpus();
int matches = 0;
boolean changed = false;
for (ICraftingCPU c : cpuSet)
{
boolean found = false;
for (CraftingCPURecord ccr : cpus)
if ( ccr.cpu == c )
found = true;
boolean matched = cpuMatches( c );
if ( matched )
matches++;
if ( !found != matched )
changed = true;
}
if ( changed || cpus.size() != matches )
{
cpus.clear();
for (ICraftingCPU c : cpuSet)
{
if ( cpuMatches( c ) )
cpus.add( new CraftingCPURecord( c.getAvailableStorage(), c.getCoProcessors(), c ) );
}
sendCPUs();
}
noCPU = cpus.size() == 0;
super.detectAndSendChanges();
}
private boolean cpuMatches(ICraftingCPU c)
{
return c.isBusy();
}
public ContainerCraftingStatus(InventoryPlayer ip, ITerminalHost te) {
super( ip, te );
}
public void cycleCpu(boolean next)
{
if ( next )
selectedCpu++;
else
selectedCpu--;
if ( selectedCpu < -1 )
selectedCpu = cpus.size() - 1;
else if ( selectedCpu >= cpus.size() )
selectedCpu = -1;
if ( selectedCpu == -1 && cpus.size() > 0 )
selectedCpu = 0;
if ( selectedCpu == -1 )
{
myName = "";
setCPU( null );
}
else
{
myName = cpus.get( selectedCpu ).myName;
setCPU( cpus.get( selectedCpu ).cpu );
}
}
}
@@ -0,0 +1,82 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerNull;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotCraftingTerm;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket
{
AppEngInternalInventory output = new AppEngInternalInventory( this, 1 );
SlotCraftingMatrix craftingSlots[] = new SlotCraftingMatrix[9];
SlotCraftingTerm outputSlot;
public PartCraftingTerminal ct;
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory par1IInventory)
{
ContainerNull cn = new ContainerNull();
InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 );
for (int x = 0; x < 9; x++)
ic.setInventorySlotContents( x, craftingSlots[x].getStack() );
outputSlot.putStack( CraftingManager.getInstance().findMatchingRecipe( ic, getPlayerInv().player.worldObj ) );
}
public ContainerCraftingTerm(InventoryPlayer ip, ITerminalHost monitorable) {
super( ip, monitorable, false );
ct = (PartCraftingTerminal) monitorable;
IInventory crafting = ct.getInventoryByName( "crafting" );
for (int y = 0; y < 3; y++)
for (int x = 0; x < 3; x++)
addSlotToContainer( craftingSlots[x + y * 3] = new SlotCraftingMatrix( this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18 ) );
addSlotToContainer( outputSlot = new SlotCraftingTerm( getPlayerInv().player, mySrc, powerSrc, monitorable, crafting, crafting, output, 131, -72 + 18, this ) );
bindPlayerInventory( ip, 0, 0 );
onCraftMatrixChanged( crafting );
}
@Override
public void saveChanges()
{
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
}
@Override
public IInventory getInventoryByName(String name)
{
return ct.getInventoryByName( name );
}
@Override
public boolean useRealItems()
{
return true;
}
}
@@ -0,0 +1,26 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileDrive;
public class ContainerDrive extends AEBaseContainer
{
TileDrive myte;
public ContainerDrive(InventoryPlayer ip, TileDrive te) {
super( ip, te, null );
myte = te;
for (int y = 0; y < 5; y++)
for (int x = 0; x < 2; x++)
{
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, te, x + y * 2, 71 + x * 18, 14 + y * 18, invPlayer ) );
}
bindPlayerInventory( ip, 0, 199 - /* height of playerinventory */82 );
}
}
@@ -0,0 +1,90 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartFormationPlane;
import appeng.util.Platform;
public class ContainerFormationPlane extends ContainerUpgradeable
{
PartFormationPlane storageBus;
public ContainerFormationPlane(InventoryPlayer ip, PartFormationPlane te) {
super( ip, te );
storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
public boolean isSlotEnabled(int idx)
{
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
return upgrades > idx;
}
@Override
protected void setupConfig()
{
int xo = 8;
int yo = 23 + 6;
IInventory config = myte.getInventoryByName( "config" );
for (int y = 0; y < 7; y++)
{
for (int x = 0; x < 9; x++)
{
if ( y < 2 )
addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
else
addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE );
}
standardDetectAndSendChanges();
}
}
@@ -0,0 +1,32 @@
package appeng.container.implementations;
import appeng.container.slot.SlotInaccessible;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.grindstone.TileGrinder;
public class ContainerGrinder extends AEBaseContainer
{
TileGrinder myte;
public ContainerGrinder(InventoryPlayer ip, TileGrinder te) {
super( ip, te, null );
myte = te;
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 0, 12, 17, invPlayer ) );
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 1, 12 + 18, 17, invPlayer ) );
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, te, 2, 12 + 36, 17, invPlayer ) );
addSlotToContainer( new SlotInaccessible( te, 6, 80, 40 ) );
addSlotToContainer( new SlotOutput( te, 3, 112, 63, 2 * 16 + 15 ) );
addSlotToContainer( new SlotOutput( te, 4, 112 + 18, 63, 2 * 16 + 15 ) );
addSlotToContainer( new SlotOutput( te, 5, 112 + 36, 63, 2 * 16 + 15 ) );
bindPlayerInventory( ip, 0, 176 - /* height of playerinventory */82 );
}
}
@@ -0,0 +1,88 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import appeng.api.config.FullnessMode;
import appeng.api.config.OperationMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.storage.TileIOPort;
import appeng.util.Platform;
public class ContainerIOPort extends ContainerUpgradeable
{
TileIOPort ioPort;
@GuiSync(2)
public FullnessMode fMode = FullnessMode.EMPTY;
@GuiSync(3)
public OperationMode opMode = OperationMode.EMPTY;
public ContainerIOPort(InventoryPlayer ip, TileIOPort te) {
super( ip, te );
ioPort = te;
}
@Override
protected int getHeight()
{
return 166;
}
@Override
public int availableUpgrades()
{
return 3;
}
@Override
protected boolean supportCapacity()
{
return false;
}
@Override
protected void setupConfig()
{
int offx = 19;
int offy = 17;
IInventory cells = myte.getInventoryByName( "cells" );
for (int y = 0; y < 3; y++)
for (int x = 0; x < 2; x++)
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, cells, x + y * 2, offx + x * 18, offy + y * 18, invPlayer ) );
offx = 122;
offy = 17;
for (int y = 0; y < 3; y++)
for (int x = 0; x < 2; x++)
addSlotToContainer( new SlotOutput( cells, 6 + x + y * 2, offx + x * 18, offy + y * 18, SlotRestrictedInput.PlacableItemType.STORAGE_CELLS.IIcon ) );
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.opMode = (OperationMode) myte.getConfigManager().getSetting( Settings.OPERATION_MODE );
this.fMode = (FullnessMode) this.myte.getConfigManager().getSetting( Settings.FULLNESS_MODE );
this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
}
standardDetectAndSendChanges();
}
}
@@ -0,0 +1,131 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.recipes.handlers.Inscribe;
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
import appeng.tile.misc.TileInscriber;
import appeng.util.Platform;
public class ContainerInscriber extends AEBaseContainer
{
TileInscriber myte;
Slot top;
Slot middle;
Slot bottom;
@GuiSync(0)
public int maxProcessingTime = -1;
@GuiSync(1)
public int processingTime = -1;
public ContainerInscriber(InventoryPlayer ip, TileInscriber te) {
super( ip, te, null );
myte = te;
addSlotToContainer( top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, myte, 0, 45, 16, invPlayer ) );
addSlotToContainer( bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, myte, 1, 45, 62, invPlayer ) );
addSlotToContainer( middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, myte, 2, 63, 39, invPlayer ) );
addSlotToContainer( new SlotOutput( myte, 3, 113, 40, -1 ) );
bindPlayerInventory( ip, 0, 176 - /* height of playerinventory */82 );
}
public boolean isValidForSlot(Slot s, ItemStack is)
{
ItemStack PlateA = myte.getStackInSlot( 0 );
ItemStack PlateB = myte.getStackInSlot( 1 );
if ( s == middle )
{
for (ItemStack i : Inscribe.plates)
{
if ( Platform.isSameItemPrecise( i, is ) )
return false;
}
boolean matches = false;
boolean found = false;
for (InscriberRecipe i : Inscribe.recipes)
{
boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and...
(PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB ));
boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and...
(PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB ));
if ( matchA || matchB )
{
matches = true;
for (ItemStack option : i.imprintable)
{
if ( Platform.isSameItemPrecise( is, option ) )
found = true;
}
}
}
if ( matches && found == false )
return false;
}
if ( (s == top && PlateB != null) || (s == bottom && PlateA != null) )
{
boolean isValid = false;
ItemStack otherSlot = null;
if ( s == top )
otherSlot = bottom.getStack();
else
otherSlot = top.getStack();
// name presses
if ( AEApi.instance().materials().materialNamePress.sameAsStack( otherSlot ) )
return AEApi.instance().materials().materialNamePress.sameAsStack( is );
// everything else
for (InscriberRecipe i : Inscribe.recipes)
{
if ( Platform.isSameItemPrecise( i.plateA, otherSlot ) )
{
isValid = Platform.isSameItemPrecise( is, i.plateB );
}
else if ( Platform.isSameItemPrecise( i.plateB, otherSlot ) )
{
isValid = Platform.isSameItemPrecise( is, i.plateA );
}
if ( isValid )
break;
}
if ( !isValid )
return false;
}
return true;
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
if ( Platform.isServer() )
{
this.maxProcessingTime = myte.maxProcessingTime;
this.processingTime = myte.processingTime;
}
}
}
@@ -0,0 +1,71 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.util.IConfigManager;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotFake;
import appeng.container.slot.SlotNormal;
import appeng.container.slot.SlotRestrictedInput;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
public class ContainerInterface extends ContainerUpgradeable
{
DualityInterface myDuality;
@GuiSync(3)
public YesNo bMode = YesNo.NO;
@GuiSync(4)
public YesNo iTermMode = YesNo.YES;
public ContainerInterface(InventoryPlayer ip, IInterfaceHost te) {
super( ip, te.getInterfaceDuality().getHost() );
myDuality = te.getInterfaceDuality();
for (int x = 0; x < 9; x++)
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, myDuality.getPatterns(), x, 8 + 18 * x, 90 + 7, invPlayer ) );
for (int x = 0; x < 8; x++)
addSlotToContainer( new SlotFake( myDuality.getConfig(), x, 17 + 18 * x, 35 ) );
for (int x = 0; x < 8; x++)
addSlotToContainer( new SlotNormal( myDuality.getStorage(), x, 17 + 18 * x, 35 + 18 ) );
}
@Override
protected int getHeight()
{
return 211;
}
@Override
protected void setupConfig()
{
setupUpgrades();
}
protected void loadSettingsFromHost(IConfigManager cm)
{
this.bMode = (YesNo) cm.getSetting( Settings.BLOCK );
this.iTermMode = (YesNo) cm.getSetting( Settings.INTERFACE_TERMINAL );
}
public int availableUpgrades()
{
return 1;
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
super.detectAndSendChanges();
}
}
@@ -0,0 +1,373 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.container.AEBaseContainer;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.parts.misc.PartInterface;
import appeng.parts.reporting.PartMonitor;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.inv.WrapperInvSlot;
public class ContainerInterfaceTerminal extends AEBaseContainer
{
/**
* this stuff is all server side..
*/
static private long autoBase = Long.MIN_VALUE;
class InvTracker
{
long which = autoBase++;
String unlocalizedName;
public InvTracker(DualityInterface dual, IInventory patterns, String unlocalizedName) {
server = patterns;
client = new AppEngInternalInventory( null, server.getSizeInventory() );
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
}
IInventory client;
IInventory server;
public long sortBy;
};
Map<IInterfaceHost, InvTracker> diList = new HashMap();
Map<Long, InvTracker> byId = new HashMap();
IGrid g;
public ContainerInterfaceTerminal(InventoryPlayer ip, PartMonitor anchor) {
super( ip, anchor );
if ( Platform.isServer() )
g = anchor.getActionableNode().getGrid();
bindPlayerInventory( ip, 0, 222 - /* height of playerinventory */82 );
}
NBTTagCompound data = new NBTTagCompound();
class PatternInvSlot extends WrapperInvSlot
{
public PatternInvSlot(IInventory inv) {
super( inv );
}
@Override
public boolean isItemValid(ItemStack itemstack)
{
return itemstack != null && itemstack.getItem() instanceof ItemEncodedPattern;
}
};
@Override
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id)
{
InvTracker inv = byId.get( id );
if ( inv != null )
{
ItemStack is = inv.server.getStackInSlot( slot );
boolean hasItemInHand = player.inventory.getItemStack() != null;
InventoryAdaptor playerHand = new AdaptorPlayerHand( player );
WrapperInvSlot slotInv = new PatternInvSlot( inv.server );
IInventory theSlot = slotInv.getWrapper( slot );
InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot );
switch (action)
{
case PICKUP_OR_SETDOWN:
if ( hasItemInHand )
{
ItemStack inSlot = theSlot.getStackInSlot( 0 );
if ( inSlot == null )
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
else
{
inSlot = inSlot.copy();
ItemStack inHand = player.inventory.getItemStack().copy();
theSlot.setInventorySlotContents( 0, null );
player.inventory.setItemStack( null );
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
if ( player.inventory.getItemStack() == null )
player.inventory.setItemStack( inSlot );
else
{
player.inventory.setItemStack( inHand );
theSlot.setInventorySlotContents( 0, inSlot );
}
}
}
else
{
IInventory mySlot = slotInv.getWrapper( slot );
mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) );
}
break;
case SPLIT_OR_PLACESINGLE:
if ( hasItemInHand )
{
ItemStack extra = playerHand.removeItems( 1, null, null );
if ( extra != null )
extra = interfaceSlot.addItems( extra );
if ( extra != null )
playerHand.addItems( extra );
}
else if ( is != null )
{
ItemStack extra = interfaceSlot.removeItems( (is.stackSize + 1) / 2, null, null );
if ( extra != null )
extra = playerHand.addItems( extra );
if ( extra != null )
interfaceSlot.addItems( extra );
}
break;
case SHIFT_CLICK:
IInventory mySlot = slotInv.getWrapper( slot );
InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
mySlot.setInventorySlotContents( 0, playerInv.addItems( mySlot.getStackInSlot( 0 ) ) );
break;
case MOVE_REGION:
InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
for (int x = 0; x < inv.server.getSizeInventory(); x++)
{
inv.server.setInventorySlotContents( x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
}
break;
case CREATIVE_DUPLICATE:
if ( player.capabilities.isCreativeMode && !hasItemInHand )
{
player.inventory.setItemStack( is == null ? null : is.copy() );
}
break;
default:
return;
}
updateHeld( player );
}
}
@Override
public void detectAndSendChanges()
{
if ( Platform.isClient() )
return;
super.detectAndSendChanges();
if ( g == null )
return;
int total = 0;
boolean missing = false;
IActionHost host = getActionHost();
if ( host != null )
{
IGridNode agn = host.getActionableNode();
if ( agn != null && agn.isActive() )
{
for (IGridNode gn : g.getMachines( TileInterface.class ))
{
if ( gn.isActive() )
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
continue;
InvTracker t = diList.get( ih );
if ( t == null )
missing = true;
else
{
DualityInterface dual = ih.getInterfaceDuality();
if ( !t.unlocalizedName.equals( dual.getTermName() ) )
missing = true;
}
total++;
}
}
for (IGridNode gn : g.getMachines( PartInterface.class ))
{
if ( gn.isActive() )
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
if ( ih.getInterfaceDuality().getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.NO )
continue;
InvTracker t = diList.get( ih );
if ( t == null )
missing = true;
else
{
DualityInterface dual = ih.getInterfaceDuality();
if ( !t.unlocalizedName.equals( dual.getTermName() ) )
missing = true;
}
total++;
}
}
}
}
if ( total != diList.size() || missing )
regenList( data );
else
{
for (Entry<IInterfaceHost, InvTracker> en : diList.entrySet())
{
InvTracker inv = en.getValue();
for (int x = 0; x < inv.server.getSizeInventory(); x++)
{
if ( isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
addItems( data, inv, x, 1 );
}
}
}
if ( !data.hasNoTags() )
{
try
{
NetworkHandler.instance.sendTo( new PacketCompressedNBT( data ), (EntityPlayerMP) getPlayerInv().player );
}
catch (IOException e)
{
// :P
}
data = new NBTTagCompound();
}
}
private boolean isDifferent(ItemStack a, ItemStack b)
{
if ( a == null && b == null )
return false;
if ( a == null || b == null )
return true;
return !ItemStack.areItemStacksEqual( a, b );
}
private void regenList(NBTTagCompound data)
{
byId.clear();
diList.clear();
IActionHost host = getActionHost();
if ( host != null )
{
IGridNode agn = host.getActionableNode();
if ( agn != null && agn.isActive() )
{
for (IGridNode gn : g.getMachines( TileInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
DualityInterface dual = ih.getInterfaceDuality();
if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) );
}
for (IGridNode gn : g.getMachines( PartInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
DualityInterface dual = ih.getInterfaceDuality();
if ( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) );
}
}
}
data.setBoolean( "clear", true );
for (Entry<IInterfaceHost, InvTracker> en : diList.entrySet())
{
InvTracker inv = en.getValue();
byId.put( inv.which, inv );
addItems( data, inv, 0, inv.server.getSizeInventory() );
}
}
private void addItems(NBTTagCompound data, InvTracker inv, int offset, int length)
{
String name = "=" + Long.toString( inv.which, Character.MAX_RADIX );
NBTTagCompound invv = data.getCompoundTag( name );
if ( invv.hasNoTags() )
{
invv.setLong( "sortBy", inv.sortBy );
invv.setString( "un", inv.unlocalizedName );
}
for (int x = 0; x < length; x++)
{
NBTTagCompound itemNBT = new NBTTagCompound();
ItemStack is = inv.server.getStackInSlot( x + offset );
// "update" client side.
inv.client.setInventorySlotContents( x + offset, is == null ? null : is.copy() );
if ( is != null )
is.writeToNBT( itemNBT );
invv.setTag( Integer.toString( x + offset ), itemNBT );
}
data.setTag( name, invv );
}
}
@@ -0,0 +1,115 @@
package appeng.container.implementations;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.YesNo;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.automation.PartLevelEmitter;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerLevelEmitter extends ContainerUpgradeable
{
PartLevelEmitter lvlEmitter;
@SideOnly(Side.CLIENT)
public GuiTextField textField;
@SideOnly(Side.CLIENT)
public void setTextField(GuiTextField level)
{
textField = level;
textField.setText( "" + EmitterValue );
}
public ContainerLevelEmitter(InventoryPlayer ip, PartLevelEmitter te) {
super( ip, te );
lvlEmitter = te;
}
@Override
public int availableUpgrades()
{
return 1;
}
@Override
protected boolean supportCapacity()
{
return false;
}
public void setLevel(long l, EntityPlayer player)
{
lvlEmitter.setReportingValue( l );
EmitterValue = l;
}
@Override
protected void setupConfig()
{
int x = 80 + 44;
int y = 40;
IInventory upgrades = myte.getInventoryByName( "upgrades" );
if ( availableUpgrades() > 0 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 1 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 2 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 3 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
IInventory inv = myte.getInventoryByName( "config" );
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
}
@GuiSync(2)
public LevelType lvType;
@GuiSync(3)
public long EmitterValue = -1;
@GuiSync(4)
public YesNo cmType;
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.EmitterValue = lvlEmitter.getReportingValue();
this.cmType = (YesNo) this.myte.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE );
this.lvType = (LevelType) this.myte.getConfigManager().getSetting( Settings.LEVEL_TYPE );
this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE );
this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_EMITTER );
}
standardDetectAndSendChanges();
}
public void onUpdate(String field, Object oldValue, Object newValue)
{
if ( field.equals( "EmitterValue" ) )
{
if ( textField != null )
textField.setText( "" + EmitterValue );
}
}
}
@@ -0,0 +1,116 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotMACPattern;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.misc.ItemEncodedPattern;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.util.Platform;
public class ContainerMAC extends ContainerUpgradeable
{
TileMolecularAssembler tma;
public ContainerMAC(InventoryPlayer ip, TileMolecularAssembler te) {
super( ip, te );
tma = te;
}
public int availableUpgrades()
{
return 5;
}
@Override
protected int getHeight()
{
return 197;
}
@Override
protected boolean supportCapacity()
{
return false;
}
@GuiSync(4)
public int craftProgress = 0;
public boolean isValidItemForSlot(int slotIndex, ItemStack i)
{
IInventory mac = myte.getInventoryByName( "mac" );
ItemStack is = mac.getStackInSlot( 10 );
if ( is == null )
return false;
if ( is.getItem() instanceof ItemEncodedPattern )
{
World w = this.getTileEntity().getWorldObj();
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
if ( ph.isCraftable() )
return ph.isValidItemForSlot( slotIndex, i, w );
}
return false;
}
@Override
protected void setupConfig()
{
int offx = 29;
int offy = 30;
IInventory mac = myte.getInventoryByName( "mac" );
for (int y = 0; y < 3; y++)
for (int x = 0; x < 3; x++)
{
SlotMACPattern s = new SlotMACPattern( this, mac, x + y * 3, offx + x * 18, offy + y * 18 );
addSlotToContainer( s );
}
offx = 126;
offy = 16;
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10, offx, offy, invPlayer ) );
addSlotToContainer( new SlotOutput( mac, 9, offx, offy + 32, -1 ) );
offx = 122;
offy = 17;
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
}
craftProgress = this.tma.getCraftingProgress();
standardDetectAndSendChanges();
}
}
@@ -0,0 +1,356 @@
package appeng.container.implementations;
import java.io.IOException;
import java.nio.BufferOverflowException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.me.helpers.ChannelPowerSrc;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigurableObject, IMEMonitorHandlerReceiver<IAEItemStack>
{
final IMEMonitor<IAEItemStack> monitor;
final IItemList<IAEItemStack> items = AEApi.instance().storage().createItemList();
IConfigManager serverCM;
IConfigManager clientCM;
@GuiSync(99)
public boolean canAccessViewCells = false;
@GuiSync(98)
public boolean hasPower = false;
public SlotRestrictedInput cellView[] = new SlotRestrictedInput[5];
public IConfigManagerHost gui;
private IGridNode networkNode;
public IGridNode getNetworkNode()
{
return networkNode;
}
protected ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost monitorable, boolean bindInventory) {
super( ip, monitorable instanceof TileEntity ? (TileEntity) monitorable : null, monitorable instanceof IPart ? (IPart) monitorable : null );
clientCM = new ConfigManager( this );
clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME );
clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
if ( Platform.isServer() )
{
serverCM = monitorable.getConfigManager();
monitor = monitorable.getItemInventory();
if ( monitor != null )
{
monitor.addListener( this, null );
cellInv = monitor;
if ( monitorable instanceof IPortableCell )
powerSrc = (IPortableCell) monitorable;
else if ( monitorable instanceof IMEChest )
powerSrc = (IMEChest) monitorable;
else if ( monitorable instanceof IGridHost )
{
IGridNode node = ((IGridHost) monitorable).getGridNode( ForgeDirection.UNKNOWN );
if ( node != null )
{
networkNode = node;
IGrid g = node.getGrid();
if ( g != null )
powerSrc = new ChannelPowerSrc( networkNode, (IEnergyGrid) g.getCache( IEnergyGrid.class ) );
}
}
}
else
isContainerValid = false;
}
else
monitor = null;
canAccessViewCells = false;
if ( monitorable instanceof IViewCellStorage )
{
for (int y = 0; y < 5; y++)
{
cellView[y] = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.VIEWCELL, ((IViewCellStorage) monitorable).getViewCellStorage(), y, 206, y * 18 + 8,
invPlayer );
cellView[y].allowEdit = canAccessViewCells;
addSlotToContainer( cellView[y] );
}
}
if ( bindInventory )
bindPlayerInventory( ip, 0, 0 );
}
public ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost monitorable) {
this( ip, monitorable, true );
}
@Override
public void detectAndSendChanges()
{
if ( Platform.isServer() )
{
for (Enum set : serverCM.getSettings())
{
Enum sideLocal = serverCM.getSetting( set );
Enum sideRemote = clientCM.getSetting( set );
if ( sideLocal != sideRemote )
{
clientCM.putSetting( set, sideLocal );
for (int j = 0; j < this.crafters.size(); ++j)
{
try
{
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) );
}
catch (IOException e)
{
AELog.error( e );
}
}
}
}
if ( !items.isEmpty() )
{
try
{
IItemList<IAEItemStack> monitorCache = monitor.getStorageList();
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
for (IAEItemStack is : items)
{
IAEItemStack send = monitorCache.findPrecise( is );
if ( send == null )
{
is.setStackSize( 0 );
piu.appendItem( is );
}
else
piu.appendItem( send );
}
if ( !piu.isEmpty() )
{
items.resetStatus();
for (Object c : this.crafters)
{
if ( c instanceof EntityPlayer )
NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c );
}
}
}
catch (IOException e)
{
AELog.error( e );
}
}
updatePowerStatus();
boolean oldCanAccessViewCells = canAccessViewCells;
canAccessViewCells = hasAccess( SecurityPermissions.BUILD, false );
if ( canAccessViewCells != oldCanAccessViewCells )
{
for (int y = 0; y < 5; y++)
{
if ( cellView[y] != null )
cellView[y].allowEdit = canAccessViewCells;
}
}
super.detectAndSendChanges();
}
}
protected void updatePowerStatus()
{
try
{
if ( networkNode != null )
hasPower = networkNode.isActive();
else if ( powerSrc instanceof IEnergyGrid )
hasPower = ((IEnergyGrid) powerSrc).isNetworkPowered();
else
hasPower = powerSrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8;
}
catch (Throwable t)
{
// :P
}
}
@Override
public void addCraftingToCrafters(ICrafting c)
{
super.addCraftingToCrafters( c );
queueInventory( c );
}
public void queueInventory(ICrafting c)
{
if ( Platform.isServer() && c instanceof EntityPlayer && monitor != null )
{
try
{
PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate();
IItemList<IAEItemStack> monitorCache = monitor.getStorageList();
for (IAEItemStack send : monitorCache)
{
try
{
piu.appendItem( send );
}
catch (BufferOverflowException boe)
{
NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c );
piu = new PacketMEInventoryUpdate();
piu.appendItem( send );
}
}
NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c );
}
catch (IOException e)
{
AELog.error( e );
}
}
}
@Override
public void onListUpdate()
{
for (Object c : this.crafters)
{
if ( c instanceof ICrafting )
{
ICrafting cr = (ICrafting) c;
queueInventory( cr );
}
}
}
@Override
public void onUpdate(String field, Object oldValue, Object newValue)
{
if ( field.equals( "canAccessViewCells" ) )
{
for (int y = 0; y < 5; y++)
if ( cellView[y] != null )
cellView[y].allowEdit = canAccessViewCells;
}
super.onUpdate( field, oldValue, newValue );
}
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed( player );
if ( monitor != null )
monitor.removeListener( this );
}
@Override
public void removeCraftingFromCrafters(ICrafting c)
{
super.removeCraftingFromCrafters( c );
if ( this.crafters.isEmpty() && monitor != null )
monitor.removeListener( this );
}
@Override
public void postChange(IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource source)
{
for (IAEItemStack is : change)
items.add( is );
}
@Override
public boolean isValid(Object verificationToken)
{
return true;
}
@Override
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
{
if ( gui != null )
gui.updateSetting( manager, settingName, newValue );
}
@Override
public IConfigManager getConfigManager()
{
if ( Platform.isServer() )
return serverCM;
return clientCM;
}
public ItemStack[] getViewCells()
{
ItemStack[] list = new ItemStack[cellView.length];
for (int x = 0; x < cellView.length; x++)
list[x] = cellView[x].getStack();
return list;
}
}
@@ -0,0 +1,58 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.storage.ITerminalHost;
import appeng.util.Platform;
public class ContainerMEPortableCell extends ContainerMEMonitorable
{
double powerMultiplier = 0.5;
IPortableCell civ;
public ContainerMEPortableCell(InventoryPlayer ip, IPortableCell monitorable) {
super( ip, (ITerminalHost) monitorable, false );
lockPlayerInventorySlot( ip.currentItem );
civ = monitorable;
bindPlayerInventory( ip, 0, 0 );
}
int ticks = 0;
@Override
public void detectAndSendChanges()
{
ItemStack currentItem = getPlayerInv().getCurrentItem();
if ( civ != null )
{
if ( currentItem != civ.getItemStack() )
{
if ( currentItem != null )
{
if ( Platform.isSameItem( civ.getItemStack(), currentItem ) )
getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, civ.getItemStack() );
else
isContainerValid = false;
}
else
isContainerValid = false;
}
}
else
isContainerValid = false;
// drain 1 ae t
ticks++;
if ( ticks > 10 )
{
civ.extractAEPower( powerMultiplier * (double) ticks, Actionable.MODULATE, PowerMultiplier.CONFIG );
ticks = 0;
}
super.detectAndSendChanges();
}
}
@@ -0,0 +1,123 @@
package appeng.container.implementations;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class ContainerNetworkStatus extends AEBaseContainer
{
IGrid network;
public ContainerNetworkStatus(InventoryPlayer ip, INetworkTool te) {
super( ip, null, null );
IGridHost host = te.getGridHost();
if ( host != null )
{
findNode( host, ForgeDirection.UNKNOWN );
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
findNode( host, d );
}
if ( network == null && Platform.isServer() )
isContainerValid = false;
}
private void findNode(IGridHost host, ForgeDirection d)
{
if ( network == null )
{
IGridNode node = host.getGridNode( d );
if ( node != null )
network = node.getGrid();
}
}
int delay = 40;
@GuiSync(0)
public long avgAddition;
@GuiSync(1)
public long powerUsage;
@GuiSync(2)
public long currentPower;
@GuiSync(3)
public long maxPower;
@Override
public void detectAndSendChanges()
{
delay++;
if ( Platform.isServer() && delay > 15 && network != null )
{
delay = 0;
IEnergyGrid eg = network.getCache( IEnergyGrid.class );
if ( eg != null )
{
avgAddition = (long) (100.0 * eg.getAvgPowerInjection());
powerUsage = (long) (100.0 * eg.getAvgPowerUsage());
currentPower = (long) (100.0 * eg.getStoredPower());
maxPower = (long) (100.0 * eg.getMaxStoredPower());
}
PacketMEInventoryUpdate piu;
try
{
piu = new PacketMEInventoryUpdate();
for (Class<? extends IGridHost> machineClass : network.getMachinesClasses())
{
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
for (IGridNode machine : network.getMachines( machineClass ))
{
IGridBlock blk = machine.getGridBlock();
ItemStack is = blk.getMachineRepresentation();
if ( is != null && is.getItem() != null )
{
IAEItemStack ais = AEItemStack.create( is );
ais.setStackSize( 1 );
ais.setCountRequestable( (long) (blk.getIdlePowerUsage() * 100.0) );
list.add( ais );
}
}
for (IAEItemStack ais : list)
piu.appendItem( ais );
}
for (Object c : this.crafters)
{
if ( c instanceof EntityPlayer )
NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c );
}
}
catch (IOException e)
{
// :P
}
}
super.detectAndSendChanges();
}
}
@@ -0,0 +1,68 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.util.Platform;
public class ContainerNetworkTool extends AEBaseContainer
{
INetworkTool toolInv;
@GuiSync(1)
public boolean facadeMode;
public ContainerNetworkTool(InventoryPlayer ip, INetworkTool te) {
super( ip, null, null );
toolInv = te;
lockPlayerInventorySlot( ip.currentItem );
for (int y = 0; y < 3; y++)
for (int x = 0; x < 3; x++)
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, invPlayer )) );
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
}
public void toggleFacadeMode()
{
NBTTagCompound data = Platform.openNbtData( toolInv.getItemStack() );
data.setBoolean( "hideFacades", !data.getBoolean( "hideFacades" ) );
this.detectAndSendChanges();
}
@Override
public void detectAndSendChanges()
{
ItemStack currentItem = getPlayerInv().getCurrentItem();
if ( currentItem != toolInv.getItemStack() )
{
if ( currentItem != null )
{
if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) )
{
getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() );
}
else
isContainerValid = false;
}
else
isContainerValid = false;
}
if ( isContainerValid )
{
NBTTagCompound data = Platform.openNbtData( currentItem );
facadeMode = data.getBoolean( "hideFacades" );
}
super.detectAndSendChanges();
}
}
@@ -0,0 +1,442 @@
package appeng.container.implementations;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternOutputs;
import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.parts.reporting.PartPatternTerminal;
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.AdaptorPlayerHand;
import appeng.util.item.AEItemStack;
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket
{
AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
IInventory crafting;
SlotFakeCraftingMatrix craftingSlots[] = new SlotFakeCraftingMatrix[9];
OptionalSlotFake outputSlots[] = new OptionalSlotFake[3];
SlotPatternTerm craftSlot;
SlotRestrictedInput patternSlotIN;
SlotRestrictedInput patternSlotOUT;
public PartPatternTerminal ct;
public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost monitorable)
{
super( ip, monitorable, false );
ct = (PartPatternTerminal) monitorable;
IInventory patternInv = ct.getInventoryByName( "pattern" );
IInventory output = ct.getInventoryByName( "output" );
crafting = ct.getInventoryByName( "crafting" );
for (int y = 0; y < 3; y++)
for (int x = 0; x < 3; x++)
addSlotToContainer( craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) );
addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, monitorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2, this ) );
craftSlot.IIcon = -1;
for (int y = 0; y < 3; y++)
{
addSlotToContainer( outputSlots[y] = new SlotPatternOutputs( output, this, y, 110, -76 + y * 18, 0, 0, 1 ) );
outputSlots[y].renderDisabled = false;
outputSlots[y].IIcon = -1;
}
addSlotToContainer( patternSlotIN = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9, invPlayer ) );
addSlotToContainer( patternSlotOUT = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34, invPlayer ) );
patternSlotOUT.setStackLimit( 1 );
bindPlayerInventory( ip, 0, 0 );
updateOrderOfOutputSlots();
}
private void updateOrderOfOutputSlots()
{
if ( !craftingMode )
{
craftSlot.xDisplayPosition = -9000;
for (int y = 0; y < 3; y++)
outputSlots[y].xDisplayPosition = outputSlots[y].defX;
}
else
{
craftSlot.xDisplayPosition = craftSlot.defX;
for (int y = 0; y < 3; y++)
outputSlots[y].xDisplayPosition = -9000;
}
}
@Override
public void putStackInSlot(int par1, ItemStack par2ItemStack)
{
super.putStackInSlot( par1, par2ItemStack );
getAndUpdateOutput();
}
@Override
public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack)
{
super.putStacksInSlots( par1ArrayOfItemStack );
getAndUpdateOutput();
}
public ItemStack getAndUpdateOutput()
{
InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );
for (int x = 0; x < ic.getSizeInventory(); x++)
ic.setInventorySlotContents( x, crafting.getStackInSlot( x ) );
ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj );
cOut.setInventorySlotContents( 0, is );
return is;
}
@GuiSync(97)
public boolean craftingMode = true;
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
if ( Platform.isServer() )
{
if ( craftingMode != ct.isCraftingRecipe() )
{
craftingMode = ct.isCraftingRecipe();
updateOrderOfOutputSlots();
}
}
}
@Override
public void onUpdate(String field, Object oldValue, Object newValue)
{
super.onUpdate( field, oldValue, newValue );
if ( field.equals( "craftingMode" ) )
{
getAndUpdateOutput();
updateOrderOfOutputSlots();
}
}
@Override
public void saveChanges()
{
}
public void encode()
{
ItemStack output = patternSlotOUT.getStack();
ItemStack[] in = getInputs();
ItemStack[] out = getOutputs();
// if theres no input, this would be silly.
if ( in == null || out == null )
return;
// first check the output slots, should either be null, or a pattern
if ( output != null && !isPattern( output ) )
return;
// if nothing is there we should snag a new pattern.
else if ( output == null )
{
output = patternSlotIN.getStack();
if ( output == null || !isPattern( output ) )
return; // no blanks.
// remove one, and clear the input slot.
output.stackSize--;
if ( output.stackSize == 0 )
patternSlotIN.putStack( null );
// add a new encoded pattern.
patternSlotOUT.putStack( output = AEApi.instance().items().itemEncodedPattern.stack( 1 ) );
}
// encode the slot.
NBTTagCompound encodedValue = new NBTTagCompound();
NBTTagList tagIn = new NBTTagList();
NBTTagList tagOut = new NBTTagList();
for (ItemStack i : in)
tagIn.appendTag( createItemTag( i ) );
for (ItemStack i : out)
tagOut.appendTag( createItemTag( i ) );
encodedValue.setTag( "in", tagIn );
encodedValue.setTag( "out", tagOut );
encodedValue.setBoolean( "crafting", craftingMode );
output.setTagCompound( encodedValue );
}
private NBTBase createItemTag(ItemStack i)
{
NBTTagCompound c = new NBTTagCompound();
if ( i != null )
i.writeToNBT( c );
return c;
}
private ItemStack[] getInputs()
{
ItemStack[] input = new ItemStack[9];
boolean hasValue = false;
for (int x = 0; x < craftingSlots.length; x++)
{
input[x] = craftingSlots[x].getStack();
if ( input[x] != null )
hasValue = true;
}
if ( hasValue )
return input;
return null;
}
private ItemStack[] getOutputs()
{
if ( craftingMode )
{
ItemStack out = getAndUpdateOutput();
if ( out != null && out.stackSize > 0 )
return new ItemStack[] { out };
}
else
{
List<ItemStack> list = new ArrayList( 3 );
boolean hasValue = false;
for (int x = 0; x < outputSlots.length; x++)
{
ItemStack out = outputSlots[x].getStack();
if ( out != null && out.stackSize > 0 )
{
list.add( out );
hasValue = true;
}
}
if ( hasValue )
return list.toArray( new ItemStack[list.size()] );
}
return null;
}
private boolean isPattern(ItemStack output)
{
if ( output == null )
return false;
return AEApi.instance().items().itemEncodedPattern.sameAsStack( output ) || AEApi.instance().materials().materialBlankPattern.sameAsStack( output );
}
@Override
public boolean isSlotEnabled(int idx)
{
if ( idx == 1 )
return Platform.isServer() ? ct.isCraftingRecipe() == false : craftingMode == false;
if ( idx == 2 )
return Platform.isServer() ? ct.isCraftingRecipe() == true : craftingMode == true;
return false;
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
}
public void craftOrGetItem(PacketPatternSlot packetPatternSlot)
{
if ( packetPatternSlot.slotItem != null && cellInv != null )
{
IAEItemStack out = packetPatternSlot.slotItem.copy();
InventoryAdaptor inv = new AdaptorPlayerHand( getPlayerInv().player );
InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( getPlayerInv().player, ForgeDirection.UNKNOWN );
if ( packetPatternSlot.shift )
inv = playerInv;
if ( inv.simulateAdd( out.getItemStack() ) != null )
return;
IAEItemStack extracted = Platform.poweredExtraction( powerSrc, cellInv, out, mySrc );
EntityPlayer p = getPlayerInv().player;
if ( extracted != null )
{
inv.addItems( extracted.getItemStack() );
if ( p instanceof EntityPlayerMP )
updateHeld( (EntityPlayerMP) p );
detectAndSendChanges();
return;
}
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
InventoryCrafting real = new InventoryCrafting( new ContainerNull(), 3, 3 );
for (int x = 0; x < 9; x++)
{
ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
}
IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );
if ( r == null )
return;
IMEMonitor<IAEItemStack> storage = ct.getItemInventory();
IItemList<IAEItemStack> all = storage.getStorageList();
ItemStack is = r.getCraftingResult( ic );
if ( r != null && inv != null )
{
for (int x = 0; x < ic.getSizeInventory(); x++)
{
if ( ic.getStackInSlot( x ) != null )
{
ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all,
Actionable.MODULATE, ItemViewCell.createFilter( getViewCells() ) );
real.setInventorySlotContents( x, pulled );
}
}
}
IRecipe rr = Platform.findMatchingRecipe( real, p.worldObj );
if ( rr == r && Platform.isSameItemPrecise( rr.getCraftingResult( real ), is ) )
{
SlotCrafting sc = new SlotCrafting( p, real, cOut, 0, 0, 0 );
sc.onPickupFromSlot( p, is );
for (int x = 0; x < real.getSizeInventory(); x++)
{
ItemStack failed = playerInv.addItems( real.getStackInSlot( x ) );
if ( failed != null )
p.dropPlayerItemWithRandomChoice( failed, false );
}
inv.addItems( is );
if ( p instanceof EntityPlayerMP )
updateHeld( (EntityPlayerMP) p );
detectAndSendChanges();
}
else
{
for (int x = 0; x < real.getSizeInventory(); x++)
{
ItemStack failed = real.getStackInSlot( x );
if ( failed != null )
{
cellInv.injectItems( AEItemStack.create( failed ), Actionable.MODULATE, new MachineSource( ct ) );
}
}
}
}
}
@Override
public void onSlotChange(Slot s)
{
if ( s == patternSlotOUT && Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
for (Object g : inventorySlots)
{
if ( g instanceof OptionalSlotFake || g instanceof SlotFakeCraftingMatrix )
{
Slot sri = (Slot) g;
icrafting.sendSlotContents( this, sri.slotNumber, sri.getStack() );
}
}
((EntityPlayerMP) icrafting).isChangingQuantityOnly = false;
}
detectAndSendChanges();
}
}
public void clear()
{
for (Slot s : craftingSlots)
s.putStack( null );
for (Slot s : outputSlots)
s.putStack( null );
detectAndSendChanges();
getAndUpdateOutput();
}
@Override
public IInventory getInventoryByName(String name)
{
return ct.getInventoryByName( name );
}
@Override
public boolean useRealItems()
{
return false;
}
}
@@ -0,0 +1,68 @@
package appeng.container.implementations;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity;
import appeng.api.config.SecurityPermissions;
import appeng.api.parts.IPart;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.helpers.IPriorityHost;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerPriority extends AEBaseContainer
{
IPriorityHost priHost;
@SideOnly(Side.CLIENT)
public GuiTextField textField;
@SideOnly(Side.CLIENT)
public void setTextField(GuiTextField level)
{
textField = level;
textField.setText( "" + PriorityValue );
}
public ContainerPriority(InventoryPlayer ip, IPriorityHost te) {
super( ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null) );
priHost = te;
}
@GuiSync(2)
public long PriorityValue = -1;
public void setPriority(int newValue, EntityPlayer player)
{
priHost.setPriority( newValue );
PriorityValue = newValue;
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.PriorityValue = priHost.getPriority();
}
}
@Override
public void onUpdate(String field, Object oldValue, Object newValue)
{
if ( field.equals( "PriorityValue" ) )
{
if ( textField != null )
textField.setText( "" + PriorityValue );
}
super.onUpdate( field, oldValue, newValue );
}
}
@@ -0,0 +1,22 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.qnb.TileQuantumBridge;
public class ContainerQNB extends AEBaseContainer
{
TileQuantumBridge myte;
public ContainerQNB(InventoryPlayer ip, TileQuantumBridge te) {
super( ip, te, null );
myte = te;
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, te, 0, 80, 37, invPlayer )).setStackLimit( 1 ) );
bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 );
}
}
@@ -0,0 +1,205 @@
package appeng.container.implementations;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import appeng.api.AEApi;
import appeng.container.AEBaseContainer;
import appeng.container.slot.QuartzKnifeOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.contents.QuartzKnifeObj;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngInventory, IInventory
{
QuartzKnifeObj toolInv;
AppEngInternalInventory inSlot = new AppEngInternalInventory( this, 1 );
SlotRestrictedInput metals;
QuartzKnifeOutput output;
String myName = "";
public void setName(String value)
{
myName = value;
}
public ContainerQuartzKnife(InventoryPlayer ip, QuartzKnifeObj te) {
super( ip, null, null );
toolInv = te;
addSlotToContainer( metals = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, inSlot, 0, 94, 44, ip ) );
addSlotToContainer( output = new QuartzKnifeOutput( this, 0, 134, 44, -1 ) );
lockPlayerInventorySlot( ip.currentItem );
bindPlayerInventory( ip, 0, 184 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
ItemStack currentItem = getPlayerInv().getCurrentItem();
if ( currentItem != toolInv.getItemStack() )
{
if ( currentItem != null )
{
if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) )
getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() );
else
isContainerValid = false;
}
else
isContainerValid = false;
}
super.detectAndSendChanges();
}
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
if ( inSlot.getStackInSlot( 0 ) != null )
par1EntityPlayer.dropPlayerItemWithRandomChoice( inSlot.getStackInSlot( 0 ), false );
}
@Override
public void saveChanges()
{
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int var1)
{
ItemStack input = inSlot.getStackInSlot( 0 );
if ( input == null )
return null;
if ( SlotRestrictedInput.isMetalIngot( input ) )
{
if ( myName.length() > 0 )
{
ItemStack name = AEApi.instance().materials().materialNamePress.stack( 1 );
NBTTagCompound c = Platform.openNbtData( name );
c.setString( "InscribeName", myName );
return name;
}
}
return null;
}
@Override
public ItemStack decrStackSize(int var1, int var2)
{
ItemStack is = getStackInSlot( 0 );
if ( is != null )
{
if ( makePlate() )
return is;
}
return null;
}
private boolean makePlate()
{
if ( inSlot.decrStackSize( 0, 1 ) != null )
{
ItemStack item = toolInv.getItemStack();
item.damageItem( 1, getPlayerInv().player );
if ( item.stackSize == 0 )
{
getPlayerInv().mainInventory[getPlayerInv().currentItem] = null;
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( getPlayerInv().player, item ) );
}
return true;
}
return false;
}
@Override
public ItemStack getStackInSlotOnClosing(int var1)
{
return null;
}
@Override
public void setInventorySlotContents(int var1, ItemStack var2)
{
if ( var2 == null && Platform.isServer() )
makePlate();
}
@Override
public String getInventoryName()
{
return "Quartz Knife Output";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void markDirty()
{
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1)
{
return false;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
@Override
public boolean isItemValidForSlot(int var1, ItemStack var2)
{
return false;
}
}
@@ -0,0 +1,148 @@
package appeng.container.implementations;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.features.INetworkEncodable;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.storage.ITerminalHost;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.tile.misc.TileSecurity;
public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppEngInventory
{
SlotRestrictedInput configSlot;
AppEngInternalInventory wirelessEncoder = new AppEngInternalInventory( this, 2 );
SlotRestrictedInput wirelessIn;
SlotOutput wirelessOut;
TileSecurity securityBox;
public ContainerSecurity(InventoryPlayer ip, ITerminalHost monitorable) {
super( ip, monitorable, false );
securityBox = (TileSecurity) monitorable;
addSlotToContainer( configSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.BIOMETRIC_CARD, securityBox.configSlot, 0, 37, -33, ip ) );
addSlotToContainer( wirelessIn = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODEABLE_ITEM, wirelessEncoder, 0, 212, 10, ip ) );
addSlotToContainer( wirelessOut = new SlotOutput( wirelessEncoder, 1, 212, 68, -1 ) );
bindPlayerInventory( ip, 0, 0 );
}
@GuiSync(0)
public int security = 0;
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed( player );
if ( wirelessIn.getHasStack() )
player.dropPlayerItemWithRandomChoice( wirelessIn.getStack(), false );
if ( wirelessOut.getHasStack() )
player.dropPlayerItemWithRandomChoice( wirelessOut.getStack(), false );
}
public void toggleSetting(String value, EntityPlayer player)
{
try
{
SecurityPermissions permission = SecurityPermissions.valueOf( value );
ItemStack a = configSlot.getStack();
if ( a != null && a.getItem() instanceof IBiometricCard )
{
IBiometricCard bc = (IBiometricCard) a.getItem();
if ( bc.hasPermission( a, permission ) )
bc.removePermission( a, permission );
else
bc.addPermission( a, permission );
}
}
catch (EnumConstantNotPresentException ex)
{
// :(
}
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.SECURITY, false );
security = 0;
ItemStack a = configSlot.getStack();
if ( a != null && a.getItem() instanceof IBiometricCard )
{
IBiometricCard bc = (IBiometricCard) a.getItem();
for (SecurityPermissions sp : bc.getPermissions( a ))
security = security | (1 << sp.ordinal());
}
updatePowerStatus();
super.detectAndSendChanges();
}
@Override
public void saveChanges()
{
// :P
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
{
if ( !wirelessOut.getHasStack() )
{
if ( wirelessIn.getHasStack() )
{
ItemStack term = wirelessIn.getStack().copy();
INetworkEncodable netEncodeable = null;
if ( term.getItem() instanceof INetworkEncodable )
netEncodeable = (INetworkEncodable) term.getItem();
IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless().getWirelessTerminalHandler( term );
if ( wTermHandler != null )
netEncodeable = wTermHandler;
if ( netEncodeable != null )
{
netEncodeable.setEncryptionKey( term, "" + securityBox.securityKey, "" );
wirelessIn.putStack( null );
wirelessOut.putStack( term );
// update the two slots in question...
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() );
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() );
}
}
}
}
}
}
@@ -0,0 +1,39 @@
package appeng.container.implementations;
import invtweaks.api.container.ChestContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotNormal;
import appeng.tile.storage.TileSkyChest;
@ChestContainer
public class ContainerSkyChest extends AEBaseContainer
{
TileSkyChest myte;
public ContainerSkyChest(InventoryPlayer ip, TileSkyChest te) {
super( ip, te, null );
myte = te;
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 9; x++)
{
addSlotToContainer( new SlotNormal( myte, y * 9 + x, 8 + 18 * x, 24 + 18 * y ) );
}
}
myte.openInventory();
bindPlayerInventory( ip, 0, 195 - /* height of playerinventory */82 );
}
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed( par1EntityPlayer );
myte.closeInventory();
}
}
@@ -0,0 +1,73 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.spatial.TileSpatialIOPort;
import appeng.util.Platform;
public class ContainerSpatialIOPort extends AEBaseContainer
{
TileSpatialIOPort myte;
IGrid network;
@GuiSync(0)
public long currentPower;
@GuiSync(1)
public long maxPower;
@GuiSync(2)
public long reqPower;
@GuiSync(3)
public long eff;
int delay = 40;
public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort te) {
super( ip, te, null );
myte = te;
if ( Platform.isServer() )
network = te.getGridNode( ForgeDirection.UNKNOWN ).getGrid();
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, te, 0, 52, 48, invPlayer ) );
addSlotToContainer( new SlotOutput( te, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
bindPlayerInventory( ip, 0, 197 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
delay++;
if ( delay > 15 && network != null )
{
delay = 0;
IEnergyGrid eg = network.getCache( IEnergyGrid.class );
ISpatialCache sc = network.getCache( ISpatialCache.class );
if ( eg != null )
{
currentPower = (long) (100.0 * eg.getStoredPower());
maxPower = (long) (100.0 * eg.getMaxStoredPower());
reqPower = (long) (100.0 * sc.requiredPower());
eff = (long) (100.0f * sc.currentEfficiency());
}
}
}
super.detectAndSendChanges();
}
}
@@ -0,0 +1,145 @@
package appeng.container.implementations;
import java.util.Iterator;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.FuzzyMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.config.Upgrades;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.parts.misc.PartStorageBus;
import appeng.util.Platform;
import appeng.util.iterators.NullIterator;
public class ContainerStorageBus extends ContainerUpgradeable
{
PartStorageBus storageBus;
@GuiSync(3)
public AccessRestriction rwMode = AccessRestriction.READ_WRITE;
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
public ContainerStorageBus(InventoryPlayer ip, PartStorageBus te) {
super( ip, te );
storageBus = te;
}
@Override
protected int getHeight()
{
return 251;
}
@Override
public int availableUpgrades()
{
return 5;
}
@Override
protected boolean supportCapacity()
{
return true;
}
@Override
public boolean isSlotEnabled(int idx)
{
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
return upgrades > idx;
}
@Override
protected void setupConfig()
{
int xo = 8;
int yo = 23 + 6;
IInventory config = myte.getInventoryByName( "config" );
for (int y = 0; y < 7; y++)
{
for (int x = 0; x < 9; x++)
{
if ( y < 2 )
addSlotToContainer( new SlotFakeTypeOnly( config, y * 9 + x, xo + x * 18, yo + y * 18 ) );
else
addSlotToContainer( new OptionalSlotFakeTypeOnly( config, this, y * 9 + x, xo, yo, x, y, y - 2 ) );
}
}
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 4, 187, 8 + 18 * 4, invPlayer )).setNotDraggable() );
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE );
this.rwMode = (AccessRestriction) this.myte.getConfigManager().getSetting( Settings.ACCESS );
this.storageFilter = (StorageFilter) this.myte.getConfigManager().getSetting( Settings.STORAGE_FILTER );
}
standardDetectAndSendChanges();
}
public void clear()
{
IInventory inv = myte.getInventoryByName( "config" );
for (int x = 0; x < inv.getSizeInventory(); x++)
inv.setInventorySlotContents( x, null );
detectAndSendChanges();
}
public void partition()
{
IInventory inv = myte.getInventoryByName( "config" );
IMEInventory<IAEItemStack> cellInv = storageBus.getInternalHandler();
Iterator<IAEItemStack> i = new NullIterator<IAEItemStack>();
if ( cellInv != null )
{
IItemList<IAEItemStack> list = cellInv.getAvailableItems( AEApi.instance().storage().createItemList() );
i = list.iterator();
}
for (int x = 0; x < inv.getSizeInventory(); x++)
{
if ( i.hasNext() && isSlotEnabled( (x / 9) - 2 ) )
{
ItemStack g = i.next().getItemStack();
g.stackSize = 1;
inv.setInventorySlotContents( x, g );
}
else
inv.setInventorySlotContents( x, null );
}
detectAndSendChanges();
}
}
@@ -0,0 +1,227 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.parts.IPart;
import appeng.api.util.IConfigManager;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.items.contents.NetworkToolViewer;
import appeng.items.tools.ToolNetworkTool;
import appeng.parts.automation.PartExportBus;
import appeng.util.Platform;
public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost
{
IUpgradeableHost myte;
int tbslot;
NetworkToolViewer tbinv;
public ContainerUpgradeable(InventoryPlayer ip, IUpgradeableHost te) {
super( ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null) );
myte = te;
World w = null;
int xCoor = 0, yCoor = 0, zCoor = 0;
if ( te instanceof TileEntity )
{
TileEntity myTile = (TileEntity) te;
w = myTile.getWorldObj();
xCoor = myTile.xCoord;
yCoor = myTile.yCoord;
zCoor = myTile.zCoord;
}
if ( te instanceof IPart )
{
IUpgradeableHost myTile = (IUpgradeableHost) te;
TileEntity mk = myTile.getTile();
w = mk.getWorldObj();
xCoor = mk.xCoord;
yCoor = mk.yCoord;
zCoor = mk.zCoord;
}
IInventory pi = getPlayerInv();
for (int x = 0; x < pi.getSizeInventory(); x++)
{
ItemStack pii = pi.getStackInSlot( x );
if ( pii != null && pii.getItem() instanceof ToolNetworkTool )
{
lockPlayerInventorySlot( x );
tbslot = x;
tbinv = (NetworkToolViewer) ((ToolNetworkTool) pii.getItem()).getGuiObject( pii, w, xCoor, yCoor, zCoor );
break;
}
}
if ( hasToolbox() )
{
for (int v = 0; v < 3; v++)
for (int u = 0; u < 3; u++)
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, tbinv, u + v * 3, 186 + u * 18, getHeight() - 82 + v * 18,
invPlayer )).setPlayerSide() );
}
setupConfig();
bindPlayerInventory( ip, 0, getHeight() - /* height of playerinventory */82 );
}
protected void setupUpgrades()
{
IInventory upgrades = myte.getInventoryByName( "upgrades" );
if ( availableUpgrades() > 0 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 1 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 2 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
if ( availableUpgrades() > 3 )
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
}
protected void setupConfig()
{
int x = 80;
int y = 40;
setupUpgrades();
IInventory inv = myte.getInventoryByName( "config" );
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
if ( supportCapacity() )
{
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
}
}
protected int getHeight()
{
return 184;
}
public int availableUpgrades()
{
return 4;
}
protected boolean supportCapacity()
{
return true;
}
@GuiSync(0)
public RedstoneMode rsMode = RedstoneMode.IGNORE;
@GuiSync(1)
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
@GuiSync(5)
public YesNo cMode = YesNo.NO;
public void checkToolbox()
{
if ( hasToolbox() )
{
ItemStack currentItem = getPlayerInv().getStackInSlot( tbslot );
if ( currentItem != tbinv.getItemStack() )
{
if ( currentItem != null )
{
if ( Platform.isSameItem( tbinv.getItemStack(), currentItem ) )
getPlayerInv().setInventorySlotContents( tbslot, tbinv.getItemStack() );
else
isContainerValid = false;
}
else
isContainerValid = false;
}
}
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
IConfigManager cm = this.myte.getConfigManager();
loadSettingsFromHost( cm );
}
checkToolbox();
for (Object o : inventorySlots)
{
if ( o instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) o;
if ( !fs.isEnabled() && fs.getDisplayStack() != null )
((OptionalSlotFake) fs).clearStack();
}
}
standardDetectAndSendChanges();
}
protected void loadSettingsFromHost(IConfigManager cm)
{
this.fzMode = (FuzzyMode) cm.getSetting( Settings.FUZZY_MODE );
this.rsMode = (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED );
if ( myte instanceof PartExportBus )
this.cMode = (YesNo) cm.getSetting( Settings.CRAFT_ONLY );
}
protected void standardDetectAndSendChanges()
{
super.detectAndSendChanges();
}
public boolean hasToolbox()
{
return tbinv != null;
}
@Override
public boolean isSlotEnabled(int idx)
{
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
if ( idx == 1 && upgrades > 0 )
return true;
if ( idx == 2 && upgrades > 1 )
return true;
return false;
}
}
@@ -0,0 +1,44 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.misc.TileVibrationChamber;
import appeng.util.Platform;
public class ContainerVibrationChamber extends AEBaseContainer
{
TileVibrationChamber myte;
public ContainerVibrationChamber(InventoryPlayer ip, TileVibrationChamber te) {
super( ip, te, null );
myte = te;
addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, te, 0, 80, 37, invPlayer ) );
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
}
public int aePerTick = 5;
@GuiSync(0)
public int burnProgress = 0;
@GuiSync(1)
public int burnSpeed = 100;
@Override
public void detectAndSendChanges()
{
if ( Platform.isServer() )
{
this.burnProgress = (int) (this.myte.maxBurnTime <= 0 ? 0 : 12 * this.myte.burnTime / this.myte.maxBurnTime);
this.burnSpeed = this.myte.burnSpeed;
}
super.detectAndSendChanges();
}
}
@@ -0,0 +1,43 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.AEConfig;
import appeng.tile.networking.TileWireless;
public class ContainerWireless extends AEBaseContainer
{
TileWireless myte;
@GuiSync(1)
public long range = 0;
@GuiSync(2)
public long drain = 0;
SlotRestrictedInput boosterSlot;
public ContainerWireless(InventoryPlayer ip, TileWireless te) {
super( ip, te, null );
myte = te;
addSlotToContainer( boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, myte, 0, 80, 47, invPlayer ) );
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
int boosters = boosterSlot.getStack() == null ? 0 : boosterSlot.getStack().stackSize;
range = (long) (10 * AEConfig.instance.wireless_getMaxRange( boosters ));
drain = (long) (100 * AEConfig.instance.wireless_getPowerDrain( boosters ));
super.detectAndSendChanges();
}
}
@@ -0,0 +1,36 @@
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import appeng.core.AEConfig;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.util.Platform;
public class ContainerWirelessTerm extends ContainerMEPortableCell
{
WirelessTerminalGuiObject wtgo;
public ContainerWirelessTerm(InventoryPlayer ip, WirelessTerminalGuiObject monitorable) {
super( ip, monitorable );
wtgo = monitorable;
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
if ( !wtgo.rangeCheck() )
{
if ( Platform.isServer() && isContainerValid )
getPlayerInv().player.addChatMessage( PlayerMessages.OutOfRange.get() );
isContainerValid = false;
}
else
{
powerMultiplier = AEConfig.instance.wireless_getDrainRate( wtgo.getRange() );
}
}
}
@@ -0,0 +1,32 @@
package appeng.container.implementations;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.util.ItemSorters;
public class CraftingCPURecord implements Comparable<CraftingCPURecord>
{
ICraftingCPU cpu;
long size;
int processors;
public String myName;
public CraftingCPURecord(long size, int proc, ICraftingCPU server) {
this.size = size;
this.processors = proc;
this.cpu = server;
myName = server.getName();
}
@Override
public int compareTo(CraftingCPURecord o)
{
int a = ItemSorters.compareLong( o.processors, processors );
if ( a != 0 )
return a;
return ItemSorters.compareLong( o.size, size );
}
}
@@ -0,0 +1,167 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.stats.AchievementList;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import cpw.mods.fml.common.FMLCommonHandler;
public class AppEngCraftingSlot extends AppEngSlot
{
/** The craft matrix inventory linked to this result slot. */
private final IInventory craftMatrix;
/** The player that is using the GUI where this slot resides. */
private EntityPlayer thePlayer;
/**
* The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
*/
private int amountCrafted;
public AppEngCraftingSlot(EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6) {
super( par3IInventory, par4, par5, par6 );
this.thePlayer = par1EntityPlayer;
this.craftMatrix = par2IInventory;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int par1)
{
if ( this.getHasStack() )
{
this.amountCrafted += Math.min( par1, this.getStack().stackSize );
}
return super.decrStackSize( par1 );
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack par1ItemStack, int par2)
{
this.amountCrafted += par2;
this.onCrafting( par1ItemStack );
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack par1ItemStack)
{
par1ItemStack.onCrafting( this.thePlayer.worldObj, this.thePlayer, this.amountCrafted );
this.amountCrafted = 0;
if ( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.crafting_table ) )
{
this.thePlayer.addStat( AchievementList.buildWorkBench, 1 );
}
if ( par1ItemStack.getItem() instanceof ItemPickaxe )
{
this.thePlayer.addStat( AchievementList.buildPickaxe, 1 );
}
if ( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.furnace ) )
{
this.thePlayer.addStat( AchievementList.buildFurnace, 1 );
}
if ( par1ItemStack.getItem() instanceof ItemHoe )
{
this.thePlayer.addStat( AchievementList.buildHoe, 1 );
}
if ( par1ItemStack.getItem() == Items.bread )
{
this.thePlayer.addStat( AchievementList.makeBread, 1 );
}
if ( par1ItemStack.getItem() == Items.cake )
{
this.thePlayer.addStat( AchievementList.bakeCake, 1 );
}
if ( par1ItemStack.getItem() instanceof ItemPickaxe && ((ItemPickaxe) par1ItemStack.getItem()).func_150913_i() != Item.ToolMaterial.WOOD )
{
this.thePlayer.addStat( AchievementList.buildBetterPickaxe, 1 );
}
if ( par1ItemStack.getItem() instanceof ItemSword )
{
this.thePlayer.addStat( AchievementList.buildSword, 1 );
}
if ( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.enchanting_table ) )
{
this.thePlayer.addStat( AchievementList.enchantments, 1 );
}
if ( par1ItemStack.getItem() == Item.getItemFromBlock( Blocks.bookshelf ) )
{
this.thePlayer.addStat( AchievementList.bookcase, 1 );
}
}
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
{
FMLCommonHandler.instance().firePlayerCraftingEvent( par1EntityPlayer, par2ItemStack, craftMatrix );
this.onCrafting( par2ItemStack );
for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
{
ItemStack itemstack1 = this.craftMatrix.getStackInSlot( i );
if ( itemstack1 != null )
{
this.craftMatrix.decrStackSize( i, 1 );
if ( itemstack1.getItem().hasContainerItem( itemstack1 ) )
{
ItemStack itemstack2 = itemstack1.getItem().getContainerItem( itemstack1 );
if ( itemstack2 != null && itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage() )
{
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( thePlayer, itemstack2 ) );
continue;
}
if ( !itemstack1.getItem().doesContainerItemLeaveCraftingGrid( itemstack1 )
|| !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) )
{
if ( this.craftMatrix.getStackInSlot( i ) == null )
{
this.craftMatrix.setInventorySlotContents( i, itemstack2 );
}
else
{
this.thePlayer.dropPlayerItemWithRandomChoice( itemstack2, false );
}
}
}
}
}
}
}
@@ -0,0 +1,154 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.container.AEBaseContainer;
import appeng.tile.inventory.AppEngInternalInventory;
public class AppEngSlot extends Slot
{
public enum hasCalculatedValidness
{
NotAvailable, Valid, Invalid
};
public boolean isDraggable = true;
public boolean isPlayerSide = false;
public AEBaseContainer myContainer = null;
public Slot setNotDraggable()
{
isDraggable = false;
return this;
}
public Slot setPlayerSide()
{
isPlayerSide = true;
return this;
}
public int IIcon = -1;
public hasCalculatedValidness isValid;
public int defX, defY;
@Override
public boolean func_111238_b()
{
return isEnabled();
}
public boolean isEnabled()
{
return true;
}
public String getTooltip()
{
return null;
}
@Override
public void onSlotChanged()
{
if ( inventory instanceof AppEngInternalInventory )
((AppEngInternalInventory) inventory).markDirty( getSlotIndex() );
else
super.onSlotChanged();
isValid = hasCalculatedValidness.NotAvailable;
}
public AppEngSlot(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
defX = x;
defY = y;
isValid = hasCalculatedValidness.NotAvailable;
}
public boolean isDisplay = false;
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
return null;
if ( inventory.getSizeInventory() <= getSlotIndex() )
return null;
if ( isDisplay )
{
isDisplay = false;
return getDisplayStack();
}
return super.getStack();
}
@Override
public void putStack(ItemStack par1ItemStack)
{
if ( isEnabled() )
{
super.putStack( par1ItemStack );
if ( myContainer != null )
myContainer.onSlotChange( this );
}
}
public void clearStack()
{
super.putStack( null );
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
if ( isEnabled() )
return super.canTakeStack( par1EntityPlayer );
return false;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
if ( isEnabled() )
return super.isItemValid( par1ItemStack );
return false;
}
public ItemStack getDisplayStack()
{
return super.getStack();
}
public float getOpacityOfIcon()
{
return 0.4f;
}
public boolean renderIconWithItem()
{
return false;
}
public int getIcon()
{
return IIcon;
}
public boolean isPlayerSide()
{
return isPlayerSide;
}
public boolean shouldDisplay()
{
return isEnabled();
}
}
@@ -0,0 +1,8 @@
package appeng.container.slot;
public interface IOptionalSlotHost
{
boolean isSlotEnabled(int idx);
}
@@ -0,0 +1,80 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class NullSlot extends Slot
{
public NullSlot() {
super( null, 0, 0, 0 );
}
@Override
public void onSlotChange(ItemStack par1ItemStack, ItemStack par2ItemStack)
{
}
@Override
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
{
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
@Override
public ItemStack getStack()
{
return null;
}
@Override
public void putStack(ItemStack par1ItemStack)
{
}
@Override
public void onSlotChanged()
{
}
@Override
public int getSlotStackLimit()
{
return 0;
}
@Override
public ItemStack decrStackSize(int par1)
{
return null;
}
@Override
public boolean isSlotInInventory(IInventory par1IInventory, int par2)
{
return false;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return false;
}
@Override
public int getSlotIndex()
{
return 0;
}
}
@@ -0,0 +1,53 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFake extends SlotFake
{
int invSlot;
final int groupNum;
IOptionalSlotHost host;
public boolean renderDisabled = true;
public int srcX;
public int srcY;
public OptionalSlotFake(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, idx, x + offX * 18, y + offY * 18 );
srcX = x;
srcY = y;
invSlot = idx;
this.groupNum = groupNum;
host = containerBus;
}
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
{
if ( getDisplayStack() != null )
clearStack();
}
return super.getStack();
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum );
}
public boolean renderDisabled()
{
return renderDisabled;
}
}
@@ -0,0 +1,27 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFakeTypeOnly extends OptionalSlotFake
{
public OptionalSlotFakeTypeOnly(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@Override
public void putStack(ItemStack is)
{
if ( is != null )
{
is = is.copy();
if ( is.stackSize > 1 )
is.stackSize = 1;
else if ( is.stackSize < -1 )
is.stackSize = -1;
}
super.putStack( is );
}
}
@@ -0,0 +1,26 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class OptionalSlotNormal extends AppEngSlot
{
final int groupNum;
IOptionalSlotHost host;
public OptionalSlotNormal(IInventory inv, IOptionalSlotHost containerBus, int slot, int xPos, int yPos, int groupNum) {
super( inv, slot, xPos, yPos );
this.groupNum = groupNum;
host = containerBus;
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum );
}
}
@@ -0,0 +1,28 @@
package appeng.container.slot;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
public class OptionalSlotRestrictedInput extends SlotRestrictedInput
{
final int groupNum;
IOptionalSlotHost host;
public OptionalSlotRestrictedInput(PlacableItemType valid, IInventory i, IOptionalSlotHost host, int slotnum, int x, int y, int grpNum,
InventoryPlayer invPlayer) {
super( valid, i, slotnum, x, y, invPlayer );
this.groupNum = grpNum;
this.host = host;
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum );
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class QuartzKnifeOutput extends SlotOutput
{
public QuartzKnifeOutput(IInventory a, int b, int c, int d, int i) {
super( a, b, c, d, i );
}
}
@@ -0,0 +1,45 @@
package appeng.container.slot;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotCraftingMatrix extends AppEngSlot
{
Container c;
public SlotCraftingMatrix(Container c, IInventory par1iInventory, int par2, int par3, int par4) {
super( par1iInventory, par2, par3, par4 );
this.c = c;
}
@Override
public boolean isPlayerSide()
{
return true;
}
@Override
public void clearStack()
{
super.clearStack();
c.onCraftMatrixChanged( inventory );
}
@Override
public ItemStack decrStackSize(int par1)
{
ItemStack is = super.decrStackSize( par1 );
c.onCraftMatrixChanged( inventory );
return is;
}
@Override
public void putStack(ItemStack par1ItemStack)
{
super.putStack( par1ItemStack );
c.onCraftMatrixChanged( inventory );
}
}
@@ -0,0 +1,236 @@
package appeng.container.slot;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.item.AEItemStack;
public class SlotCraftingTerm extends AppEngCraftingSlot
{
protected final IInventory craftInv;
protected final IInventory pattern;
private final BaseActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix,
IInventory secondMatrix, IInventory output, int x, int y, IContainerCraftingPacket ccp)
{
super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc;
this.storage = storage;
this.mySrc = mySrc;
pattern = cMatrix;
craftInv = secondMatrix;
container = ccp;
}
public IInventory getCraftingMatrix()
{
return craftInv;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer p, ItemStack is)
{
}
public void makeItem(EntityPlayer p, ItemStack is)
{
super.onPickupFromSlot( p, is );
}
public ItemStack craftItem(EntityPlayer p, ItemStack request, IMEMonitor<IAEItemStack> inv, IItemList all)
{
// update crafting matrix...
ItemStack is = getStack();
if ( is != null && Platform.isSameItem( request, is ) )
{
ItemStack[] set = new ItemStack[pattern.getSizeInventory()];
// add one of each item to the items on the board...
if ( Platform.isServer() )
{
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
for (int x = 0; x < 9; x++)
ic.setInventorySlotContents( x, pattern.getStackInSlot( x ) );
IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );
if ( r == null )
{
Item target = request.getItem();
if ( target.isDamageable() && target.isRepairable() )
{
boolean isBad = false;
for (int x = 0; x < ic.getSizeInventory(); x++)
{
ItemStack pis = ic.getStackInSlot( x );
if ( pis == null )
continue;
if ( pis.getItem() != target )
isBad = true;
}
if ( !isBad )
{
super.onPickupFromSlot( p, is );
return request;
}
}
return null;
}
is = r.getCraftingResult( ic );
if ( r != null && inv != null )
{
for (int x = 0; x < pattern.getSizeInventory(); x++)
{
if ( pattern.getStackInSlot( x ) != null )
{
set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all,
Actionable.MODULATE, ItemViewCell.createFilter( container.getViewCells() ) );
ic.setInventorySlotContents( x, set[x] );
}
}
}
}
if ( preCraft( p, inv, set, is ) )
{
makeItem( p, is );
postCraft( p, inv, set, is );
}
// shouldn't be necessary...
p.openContainer.onCraftMatrixChanged( getCraftingMatrix() );
return is;
}
return null;
}
public boolean preCraft(EntityPlayer p, IMEMonitor<IAEItemStack> inv, ItemStack[] set, ItemStack result)
{
return true;
}
public void postCraft(EntityPlayer p, IMEMonitor<IAEItemStack> inv, ItemStack set[], ItemStack result)
{
List<ItemStack> drops = new ArrayList();
// add one of each item to the items on the board...
if ( Platform.isServer() )
{
// set new items onto the crafting table...
for (int x = 0; x < getCraftingMatrix().getSizeInventory(); x++)
{
if ( getCraftingMatrix().getStackInSlot( x ) == null )
getCraftingMatrix().setInventorySlotContents( x, set[x] );
else if ( set[x] != null )
{
// eek! put it back!
IAEItemStack fail = inv.injectItems( AEItemStack.create( set[x] ), Actionable.MODULATE, mySrc );
if ( fail != null )
drops.add( fail.getItemStack() );
}
}
}
if ( drops.size() > 0 )
Platform.spawnDrops( p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ, drops );
}
public void doClick(InventoryAction action, EntityPlayer who)
{
if ( getStack() == null )
return;
if ( Platform.isClient() )
return;
IMEMonitor<IAEItemStack> inv = storage.getItemInventory();
int howManyPerCraft = getStack().stackSize;
int maxTimesToCraft = 0;
InventoryAdaptor ia = null;
if ( action == InventoryAction.CRAFT_SHIFT ) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor( who, null );
maxTimesToCraft = (int) Math.floor( (double) getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else if ( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack
{
ia = new AdaptorPlayerHand( who );
maxTimesToCraft = (int) Math.floor( (double) getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else
// pick up what was crafted...
{
ia = new AdaptorPlayerHand( who );
maxTimesToCraft = 1;
}
maxTimesToCraft = CapCraftingAttempts( maxTimesToCraft );
if ( ia == null )
return;
ItemStack rs = Platform.cloneItemStack( getStack() );
if ( rs == null )
return;
for (int x = 0; x < maxTimesToCraft; x++)
{
if ( ia.simulateAdd( rs ) == null )
{
IItemList<IAEItemStack> all = inv.getStorageList();
ItemStack extra = ia.addItems( craftItem( who, rs, inv, all ) );
if ( extra != null )
{
List<ItemStack> drops = new ArrayList();
drops.add( extra );
Platform.spawnDrops( who.worldObj, (int) who.posX, (int) who.posY, (int) who.posZ, drops );
return;
}
}
}
}
protected int CapCraftingAttempts(int maxTimesToCraft)
{
return maxTimesToCraft;
}
}
@@ -0,0 +1,25 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotDisabled extends AppEngSlot
{
public SlotDisabled(IInventory par1iInventory, int slotIndex, int x, int y) {
super( par1iInventory, slotIndex, x, y );
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return false;
}
}
@@ -0,0 +1,49 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotFake extends AppEngSlot
{
int invSlot;
public SlotFake(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
invSlot = idx;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return false;
}
@Override
public ItemStack decrStackSize(int par1)
{
return null;
}
@Override
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
{
}
@Override
public void putStack(ItemStack is)
{
if ( is != null )
is = is.copy();
super.putStack( is );
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
}
@@ -0,0 +1,34 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotFakeBlacklist extends SlotFakeTypeOnly
{
public SlotFakeBlacklist(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
}
@Override
public boolean renderIconWithItem()
{
return true;
}
@Override
public float getOpacityOfIcon()
{
return 0.8f;
}
@Override
public int getIcon()
{
if ( getHasStack() )
{
return getStack().stackSize > 0 ? 16 + 14 : 14;
}
return -1;
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotFakeCraftingMatrix extends SlotFake
{
public SlotFakeCraftingMatrix(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
}
}
@@ -0,0 +1,27 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotFakeTypeOnly extends SlotFake
{
public SlotFakeTypeOnly(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
}
@Override
public void putStack(ItemStack is)
{
if ( is != null )
{
is = is.copy();
if ( is.stackSize > 1 )
is.stackSize = 1;
else if ( is.stackSize < -1 )
is.stackSize = -1;
}
super.putStack( is );
}
}
@@ -0,0 +1,47 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotInaccessible extends AppEngSlot
{
public SlotInaccessible(IInventory i, int slotIdx, int x, int y) {
super( i, slotIdx, x, y );
}
ItemStack dspStack = null;
@Override
public ItemStack getDisplayStack()
{
if ( dspStack == null )
{
ItemStack dsp = super.getDisplayStack();
if ( dsp != null )
dspStack = dsp.copy();
}
return dspStack;
}
@Override
public void onSlotChanged()
{
super.onSlotChanged();
dspStack = null;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return false;
}
@Override
public boolean isItemValid(ItemStack i)
{
return false;
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotInaccessibleHD extends SlotInaccessible
{
public SlotInaccessibleHD(IInventory i, int slotIdx, int x, int y) {
super( i, slotIdx, x, y );
}
}
@@ -0,0 +1,23 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.container.implementations.ContainerMAC;
public class SlotMACPattern extends AppEngSlot
{
ContainerMAC mac;
public SlotMACPattern(ContainerMAC mac, IInventory i, int slotIdx, int x, int y) {
super( i, slotIdx, x, y );
this.mac = mac;
}
@Override
public boolean isItemValid(ItemStack i)
{
return mac.isValidItemForSlot( this.getSlotIndex(), i );
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotNormal extends AppEngSlot
{
public SlotNormal(IInventory inv, int slot, int xPos, int yPos) {
super( inv, slot, xPos, yPos );
}
}
@@ -0,0 +1,19 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class SlotOutput extends AppEngSlot
{
public SlotOutput(IInventory a, int b, int c, int d, int i) {
super( a, b, c, d );
IIcon = i;
}
@Override
public boolean isItemValid(ItemStack i)
{
return false;
}
}
@@ -0,0 +1,23 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotPatternOutputs extends OptionalSlotFake
{
public SlotPatternOutputs(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@Override
public boolean isEnabled()
{
return true;
}
@Override
public boolean shouldDisplay()
{
return super.isEnabled();
}
}
@@ -0,0 +1,58 @@
package appeng.container.slot;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IStorageMonitorable;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
public class SlotPatternTerm extends SlotCraftingTerm
{
int groupNum;
IOptionalSlotHost host;
public SlotPatternTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix,
IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum, IContainerCraftingPacket c)
{
super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c );
host = h;
groupNum = grpnum;
}
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
{
if ( getDisplayStack() != null )
clearStack();
}
return super.getStack();
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum );
}
public AppEngPacket getRequest(boolean shift) throws IOException
{
return new PacketPatternSlot( this.pattern, AEApi.instance().storage().createItemStack( getStack() ), shift );
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotPlayerHotBar extends AppEngSlot
{
public SlotPlayerHotBar(IInventory par1iInventory, int par2, int par3, int par4) {
super( par1iInventory, par2, par3, par4 );
isPlayerSide = true;
}
}
@@ -0,0 +1,15 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
// there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot.
public class SlotPlayerInv extends AppEngSlot
{
public SlotPlayerInv(IInventory par1iInventory, int par2, int par3, int par4) {
super( par1iInventory, par2, par3, par4 );
;
isPlayerSide = true;
}
}
@@ -0,0 +1,238 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.AEApi;
import appeng.api.IAppEngApi;
import appeng.api.features.INetworkEncodable;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.items.IBiometricCard;
import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.implementations.items.IStorageComponent;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.ICellWorkbenchItem;
import appeng.items.misc.ItemEncodedPattern;
import appeng.recipes.handlers.Inscribe;
import appeng.util.Platform;
public class SlotRestrictedInput extends AppEngSlot
{
public enum PlacableItemType
{
STORAGE_CELLS(15), ORE(1 * 16 + 15), STORAGE_COMPONENT(3 * 16 + 15),
ENCODEABLE_ITEM(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15), ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15),
ENCODED_CRAFTING_PATTERN(7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), PATTERN(8 * 16 + 15), BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15),
RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARITY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15),
FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15), WORKBENCH_CELL(15), BIOMETRIC_CARD(14 * 16 + 15), VIEWCELL(4 * 16 + 14),
INSCRIBER_PLATE(2 * 16 + 14), INSCRIBER_INPUT(3 * 16 + 14), METAL_INGOTS(3 * 16 + 14);
public final int IIcon;
private PlacableItemType(int o) {
IIcon = o;
}
};
@Override
public int getSlotStackLimit()
{
if ( stackLimit != -1 )
return stackLimit;
return super.getSlotStackLimit();
}
public boolean isValid(ItemStack is, World theWorld)
{
if ( which == PlacableItemType.VALID_ENCODED_PATTERN_W_OUTPUT )
{
ICraftingPatternDetails ap = is.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem) is.getItem()).getPatternForItem( is, theWorld )
: null;
if ( ap != null )
return true;
return false;
}
return true;
}
public PlacableItemType which;
public boolean allowEdit = true;
public int stackLimit = -1;
private InventoryPlayer p;
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
return allowEdit;
}
public Slot setStackLimit(int i)
{
stackLimit = i;
return this;
}
public SlotRestrictedInput(PlacableItemType valid, IInventory i, int slotnum, int x, int y, InventoryPlayer p) {
super( i, slotnum, x, y );
which = valid;
IIcon = valid.IIcon;
this.p = p;
}
@Override
public ItemStack getDisplayStack()
{
if ( Platform.isClient() && (which == PlacableItemType.ENCODED_PATTERN) )
{
ItemStack is = super.getStack();
if ( is != null && is.getItem() instanceof ItemEncodedPattern )
{
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
ItemStack out = iep.getOutput( is );
if ( out != null )
return out;
}
}
return super.getStack();
}
@Override
public boolean isItemValid(ItemStack i)
{
if ( !myContainer.isValidForSlot( this, i ) )
return false;
if ( i == null )
return false;
if ( i.getItem() == null )
return false;
if ( !inventory.isItemValidForSlot( this.getSlotIndex(), i ) )
return false;
IAppEngApi api = AEApi.instance();
if ( !allowEdit )
return false;
switch (which)
{
case ENCODED_CRAFTING_PATTERN:
if ( i.getItem() instanceof ICraftingPatternItem )
{
ICraftingPatternItem b = (ICraftingPatternItem) i.getItem();
ICraftingPatternDetails de = b.getPatternForItem( i, p.player.worldObj );
if ( de != null )
return de.isCraftable();
}
return false;
case VALID_ENCODED_PATTERN_W_OUTPUT:
case ENCODED_PATTERN_W_OUTPUT:
case ENCODED_PATTERN: {
if ( i.getItem() instanceof ICraftingPatternItem )
return true;
// ICraftingPatternDetails pattern = i.getItem() instanceof ICraftingPatternItem ? ((ICraftingPatternItem)
// i.getItem()).getPatternForItem( i ) : null;
return false;// pattern != null;
}
case BLANK_PATTERN:
return AEApi.instance().materials().materialBlankPattern.sameAsStack( i );
case PATTERN:
if ( i.getItem() instanceof ICraftingPatternItem )
return true;
return AEApi.instance().materials().materialBlankPattern.sameAsStack( i );
case INSCRIBER_PLATE:
if ( AEApi.instance().materials().materialNamePress.sameAsStack( i ) )
return true;
for (ItemStack is : Inscribe.plates)
if ( Platform.isSameItemPrecise( is, i ) )
return true;
return false;
case INSCRIBER_INPUT:
return true;/*
* for (ItemStack is : Inscribe.inputs) if ( Platform.isSameItemPrecise( is, i ) ) return true;
*
* return false;
*/
case METAL_INGOTS:
return isMetalIngot( i );
case VIEWCELL:
return AEApi.instance().items().itemViewCell.sameAsStack( i );
case ORE:
return appeng.api.AEApi.instance().registries().grinder().getRecipeForInput( i ) != null;
case FUEL:
return TileEntityFurnace.getItemBurnTime( i ) > 0;
case POWERED_TOOL:
return Platform.isChargeable( i );
case QE_SINGULARITY:
return api.materials().materialQESingularity.sameAsStack( i );
case RANGE_BOOSTER:
return api.materials().materialWirelessBooster.sameAsStack( i );
case SPATIAL_STORAGE_CELLS:
return i.getItem() instanceof ISpatialStorageCell && ((ISpatialStorageCell) i.getItem()).isSpatialStorage( i );
case STORAGE_CELLS:
return AEApi.instance().registries().cell().isCellHandled( i );
case WORKBENCH_CELL:
return i != null && i.getItem() instanceof ICellWorkbenchItem && ((ICellWorkbenchItem) i.getItem()).isEditable( i );
case STORAGE_COMPONENT:
boolean isComp = i.getItem() instanceof IStorageComponent && ((IStorageComponent) i.getItem()).isStorageComponent( i );
return isComp;
case TRASH:
if ( AEApi.instance().registries().cell().isCellHandled( i ) )
return false;
if ( i.getItem() instanceof IStorageComponent && ((IStorageComponent) i.getItem()).isStorageComponent( i ) )
return false;
return true;
case ENCODEABLE_ITEM:
return i.getItem() instanceof INetworkEncodable || AEApi.instance().registries().wireless().isWirelessTerminal( i );
case BIOMETRIC_CARD:
return i.getItem() instanceof IBiometricCard;
case UPGRADES:
return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType( i ) != null;
default:
break;
}
return false;
}
static public boolean isMetalIngot(ItemStack i)
{
if ( Platform.isSameItemPrecise( i, new ItemStack( Items.iron_ingot ) ) )
return true;
for (String name : new String[] { "Copper", "Tin", "Obsidian", "Iron", "Lead", "Bronze", "Brass", "Nickel", "Aluminium" })
{
for (ItemStack ingot : OreDictionary.getOres( "ingot" + name ))
{
if ( Platform.isSameItemPrecise( i, ingot ) )
return true;
}
}
return false;
}
}