Added Shit+Mouse wheel to pick up / drop items.

Added Partial ItemStack packets to report to the server what itemstack is the target of interation.
Fixed Repairing Items in CraftingTerminal.
This commit is contained in:
AlgorithmX2
2014-05-12 23:11:19 -05:00
parent 9ba6f195fd
commit ff12aa1673
7 changed files with 291 additions and 34 deletions
+156 -17
View File
@@ -1,5 +1,6 @@
package appeng.container;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
@@ -13,6 +14,8 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
@@ -42,6 +45,7 @@ import appeng.container.slot.SlotPlayerInv;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketPartialItem;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.InventoryAction;
@@ -50,6 +54,8 @@ import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.item.AEItemStack;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
public abstract class AEBaseContainer extends Container
{
@@ -65,6 +71,101 @@ public abstract class AEBaseContainer extends Container
int ticksSinceCheck = 900;
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;
ByteOutputStream stream = new ByteOutputStream();
NBTTagCompound item = new NBTTagCompound();
if ( stack != null )
stack.writeToNBT( item );
try
{
CompressedStreamTools.writeCompressed( item, stream );
int maxChunkSize = 30000;
List<byte[]> miniPackets = new LinkedList();
byte[] data = stream.getBytes();
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;
}
public BaseActionSource getSource()
{
return mySrc;
@@ -492,7 +593,7 @@ public abstract class AEBaseContainer extends Container
return ais.getItemStack();
}
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, IAEItemStack slotItem)
public void doAction(EntityPlayerMP player, InventoryAction action, int slot)
{
if ( slot >= 0 && slot < inventorySlots.size() )
{
@@ -576,6 +677,9 @@ public abstract class AEBaseContainer extends Container
return;
}
// get target item.
IAEItemStack slotItem = getTargetStack();
switch (action)
{
case SHIFT_CLICK:
@@ -601,6 +705,34 @@ public abstract class AEBaseContainer extends Container
adp.addItems( ais.getItemStack() );
}
break;
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:
case PICKUP_SINGLE:
if ( powerSrc == null || cellInv == null )
return;
@@ -608,13 +740,13 @@ public abstract class AEBaseContainer extends Container
if ( slotItem != null )
{
int liftQty = 1;
ItemStack isg = player.inventory.getItemStack();
ItemStack isgg = player.inventory.getItemStack();
if ( isg != null )
if ( isgg != null )
{
if ( isg.stackSize >= isg.getMaxStackSize() )
if ( isgg.stackSize >= isgg.getMaxStackSize() )
liftQty = 0;
if ( !Platform.isSameItemPrecise( slotItem.getItemStack(), isg ) )
if ( !Platform.isSameItemPrecise( slotItem.getItemStack(), isgg ) )
liftQty = 0;
}
@@ -623,14 +755,16 @@ public abstract class AEBaseContainer extends Container
IAEItemStack ais = slotItem.copy();
ais.setStackSize( 1 );
ais = Platform.poweredExtraction( powerSrc, cellInv, ais, mySrc );
if ( ais != null )
{
InventoryAdaptor ia = new AdaptorPlayerHand( player );
InventoryAdaptor ia = new AdaptorPlayerHand( player );
ItemStack fail = ia.addItems( ais.getItemStack() );
if ( fail != null )
cellInv.injectItems( ais, Actionable.MODULATE, mySrc );
ItemStack fail = ia.addItems( ais.getItemStack() );
if ( fail != null )
cellInv.injectItems( ais, Actionable.MODULATE, mySrc );
updateHeld( player );
updateHeld( player );
}
}
}
break;
@@ -751,13 +885,17 @@ public abstract class AEBaseContainer extends Container
private void updateHeld(EntityPlayerMP p)
{
try
if ( Platform.isServer() )
{
NetworkHandler.instance.sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.create( p.inventory.getItemStack() ) ), p );
}
catch (IOException e)
{
AELog.error( e );
try
{
NetworkHandler.instance.sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.create( p.inventory.getItemStack() ) ),
p );
}
catch (IOException e)
{
AELog.error( e );
}
}
}
@@ -824,4 +962,5 @@ public abstract class AEBaseContainer extends Container
a.putStack( testA );
b.putStack( testB );
}
}