2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync.packets;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-01-05 09:39:48 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2014-02-10 01:56:35 +01:00
|
|
|
import appeng.client.ClientHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.core.sync.AppEngPacket;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.INetworkInfo;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.helpers.InventoryAction;
|
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
|
|
|
|
public class PacketInventoryAction extends AppEngPacket
|
|
|
|
{
|
|
|
|
|
|
|
|
final public InventoryAction action;
|
|
|
|
final public int slot;
|
|
|
|
final public IAEItemStack slotItem;
|
|
|
|
|
|
|
|
// automatic.
|
2014-02-09 02:34:52 +01:00
|
|
|
public PacketInventoryAction(ByteBuf stream) throws IOException {
|
2013-12-27 23:59:59 +01:00
|
|
|
action = InventoryAction.values()[stream.readInt()];
|
|
|
|
slot = stream.readInt();
|
|
|
|
boolean hasItem = stream.readBoolean();
|
|
|
|
if ( hasItem )
|
|
|
|
slotItem = AEItemStack.loadItemStackFromPacket( stream );
|
|
|
|
else
|
|
|
|
slotItem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
EntityPlayerMP sender = (EntityPlayerMP) player;
|
2014-01-23 17:28:12 +01:00
|
|
|
if ( sender.openContainer instanceof AEBaseContainer )
|
|
|
|
{
|
|
|
|
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
|
|
|
|
aebc.doAction( sender, action, slot, slotItem );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:56:35 +01:00
|
|
|
@Override
|
|
|
|
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
|
|
|
|
{
|
|
|
|
if ( action == InventoryAction.UPDATE_HAND )
|
|
|
|
{
|
|
|
|
if ( slotItem == null )
|
|
|
|
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( null );
|
|
|
|
else
|
|
|
|
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( slotItem.getItemStack() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
// api
|
|
|
|
public PacketInventoryAction(InventoryAction action, int slot, IAEItemStack slotItem) throws IOException {
|
|
|
|
this.action = action;
|
|
|
|
this.slot = slot;
|
|
|
|
this.slotItem = slotItem;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
ByteBuf data = Unpooled.buffer();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
data.writeInt( getPacketID() );
|
|
|
|
data.writeInt( action.ordinal() );
|
|
|
|
data.writeInt( slot );
|
|
|
|
|
|
|
|
if ( slotItem == null )
|
|
|
|
data.writeBoolean( false );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data.writeBoolean( true );
|
|
|
|
slotItem.writeToPacket( data );
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
configureWrite( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|