GUI Rendering and various fixes

This commit is contained in:
Sebastian Hartte
2020-06-07 03:29:57 +02:00
parent 97f04922b9
commit 46b1d1ffdc
72 changed files with 650 additions and 552 deletions
@@ -19,6 +19,7 @@
package appeng.core.sync;
import appeng.core.sync.network.NetworkHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.IPacket;
import net.minecraft.network.PacketBuffer;
@@ -28,6 +29,7 @@ import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.api.features.AEFeature;
import appeng.core.sync.network.INetworkInfo;
import org.apache.commons.lang3.tuple.Pair;
public abstract class AppEngPacket
@@ -41,8 +43,7 @@ public abstract class AppEngPacket
public final int getPacketID()
{
throw new IllegalStateException();
// FIXME return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
}
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
@@ -68,7 +69,6 @@ public abstract class AppEngPacket
AELog.info( this.getClass().getName() + " : " + p.readableBytes() );
}
// FIXME return direction.buildPacket( Pair.of( p, 0 ), NetworkHandler.instance().getChannel() ).getThis();
return null;
return direction.buildPacket( Pair.of( p, 0 ), NetworkHandler.instance().getChannel() ).getThis();
}
}
@@ -61,70 +61,63 @@ public class AppEngPacketHandlerBase
public enum PacketTypes
{
PACKET_COMPASS_REQUEST( PacketCompassRequest::new ),
PACKET_COMPASS_REQUEST( PacketCompassRequest.class, PacketCompassRequest::new ),
PACKET_COMPASS_RESPONSE( PacketCompassResponse::new ),
PACKET_COMPASS_RESPONSE( PacketCompassResponse.class, PacketCompassResponse::new ),
PACKET_INVENTORY_ACTION( PacketInventoryAction::new ),
PACKET_INVENTORY_ACTION( PacketInventoryAction.class, PacketInventoryAction::new ),
PACKET_ME_INVENTORY_UPDATE( PacketMEInventoryUpdate::new ),
PACKET_ME_INVENTORY_UPDATE( PacketMEInventoryUpdate.class, PacketMEInventoryUpdate::new ),
PACKET_ME_FLUID_INVENTORY_UPDATE( PacketMEFluidInventoryUpdate::new ),
PACKET_ME_FLUID_INVENTORY_UPDATE( PacketMEFluidInventoryUpdate.class, PacketMEFluidInventoryUpdate::new ),
PACKET_CONFIG_BUTTON( PacketConfigButton::new ),
PACKET_CONFIG_BUTTON( PacketConfigButton.class, PacketConfigButton::new ),
PACKET_PART_PLACEMENT( PacketPartPlacement::new ),
PACKET_PART_PLACEMENT( PacketPartPlacement.class, PacketPartPlacement::new ),
PACKET_LIGHTNING( PacketLightning::new ),
PACKET_LIGHTNING( PacketLightning.class, PacketLightning::new ),
PACKET_MATTER_CANNON( PacketMatterCannon::new ),
PACKET_MATTER_CANNON( PacketMatterCannon.class, PacketMatterCannon::new ),
PACKET_MOCK_EXPLOSION( PacketMockExplosion::new ),
PACKET_MOCK_EXPLOSION( PacketMockExplosion.class, PacketMockExplosion::new ),
PACKET_VALUE_CONFIG( PacketValueConfig::new ),
PACKET_VALUE_CONFIG( PacketValueConfig.class, PacketValueConfig::new ),
PACKET_TRANSITION_EFFECT( PacketTransitionEffect::new ),
PACKET_TRANSITION_EFFECT( PacketTransitionEffect.class, PacketTransitionEffect::new ),
PACKET_PROGRESS_VALUE( PacketProgressBar::new ),
PACKET_PROGRESS_VALUE( PacketProgressBar.class, PacketProgressBar::new ),
PACKET_CLICK( PacketClick::new ),
PACKET_CLICK( PacketClick.class, PacketClick::new ),
PACKET_SWITCH_GUIS( PacketSwitchGuis::new ),
PACKET_SWITCH_GUIS( PacketSwitchGuis.class, PacketSwitchGuis::new ),
PACKET_SWAP_SLOTS( PacketSwapSlots::new ),
PACKET_SWAP_SLOTS( PacketSwapSlots.class, PacketSwapSlots::new ),
PACKET_PATTERN_SLOT( PacketPatternSlot::new ),
PACKET_PATTERN_SLOT( PacketPatternSlot.class, PacketPatternSlot::new ),
PACKET_RECIPE_JEI( PacketJEIRecipe::new ),
PACKET_RECIPE_JEI( PacketJEIRecipe.class, PacketJEIRecipe::new ),
PACKET_TARGET_ITEM( PacketTargetItemStack::new ),
PACKET_TARGET_ITEM( PacketTargetItemStack.class, PacketTargetItemStack::new ),
PACKET_TARGET_FLUID( PacketTargetFluidStack::new ),
PACKET_TARGET_FLUID( PacketTargetFluidStack.class, PacketTargetFluidStack::new ),
PACKET_CRAFTING_REQUEST( PacketCraftRequest::new ),
PACKET_CRAFTING_REQUEST( PacketCraftRequest.class, PacketCraftRequest::new ),
PACKET_ASSEMBLER_ANIMATION( PacketAssemblerAnimation::new ),
PACKET_ASSEMBLER_ANIMATION( PacketAssemblerAnimation.class, PacketAssemblerAnimation::new ),
PACKET_COMPRESSED_NBT( PacketCompressedNBT::new ),
PACKET_COMPRESSED_NBT( PacketCompressedNBT.class, PacketCompressedNBT::new ),
PACKET_PAINTED_ENTITY( PacketPaintedEntity::new ),
PACKET_PAINTED_ENTITY( PacketPaintedEntity.class, PacketPaintedEntity::new ),
PACKET_FLUID_TANK( PacketFluidSlot::new );
PACKET_FLUID_TANK( PacketFluidSlot.class, PacketFluidSlot::new );
private final Class<? extends AppEngPacket> packetClass;
private final Function<PacketBuffer, AppEngPacket> factory;
PacketTypes( Function<PacketBuffer, AppEngPacket> factory )
PacketTypes( Class<? extends AppEngPacket> packetClass, Function<PacketBuffer, AppEngPacket> factory )
{
Type c = TypeResolver.resolveGenericType( Function.class, factory.getClass() );
if( c == TypeResolver.Unknown.class )
{
throw new IllegalStateException("Failed to resolve type for AE packet type: " + factory.toString());
}
this.packetClass = (Class<? extends AppEngPacket>) c;
this.factory = factory;
REVERSE_LOOKUP.put( this.packetClass, this );
REVERSE_LOOKUP.put(packetClass, this );
}
public static PacketTypes getPacket( final int id )
@@ -72,8 +72,7 @@ public class NetworkHandler
{
try
{
// FIXME return new AppEngClientPacketHandler();
return null;
return new AppEngClientPacketHandler();
}
catch( final Throwable t )
{
@@ -85,8 +84,7 @@ public class NetworkHandler
{
try
{
// FIXME return new AppEngServerPacketHandler();
return null;
return new AppEngServerPacketHandler();
}
catch( final Throwable t )
{
@@ -56,7 +56,7 @@ public class PacketAssemblerAnimation extends AppEngPacket
}
// api
public PacketAssemblerAnimation( final BlockPos pos, final byte rate, final IAEItemStack is ) throws IOException
public PacketAssemblerAnimation( final BlockPos pos, final byte rate, final IAEItemStack is )
{
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
@@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import appeng.client.gui.implementations.GuiInterfaceTerminal;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
@@ -61,7 +62,7 @@ public class PacketCompressedNBT extends AppEngPacket
{
@Override
public int read() throws IOException
public int read()
{
if( stream.readableBytes() <= 0 )
{
@@ -80,6 +81,7 @@ public class PacketCompressedNBT extends AppEngPacket
}
}
// FIXME: this is pointless, PacketBuffer.writeNBT will already compress
// api
public PacketCompressedNBT( final CompoundNBT din ) throws IOException
{
@@ -93,7 +95,7 @@ public class PacketCompressedNBT extends AppEngPacket
{
@Override
public void write( final int value ) throws IOException
public void write( final int value )
{
PacketCompressedNBT.this.data.writeByte( value );
}
@@ -111,9 +113,9 @@ public class PacketCompressedNBT extends AppEngPacket
{
final Screen gs = Minecraft.getInstance().currentScreen;
// FIXME if( gs instanceof GuiInterfaceTerminal )
// FIXME {
// FIXME ( (GuiInterfaceTerminal) gs ).postUpdate( this.in );
// FIXME }
if( gs instanceof GuiInterfaceTerminal)
{
( (GuiInterfaceTerminal) gs ).postUpdate( this.in );
}
}
}
@@ -19,21 +19,10 @@
package appeng.core.sync.packets;
import java.io.IOException;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerInscriber;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.core.AppEng;
import appeng.core.sync.AppEngPacket;
@@ -41,6 +30,11 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.InventoryAction;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
public class PacketInventoryAction extends AppEngPacket
@@ -68,7 +62,7 @@ public class PacketInventoryAction extends AppEngPacket
}
// api
public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem ) throws IOException
public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem )
{
if( Platform.isClient() )
@@ -83,7 +83,7 @@ public class PacketJEIRecipe extends AppEngPacket
}
// api
public PacketJEIRecipe( final CompoundNBT recipe ) throws IOException
public PacketJEIRecipe( final CompoundNBT recipe )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
@@ -80,12 +80,10 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket
this.list = new LinkedList<>();
this.ref = stream.readByte();
// int originalBytes = stream.readableBytes();
try( final GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
{
@Override
public int read() throws IOException
public int read()
{
if( stream.readableBytes() <= 0 )
{
@@ -140,7 +138,7 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
@Override
public void write( final int value ) throws IOException
public void write( final int value )
{
PacketMEFluidInventoryUpdate.this.data.writeByte( value );
}
@@ -29,6 +29,10 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingCPU;
import appeng.client.gui.implementations.GuiMEMonitorable;
import appeng.client.gui.implementations.GuiNetworkStatus;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
@@ -80,7 +84,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
try( GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
{
@Override
public int read() throws IOException
public int read()
{
if( stream.readableBytes() <= 0 )
{
@@ -134,7 +138,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
@Override
public void write( final int value ) throws IOException
public void write( final int value )
{
PacketMEInventoryUpdate.this.data.writeByte( value );
}
@@ -149,25 +153,25 @@ public class PacketMEInventoryUpdate extends AppEngPacket
{
final Screen gs = Minecraft.getInstance().currentScreen;
// FIXME if( gs instanceof GuiCraftConfirm )
// FIXME {
// FIXME ( (GuiCraftConfirm) gs ).postUpdate( this.list, this.ref );
// FIXME }
// FIXME
// FIXME if( gs instanceof GuiCraftingCPU )
// FIXME {
// FIXME ( (GuiCraftingCPU) gs ).postUpdate( this.list, this.ref );
// FIXME }
// FIXME
// FIXME if( gs instanceof GuiMEMonitorable )
// FIXME {
// FIXME ( (GuiMEMonitorable) gs ).postUpdate( this.list );
// FIXME }
// FIXME
// FIXME if( gs instanceof GuiNetworkStatus )
// FIXME {
// FIXME ( (GuiNetworkStatus) gs ).postUpdate( this.list );
// FIXME }
if( gs instanceof GuiCraftConfirm)
{
( (GuiCraftConfirm) gs ).postUpdate( this.list, this.ref );
}
if( gs instanceof GuiCraftingCPU)
{
( (GuiCraftingCPU<?>) gs ).postUpdate( this.list, this.ref );
}
if( gs instanceof GuiMEMonitorable)
{
( (GuiMEMonitorable<?>) gs ).postUpdate( this.list );
}
if( gs instanceof GuiNetworkStatus)
{
( (GuiNetworkStatus) gs ).postUpdate( this.list );
}
}
@Nullable
@@ -72,7 +72,7 @@ public class PacketPatternSlot extends AppEngPacket
}
// api
public PacketPatternSlot( final IItemHandler pat, final IAEItemStack slotItem, final boolean shift ) throws IOException
public PacketPatternSlot( final IItemHandler pat, final IAEItemStack slotItem, final boolean shift )
{
this.slotItem = slotItem;
@@ -94,7 +94,7 @@ public class PacketPatternSlot extends AppEngPacket
this.configureWrite( data );
}
private void writeItem( final IAEItemStack slotItem, final PacketBuffer data ) throws IOException
private void writeItem( final IAEItemStack slotItem, final PacketBuffer data )
{
if( slotItem == null )
{