2013-12-27 23:59:59 +01:00
|
|
|
package appeng.container;
|
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
import java.io.ByteArrayInputStream;
|
2014-05-13 06:28:29 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
2014-02-10 01:56:35 +01:00
|
|
|
import java.io.IOException;
|
2014-05-07 07:22:42 +02:00
|
|
|
import java.lang.reflect.Field;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.ArrayList;
|
2014-05-07 07:22:42 +02:00
|
|
|
import java.util.HashMap;
|
2014-01-23 17:28:12 +01:00
|
|
|
import java.util.HashSet;
|
2014-02-27 04:56:00 +01:00
|
|
|
import java.util.LinkedList;
|
2013-12-27 23:59:59 +01:00
|
|
|
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.Container;
|
2014-05-07 07:22:42 +02:00
|
|
|
import net.minecraft.inventory.ICrafting;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-05-13 06:11:19 +02:00
|
|
|
import net.minecraft.nbt.CompressedStreamTools;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-01-30 02:20:48 +01:00
|
|
|
import appeng.api.config.Actionable;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.api.implementations.guiobjects.IGuiItemObject;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.energy.IEnergySource;
|
2014-01-05 09:43:49 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.security.IActionHost;
|
|
|
|
import appeng.api.networking.security.ISecurityGrid;
|
2014-01-05 09:43:49 +01:00
|
|
|
import appeng.api.networking.security.PlayerSource;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.parts.IPart;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.IMEInventoryHandler;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.client.me.InternalSlotME;
|
|
|
|
import appeng.client.me.SlotME;
|
2014-05-07 07:22:42 +02:00
|
|
|
import appeng.container.guisync.GuiSync;
|
|
|
|
import appeng.container.guisync.SyncDat;
|
2013-12-30 06:52:00 +01:00
|
|
|
import appeng.container.slot.AppEngSlot;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.slot.SlotCraftingMatrix;
|
2014-02-05 08:25:44 +01:00
|
|
|
import appeng.container.slot.SlotCraftingTerm;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.slot.SlotDisabled;
|
|
|
|
import appeng.container.slot.SlotFake;
|
|
|
|
import appeng.container.slot.SlotInaccessable;
|
|
|
|
import appeng.container.slot.SlotPlayerHotBar;
|
|
|
|
import appeng.container.slot.SlotPlayerInv;
|
2014-02-10 01:56:35 +01:00
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.core.sync.packets.PacketInventoryAction;
|
2014-05-13 06:11:19 +02:00
|
|
|
import appeng.core.sync.packets.PacketPartialItem;
|
2014-03-15 07:58:21 +01:00
|
|
|
import appeng.core.sync.packets.PacketValueConfig;
|
|
|
|
import appeng.helpers.ICustomNameObject;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.helpers.InventoryAction;
|
|
|
|
import appeng.util.InventoryAdaptor;
|
|
|
|
import appeng.util.Platform;
|
2014-01-30 02:20:48 +01:00
|
|
|
import appeng.util.inv.AdaptorPlayerHand;
|
2014-02-10 01:56:35 +01:00
|
|
|
import appeng.util.item.AEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public abstract class AEBaseContainer extends Container
|
|
|
|
{
|
|
|
|
|
2014-07-13 03:03:17 +02:00
|
|
|
protected final InventoryPlayer invPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
final TileEntity tileEntity;
|
2014-01-02 06:51:41 +01:00
|
|
|
final IPart part;
|
2014-05-24 06:20:56 +02:00
|
|
|
final IGuiItemObject obj;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-05 08:25:44 +01:00
|
|
|
final protected BaseActionSource mySrc;
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean isContainerValid = true;
|
2014-01-05 09:43:49 +01:00
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
boolean sentCustomName;
|
|
|
|
public String customName;
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
int ticksSinceCheck = 900;
|
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
IAEItemStack clientRequestedTargetItem = null;
|
|
|
|
List<PacketPartialItem> dataChunks = new LinkedList();
|
|
|
|
|
|
|
|
public void postPartial(PacketPartialItem packetPartialItem)
|
|
|
|
{
|
|
|
|
dataChunks.add( packetPartialItem );
|
|
|
|
if ( packetPartialItem.getPageCount() == dataChunks.size() )
|
|
|
|
parsePartials();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void parsePartials()
|
|
|
|
{
|
|
|
|
int total = 0;
|
|
|
|
for (PacketPartialItem ppi : dataChunks)
|
|
|
|
total += ppi.getSize();
|
|
|
|
|
|
|
|
byte[] buffer = new byte[total];
|
|
|
|
int cursor = 0;
|
|
|
|
|
|
|
|
for (PacketPartialItem ppi : dataChunks)
|
|
|
|
cursor = ppi.write( buffer, cursor );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NBTTagCompound data = CompressedStreamTools.readCompressed( new ByteArrayInputStream( buffer ) );
|
|
|
|
if ( data != null )
|
|
|
|
setTargetStack( AEApi.instance().storage().createItemStack( ItemStack.loadItemStackFromNBT( data ) ) );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
dataChunks.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTargetStack(IAEItemStack stack)
|
|
|
|
{
|
|
|
|
// client dosn't need to re-send, makes for lower overhead rapid packets.
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
{
|
|
|
|
ItemStack a = stack == null ? null : stack.getItemStack();
|
|
|
|
ItemStack b = clientRequestedTargetItem == null ? null : clientRequestedTargetItem.getItemStack();
|
|
|
|
|
|
|
|
if ( Platform.isSameItemPrecise( a, b ) )
|
|
|
|
return;
|
|
|
|
|
2014-05-13 06:28:29 +02:00
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
2014-05-13 06:11:19 +02:00
|
|
|
NBTTagCompound item = new NBTTagCompound();
|
|
|
|
|
|
|
|
if ( stack != null )
|
|
|
|
stack.writeToNBT( item );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CompressedStreamTools.writeCompressed( item, stream );
|
|
|
|
|
|
|
|
int maxChunkSize = 30000;
|
|
|
|
List<byte[]> miniPackets = new LinkedList();
|
|
|
|
|
2014-05-13 06:28:29 +02:00
|
|
|
byte[] data = stream.toByteArray();
|
2014-05-13 06:11:19 +02:00
|
|
|
|
|
|
|
ByteArrayInputStream bis = new ByteArrayInputStream( data, 0, stream.size() );
|
|
|
|
while (bis.available() > 0)
|
|
|
|
{
|
|
|
|
int nextBLock = bis.available() > maxChunkSize ? maxChunkSize : bis.available();
|
|
|
|
byte[] nextSegment = new byte[nextBLock];
|
|
|
|
bis.read( nextSegment );
|
|
|
|
miniPackets.add( nextSegment );
|
|
|
|
}
|
|
|
|
bis.close();
|
|
|
|
stream.close();
|
|
|
|
|
|
|
|
int page = 0;
|
|
|
|
for (byte[] packet : miniPackets)
|
|
|
|
{
|
|
|
|
PacketPartialItem ppi = new PacketPartialItem( page++, miniPackets.size(), packet );
|
|
|
|
NetworkHandler.instance.sendToServer( ppi );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clientRequestedTargetItem = stack == null ? null : stack.copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public IAEItemStack getTargetStack()
|
|
|
|
{
|
|
|
|
return clientRequestedTargetItem;
|
|
|
|
}
|
|
|
|
|
2014-05-01 06:01:22 +02:00
|
|
|
public BaseActionSource getSource()
|
|
|
|
{
|
|
|
|
return mySrc;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
public void verifyPermissions(SecurityPermissions security, boolean requirePower)
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ticksSinceCheck++;
|
|
|
|
if ( ticksSinceCheck < 20 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ticksSinceCheck = 0;
|
2014-03-05 04:12:23 +01:00
|
|
|
isContainerValid = isContainerValid && hasAccess( security, requirePower );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean hasAccess(SecurityPermissions perm, boolean requirePower)
|
|
|
|
{
|
2014-05-24 06:20:56 +02:00
|
|
|
IActionHost host = getActionHost();
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( host != null )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
IGridNode gn = host.getActionableNode();
|
|
|
|
if ( gn != null )
|
|
|
|
{
|
|
|
|
IGrid g = gn.getGrid();
|
|
|
|
if ( g != null )
|
|
|
|
{
|
|
|
|
if ( requirePower )
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
|
|
|
if ( !eg.isNetworkPowered() )
|
2014-03-05 04:12:23 +01:00
|
|
|
return false;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
|
2014-03-05 04:12:23 +01:00
|
|
|
if ( sg.hasPermission( invPlayer.player, perm ) )
|
|
|
|
return true;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 04:12:23 +01:00
|
|
|
|
|
|
|
return false;
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
|
2014-01-26 07:44:50 +01:00
|
|
|
public ContainerOpenContext openContext;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
protected IMEInventoryHandler<IAEItemStack> cellInv;
|
2014-01-23 17:28:12 +01:00
|
|
|
protected HashSet<Integer> locked = new HashSet();
|
2014-03-28 05:31:06 +01:00
|
|
|
protected IEnergySource powerSrc;
|
2014-01-23 17:28:12 +01:00
|
|
|
|
|
|
|
public void lockPlayerInventorySlot(int idx)
|
|
|
|
{
|
|
|
|
locked.add( idx );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
public Object getTarget()
|
|
|
|
{
|
|
|
|
if ( tileEntity != null )
|
|
|
|
return tileEntity;
|
|
|
|
if ( part != null )
|
|
|
|
return part;
|
2014-07-18 06:12:59 +02:00
|
|
|
if ( obj != null )
|
|
|
|
return obj;
|
2014-01-02 06:51:41 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AEBaseContainer(InventoryPlayer ip, TileEntity myTile, IPart myPart) {
|
2014-05-24 06:20:56 +02:00
|
|
|
this( ip, myTile, myPart, null );
|
|
|
|
}
|
|
|
|
|
|
|
|
public AEBaseContainer(InventoryPlayer ip, TileEntity myTile, IPart myPart, IGuiItemObject gio) {
|
2013-12-27 23:59:59 +01:00
|
|
|
invPlayer = ip;
|
2014-01-02 06:51:41 +01:00
|
|
|
tileEntity = myTile;
|
|
|
|
part = myPart;
|
2014-05-24 06:20:56 +02:00
|
|
|
obj = gio;
|
|
|
|
mySrc = new PlayerSource( ip.player, getActionHost() );
|
2014-05-07 07:22:42 +02:00
|
|
|
prepareSync();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
public AEBaseContainer(InventoryPlayer ip, Object anchor) {
|
|
|
|
invPlayer = ip;
|
|
|
|
tileEntity = anchor instanceof TileEntity ? (TileEntity) anchor : null;
|
|
|
|
part = anchor instanceof IPart ? (IPart) anchor : null;
|
|
|
|
obj = anchor instanceof IGuiItemObject ? (IGuiItemObject) anchor : null;
|
|
|
|
|
|
|
|
if ( tileEntity == null && part == null && obj == null )
|
|
|
|
throw new RuntimeException( "Must have a valid anchor" );
|
|
|
|
|
|
|
|
mySrc = new PlayerSource( ip.player, getActionHost() );
|
|
|
|
|
|
|
|
prepareSync();
|
|
|
|
}
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
protected IActionHost getActionHost()
|
2014-05-24 06:20:56 +02:00
|
|
|
{
|
|
|
|
if ( obj instanceof IActionHost )
|
|
|
|
return (IActionHost) obj;
|
|
|
|
|
|
|
|
if ( tileEntity instanceof IActionHost )
|
|
|
|
return (IActionHost) tileEntity;
|
|
|
|
|
|
|
|
if ( part instanceof IActionHost )
|
|
|
|
return (IActionHost) part;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
public boolean canDragIntoSlot(Slot s)
|
|
|
|
{
|
|
|
|
return ((AppEngSlot) s).isDraggable;
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public InventoryPlayer getPlayerInv()
|
|
|
|
{
|
|
|
|
return invPlayer;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public TileEntity getTileEntity()
|
|
|
|
{
|
|
|
|
return tileEntity;
|
|
|
|
}
|
|
|
|
|
2013-12-30 06:52:00 +01:00
|
|
|
@Override
|
|
|
|
protected Slot addSlotToContainer(Slot newSlot)
|
|
|
|
{
|
|
|
|
if ( newSlot instanceof AppEngSlot )
|
2014-07-19 21:33:28 +02:00
|
|
|
{
|
|
|
|
AppEngSlot s = (AppEngSlot) newSlot;
|
|
|
|
s.myContainer = this;
|
2013-12-30 06:52:00 +01:00
|
|
|
return super.addSlotToContainer( newSlot );
|
2014-07-19 21:33:28 +02:00
|
|
|
}
|
2013-12-30 06:52:00 +01:00
|
|
|
else
|
|
|
|
throw new RuntimeException( "Invalid Slot for AE Container." );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( isContainerValid )
|
|
|
|
{
|
|
|
|
if ( tileEntity instanceof IInventory )
|
|
|
|
return ((IInventory) tileEntity).isUseableByPlayer( entityplayer );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack transferStackInSlot(EntityPlayer p, int idx)
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
boolean hasMETiles = false;
|
|
|
|
for (Object is : this.inventorySlots)
|
|
|
|
{
|
|
|
|
if ( is instanceof InternalSlotME )
|
|
|
|
{
|
|
|
|
hasMETiles = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasMETiles && Platform.isClient() )
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack tis = null;
|
2013-12-30 06:52:00 +01:00
|
|
|
AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots!
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessable )
|
|
|
|
return null;
|
|
|
|
if ( clickSlot != null && clickSlot.getHasStack() )
|
|
|
|
{
|
|
|
|
tis = clickSlot.getStack();
|
|
|
|
|
|
|
|
if ( tis == null )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
List<Slot> selectedSlots = new ArrayList<Slot>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather a list of valid destinations.
|
|
|
|
*/
|
2013-12-30 06:52:00 +01:00
|
|
|
if ( clickSlot.isPlayerSide() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
tis = shiftStoreItem( tis );
|
|
|
|
|
|
|
|
// target slots in the container...
|
|
|
|
for (int x = 0; x < this.inventorySlots.size(); x++)
|
|
|
|
{
|
2013-12-30 06:52:00 +01:00
|
|
|
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2013-12-30 06:52:00 +01:00
|
|
|
if ( !(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( cs.isItemValid( tis ) )
|
|
|
|
selectedSlots.add( cs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// target slots in the container...
|
|
|
|
for (int x = 0; x < this.inventorySlots.size(); x++)
|
|
|
|
{
|
2013-12-30 06:52:00 +01:00
|
|
|
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2013-12-30 06:52:00 +01:00
|
|
|
if ( (cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( cs.isItemValid( tis ) )
|
|
|
|
selectedSlots.add( cs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Fake Slot Shift clicking.
|
|
|
|
*/
|
2013-12-30 06:52:00 +01:00
|
|
|
if ( selectedSlots.isEmpty() && clickSlot.isPlayerSide() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( tis != null )
|
|
|
|
{
|
|
|
|
// target slots in the container...
|
|
|
|
for (int x = 0; x < this.inventorySlots.size(); x++)
|
|
|
|
{
|
2013-12-30 06:52:00 +01:00
|
|
|
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x );
|
2013-12-27 23:59:59 +01:00
|
|
|
ItemStack dest = cs.getStack();
|
|
|
|
|
2013-12-30 06:52:00 +01:00
|
|
|
if ( !(cs.isPlayerSide()) && cs instanceof SlotFake )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-03-07 04:02:15 +01:00
|
|
|
if ( Platform.isSameItemPrecise( dest, tis ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
|
|
|
else if ( dest == null )
|
|
|
|
{
|
|
|
|
cs.putStack( tis != null ? tis.copy() : null );
|
|
|
|
cs.onSlotChanged();
|
|
|
|
updateSlot( cs );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tis != null )
|
|
|
|
{
|
|
|
|
// find partials..
|
|
|
|
for (Slot d : selectedSlots)
|
|
|
|
{
|
|
|
|
if ( d instanceof SlotDisabled || d instanceof SlotME )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( d.isItemValid( tis ) && tis != null )
|
|
|
|
{
|
|
|
|
if ( d.getHasStack() )
|
|
|
|
{
|
|
|
|
ItemStack t = d.getStack();
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
if ( tis != null && Platform.isSameItemPrecise( tis, t ) ) // t.isItemEqual(tis))
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int maxSize = t.getMaxStackSize();
|
|
|
|
if ( maxSize > d.getSlotStackLimit() )
|
|
|
|
maxSize = d.getSlotStackLimit();
|
|
|
|
|
|
|
|
int placeAble = maxSize - t.stackSize;
|
|
|
|
|
|
|
|
if ( tis.stackSize < placeAble )
|
|
|
|
{
|
|
|
|
placeAble = tis.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
t.stackSize += placeAble;
|
|
|
|
tis.stackSize -= placeAble;
|
|
|
|
|
|
|
|
if ( tis.stackSize <= 0 )
|
|
|
|
{
|
|
|
|
clickSlot.putStack( null );
|
|
|
|
d.onSlotChanged();
|
|
|
|
|
|
|
|
// if ( hasMETiles ) updateClient();
|
|
|
|
|
|
|
|
updateSlot( clickSlot );
|
|
|
|
updateSlot( d );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
updateSlot( d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// any match..
|
|
|
|
for (Slot d : selectedSlots)
|
|
|
|
{
|
|
|
|
if ( d instanceof SlotDisabled || d instanceof SlotME )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( d.isItemValid( tis ) && tis != null )
|
|
|
|
{
|
|
|
|
if ( d.getHasStack() )
|
|
|
|
{
|
|
|
|
ItemStack t = d.getStack();
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
if ( tis != null && Platform.isSameItemPrecise( t, tis ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int maxSize = t.getMaxStackSize();
|
|
|
|
if ( d.getSlotStackLimit() < maxSize )
|
|
|
|
maxSize = d.getSlotStackLimit();
|
|
|
|
|
|
|
|
int placeAble = maxSize - t.stackSize;
|
|
|
|
|
|
|
|
if ( tis.stackSize < placeAble )
|
|
|
|
{
|
|
|
|
placeAble = tis.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
t.stackSize += placeAble;
|
|
|
|
tis.stackSize -= placeAble;
|
|
|
|
|
|
|
|
if ( tis.stackSize <= 0 )
|
|
|
|
{
|
|
|
|
clickSlot.putStack( null );
|
|
|
|
d.onSlotChanged();
|
|
|
|
|
|
|
|
// if ( worldEntity != null )
|
2014-02-09 02:34:52 +01:00
|
|
|
// worldEntity.markDirty();
|
2013-12-27 23:59:59 +01:00
|
|
|
// if ( hasMETiles ) updateClient();
|
|
|
|
|
|
|
|
updateSlot( clickSlot );
|
|
|
|
updateSlot( d );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
updateSlot( d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int maxSize = tis.getMaxStackSize();
|
|
|
|
if ( maxSize > d.getSlotStackLimit() )
|
|
|
|
maxSize = d.getSlotStackLimit();
|
|
|
|
|
|
|
|
ItemStack tmp = tis.copy();
|
|
|
|
if ( tmp.stackSize > maxSize )
|
|
|
|
tmp.stackSize = maxSize;
|
|
|
|
|
|
|
|
tis.stackSize -= tmp.stackSize;
|
|
|
|
d.putStack( tmp );
|
|
|
|
|
|
|
|
if ( tis.stackSize <= 0 )
|
|
|
|
{
|
|
|
|
clickSlot.putStack( null );
|
|
|
|
d.onSlotChanged();
|
|
|
|
|
|
|
|
// if ( worldEntity != null )
|
2014-02-09 02:34:52 +01:00
|
|
|
// worldEntity.markDirty();
|
2013-12-27 23:59:59 +01:00
|
|
|
// if ( hasMETiles ) updateClient();
|
|
|
|
|
|
|
|
updateSlot( clickSlot );
|
|
|
|
updateSlot( d );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
updateSlot( d );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clickSlot.putStack( tis != null ? tis.copy() : null );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSlot( clickSlot );
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateSlot(Slot clickSlot)
|
|
|
|
{
|
2014-01-01 09:57:16 +01:00
|
|
|
// ???
|
2013-12-27 23:59:59 +01:00
|
|
|
detectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
HashMap<Integer, SyncDat> syncData = new HashMap<Integer, SyncDat>();
|
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
|
|
|
sendCustomName();
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
|
|
|
for (int i = 0; i < this.crafters.size(); ++i)
|
|
|
|
{
|
|
|
|
ICrafting icrafting = (ICrafting) this.crafters.get( i );
|
|
|
|
|
|
|
|
for (SyncDat sd : syncData.values())
|
|
|
|
sd.tick( icrafting );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
final public void updateProgressBar(int idx, int value)
|
|
|
|
{
|
|
|
|
if ( syncData.containsKey( idx ) )
|
|
|
|
{
|
2014-07-16 05:26:12 +02:00
|
|
|
syncData.get( idx ).update( (long) value );
|
2014-05-07 07:22:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
final public void updateFullProgressBar(int idx, long value)
|
|
|
|
{
|
|
|
|
if ( syncData.containsKey( idx ) )
|
|
|
|
{
|
2014-07-16 05:26:12 +02:00
|
|
|
syncData.get( idx ).update( (long) value );
|
2014-05-07 07:22:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateProgressBar( idx, (int) value );
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:26:12 +02:00
|
|
|
public void stringSync(int idx, String value)
|
|
|
|
{
|
|
|
|
if ( syncData.containsKey( idx ) )
|
|
|
|
{
|
|
|
|
syncData.get( idx ).update( value );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
private void prepareSync()
|
|
|
|
{
|
|
|
|
for (Field f : getClass().getFields())
|
|
|
|
{
|
|
|
|
if ( f.isAnnotationPresent( GuiSync.class ) )
|
|
|
|
{
|
|
|
|
GuiSync anno = f.getAnnotation( GuiSync.class );
|
|
|
|
if ( syncData.containsKey( anno.value() ) )
|
|
|
|
AELog.warning( "Channel already in use: " + anno.value() + " for " + f.getName() );
|
|
|
|
else
|
|
|
|
syncData.put( anno.value(), new SyncDat( this, f, anno ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
protected void sendCustomName()
|
|
|
|
{
|
|
|
|
if ( !sentCustomName )
|
|
|
|
{
|
|
|
|
sentCustomName = true;
|
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
|
|
|
ICustomNameObject name = null;
|
|
|
|
|
|
|
|
if ( part instanceof ICustomNameObject )
|
|
|
|
name = (ICustomNameObject) part;
|
|
|
|
|
|
|
|
if ( tileEntity instanceof ICustomNameObject )
|
|
|
|
name = (ICustomNameObject) tileEntity;
|
|
|
|
|
2014-07-16 05:26:12 +02:00
|
|
|
if ( obj instanceof ICustomNameObject )
|
|
|
|
name = (ICustomNameObject) obj;
|
|
|
|
|
|
|
|
if ( this instanceof ICustomNameObject )
|
|
|
|
name = (ICustomNameObject) this;
|
|
|
|
|
2014-03-15 07:58:21 +01:00
|
|
|
if ( name != null )
|
|
|
|
{
|
|
|
|
if ( name.hasCustomName() )
|
|
|
|
customName = name.getCustomName();
|
|
|
|
|
|
|
|
if ( customName != null )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendTo( new PacketValueConfig( "CustomName", customName ), (EntityPlayerMP) invPlayer.player );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer, int offset_x, int offset_y)
|
|
|
|
{
|
2014-08-28 18:32:53 +02:00
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
{
|
|
|
|
if ( locked.contains( i ) )
|
|
|
|
addSlotToContainer( new SlotDisabled( inventoryPlayer, i, 8 + i * 18 + offset_x, 58 + offset_y ) );
|
|
|
|
else
|
|
|
|
addSlotToContainer( new SlotPlayerHotBar( inventoryPlayer, i, 8 + i * 18 + offset_x, 58 + offset_y ) );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 9; j++)
|
|
|
|
{
|
2014-01-23 17:28:12 +01:00
|
|
|
if ( locked.contains( j + i * 9 + 9 ) )
|
|
|
|
addSlotToContainer( new SlotDisabled( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offset_x, offset_y + i * 18 ) );
|
|
|
|
else
|
|
|
|
addSlotToContainer( new SlotPlayerInv( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offset_x, offset_y + i * 18 ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack shiftStoreItem(ItemStack input)
|
|
|
|
{
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return input;
|
2014-01-05 09:43:49 +01:00
|
|
|
IAEItemStack ais = Platform.poweredInsert( powerSrc, cellInv, AEApi.instance().storage().createItemStack( input ), mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais == null )
|
|
|
|
return null;
|
|
|
|
return ais.getItemStack();
|
|
|
|
}
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-01 09:57:16 +01:00
|
|
|
if ( slot >= 0 && slot < inventorySlots.size() )
|
|
|
|
{
|
|
|
|
Slot s = getSlot( slot );
|
|
|
|
|
2014-02-05 08:25:44 +01:00
|
|
|
if ( s instanceof SlotCraftingTerm )
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CRAFT_SHIFT:
|
|
|
|
case CRAFT_ITEM:
|
|
|
|
case CRAFT_STACK:
|
|
|
|
((SlotCraftingTerm) s).doClick( action, player );
|
2014-02-11 06:49:40 +01:00
|
|
|
updateHeld( player );
|
2014-02-05 08:25:44 +01:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
if ( s instanceof SlotFake )
|
|
|
|
{
|
|
|
|
ItemStack hand = player.inventory.getItemStack();
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PICKUP_OR_SETDOWN:
|
|
|
|
|
|
|
|
if ( hand == null )
|
|
|
|
s.putStack( null );
|
|
|
|
else
|
|
|
|
s.putStack( hand.copy() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SPLIT_OR_PLACESINGLE:
|
|
|
|
|
|
|
|
ItemStack is = s.getStack();
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
if ( hand == null )
|
|
|
|
is.stackSize--;
|
|
|
|
else if ( hand.isItemEqual( is ) )
|
|
|
|
is.stackSize = Math.min( is.getMaxStackSize(), is.stackSize + 1 );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is = hand.copy();
|
|
|
|
is.stackSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s.putStack( is );
|
|
|
|
}
|
|
|
|
else if ( hand != null )
|
|
|
|
{
|
|
|
|
is = hand.copy();
|
|
|
|
is.stackSize = 1;
|
|
|
|
s.putStack( is );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CREATIVE_DUPLICATE:
|
|
|
|
case MOVE_REGION:
|
|
|
|
case SHIFT_CLICK:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 04:56:00 +01:00
|
|
|
if ( action == InventoryAction.MOVE_REGION )
|
|
|
|
{
|
|
|
|
List<Slot> from = new LinkedList();
|
|
|
|
|
|
|
|
for (Object j : inventorySlots)
|
|
|
|
{
|
|
|
|
if ( j instanceof Slot && j.getClass() == s.getClass() )
|
|
|
|
from.add( (Slot) j );
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Slot fr : from)
|
|
|
|
transferStackInSlot( player, fr.slotNumber );
|
|
|
|
}
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
// get target item.
|
|
|
|
IAEItemStack slotItem = getTargetStack();
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case SHIFT_CLICK:
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( slotItem != null )
|
|
|
|
{
|
|
|
|
IAEItemStack ais = slotItem.copy();
|
|
|
|
ItemStack myItem = ais.getItemStack();
|
|
|
|
|
|
|
|
ais.setStackSize( myItem.getMaxStackSize() );
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
|
2013-12-27 23:59:59 +01:00
|
|
|
myItem.stackSize = (int) ais.getStackSize();
|
|
|
|
myItem = adp.simulateAdd( myItem );
|
|
|
|
|
|
|
|
if ( myItem != null )
|
|
|
|
ais.setStackSize( ais.getStackSize() - myItem.stackSize );
|
|
|
|
|
2014-01-05 09:43:49 +01:00
|
|
|
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais != null )
|
|
|
|
adp.addItems( ais.getItemStack() );
|
|
|
|
}
|
|
|
|
break;
|
2014-05-13 06:11:19 +02:00
|
|
|
case ROLLDOWN:
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int releaseQty = 1;
|
|
|
|
ItemStack isg = player.inventory.getItemStack();
|
|
|
|
|
|
|
|
if ( isg != null && releaseQty > 0 )
|
|
|
|
{
|
|
|
|
IAEItemStack ais = AEApi.instance().storage().createItemStack( isg );
|
|
|
|
ais.setStackSize( 1 );
|
|
|
|
IAEItemStack extracted = ais.copy();
|
|
|
|
|
|
|
|
ais = Platform.poweredInsert( powerSrc, cellInv, ais, mySrc );
|
|
|
|
if ( ais == null )
|
|
|
|
{
|
|
|
|
InventoryAdaptor ia = new AdaptorPlayerHand( player );
|
|
|
|
|
|
|
|
ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null );
|
|
|
|
if ( fail == null )
|
|
|
|
cellInv.extractItems( extracted, Actionable.MODULATE, mySrc );
|
|
|
|
|
|
|
|
updateHeld( player );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case ROLLUP:
|
2014-01-30 02:20:48 +01:00
|
|
|
case PICKUP_SINGLE:
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( slotItem != null )
|
|
|
|
{
|
|
|
|
int liftQty = 1;
|
2014-05-13 06:11:19 +02:00
|
|
|
ItemStack isgg = player.inventory.getItemStack();
|
2014-01-30 02:20:48 +01:00
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
if ( isgg != null )
|
2014-01-30 02:20:48 +01:00
|
|
|
{
|
2014-05-13 06:11:19 +02:00
|
|
|
if ( isgg.stackSize >= isgg.getMaxStackSize() )
|
2014-01-30 02:20:48 +01:00
|
|
|
liftQty = 0;
|
2014-05-13 06:11:19 +02:00
|
|
|
if ( !Platform.isSameItemPrecise( slotItem.getItemStack(), isgg ) )
|
2014-01-30 02:20:48 +01:00
|
|
|
liftQty = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( liftQty > 0 )
|
|
|
|
{
|
|
|
|
IAEItemStack ais = slotItem.copy();
|
|
|
|
ais.setStackSize( 1 );
|
|
|
|
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
|
2014-05-13 06:11:19 +02:00
|
|
|
if ( ais != null )
|
|
|
|
{
|
|
|
|
InventoryAdaptor ia = new AdaptorPlayerHand( player );
|
2014-01-30 02:20:48 +01:00
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
ItemStack fail = ia.addItems( ais.getItemStack() );
|
|
|
|
if ( fail != null )
|
|
|
|
cellInv.injectItems( ais, Actionable.MODULATE, mySrc );
|
2014-01-30 02:20:48 +01:00
|
|
|
|
2014-05-13 06:11:19 +02:00
|
|
|
updateHeld( player );
|
|
|
|
}
|
2014-01-30 02:20:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-12-27 23:59:59 +01:00
|
|
|
case PICKUP_OR_SETDOWN:
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( player.inventory.getItemStack() == null )
|
|
|
|
{
|
|
|
|
if ( slotItem != null )
|
|
|
|
{
|
|
|
|
IAEItemStack ais = slotItem.copy();
|
|
|
|
ais.setStackSize( ais.getItemStack().getMaxStackSize() );
|
2014-01-05 09:43:49 +01:00
|
|
|
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais != null )
|
|
|
|
player.inventory.setItemStack( ais.getItemStack() );
|
|
|
|
else
|
|
|
|
player.inventory.setItemStack( null );
|
2014-02-10 01:56:35 +01:00
|
|
|
updateHeld( player );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() );
|
2014-01-05 09:43:49 +01:00
|
|
|
ais = Platform.poweredInsert( powerSrc, cellInv, ais, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais != null )
|
|
|
|
player.inventory.setItemStack( ais.getItemStack() );
|
|
|
|
else
|
|
|
|
player.inventory.setItemStack( null );
|
2014-02-10 01:56:35 +01:00
|
|
|
updateHeld( player );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SPLIT_OR_PLACESINGLE:
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( player.inventory.getItemStack() == null )
|
|
|
|
{
|
|
|
|
if ( slotItem != null )
|
|
|
|
{
|
|
|
|
IAEItemStack ais = slotItem.copy();
|
2014-05-14 06:33:48 +02:00
|
|
|
long maxSize = ais.getItemStack().getMaxStackSize();
|
|
|
|
ais.setStackSize( maxSize );
|
|
|
|
ais = cellInv.extractItems( ais, Actionable.SIMULATE, mySrc );
|
2014-05-25 01:23:40 +02:00
|
|
|
|
|
|
|
if ( ais != null )
|
|
|
|
{
|
|
|
|
long stackSize = Math.min( maxSize, ais.getStackSize() );
|
|
|
|
ais.setStackSize( (stackSize + 1) >> 1 );
|
|
|
|
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais != null )
|
|
|
|
player.inventory.setItemStack( ais.getItemStack() );
|
|
|
|
else
|
|
|
|
player.inventory.setItemStack( null );
|
2014-02-10 01:56:35 +01:00
|
|
|
updateHeld( player );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IAEItemStack ais = AEApi.instance().storage().createItemStack( player.inventory.getItemStack() );
|
|
|
|
ais.setStackSize( 1 );
|
2014-01-05 09:43:49 +01:00
|
|
|
ais = Platform.poweredInsert( powerSrc, cellInv, ais, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( ais == null )
|
|
|
|
{
|
|
|
|
ItemStack is = player.inventory.getItemStack();
|
|
|
|
is.stackSize--;
|
|
|
|
if ( is.stackSize <= 0 )
|
|
|
|
player.inventory.setItemStack( null );
|
2014-02-10 01:56:35 +01:00
|
|
|
updateHeld( player );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CREATIVE_DUPLICATE:
|
|
|
|
if ( player.capabilities.isCreativeMode && slotItem != null )
|
|
|
|
{
|
|
|
|
ItemStack is = slotItem.getItemStack();
|
|
|
|
is.stackSize = is.getMaxStackSize();
|
|
|
|
player.inventory.setItemStack( is );
|
2014-02-10 01:56:35 +01:00
|
|
|
updateHeld( player );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOVE_REGION:
|
2014-02-27 04:56:00 +01:00
|
|
|
|
|
|
|
if ( powerSrc == null || cellInv == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( slotItem != null )
|
|
|
|
{
|
2014-03-07 04:02:15 +01:00
|
|
|
int playerInv = 9 * 4;
|
|
|
|
for (int slotNum = 0; slotNum < playerInv; slotNum++)
|
2014-02-27 04:56:00 +01:00
|
|
|
{
|
|
|
|
IAEItemStack ais = slotItem.copy();
|
|
|
|
ItemStack myItem = ais.getItemStack();
|
|
|
|
|
|
|
|
ais.setStackSize( myItem.getMaxStackSize() );
|
|
|
|
|
2014-03-07 04:02:15 +01:00
|
|
|
InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
|
2014-02-27 04:56:00 +01:00
|
|
|
myItem.stackSize = (int) ais.getStackSize();
|
|
|
|
myItem = adp.simulateAdd( myItem );
|
|
|
|
|
|
|
|
if ( myItem != null )
|
|
|
|
ais.setStackSize( ais.getStackSize() - myItem.stackSize );
|
|
|
|
|
|
|
|
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
|
|
|
|
if ( ais != null )
|
|
|
|
adp.addItems( ais.getItemStack() );
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-02 06:51:41 +01:00
|
|
|
|
2014-04-17 08:15:56 +02:00
|
|
|
protected void updateHeld(EntityPlayerMP p)
|
2014-02-10 01:56:35 +01:00
|
|
|
{
|
2014-05-13 06:11:19 +02:00
|
|
|
if ( Platform.isServer() )
|
2014-02-10 01:56:35 +01:00
|
|
|
{
|
2014-05-13 06:11:19 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.create( p.inventory.getItemStack() ) ),
|
|
|
|
p );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
2014-02-10 01:56:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 00:36:37 +01:00
|
|
|
public void swapSlotContents(int slotA, int slotB)
|
|
|
|
{
|
|
|
|
Slot a = getSlot( slotA );
|
|
|
|
Slot b = getSlot( slotB );
|
|
|
|
|
|
|
|
// NPE protection...
|
|
|
|
if ( a == null || b == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ItemStack isA = a.getStack();
|
|
|
|
ItemStack isB = b.getStack();
|
|
|
|
|
|
|
|
// something to do?
|
|
|
|
if ( isA == null && isB == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// can take?
|
|
|
|
|
|
|
|
if ( isA != null && !a.canTakeStack( invPlayer.player ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( isB != null && !b.canTakeStack( invPlayer.player ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// swap valid?
|
|
|
|
|
|
|
|
if ( isB != null && !a.isItemValid( isB ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( isA != null && !b.isItemValid( isA ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ItemStack testA = isB == null ? null : isB.copy();
|
|
|
|
ItemStack testB = isA == null ? null : isA.copy();
|
|
|
|
|
|
|
|
// can put some back?
|
|
|
|
if ( testA != null && testA.stackSize > a.getSlotStackLimit() )
|
|
|
|
{
|
|
|
|
if ( testB != null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int totalA = testA.stackSize;
|
|
|
|
testA.stackSize = a.getSlotStackLimit();
|
|
|
|
testB = testA.copy();
|
|
|
|
|
|
|
|
testB.stackSize = totalA - testA.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( testB != null && testB.stackSize > b.getSlotStackLimit() )
|
|
|
|
{
|
|
|
|
if ( testA != null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int totalB = testB.stackSize;
|
|
|
|
testB.stackSize = b.getSlotStackLimit();
|
|
|
|
testA = testB.copy();
|
|
|
|
|
|
|
|
testA.stackSize = totalB - testA.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
a.putStack( testA );
|
|
|
|
b.putStack( testB );
|
|
|
|
}
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
public void onUpdate(String field, Object oldValue, Object newValue)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-07-16 05:26:12 +02:00
|
|
|
|
2014-07-19 21:33:28 +02:00
|
|
|
public void onSlotChange(Slot s)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isValidForSlot(Slot s, ItemStack i)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|