Cellworkbench acts weird

missing bookmark dragging
This commit is contained in:
Salomão
2021-04-12 23:51:49 -03:00
parent 2269c05d98
commit 41180792e1
8 changed files with 422 additions and 16 deletions
@@ -21,9 +21,17 @@ package appeng.core.sync.packets;
import java.io.IOException;
import appeng.api.storage.data.IAEFluidStack;
import appeng.client.gui.implementations.GuiUpgradeable;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.container.slot.SlotFake;
import appeng.fluids.client.gui.GuiFluidInterface;
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
import appeng.fluids.util.AEFluidStack;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
@@ -49,6 +57,7 @@ public class PacketInventoryAction extends AppEngPacket
private final int slot;
private final long id;
private final IAEItemStack slotItem;
private final IAEFluidStack slotFluid;
// automatic.
public PacketInventoryAction( final ByteBuf stream ) throws IOException
@@ -57,6 +66,8 @@ public class PacketInventoryAction extends AppEngPacket
this.slot = stream.readInt();
this.id = stream.readLong();
final boolean hasItem = stream.readBoolean();
final boolean hasFluid = stream.readBoolean();
if( hasItem )
{
this.slotItem = AEItemStack.fromPacket( stream );
@@ -65,12 +76,19 @@ public class PacketInventoryAction extends AppEngPacket
{
this.slotItem = null;
}
if( hasFluid )
{
this.slotFluid = AEFluidStack.fromPacket( stream );
}
else
{
this.slotFluid = null;
}
}
// api
public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem ) throws IOException
{
if( Platform.isClient() )
{
throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." );
@@ -80,6 +98,7 @@ public class PacketInventoryAction extends AppEngPacket
this.slot = slot;
this.id = 0;
this.slotItem = slotItem;
this.slotFluid = null;
final ByteBuf data = Unpooled.buffer();
@@ -91,16 +110,88 @@ public class PacketInventoryAction extends AppEngPacket
if( slotItem == null )
{
data.writeBoolean( false );
data.writeBoolean( false );
}
else
{
data.writeBoolean( true );
data.writeBoolean( false );
slotItem.writeToPacket( data );
}
this.configureWrite( data );
}
public PacketInventoryAction( final InventoryAction action, final SlotFake slot, final IAEItemStack slotItem ) throws IOException
{
if( action != InventoryAction.PLACE_JEI_GHOST_ITEM )
{
throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." );
}
this.action = action;
this.slot = slot.slotNumber;
this.id = 0;
this.slotItem = slotItem;
this.slotFluid = null;
final ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot.slotNumber );
data.writeLong( this.id );
if( slotItem == null )
{
data.writeBoolean( false );
data.writeBoolean( false );
}
else
{
data.writeBoolean( true );
data.writeBoolean( false );
slotItem.writeToPacket( data );
}
this.configureWrite( data );
}
public PacketInventoryAction( final InventoryAction action, final GuiFluidSlot slot, final IAEFluidStack slotFluid ) throws IOException
{
if( action != InventoryAction.PLACE_JEI_GHOST_ITEM )
{
throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." );
}
this.action = action;
this.slot = slot.getId();
this.id = 2;
this.slotFluid = slotFluid;
this.slotItem = null;
final ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot.getId() );
data.writeLong( this.id );
data.writeBoolean( false );
if( slotFluid == null )
{
data.writeBoolean( false );
}
else
{
data.writeBoolean( true );
slotFluid.writeToPacket( data );
}
this.configureWrite( data );
}
// api
public PacketInventoryAction( final InventoryAction action, final int slot, final long id )
{
@@ -108,6 +199,7 @@ public class PacketInventoryAction extends AppEngPacket
this.slot = slot;
this.id = id;
this.slotItem = null;
this.slotFluid = null;
final ByteBuf data = Unpooled.buffer();
@@ -116,6 +208,7 @@ public class PacketInventoryAction extends AppEngPacket
data.writeInt( slot );
data.writeLong( id );
data.writeBoolean( false );
data.writeBoolean( false );
this.configureWrite( data );
}
@@ -150,6 +243,38 @@ public class PacketInventoryAction extends AppEngPacket
}
}
}
else if( this.action == InventoryAction.PLACE_JEI_GHOST_ITEM )
{
if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake )
{
if( this.slotItem != null ) sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() );
else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY );
}
if( Minecraft.getMinecraft().currentScreen instanceof GuiUpgradeable )
{
GuiUpgradeable cs = ( (GuiUpgradeable) Minecraft.getMinecraft().currentScreen );
if( cs.getGuiSlots().size() > 0 )
{
GuiCustomSlot ct = cs.getGuiSlots().get( this.slot );
if( this.slotFluid != null )
{
if( ct instanceof GuiFluidSlot )
{
GuiFluidSlot gfs = (GuiFluidSlot) ct;
gfs.setFluidStack( this.slotFluid );
}
}
else
{
if( ct instanceof GuiFluidSlot )
{
GuiFluidSlot gfs = (GuiFluidSlot) ct;
gfs.setFluidStack( null );
}
}
}
}
}
else
{
baseContainer.doAction( sender, this.action, this.slot, this.id );