pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,57 +18,52 @@
package appeng.core.sync;
import org.apache.commons.lang3.tuple.Pair;
import appeng.core.sync.network.NetworkHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.IPacket;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkDirection;
import appeng.api.features.AEFeature;
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;
import appeng.core.sync.network.NetworkHandler;
public abstract class AppEngPacket {
private PacketBuffer p;
public abstract class AppEngPacket
{
private PacketBuffer p;
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
throw new UnsupportedOperationException(
"This packet ( " + this.getPacketID() + " does not implement a server side handler.");
}
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
throw new UnsupportedOperationException( "This packet ( " + this.getPacketID() + " does not implement a server side handler." );
}
public final int getPacketID() {
return AppEngPacketHandlerBase.PacketTypes.getID(this.getClass()).ordinal();
}
public final int getPacketID()
{
return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
}
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
throw new UnsupportedOperationException(
"This packet ( " + this.getPacketID() + " does not implement a client side handler.");
}
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
throw new UnsupportedOperationException( "This packet ( " + this.getPacketID() + " does not implement a client side handler." );
}
protected void configureWrite(final PacketBuffer data) {
data.capacity(data.readableBytes());
this.p = data;
}
protected void configureWrite( final PacketBuffer data )
{
data.capacity( data.readableBytes() );
this.p = data;
}
public IPacket<?> toPacket(NetworkDirection direction) {
if (this.p.array().length > 2 * 1024 * 1024) // 2k walking room :)
{
throw new IllegalArgumentException(
"Sorry AE2 made a " + this.p.array().length + " byte packet by accident!");
}
public IPacket<?> toPacket( NetworkDirection direction )
{
if( this.p.array().length > 2 * 1024 * 1024 ) // 2k walking room :)
{
throw new IllegalArgumentException( "Sorry AE2 made a " + this.p.array().length + " byte packet by accident!" );
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.PACKET_LOGGING)) {
AELog.info(this.getClass().getName() + " : " + p.readableBytes());
}
if( AEConfig.instance().isFeatureEnabled( AEFeature.PACKET_LOGGING ) )
{
AELog.info( this.getClass().getName() + " : " + p.readableBytes() );
}
return direction.buildPacket( Pair.of( p, 0 ), NetworkHandler.instance().getChannel() ).getThis();
}
return direction.buildPacket(Pair.of(p, 0), NetworkHandler.instance().getChannel()).getThis();
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
@@ -53,86 +52,78 @@ import appeng.core.sync.packets.PacketTargetItemStack;
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.core.sync.packets.PacketValueConfig;
public class AppEngPacketHandlerBase {
private static final Map<Class<? extends AppEngPacket>, PacketTypes> REVERSE_LOOKUP = new HashMap<>();
public class AppEngPacketHandlerBase
{
private static final Map<Class<? extends AppEngPacket>, PacketTypes> REVERSE_LOOKUP = new HashMap<>();
public enum PacketTypes {
PACKET_COMPASS_REQUEST(PacketCompassRequest.class, PacketCompassRequest::new),
PACKET_COMPASS_RESPONSE(PacketCompassResponse.class, PacketCompassResponse::new),
public enum PacketTypes
{
PACKET_COMPASS_REQUEST( PacketCompassRequest.class, PacketCompassRequest::new ),
PACKET_INVENTORY_ACTION(PacketInventoryAction.class, PacketInventoryAction::new),
PACKET_COMPASS_RESPONSE( PacketCompassResponse.class, PacketCompassResponse::new ),
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class, PacketMEInventoryUpdate::new),
PACKET_INVENTORY_ACTION( PacketInventoryAction.class, PacketInventoryAction::new ),
PACKET_ME_FLUID_INVENTORY_UPDATE(PacketMEFluidInventoryUpdate.class, PacketMEFluidInventoryUpdate::new),
PACKET_ME_INVENTORY_UPDATE( PacketMEInventoryUpdate.class, PacketMEInventoryUpdate::new ),
PACKET_CONFIG_BUTTON(PacketConfigButton.class, PacketConfigButton::new),
PACKET_ME_FLUID_INVENTORY_UPDATE( PacketMEFluidInventoryUpdate.class, PacketMEFluidInventoryUpdate::new ),
PACKET_PART_PLACEMENT(PacketPartPlacement.class, PacketPartPlacement::new),
PACKET_CONFIG_BUTTON( PacketConfigButton.class, PacketConfigButton::new ),
PACKET_LIGHTNING(PacketLightning.class, PacketLightning::new),
PACKET_PART_PLACEMENT( PacketPartPlacement.class, PacketPartPlacement::new ),
PACKET_MATTER_CANNON(PacketMatterCannon.class, PacketMatterCannon::new),
PACKET_LIGHTNING( PacketLightning.class, PacketLightning::new ),
PACKET_MOCK_EXPLOSION(PacketMockExplosion.class, PacketMockExplosion::new),
PACKET_MATTER_CANNON( PacketMatterCannon.class, PacketMatterCannon::new ),
PACKET_VALUE_CONFIG(PacketValueConfig.class, PacketValueConfig::new),
PACKET_MOCK_EXPLOSION( PacketMockExplosion.class, PacketMockExplosion::new ),
PACKET_TRANSITION_EFFECT(PacketTransitionEffect.class, PacketTransitionEffect::new),
PACKET_VALUE_CONFIG( PacketValueConfig.class, PacketValueConfig::new ),
PACKET_PROGRESS_VALUE(PacketProgressBar.class, PacketProgressBar::new),
PACKET_TRANSITION_EFFECT( PacketTransitionEffect.class, PacketTransitionEffect::new ),
PACKET_CLICK(PacketClick.class, PacketClick::new),
PACKET_PROGRESS_VALUE( PacketProgressBar.class, PacketProgressBar::new ),
PACKET_SWITCH_GUIS(PacketSwitchGuis.class, PacketSwitchGuis::new),
PACKET_CLICK( PacketClick.class, PacketClick::new ),
PACKET_SWAP_SLOTS(PacketSwapSlots.class, PacketSwapSlots::new),
PACKET_SWITCH_GUIS( PacketSwitchGuis.class, PacketSwitchGuis::new ),
PACKET_PATTERN_SLOT(PacketPatternSlot.class, PacketPatternSlot::new),
PACKET_SWAP_SLOTS( PacketSwapSlots.class, PacketSwapSlots::new ),
PACKET_RECIPE_JEI(PacketJEIRecipe.class, PacketJEIRecipe::new),
PACKET_PATTERN_SLOT( PacketPatternSlot.class, PacketPatternSlot::new ),
PACKET_TARGET_ITEM(PacketTargetItemStack.class, PacketTargetItemStack::new),
PACKET_RECIPE_JEI( PacketJEIRecipe.class, PacketJEIRecipe::new ),
PACKET_TARGET_FLUID(PacketTargetFluidStack.class, PacketTargetFluidStack::new),
PACKET_TARGET_ITEM( PacketTargetItemStack.class, PacketTargetItemStack::new ),
PACKET_CRAFTING_REQUEST(PacketCraftRequest.class, PacketCraftRequest::new),
PACKET_TARGET_FLUID( PacketTargetFluidStack.class, PacketTargetFluidStack::new ),
PACKET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class, PacketAssemblerAnimation::new),
PACKET_CRAFTING_REQUEST( PacketCraftRequest.class, PacketCraftRequest::new ),
PACKET_COMPRESSED_NBT(PacketCompressedNBT.class, PacketCompressedNBT::new),
PACKET_ASSEMBLER_ANIMATION( PacketAssemblerAnimation.class, PacketAssemblerAnimation::new ),
PACKET_PAINTED_ENTITY(PacketPaintedEntity.class, PacketPaintedEntity::new),
PACKET_COMPRESSED_NBT( PacketCompressedNBT.class, PacketCompressedNBT::new ),
PACKET_FLUID_TANK(PacketFluidSlot.class, PacketFluidSlot::new);
PACKET_PAINTED_ENTITY( PacketPaintedEntity.class, PacketPaintedEntity::new ),
private final Function<PacketBuffer, AppEngPacket> factory;
PACKET_FLUID_TANK( PacketFluidSlot.class, PacketFluidSlot::new );
PacketTypes(Class<? extends AppEngPacket> packetClass, Function<PacketBuffer, AppEngPacket> factory) {
this.factory = factory;
private final Function<PacketBuffer, AppEngPacket> factory;
REVERSE_LOOKUP.put(packetClass, this);
}
PacketTypes( Class<? extends AppEngPacket> packetClass, Function<PacketBuffer, AppEngPacket> factory )
{
this.factory = factory;
public static PacketTypes getPacket(final int id) {
return (values())[id];
}
REVERSE_LOOKUP.put(packetClass, this );
}
static PacketTypes getID(final Class<? extends AppEngPacket> c) {
return REVERSE_LOOKUP.get(c);
}
public static PacketTypes getPacket( final int id )
{
return ( values() )[id];
}
static PacketTypes getID( final Class<? extends AppEngPacket> c )
{
return REVERSE_LOOKUP.get( c );
}
public AppEngPacket parsePacket( final PacketBuffer in ) throws IllegalArgumentException
{
return this.factory.apply( in );
}
}
public AppEngPacket parsePacket(final PacketBuffer in) throws IllegalArgumentException {
return this.factory.apply(in);
}
}
}
+322 -375
View File
@@ -18,7 +18,6 @@
package appeng.core.sync;
import java.lang.reflect.Constructor;
import net.minecraft.entity.player.PlayerEntity;
@@ -48,8 +47,8 @@ import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerNull;
import appeng.container.ContainerLocator;
import appeng.container.ContainerNull;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.container.implementations.ContainerChest;
import appeng.container.implementations.ContainerCondenser;
@@ -121,420 +120,368 @@ import appeng.tile.storage.TileIOPort;
import appeng.tile.storage.TileSkyChest;
import appeng.util.Platform;
public enum GuiBridge {
GUI_Handler(),
public enum GuiBridge
{
GUI_Handler(),
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, GuiHostType.WORLD, null),
GUI_GRINDER( ContainerGrinder.class, TileGrinder.class, GuiHostType.WORLD, null ),
GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_QNB( ContainerQNB.class, TileQuantumBridge.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, GuiHostType.WORLD, null),
GUI_SKYCHEST( ContainerSkyChest.class, TileSkyChest.class, GuiHostType.WORLD, null ),
GUI_CHEST(ContainerChest.class, TileChest.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_CHEST( ContainerChest.class, TileChest.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_WIRELESS(ContainerWireless.class, TileWireless.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_WIRELESS( ContainerWireless.class, TileWireless.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, GuiHostType.WORLD, null),
GUI_ME( ContainerMEMonitorable.class, ITerminalHost.class, GuiHostType.WORLD, null ),
GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, GuiHostType.ITEM, null),
GUI_PORTABLE_CELL( ContainerMEPortableCell.class, IPortableCell.class, GuiHostType.ITEM, null ),
GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null),
GUI_WIRELESS_TERM( ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, GuiHostType.ITEM, null ),
GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, GuiHostType.ITEM, null),
GUI_NETWORK_STATUS( ContainerNetworkStatus.class, INetworkTool.class, GuiHostType.ITEM, null ),
GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, GuiHostType.WORLD, SecurityPermissions.CRAFT),
GUI_CRAFTING_CPU( ContainerCraftingCPU.class, TileCraftingTile.class, GuiHostType.WORLD, SecurityPermissions.CRAFT ),
GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, GuiHostType.ITEM, null),
GUI_NETWORK_TOOL( ContainerNetworkTool.class, INetworkTool.class, GuiHostType.ITEM, null ),
GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, GuiHostType.ITEM, null),
GUI_QUARTZ_KNIFE( ContainerQuartzKnife.class, QuartzKnifeObj.class, GuiHostType.ITEM, null ),
GUI_DRIVE(ContainerDrive.class, TileDrive.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_DRIVE( ContainerDrive.class, TileDrive.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_VIBRATION_CHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, GuiHostType.WORLD, null),
GUI_VIBRATION_CHAMBER( ContainerVibrationChamber.class, TileVibrationChamber.class, GuiHostType.WORLD, null ),
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, GuiHostType.WORLD, null),
GUI_CONDENSER( ContainerCondenser.class, TileCondenser.class, GuiHostType.WORLD, null ),
GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_INTERFACE( ContainerInterface.class, IInterfaceHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_FLUID_INTERFACE(ContainerFluidInterface.class, IFluidInterfaceHost.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_FLUID_INTERFACE( ContainerFluidInterface.class, IFluidInterfaceHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_BUS( ContainerUpgradeable.class, IUpgradeableHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_BUS_FLUID(ContainerFluidIO.class, PartSharedFluidBus.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_BUS_FLUID( ContainerFluidIO.class, PartSharedFluidBus.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_IOPORT( ContainerIOPort.class, TileIOPort.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_STORAGEBUS( ContainerStorageBus.class, PartStorageBus.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_STORAGEBUS_FLUID(ContainerFluidStorageBus.class, PartFluidStorageBus.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_STORAGEBUS_FLUID( ContainerFluidStorageBus.class, PartFluidStorageBus.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_FORMATION_PLANE(ContainerFormationPlane.class, PartFormationPlane.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_FORMATION_PLANE( ContainerFormationPlane.class, PartFormationPlane.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_FLUID_FORMATION_PLANE(ContainerFluidFormationPlane.class, PartFluidFormationPlane.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_FLUID_FORMATION_PLANE( ContainerFluidFormationPlane.class, PartFluidFormationPlane.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_PRIORITY( ContainerPriority.class, IPriorityHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_SECURITY(ContainerSecurityStation.class, TileSecurityStation.class, GuiHostType.WORLD,
SecurityPermissions.SECURITY),
GUI_SECURITY( ContainerSecurityStation.class, TileSecurityStation.class, GuiHostType.WORLD, SecurityPermissions.SECURITY ),
GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, GuiHostType.WORLD,
SecurityPermissions.CRAFT),
GUI_CRAFTING_TERMINAL( ContainerCraftingTerm.class, PartCraftingTerminal.class, GuiHostType.WORLD, SecurityPermissions.CRAFT ),
GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, GuiHostType.WORLD,
SecurityPermissions.CRAFT),
GUI_PATTERN_TERMINAL( ContainerPatternTerm.class, PartPatternTerminal.class, GuiHostType.WORLD, SecurityPermissions.CRAFT ),
GUI_FLUID_TERMINAL(ContainerFluidTerminal.class, ITerminalHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD),
GUI_FLUID_TERMINAL( ContainerFluidTerminal.class, ITerminalHost.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
// extends (Container/Gui) + Bus
GUI_LEVEL_EMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
// extends (Container/Gui) + Bus
GUI_LEVEL_EMITTER( ContainerLevelEmitter.class, PartLevelEmitter.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_FLUID_LEVEL_EMITTER(ContainerFluidLevelEmitter.class, PartFluidLevelEmitter.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_FLUID_LEVEL_EMITTER( ContainerFluidLevelEmitter.class, PartFluidLevelEmitter.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_SPATIAL_IO_PORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_SPATIAL_IO_PORT( ContainerSpatialIOPort.class, TileSpatialIOPort.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, GuiHostType.WORLD, null),
GUI_INSCRIBER( ContainerInscriber.class, TileInscriber.class, GuiHostType.WORLD, null ),
GUI_CELL_WORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, GuiHostType.WORLD, null),
GUI_CELL_WORKBENCH( ContainerCellWorkbench.class, TileCellWorkbench.class, GuiHostType.WORLD, null ),
GUI_MAC(ContainerMAC.class, TileMolecularAssembler.class, GuiHostType.WORLD, null),
GUI_MAC( ContainerMAC.class, TileMolecularAssembler.class, GuiHostType.WORLD, null ),
GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD,
SecurityPermissions.CRAFT),
GUI_CRAFTING_AMOUNT( ContainerCraftAmount.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD,
SecurityPermissions.CRAFT),
GUI_CRAFTING_CONFIRM( ContainerCraftConfirm.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartInterfaceTerminal.class, GuiHostType.WORLD,
SecurityPermissions.BUILD),
GUI_INTERFACE_TERMINAL( ContainerInterfaceTerminal.class, PartInterfaceTerminal.class, GuiHostType.WORLD, SecurityPermissions.BUILD ),
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD,
SecurityPermissions.CRAFT);
GUI_CRAFTING_STATUS( ContainerCraftingStatus.class, ITerminalHost.class, GuiHostType.ITEM_OR_WORLD, SecurityPermissions.CRAFT );
private final Class tileClass;
private final Class containerClass;
private Class guiClass;
private GuiHostType type;
private SecurityPermissions requiredPermission;
private final Class tileClass;
private final Class containerClass;
private Class guiClass;
private GuiHostType type;
private SecurityPermissions requiredPermission;
GuiBridge() {
this.tileClass = null;
this.guiClass = null;
this.containerClass = null;
}
GuiBridge()
{
this.tileClass = null;
this.guiClass = null;
this.containerClass = null;
}
GuiBridge( final Class containerClass, final SecurityPermissions requiredPermission )
{
this.requiredPermission = requiredPermission;
this.containerClass = containerClass;
this.tileClass = null;
this.getGui();
}
/**
* I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server
* Exploding.
*/
private void getGui()
{
if( Platform.isClient() )
{
AEBaseGui.class.getName();
final String start = this.containerClass.getName();
final String guiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if( start.equals( guiClass ) )
{
throw new IllegalStateException( "Unable to find gui class" );
}
this.guiClass = null; // FIXME ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass );
if( this.guiClass == null )
{
throw new IllegalStateException( "Cannot Load class: " + guiClass );
}
}
}
GuiBridge( final Class containerClass, final Class tileClass, final GuiHostType type, final SecurityPermissions requiredPermission )
{
this.requiredPermission = requiredPermission;
this.containerClass = containerClass;
this.type = type;
this.tileClass = tileClass;
this.getGui();
}
public Object getServerGuiElement( final int ordinal, final PlayerEntity player, final World w, final int x, final int y, final int z )
{
final AEPartLocation side = AEPartLocation.fromOrdinal( ordinal & 0x07 );
final GuiBridge ID = values()[ordinal >> 4];
final boolean stem = ( ( ordinal >> 3 ) & 1 ) == 1;
if( ID.type.isItem() )
{
ItemStack it = ItemStack.EMPTY;
if( stem )
{
it = player.inventory.getCurrentItem();
}
else if( x >= 0 && x < player.inventory.mainInventory.size() )
{
it = player.inventory.getStackInSlot( x );
}
final Object myItem = this.getGuiObject( it, player, w, x, y, z );
if( myItem != null && ID.CorrectTileOrPart( myItem ) )
{
return this.updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem );
}
}
if( ID.type.isTile() )
{
final TileEntity TE = w.getTileEntity( new BlockPos( x, y, z ) );
if( TE instanceof IPartHost )
{
( (IPartHost) TE ).getPart( side );
final IPart part = ( (IPartHost) TE ).getPart( side );
if( ID.CorrectTileOrPart( part ) )
{
return this.updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part );
}
}
else
{
if( ID.CorrectTileOrPart( TE ) )
{
return this.updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE );
}
}
}
return new ContainerNull();
}
private Object getGuiObject( final ItemStack it, final PlayerEntity player, final World w, final int x, final int y, final int z )
{
return null;
}
public boolean CorrectTileOrPart( final Object tE )
{
if( this.tileClass == null )
{
throw new IllegalArgumentException( "This Gui Cannot use the standard Handler." );
}
return this.tileClass.isInstance( tE );
}
private Object updateGui( final Object newContainer, final World w, final int x, final int y, final int z, final AEPartLocation side, final Object myItem )
{
if( newContainer instanceof AEBaseContainer )
{
// FIXME final AEBaseContainer bc = (AEBaseContainer) newContainer;
// FIXME bc.setLocator( new ContainerLocator( myItem ) );
// FIXME bc.getLocator().setWorld( w );
// FIXME bc.getLocator().setX( x );
// FIXME bc.getLocator().setY( y );
// FIXME bc.getLocator().setZ( z );
// FIXME bc.getLocator().setSide( side );
}
return newContainer;
}
public Object ConstructContainer( final PlayerInventory inventory, final AEPartLocation side, final Object tE )
{
try
{
final Constructor[] c = this.containerClass.getConstructors();
if( c.length == 0 )
{
throw new AppEngException( "Invalid Gui Class" );
}
final Constructor target = this.findConstructor( c, inventory, tE );
if( target == null )
{
throw new IllegalStateException( "Cannot find " + this.containerClass.getName() + "( " + this.typeName( inventory ) + ", " + this
.typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch( final Throwable t )
{
throw new IllegalStateException( t );
}
}
private Constructor findConstructor( final Constructor[] c, final PlayerInventory inventory, final Object tE )
{
for( final Constructor con : c )
{
final Class[] types = con.getParameterTypes();
if( types.length == 2 )
{
if( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
{
return con;
}
}
}
return null;
}
private String typeName( final Object inventory )
{
if( inventory == null )
{
return "NULL";
}
return inventory.getClass().getName();
}
public Object getClientGuiElement( final int ordinal, final PlayerEntity player, final World w, final int x, final int y, final int z )
{
final AEPartLocation side = AEPartLocation.fromOrdinal( ordinal & 0x07 );
final GuiBridge ID = values()[ordinal >> 4];
final boolean stem = ( ( ordinal >> 3 ) & 1 ) == 1;
if( ID.type.isItem() )
{
ItemStack it = ItemStack.EMPTY;
if( stem )
{
it = player.inventory.getCurrentItem();
}
else if( x >= 0 && x < player.inventory.mainInventory.size() )
{
it = player.inventory.getStackInSlot( x );
}
final Object myItem = this.getGuiObject( it, player, w, x, y, z );
if( myItem != null && ID.CorrectTileOrPart( myItem ) )
{
return ID.ConstructGui( player.inventory, side, myItem );
}
}
if( ID.type.isTile() )
{
final TileEntity TE = w.getTileEntity( new BlockPos( x, y, z ) );
if( TE instanceof IPartHost )
{
( (IPartHost) TE ).getPart( side );
final IPart part = ( (IPartHost) TE ).getPart( side );
if( ID.CorrectTileOrPart( part ) )
{
return ID.ConstructGui( player.inventory, side, part );
}
}
else
{
if( ID.CorrectTileOrPart( TE ) )
{
return ID.ConstructGui( player.inventory, side, TE );
}
}
}
return null; // FIXME
}
public Object ConstructGui( final PlayerInventory inventory, final AEPartLocation side, final Object tE )
{
try
{
final Constructor[] c = this.guiClass.getConstructors();
if( c.length == 0 )
{
throw new AppEngException( "Invalid Gui Class" );
}
final Constructor target = this.findConstructor( c, inventory, tE );
if( target == null )
{
throw new IllegalStateException( "Cannot find " + this.containerClass.getName() + "( " + this.typeName( inventory ) + ", " + this
.typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch( final Throwable t )
{
throw new IllegalStateException( t );
}
}
public boolean hasPermissions( final TileEntity te, final int x, final int y, final int z, final AEPartLocation side, final PlayerEntity player )
{
final World w = player.getEntityWorld();
final BlockPos pos = new BlockPos( x, y, z );
if( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.world, pos ), player ) )
{
if( this.type.isItem() )
{
final ItemStack it = player.inventory.getCurrentItem();
if( !it.isEmpty() && it.getItem() instanceof IGuiItem )
{
}
}
if( this.type.isTile() )
{
final TileEntity TE = w.getTileEntity( pos );
if( TE instanceof IPartHost )
{
( (IPartHost) TE ).getPart( side );
final IPart part = ( (IPartHost) TE ).getPart( side );
if( this.CorrectTileOrPart( part ) )
{
return this.securityCheck( part, player );
}
}
else
{
if( this.CorrectTileOrPart( TE ) )
{
return this.securityCheck( TE, player );
}
}
}
}
return false;
}
private boolean securityCheck( final Object te, final PlayerEntity player )
{
if( te instanceof IActionHost && this.requiredPermission != null )
{
final IGridNode gn = ( (IActionHost) te ).getActionableNode();
if( gn != null )
{
final IGrid g = gn.getGrid();
if( g != null )
{
final boolean requirePower = false;
if( requirePower )
{
final IEnergyGrid eg = g.getCache( IEnergyGrid.class );
if( !eg.isNetworkPowered() )
{
return false;
}
}
final ISecurityGrid sg = g.getCache( ISecurityGrid.class );
if( sg.hasPermission( player, this.requiredPermission ) )
{
return true;
}
}
}
return false;
}
return true;
}
public GuiHostType getType()
{
return this.type;
}
GuiBridge(final Class containerClass, final SecurityPermissions requiredPermission) {
this.requiredPermission = requiredPermission;
this.containerClass = containerClass;
this.tileClass = null;
this.getGui();
}
/**
* I honestly wish I could just use the GuiClass Names myself, but I can't
* access them without MC's Server Exploding.
*/
private void getGui() {
if (Platform.isClient()) {
AEBaseGui.class.getName();
final String start = this.containerClass.getName();
final String guiClass = start.replaceFirst("container.", "client.gui.").replace(".Container", ".Gui");
if (start.equals(guiClass)) {
throw new IllegalStateException("Unable to find gui class");
}
this.guiClass = null; // FIXME ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass
// );
if (this.guiClass == null) {
throw new IllegalStateException("Cannot Load class: " + guiClass);
}
}
}
GuiBridge(final Class containerClass, final Class tileClass, final GuiHostType type,
final SecurityPermissions requiredPermission) {
this.requiredPermission = requiredPermission;
this.containerClass = containerClass;
this.type = type;
this.tileClass = tileClass;
this.getGui();
}
public Object getServerGuiElement(final int ordinal, final PlayerEntity player, final World w, final int x,
final int y, final int z) {
final AEPartLocation side = AEPartLocation.fromOrdinal(ordinal & 0x07);
final GuiBridge ID = values()[ordinal >> 4];
final boolean stem = ((ordinal >> 3) & 1) == 1;
if (ID.type.isItem()) {
ItemStack it = ItemStack.EMPTY;
if (stem) {
it = player.inventory.getCurrentItem();
} else if (x >= 0 && x < player.inventory.mainInventory.size()) {
it = player.inventory.getStackInSlot(x);
}
final Object myItem = this.getGuiObject(it, player, w, x, y, z);
if (myItem != null && ID.CorrectTileOrPart(myItem)) {
return this.updateGui(ID.ConstructContainer(player.inventory, side, myItem), w, x, y, z, side, myItem);
}
}
if (ID.type.isTile()) {
final TileEntity TE = w.getTileEntity(new BlockPos(x, y, z));
if (TE instanceof IPartHost) {
((IPartHost) TE).getPart(side);
final IPart part = ((IPartHost) TE).getPart(side);
if (ID.CorrectTileOrPart(part)) {
return this.updateGui(ID.ConstructContainer(player.inventory, side, part), w, x, y, z, side, part);
}
} else {
if (ID.CorrectTileOrPart(TE)) {
return this.updateGui(ID.ConstructContainer(player.inventory, side, TE), w, x, y, z, side, TE);
}
}
}
return new ContainerNull();
}
private Object getGuiObject(final ItemStack it, final PlayerEntity player, final World w, final int x, final int y,
final int z) {
return null;
}
public boolean CorrectTileOrPart(final Object tE) {
if (this.tileClass == null) {
throw new IllegalArgumentException("This Gui Cannot use the standard Handler.");
}
return this.tileClass.isInstance(tE);
}
private Object updateGui(final Object newContainer, final World w, final int x, final int y, final int z,
final AEPartLocation side, final Object myItem) {
if (newContainer instanceof AEBaseContainer) {
// FIXME final AEBaseContainer bc = (AEBaseContainer) newContainer;
// FIXME bc.setLocator( new ContainerLocator( myItem ) );
// FIXME bc.getLocator().setWorld( w );
// FIXME bc.getLocator().setX( x );
// FIXME bc.getLocator().setY( y );
// FIXME bc.getLocator().setZ( z );
// FIXME bc.getLocator().setSide( side );
}
return newContainer;
}
public Object ConstructContainer(final PlayerInventory inventory, final AEPartLocation side, final Object tE) {
try {
final Constructor[] c = this.containerClass.getConstructors();
if (c.length == 0) {
throw new AppEngException("Invalid Gui Class");
}
final Constructor target = this.findConstructor(c, inventory, tE);
if (target == null) {
throw new IllegalStateException("Cannot find " + this.containerClass.getName() + "( "
+ this.typeName(inventory) + ", " + this.typeName(tE) + " )");
}
return target.newInstance(inventory, tE);
} catch (final Throwable t) {
throw new IllegalStateException(t);
}
}
private Constructor findConstructor(final Constructor[] c, final PlayerInventory inventory, final Object tE) {
for (final Constructor con : c) {
final Class[] types = con.getParameterTypes();
if (types.length == 2) {
if (types[0].isAssignableFrom(inventory.getClass()) && types[1].isAssignableFrom(tE.getClass())) {
return con;
}
}
}
return null;
}
private String typeName(final Object inventory) {
if (inventory == null) {
return "NULL";
}
return inventory.getClass().getName();
}
public Object getClientGuiElement(final int ordinal, final PlayerEntity player, final World w, final int x,
final int y, final int z) {
final AEPartLocation side = AEPartLocation.fromOrdinal(ordinal & 0x07);
final GuiBridge ID = values()[ordinal >> 4];
final boolean stem = ((ordinal >> 3) & 1) == 1;
if (ID.type.isItem()) {
ItemStack it = ItemStack.EMPTY;
if (stem) {
it = player.inventory.getCurrentItem();
} else if (x >= 0 && x < player.inventory.mainInventory.size()) {
it = player.inventory.getStackInSlot(x);
}
final Object myItem = this.getGuiObject(it, player, w, x, y, z);
if (myItem != null && ID.CorrectTileOrPart(myItem)) {
return ID.ConstructGui(player.inventory, side, myItem);
}
}
if (ID.type.isTile()) {
final TileEntity TE = w.getTileEntity(new BlockPos(x, y, z));
if (TE instanceof IPartHost) {
((IPartHost) TE).getPart(side);
final IPart part = ((IPartHost) TE).getPart(side);
if (ID.CorrectTileOrPart(part)) {
return ID.ConstructGui(player.inventory, side, part);
}
} else {
if (ID.CorrectTileOrPart(TE)) {
return ID.ConstructGui(player.inventory, side, TE);
}
}
}
return null; // FIXME
}
public Object ConstructGui(final PlayerInventory inventory, final AEPartLocation side, final Object tE) {
try {
final Constructor[] c = this.guiClass.getConstructors();
if (c.length == 0) {
throw new AppEngException("Invalid Gui Class");
}
final Constructor target = this.findConstructor(c, inventory, tE);
if (target == null) {
throw new IllegalStateException("Cannot find " + this.containerClass.getName() + "( "
+ this.typeName(inventory) + ", " + this.typeName(tE) + " )");
}
return target.newInstance(inventory, tE);
} catch (final Throwable t) {
throw new IllegalStateException(t);
}
}
public boolean hasPermissions(final TileEntity te, final int x, final int y, final int z, final AEPartLocation side,
final PlayerEntity player) {
final World w = player.getEntityWorld();
final BlockPos pos = new BlockPos(x, y, z);
if (Platform.hasPermissions(te != null ? new DimensionalCoord(te) : new DimensionalCoord(player.world, pos),
player)) {
if (this.type.isItem()) {
final ItemStack it = player.inventory.getCurrentItem();
if (!it.isEmpty() && it.getItem() instanceof IGuiItem) {
}
}
if (this.type.isTile()) {
final TileEntity TE = w.getTileEntity(pos);
if (TE instanceof IPartHost) {
((IPartHost) TE).getPart(side);
final IPart part = ((IPartHost) TE).getPart(side);
if (this.CorrectTileOrPart(part)) {
return this.securityCheck(part, player);
}
} else {
if (this.CorrectTileOrPart(TE)) {
return this.securityCheck(TE, player);
}
}
}
}
return false;
}
private boolean securityCheck(final Object te, final PlayerEntity player) {
if (te instanceof IActionHost && this.requiredPermission != null) {
final IGridNode gn = ((IActionHost) te).getActionableNode();
if (gn != null) {
final IGrid g = gn.getGrid();
if (g != null) {
final boolean requirePower = false;
if (requirePower) {
final IEnergyGrid eg = g.getCache(IEnergyGrid.class);
if (!eg.isNetworkPowered()) {
return false;
}
}
final ISecurityGrid sg = g.getCache(ISecurityGrid.class);
if (sg.hasPermission(player, this.requiredPermission)) {
return true;
}
}
}
return false;
}
return true;
}
public GuiHostType getType() {
return this.type;
}
}
@@ -18,18 +18,14 @@
package appeng.core.sync;
public enum GuiHostType {
ITEM_OR_WORLD, ITEM, WORLD;
public enum GuiHostType
{
ITEM_OR_WORLD, ITEM, WORLD;
public boolean isItem() {
return this != WORLD;
}
public boolean isItem()
{
return this != WORLD;
}
boolean isTile()
{
return this != ITEM;
}
boolean isTile() {
return this != ITEM;
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.network;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.client.Minecraft;
@@ -30,22 +29,17 @@ import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler {
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData( final INetworkInfo manager, final INetHandler handler, final PacketBuffer packet, final PlayerEntity player )
{
try
{
final int packetType = packet.readInt();
final AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( packet );
pack.clientPacketData( manager, Minecraft.getInstance().player );
}
catch( final IllegalArgumentException e )
{
AELog.debug( e );
}
}
@Override
public void onPacketData(final INetworkInfo manager, final INetHandler handler, final PacketBuffer packet,
final PlayerEntity player) {
try {
final int packetType = packet.readInt();
final AppEngPacket pack = PacketTypes.getPacket(packetType).parsePacket(packet);
pack.clientPacketData(manager, Minecraft.getInstance().player);
} catch (final IllegalArgumentException e) {
AELog.debug(e);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.network;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.entity.player.PlayerEntity;
@@ -29,22 +28,17 @@ import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler {
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData( final INetworkInfo manager, final INetHandler handler, final PacketBuffer packet, final PlayerEntity player )
{
try
{
final int packetType = packet.readInt();
final AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( packet );
pack.serverPacketData( manager, player );
}
catch( final IllegalArgumentException e )
{
AELog.debug( e );
}
}
@Override
public void onPacketData(final INetworkInfo manager, final INetHandler handler, final PacketBuffer packet,
final PlayerEntity player) {
try {
final int packetType = packet.readInt();
final AppEngPacket pack = PacketTypes.getPacket(packetType).parsePacket(packet);
pack.serverPacketData(manager, player);
} catch (final IllegalArgumentException e) {
AELog.debug(e);
}
}
}
@@ -18,8 +18,6 @@
package appeng.core.sync.network;
public interface INetworkInfo
{
public interface INetworkInfo {
}
@@ -18,15 +18,12 @@
package appeng.core.sync.network;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.INetHandler;
import net.minecraft.network.PacketBuffer;
public interface IPacketHandler {
public interface IPacketHandler
{
void onPacketData(INetworkInfo manager, INetHandler handler, PacketBuffer packet, PlayerEntity player );
void onPacketData(INetworkInfo manager, INetHandler handler, PacketBuffer packet, PlayerEntity player);
}
@@ -18,7 +18,6 @@
package appeng.core.sync.network;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.INetHandler;
@@ -38,136 +37,109 @@ import net.minecraftforge.fml.network.event.EventNetworkChannel;
import appeng.core.sync.AppEngPacket;
public class NetworkHandler {
private static NetworkHandler instance;
public class NetworkHandler
{
private static NetworkHandler instance;
private final EventNetworkChannel ec;
private final ResourceLocation myChannelName;
private final EventNetworkChannel ec;
private final ResourceLocation myChannelName;
private final IPacketHandler clientHandler;
private final IPacketHandler serveHandler;
private final IPacketHandler clientHandler;
private final IPacketHandler serveHandler;
public NetworkHandler(final ResourceLocation channelName) {
ec = NetworkRegistry.ChannelBuilder.named(myChannelName = channelName).networkProtocolVersion(() -> "1")
.clientAcceptedVersions(s -> true).serverAcceptedVersions(s -> true).eventNetworkChannel();
ec.registerObject(this);
public NetworkHandler( final ResourceLocation channelName )
{
ec = NetworkRegistry.ChannelBuilder.named( myChannelName = channelName ).networkProtocolVersion( () -> "1" ).clientAcceptedVersions( s -> true ).serverAcceptedVersions( s -> true ).eventNetworkChannel();
ec.registerObject( this );
this.clientHandler = this.createClientSide();
this.serveHandler = this.createServerSide();
}
this.clientHandler = this.createClientSide();
this.serveHandler = this.createServerSide();
}
public static void init(final ResourceLocation channelName) {
instance = new NetworkHandler(channelName);
}
public static void init( final ResourceLocation channelName )
{
instance = new NetworkHandler( channelName );
}
public static NetworkHandler instance() {
return instance;
}
public static NetworkHandler instance()
{
return instance;
}
private IPacketHandler createClientSide() {
try {
return new AppEngClientPacketHandler();
} catch (final Throwable t) {
return null;
}
}
private IPacketHandler createClientSide()
{
try
{
return new AppEngClientPacketHandler();
}
catch( final Throwable t )
{
return null;
}
}
private IPacketHandler createServerSide() {
try {
return new AppEngServerPacketHandler();
} catch (final Throwable t) {
return null;
}
}
private IPacketHandler createServerSide()
{
try
{
return new AppEngServerPacketHandler();
}
catch( final Throwable t )
{
return null;
}
}
@SubscribeEvent
public void serverPacket(final NetworkEvent.ClientCustomPayloadEvent ev) {
if (this.serveHandler != null) {
try {
NetworkEvent.Context ctx = ev.getSource().get();
ServerPlayNetHandler netHandler = (ServerPlayNetHandler) ctx.getNetworkManager().getNetHandler();
ctx.setPacketHandled(true);
ctx.enqueueWork(
() -> this.serveHandler.onPacketData(null, netHandler, ev.getPayload(), netHandler.player));
@SubscribeEvent
public void serverPacket( final NetworkEvent.ClientCustomPayloadEvent ev )
{
if( this.serveHandler != null )
{
try
{
NetworkEvent.Context ctx = ev.getSource().get();
ServerPlayNetHandler netHandler = (ServerPlayNetHandler) ctx.getNetworkManager().getNetHandler();
ctx.setPacketHandled( true );
ctx.enqueueWork( () -> this.serveHandler.onPacketData( null, netHandler, ev.getPayload(), netHandler.player ) );
} catch (final ThreadQuickExitException ignored) {
}
catch( final ThreadQuickExitException ignored )
{
}
}
}
}
}
}
@SubscribeEvent
public void clientPacket(final NetworkEvent.ServerCustomPayloadEvent ev) {
if (ev instanceof NetworkEvent.ServerCustomPayloadLoginEvent) {
return;
}
if (this.clientHandler != null) {
try {
NetworkEvent.Context ctx = ev.getSource().get();
INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
ctx.setPacketHandled(true);
ctx.enqueueWork(() -> this.clientHandler.onPacketData(null, netHandler, ev.getPayload(), null));
} catch (final ThreadQuickExitException ignored) {
@SubscribeEvent
public void clientPacket( final NetworkEvent.ServerCustomPayloadEvent ev )
{
if( ev instanceof NetworkEvent.ServerCustomPayloadLoginEvent )
{
return;
}
if( this.clientHandler != null )
{
try
{
NetworkEvent.Context ctx = ev.getSource().get();
INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
ctx.setPacketHandled( true );
ctx.enqueueWork( () -> this.clientHandler.onPacketData( null, netHandler, ev.getPayload(), null ) );
}
catch( final ThreadQuickExitException ignored )
{
}
}
}
}
}
}
public ResourceLocation getChannel() {
return this.myChannelName;
}
public ResourceLocation getChannel()
{
return this.myChannelName;
}
public void sendToAll(final AppEngPacket message) {
getServer().getPlayerList().sendPacketToAllPlayers(message.toPacket(NetworkDirection.PLAY_TO_CLIENT));
}
public void sendToAll( final AppEngPacket message )
{
getServer().getPlayerList().sendPacketToAllPlayers( message.toPacket( NetworkDirection.PLAY_TO_CLIENT ) );
}
public void sendTo(final AppEngPacket message, final ServerPlayerEntity player) {
player.connection.sendPacket(message.toPacket(NetworkDirection.PLAY_TO_CLIENT));
}
public void sendTo( final AppEngPacket message, final ServerPlayerEntity player )
{
player.connection.sendPacket( message.toPacket( NetworkDirection.PLAY_TO_CLIENT ) );
}
public void sendToAllAround(final AppEngPacket message, final TargetPoint point) {
IPacket<?> pkt = message.toPacket(NetworkDirection.PLAY_TO_CLIENT);
getServer().getPlayerList().sendToAllNearExcept(point.excluded, point.x, point.y, point.z, point.r2, point.dim,
pkt);
}
public void sendToAllAround( final AppEngPacket message, final TargetPoint point )
{
IPacket<?> pkt = message.toPacket( NetworkDirection.PLAY_TO_CLIENT );
getServer().getPlayerList().sendToAllNearExcept( point.excluded, point.x, point.y, point.z, point.r2, point.dim, pkt);
}
public void sendToDimension(final AppEngPacket message, final DimensionType dim) {
getServer().getPlayerList().sendPacketToAllPlayersInDimension(message.toPacket(NetworkDirection.PLAY_TO_CLIENT),
dim);
}
public void sendToDimension( final AppEngPacket message, final DimensionType dim )
{
getServer().getPlayerList().sendPacketToAllPlayersInDimension( message.toPacket( NetworkDirection.PLAY_TO_CLIENT ), dim );
}
public void sendToServer(final AppEngPacket message) {
Minecraft.getInstance().getConnection().sendPacket(message.toPacket(NetworkDirection.PLAY_TO_SERVER));
}
public void sendToServer( final AppEngPacket message )
{
Minecraft.getInstance().getConnection().sendPacket( message.toPacket( NetworkDirection.PLAY_TO_SERVER ) );
}
private MinecraftServer getServer()
{
return LogicalSidedProvider.INSTANCE.get( LogicalSide.SERVER );
}
private MinecraftServer getServer() {
return LogicalSidedProvider.INSTANCE.get(LogicalSide.SERVER);
}
}
@@ -1,44 +1,39 @@
package appeng.core.sync.network;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.world.dimension.DimensionType;
/**
* Created by covers1624 on 1/6/20.
*/
public class TargetPoint
{
public final ServerPlayerEntity excluded;
public final double x;
public final double y;
public final double z;
public final double r2;
public final DimensionType dim;
public class TargetPoint {
public TargetPoint( double x, double y, double z, double r2, DimensionType dim )
{
this( null, x, y, z, r2, dim );
}
public final ServerPlayerEntity excluded;
public final double x;
public final double y;
public final double z;
public final double r2;
public final DimensionType dim;
public TargetPoint( ServerPlayerEntity excluded, double x, double y, double z, double r2, DimensionType dim )
{
this.excluded = excluded;
this.x = x;
this.y = y;
this.z = z;
this.r2 = r2;
this.dim = dim;
}
public TargetPoint(double x, double y, double z, double r2, DimensionType dim) {
this(null, x, y, z, r2, dim);
}
public TargetPoint(ServerPlayerEntity excluded, double x, double y, double z, double r2, DimensionType dim) {
this.excluded = excluded;
this.x = x;
this.y = y;
this.z = z;
this.r2 = r2;
this.dim = dim;
}
public static TargetPoint at(double x, double y, double z, double r2, DimensionType dim) {
return new TargetPoint( x, y, z, r2, dim );
}
public static TargetPoint at(double x, double y, double z, double r2, DimensionType dim) {
return new TargetPoint(x, y, z, r2, dim);
}
public static TargetPoint at(ServerPlayerEntity excluded, double x, double y, double z, double r2, DimensionType dim) {
return new TargetPoint( excluded, x, y, z, r2, dim );
}
public static TargetPoint at(ServerPlayerEntity excluded, double x, double y, double z, double r2,
DimensionType dim) {
return new TargetPoint(excluded, x, y, z, r2, dim);
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.Unpooled;
@@ -36,50 +35,46 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketAssemblerAnimation extends AppEngPacket {
public class PacketAssemblerAnimation extends AppEngPacket
{
private final int x;
private final int y;
private final int z;
public final byte rate;
public final IAEItemStack is;
private final int x;
private final int y;
private final int z;
public final byte rate;
public final IAEItemStack is;
public PacketAssemblerAnimation(final PacketBuffer stream) {
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
this.rate = stream.readByte();
this.is = AEItemStack.fromPacket(stream);
}
public PacketAssemblerAnimation( final PacketBuffer stream )
{
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
this.rate = stream.readByte();
this.is = AEItemStack.fromPacket( stream );
}
// api
public PacketAssemblerAnimation(final BlockPos pos, final byte rate, final IAEItemStack is) {
// api
public PacketAssemblerAnimation( final BlockPos pos, final byte rate, final IAEItemStack is )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(this.x = pos.getX());
data.writeInt(this.y = pos.getY());
data.writeInt(this.z = pos.getZ());
data.writeByte(this.rate = rate);
is.writeToPacket(data);
this.is = is;
data.writeInt( this.getPacketID() );
data.writeInt( this.x = pos.getX() );
data.writeInt( this.y = pos.getY() );
data.writeInt( this.z = pos.getZ() );
data.writeByte( this.rate = rate );
is.writeToPacket( data );
this.is = is;
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final double d0 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
final double d1 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
final double d2 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final double d0 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
final double d1 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
final double d2 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
AppEng.proxy.spawnEffect( EffectType.Assembler, player.getEntityWorld(), this.x + d0, this.y + d1, this.z + d2, this );
}
AppEng.proxy.spawnEffect(EffectType.Assembler, player.getEntityWorld(), this.x + d0, this.y + d1, this.z + d2,
this);
}
}
@@ -18,6 +18,18 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import appeng.api.AEApi;
import appeng.api.definitions.IComparableDefinition;
@@ -32,149 +44,122 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.items.tools.ToolNetworkTool;
import appeng.items.tools.powered.ToolColorApplicator;
import io.netty.buffer.Unpooled;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
public class PacketClick extends AppEngPacket {
public class PacketClick extends AppEngPacket
{
private final int x;
private final int y;
private final int z;
private Direction side;
private final float hitX;
private final float hitY;
private final float hitZ;
private Hand hand;
private final boolean leftClick;
private final int x;
private final int y;
private final int z;
private Direction side;
private final float hitX;
private final float hitY;
private final float hitZ;
private Hand hand;
private final boolean leftClick;
public PacketClick(final PacketBuffer stream) {
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
byte side = stream.readByte();
if (side != -1) {
this.side = Direction.values()[side];
} else {
this.side = null;
}
this.hitX = stream.readFloat();
this.hitY = stream.readFloat();
this.hitZ = stream.readFloat();
this.hand = Hand.values()[stream.readByte()];
this.leftClick = stream.readBoolean();
}
public PacketClick( final PacketBuffer stream )
{
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
byte side = stream.readByte();
if( side != -1 )
{
this.side = Direction.values()[side];
}
else
{
this.side = null;
}
this.hitX = stream.readFloat();
this.hitY = stream.readFloat();
this.hitZ = stream.readFloat();
this.hand = Hand.values()[stream.readByte()];
this.leftClick = stream.readBoolean();
}
// API for when a block was right clicked
public PacketClick(ItemUseContext context) {
this(context.getPos(), context.getFace(), context.getPos().getX(), context.getPos().getY(),
context.getPos().getZ(), context.getHand());
}
// API for when a block was right clicked
public PacketClick( ItemUseContext context )
{
this(context.getPos(), context.getFace(), context.getPos().getX(), context.getPos().getY(), context.getPos().getZ(), context.getHand());
}
// API for when an item in hand was right-clicked, with no block context
public PacketClick(Hand hand) {
this(BlockPos.ZERO, null, 0, 0, 0, hand);
}
// API for when an item in hand was right-clicked, with no block context
public PacketClick( Hand hand )
{
this(BlockPos.ZERO, null, 0, 0, 0, hand);
}
private PacketClick(final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ,
final Hand hand) {
this(pos, side, hitX, hitY, hitZ, hand, false);
}
private PacketClick( final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ, final Hand hand )
{
this( pos, side, hitX, hitY, hitZ, hand, false );
}
public PacketClick(final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ,
final Hand hand, boolean leftClick) {
public PacketClick( final BlockPos pos, final Direction side, final float hitX, final float hitY, final float hitZ, final Hand hand, boolean leftClick )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(this.x = pos.getX());
data.writeInt(this.y = pos.getY());
data.writeInt(this.z = pos.getZ());
if (side == null) {
data.writeByte(-1);
} else {
data.writeByte(side.ordinal());
}
data.writeFloat(this.hitX = hitX);
data.writeFloat(this.hitY = hitY);
data.writeFloat(this.hitZ = hitZ);
data.writeByte(hand.ordinal());
data.writeBoolean(this.leftClick = leftClick);
data.writeInt( this.getPacketID() );
data.writeInt( this.x = pos.getX() );
data.writeInt( this.y = pos.getY() );
data.writeInt( this.z = pos.getZ() );
if( side == null )
{
data.writeByte( -1 );
}
else
{
data.writeByte( side.ordinal() );
}
data.writeFloat( this.hitX = hitX );
data.writeFloat( this.hitY = hitY );
data.writeFloat( this.hitZ = hitZ );
data.writeByte( hand.ordinal() );
data.writeBoolean( this.leftClick = leftClick );
this.configureWrite(data);
}
this.configureWrite( data );
}
// Indicates that block pos, side and hit vector have valid data
private boolean hasBlockContext() {
return side != null;
}
// Indicates that block pos, side and hit vector have valid data
private boolean hasBlockContext() {
return side != null;
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final BlockPos pos = new BlockPos(this.x, this.y, this.z);
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final BlockPos pos = new BlockPos( this.x, this.y, this.z );
final ItemStack is = player.getHeldItem(hand);
final IItems items = AEApi.instance().definitions().items();
final IComparableDefinition maybeMemoryCard = items.memoryCard();
final IComparableDefinition maybeColorApplicator = items.colorApplicator();
final ItemStack is = player.getHeldItem(hand);
final IItems items = AEApi.instance().definitions().items();
final IComparableDefinition maybeMemoryCard = items.memoryCard();
final IComparableDefinition maybeColorApplicator = items.colorApplicator();
if (this.leftClick) {
final Block block = player.world.getBlockState(pos).getBlock();
if (block instanceof BlockCableBus) {
((BlockCableBus) block).onBlockClickPacket(player.world, pos, player, this.hand,
new Vec3d(this.hitX, this.hitY, this.hitZ));
}
} else {
if (!is.isEmpty()) {
if (is.getItem() instanceof ToolNetworkTool) {
final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
if( this.leftClick )
{
final Block block = player.world.getBlockState( pos ).getBlock();
if( block instanceof BlockCableBus)
{
( (BlockCableBus) block ).onBlockClickPacket( player.world, pos, player, this.hand, new Vec3d( this.hitX, this.hitY, this.hitZ ) );
}
}
else
{
if( !is.isEmpty() )
{
if( is.getItem() instanceof ToolNetworkTool)
{
final ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
if (hasBlockContext()) {
// Reconstruct an item use context
ItemUseContext useContext = new ItemUseContext(player, hand,
new BlockRayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos, false));
tnt.serverSideToolLogic(useContext);
} else {
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, player,
ContainerLocator.forHand(player, hand));
}
}
if (hasBlockContext()) {
// Reconstruct an item use context
ItemUseContext useContext = new ItemUseContext(player, hand, new BlockRayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos, false));
tnt.serverSideToolLogic(useContext);
} else {
ContainerOpener.openContainer(ContainerNetworkTool.TYPE, player, ContainerLocator.forHand(player, hand));
}
}
if (maybeMemoryCard.isSameAs(is)) {
final IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser(player, MemoryCardMessages.SETTINGS_CLEARED);
is.setTag(null);
}
if( maybeMemoryCard.isSameAs( is ) )
{
final IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
is.setTag( null );
}
else if( maybeColorApplicator.isSameAs( is ) )
{
final ToolColorApplicator mem = (ToolColorApplicator) is.getItem();
mem.cycleColors( is, mem.getColor( is ), 1 );
}
}
}
}
else if (maybeColorApplicator.isSameAs(is)) {
final ToolColorApplicator mem = (ToolColorApplicator) is.getItem();
mem.cycleColors(is, mem.getColor(is), 1);
}
}
}
}
}
@@ -18,8 +18,6 @@
package appeng.core.sync.packets;
import appeng.core.worlddata.WorldData;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -30,54 +28,51 @@ import appeng.api.util.DimensionalCoord;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.worlddata.WorldData;
import appeng.services.compass.ICompassCallback;
public class PacketCompassRequest extends AppEngPacket implements ICompassCallback {
public class PacketCompassRequest extends AppEngPacket implements ICompassCallback
{
final long attunement;
final int cx;
final int cz;
final int cdy;
final long attunement;
final int cx;
final int cz;
final int cdy;
private PlayerEntity talkBackTo;
private PlayerEntity talkBackTo;
public PacketCompassRequest(final PacketBuffer stream) {
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
this.cdy = stream.readInt();
}
public PacketCompassRequest( final PacketBuffer stream )
{
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
this.cdy = stream.readInt();
}
// api
public PacketCompassRequest(final long attunement, final int cx, final int cz, final int cdy) {
// api
public PacketCompassRequest( final long attunement, final int cx, final int cz, final int cdy )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeLong(this.attunement = attunement);
data.writeInt(this.cx = cx);
data.writeInt(this.cz = cz);
data.writeInt(this.cdy = cdy);
data.writeInt( this.getPacketID() );
data.writeLong( this.attunement = attunement );
data.writeInt( this.cx = cx );
data.writeInt( this.cz = cz );
data.writeInt( this.cdy = cdy );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void calculatedDirection(final boolean hasResult, final boolean spin, final double radians,
final double dist) {
NetworkHandler.instance().sendTo(new PacketCompassResponse(this, hasResult, spin, radians),
(ServerPlayerEntity) this.talkBackTo);
}
@Override
public void calculatedDirection( final boolean hasResult, final boolean spin, final double radians, final double dist )
{
NetworkHandler.instance().sendTo( new PacketCompassResponse( this, hasResult, spin, radians ), (ServerPlayerEntity) this.talkBackTo );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
this.talkBackTo = player;
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
this.talkBackTo = player;
final DimensionalCoord loc = new DimensionalCoord( player.world, this.cx << 4, this.cdy << 5, this.cz << 4 );
WorldData.instance().compassData().service().getCompassDirection( loc, 174, this );
}
final DimensionalCoord loc = new DimensionalCoord(player.world, this.cx << 4, this.cdy << 5, this.cz << 4);
WorldData.instance().compassData().service().getCompassDirection(loc, 174, this);
}
}
@@ -18,9 +18,6 @@
package appeng.core.sync.packets;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -28,50 +25,48 @@ import net.minecraft.network.PacketBuffer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
public class PacketCompassResponse extends AppEngPacket {
public class PacketCompassResponse extends AppEngPacket
{
private final long attunement;
private final int cx;
private final int cz;
private final int cdy;
private final long attunement;
private final int cx;
private final int cz;
private final int cdy;
private CompassResult cr;
private CompassResult cr;
public PacketCompassResponse(final PacketBuffer stream) {
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
this.cdy = stream.readInt();
public PacketCompassResponse( final PacketBuffer stream )
{
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
this.cdy = stream.readInt();
this.cr = new CompassResult(stream.readBoolean(), stream.readBoolean(), stream.readDouble());
}
this.cr = new CompassResult( stream.readBoolean(), stream.readBoolean(), stream.readDouble() );
}
// api
public PacketCompassResponse(final PacketCompassRequest req, final boolean hasResult, final boolean spin,
final double radians) {
// api
public PacketCompassResponse( final PacketCompassRequest req, final boolean hasResult, final boolean spin, final double radians )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeLong(this.attunement = req.attunement);
data.writeInt(this.cx = req.cx);
data.writeInt(this.cz = req.cz);
data.writeInt(this.cdy = req.cdy);
data.writeInt( this.getPacketID() );
data.writeLong( this.attunement = req.attunement );
data.writeInt( this.cx = req.cx );
data.writeInt( this.cz = req.cz );
data.writeInt( this.cdy = req.cdy );
data.writeBoolean(hasResult);
data.writeBoolean(spin);
data.writeDouble(radians);
data.writeBoolean( hasResult );
data.writeBoolean( spin );
data.writeDouble( radians );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
CompassManager.INSTANCE.postResult( this.attunement, this.cx << 4, this.cdy << 5, this.cz << 4, this.cr );
}
@Override
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
CompassManager.INSTANCE.postResult(this.attunement, this.cx << 4, this.cdy << 5, this.cz << 4, this.cr);
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -27,7 +26,6 @@ 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;
@@ -39,83 +37,70 @@ import net.minecraft.network.PacketBuffer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.client.gui.implementations.GuiInterfaceTerminal;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
//TODO, this is pointless, NBT is already compressed when written to a PacketBuffer.
public class PacketCompressedNBT extends AppEngPacket
{
public class PacketCompressedNBT extends AppEngPacket {
// input.
private final CompoundNBT in;
// output...
private final PacketBuffer data;
private final GZIPOutputStream compressFrame;
// input.
private final CompoundNBT in;
// output...
private final PacketBuffer data;
private final GZIPOutputStream compressFrame;
public PacketCompressedNBT( final PacketBuffer stream )
{
this.data = null;
this.compressFrame = null;
public PacketCompressedNBT(final PacketBuffer stream) {
this.data = null;
this.compressFrame = null;
try( DataInputStream inStream = new DataInputStream( new GZIPInputStream( new InputStream()
{
try (DataInputStream inStream = new DataInputStream(new GZIPInputStream(new InputStream() {
@Override
public int read()
{
if( stream.readableBytes() <= 0 )
{
return -1;
}
@Override
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
return stream.readByte() & 0xff;
}
} ) ) )
{
this.in = CompressedStreamTools.read( inStream );
}
catch( IOException e )
{
throw new RuntimeException( "Failed to decompress packet.", e );
}
}
return stream.readByte() & 0xff;
}
}))) {
this.in = CompressedStreamTools.read(inStream);
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
}
}
// FIXME: this is pointless, PacketBuffer.writeNBT will already compress
// api
public PacketCompressedNBT( final CompoundNBT din ) throws IOException
{
// FIXME: this is pointless, PacketBuffer.writeNBT will already compress
// api
public PacketCompressedNBT(final CompoundNBT din) throws IOException {
this.data = new PacketBuffer( Unpooled.buffer( 2048 ) );
this.data.writeInt( this.getPacketID() );
this.data = new PacketBuffer(Unpooled.buffer(2048));
this.data.writeInt(this.getPacketID());
this.in = din;
this.in = din;
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write( final int value )
{
PacketCompressedNBT.this.data.writeByte( value );
}
} );
@Override
public void write(final int value) {
PacketCompressedNBT.this.data.writeByte(value);
}
});
CompressedStreamTools.write( din, new DataOutputStream( this.compressFrame ) );
this.compressFrame.close();
CompressedStreamTools.write(din, new DataOutputStream(this.compressFrame));
this.compressFrame.close();
this.configureWrite( this.data );
}
this.configureWrite(this.data);
}
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final Screen gs = Minecraft.getInstance().currentScreen;
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final Screen gs = Minecraft.getInstance().currentScreen;
if( gs instanceof GuiInterfaceTerminal)
{
( (GuiInterfaceTerminal) gs ).postUpdate( this.in );
}
}
if (gs instanceof GuiInterfaceTerminal) {
((GuiInterfaceTerminal) gs).postUpdate(this.in);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -32,46 +31,44 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public final class PacketConfigButton extends AppEngPacket {
private final Settings option;
private final boolean rotationDirection;
public final class PacketConfigButton extends AppEngPacket
{
private final Settings option;
private final boolean rotationDirection;
public PacketConfigButton(final PacketBuffer stream) {
this.option = Settings.values()[stream.readInt()];
this.rotationDirection = stream.readBoolean();
}
public PacketConfigButton( final PacketBuffer stream )
{
this.option = Settings.values()[stream.readInt()];
this.rotationDirection = stream.readBoolean();
}
// api
public PacketConfigButton(final Settings option, final boolean rotationDirection) {
this.option = option;
this.rotationDirection = rotationDirection;
// api
public PacketConfigButton( final Settings option, final boolean rotationDirection )
{
this.option = option;
this.rotationDirection = rotationDirection;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(option.ordinal());
data.writeBoolean(rotationDirection);
data.writeInt( this.getPacketID() );
data.writeInt( option.ordinal() );
data.writeBoolean( rotationDirection );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
// FIXME if( sender.openContainer instanceof AEBaseContainer )
// FIXME {
// FIXME final AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
// FIXME if( baseContainer.getTarget() instanceof IConfigurableObject )
// FIXME {
// FIXME final IConfigManager cm = ( (IConfigurableObject) baseContainer.getTarget() ).getConfigManager();
// FIXME final Enum<?> newState = EnumCycler.rotateEnum( cm.getSetting( this.option ), this.rotationDirection, this.option.getPossibleValues() );
// FIXME cm.putSetting( this.option, newState );
// FIXME }
// FIXME }
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
// FIXME if( sender.openContainer instanceof AEBaseContainer )
// FIXME {
// FIXME final AEBaseContainer baseContainer = (AEBaseContainer)
// sender.openContainer;
// FIXME if( baseContainer.getTarget() instanceof IConfigurableObject )
// FIXME {
// FIXME final IConfigManager cm = ( (IConfigurableObject)
// baseContainer.getTarget() ).getConfigManager();
// FIXME final Enum<?> newState = EnumCycler.rotateEnum( cm.getSetting(
// this.option ), this.rotationDirection, this.option.getPossibleValues() );
// FIXME cm.putSetting( this.option, newState );
// FIXME }
// FIXME }
}
}
@@ -18,11 +18,8 @@
package appeng.core.sync.packets;
import java.util.concurrent.Future;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerInscriber;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -35,92 +32,80 @@ import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.IActionHost;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerInscriber;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketCraftRequest extends AppEngPacket {
public class PacketCraftRequest extends AppEngPacket
{
private final long amount;
private final boolean heldShift;
private final long amount;
private final boolean heldShift;
public PacketCraftRequest(final PacketBuffer stream) {
this.heldShift = stream.readBoolean();
this.amount = stream.readLong();
}
public PacketCraftRequest( final PacketBuffer stream )
{
this.heldShift = stream.readBoolean();
this.amount = stream.readLong();
}
public PacketCraftRequest(final int craftAmt, final boolean shift) {
this.amount = craftAmt;
this.heldShift = shift;
public PacketCraftRequest( final int craftAmt, final boolean shift )
{
this.amount = craftAmt;
this.heldShift = shift;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeBoolean(shift);
data.writeLong(this.amount);
data.writeInt( this.getPacketID() );
data.writeBoolean( shift );
data.writeLong( this.amount );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
if (player.openContainer instanceof ContainerCraftAmount) {
final ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
final Object target = cca.getTarget();
if (target instanceof IActionHost) {
final IActionHost ah = (IActionHost) target;
final IGridNode gn = ah.getActionableNode();
if (gn == null) {
return;
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
if( player.openContainer instanceof ContainerCraftAmount )
{
final ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
final Object target = cca.getTarget();
if( target instanceof IActionHost )
{
final IActionHost ah = (IActionHost) target;
final IGridNode gn = ah.getActionableNode();
if( gn == null )
{
return;
}
final IGrid g = gn.getGrid();
if (g == null || cca.getItemToCraft() == null) {
return;
}
final IGrid g = gn.getGrid();
if( g == null || cca.getItemToCraft() == null )
{
return;
}
cca.getItemToCraft().setStackSize(this.amount);
cca.getItemToCraft().setStackSize( this.amount );
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = g.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(cca.getWorld(), cca.getGrid(), cca.getActionSrc(),
cca.getItemToCraft(), null);
Future<ICraftingJob> futureJob = null;
try
{
final ICraftingGrid cg = g.getCache( ICraftingGrid.class );
futureJob = cg.beginCraftingJob( cca.getWorld(), cca.getGrid(), cca.getActionSrc(), cca.getItemToCraft(), null );
final ContainerLocator locator = cca.getLocator();
if (locator != null) {
ContainerOpener.openContainer(ContainerCraftConfirm.TYPE, player, locator);
final ContainerLocator locator = cca.getLocator();
if( locator != null )
{
ContainerOpener.openContainer(ContainerCraftConfirm.TYPE, player, locator);
if( player.openContainer instanceof ContainerCraftConfirm )
{
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setAutoStart( this.heldShift );
ccc.setJob( futureJob );
cca.detectAndSendChanges();
}
}
}
catch( final Throwable e )
{
if( futureJob != null )
{
futureJob.cancel( true );
}
AELog.debug( e );
}
}
}
}
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setAutoStart(this.heldShift);
ccc.setJob(futureJob);
cca.detectAndSendChanges();
}
}
} catch (final Throwable e) {
if (futureJob != null) {
futureJob.cancel(true);
}
AELog.debug(e);
}
}
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.util.HashMap;
import java.util.Map;
@@ -35,60 +34,49 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.container.IFluidSyncContainer;
import appeng.fluids.util.AEFluidStack;
public class PacketFluidSlot extends AppEngPacket {
private final Map<Integer, IAEFluidStack> list;
public class PacketFluidSlot extends AppEngPacket
{
private final Map<Integer, IAEFluidStack> list;
public PacketFluidSlot(final PacketBuffer stream) {
this.list = new HashMap<>();
CompoundNBT tag = stream.readCompoundTag();
public PacketFluidSlot( final PacketBuffer stream )
{
this.list = new HashMap<>();
CompoundNBT tag = stream.readCompoundTag();
for (final String key : tag.keySet()) {
this.list.put(Integer.parseInt(key), AEFluidStack.fromNBT(tag.getCompound(key)));
}
}
for( final String key : tag.keySet() )
{
this.list.put( Integer.parseInt( key ), AEFluidStack.fromNBT( tag.getCompound( key ) ) );
}
}
// api
public PacketFluidSlot(final Map<Integer, IAEFluidStack> list) {
this.list = list;
final CompoundNBT sendTag = new CompoundNBT();
for (Map.Entry<Integer, IAEFluidStack> fs : list.entrySet()) {
final CompoundNBT tag = new CompoundNBT();
if (fs.getValue() != null) {
fs.getValue().writeToNBT(tag);
}
sendTag.put(fs.getKey().toString(), tag);
}
// api
public PacketFluidSlot( final Map<Integer, IAEFluidStack> list )
{
this.list = list;
final CompoundNBT sendTag = new CompoundNBT();
for( Map.Entry<Integer, IAEFluidStack> fs : list.entrySet() )
{
final CompoundNBT tag = new CompoundNBT();
if( fs.getValue() != null )
{
fs.getValue().writeToNBT( tag );
}
sendTag.put( fs.getKey().toString(), tag );
}
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
data.writeInt(this.getPacketID());
data.writeCompoundTag(sendTag);
this.configureWrite(data);
}
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt( this.getPacketID() );
data.writeCompoundTag( sendTag );
this.configureWrite( data );
}
@Override
public void clientPacketData(final INetworkInfo manager, final PlayerEntity player) {
final Container c = player.openContainer;
if (c instanceof IFluidSyncContainer) {
((IFluidSyncContainer) c).receiveFluidSlots(this.list);
}
}
@Override
public void clientPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final Container c = player.openContainer;
if( c instanceof IFluidSyncContainer )
{
( (IFluidSyncContainer) c ).receiveFluidSlots( this.list );
}
}
@Override
public void serverPacketData( INetworkInfo manager, PlayerEntity player )
{
final Container c = player.openContainer;
if( c instanceof IFluidSyncContainer )
{
( (IFluidSyncContainer) c ).receiveFluidSlots( this.list );
}
}
@Override
public void serverPacketData(INetworkInfo manager, PlayerEntity player) {
final Container c = player.openContainer;
if (c instanceof IFluidSyncContainer) {
((IFluidSyncContainer) c).receiveFluidSlots(this.list);
}
}
}
@@ -18,6 +18,12 @@
package appeng.core.sync.packets;
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 appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
@@ -30,139 +36,109 @@ 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 {
public class PacketInventoryAction extends AppEngPacket
{
private final InventoryAction action;
private final int slot;
private final long id;
private final IAEItemStack slotItem;
private final InventoryAction action;
private final int slot;
private final long id;
private final IAEItemStack slotItem;
public PacketInventoryAction(final PacketBuffer stream) {
this.action = InventoryAction.values()[stream.readInt()];
this.slot = stream.readInt();
this.id = stream.readLong();
final boolean hasItem = stream.readBoolean();
if (hasItem) {
this.slotItem = AEItemStack.fromPacket(stream);
} else {
this.slotItem = null;
}
}
public PacketInventoryAction( final PacketBuffer stream )
{
this.action = InventoryAction.values()[stream.readInt()];
this.slot = stream.readInt();
this.id = stream.readLong();
final boolean hasItem = stream.readBoolean();
if( hasItem )
{
this.slotItem = AEItemStack.fromPacket( stream );
}
else
{
this.slotItem = null;
}
}
// api
public PacketInventoryAction(final InventoryAction action, final int slot, final IAEItemStack slotItem) {
// api
public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem )
{
if (Platform.isClient()) {
throw new IllegalStateException("invalid packet, client cannot post inv actions with stacks.");
}
if( Platform.isClient() )
{
throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." );
}
this.action = action;
this.slot = slot;
this.id = 0;
this.slotItem = slotItem;
this.action = action;
this.slot = slot;
this.id = 0;
this.slotItem = slotItem;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(action.ordinal());
data.writeInt(slot);
data.writeLong(this.id);
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( this.id );
if (slotItem == null) {
data.writeBoolean(false);
} else {
data.writeBoolean(true);
slotItem.writeToPacket(data);
}
if( slotItem == null )
{
data.writeBoolean( false );
}
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
this.configureWrite(data);
}
this.configureWrite( data );
}
// api
public PacketInventoryAction(final InventoryAction action, final int slot, final long id) {
this.action = action;
this.slot = slot;
this.id = id;
this.slotItem = null;
// api
public PacketInventoryAction( final InventoryAction action, final int slot, final long id )
{
this.action = action;
this.slot = slot;
this.id = id;
this.slotItem = null;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(action.ordinal());
data.writeInt(slot);
data.writeLong(id);
data.writeBoolean(false);
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( id );
data.writeBoolean( false );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
if (sender.openContainer instanceof AEBaseContainer) {
final AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if (this.action == InventoryAction.AUTO_CRAFT) {
final ContainerLocator locator = baseContainer.getLocator();
if (locator != null) {
ContainerOpener.openContainer(ContainerCraftAmount.TYPE, player, locator);
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
if( sender.openContainer instanceof AEBaseContainer )
{
final AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if( this.action == InventoryAction.AUTO_CRAFT )
{
final ContainerLocator locator = baseContainer.getLocator();
if( locator != null )
{
ContainerOpener.openContainer(ContainerCraftAmount.TYPE, player, locator);
if (sender.openContainer instanceof ContainerCraftAmount) {
final ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
if( sender.openContainer instanceof ContainerCraftAmount )
{
final ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
if (baseContainer.getTargetStack() != null) {
cca.getCraftingItem().putStack(baseContainer.getTargetStack().asItemStackRepresentation());
// This is the *actual* item that matters, not the display item above
cca.setItemToCraft(baseContainer.getTargetStack());
}
if( baseContainer.getTargetStack() != null )
{
cca.getCraftingItem().putStack( baseContainer.getTargetStack().asItemStackRepresentation() );
// This is the *actual* item that matters, not the display item above
cca.setItemToCraft( baseContainer.getTargetStack() );
}
cca.detectAndSendChanges();
}
}
} else {
baseContainer.doAction(sender, this.action, this.slot, this.id);
}
}
}
cca.detectAndSendChanges();
}
}
}
else
{
baseContainer.doAction( sender, this.action, this.slot, this.id );
}
}
}
@Override
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
if( this.action == InventoryAction.UPDATE_HAND )
{
if( this.slotItem == null )
{
AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( ItemStack.EMPTY );
}
else
{
AppEng.proxy.getPlayers().get( 0 ).inventory.setItemStack( this.slotItem.createItemStack() );
}
}
}
@Override
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
if (this.action == InventoryAction.UPDATE_HAND) {
if (this.slotItem == null) {
AppEng.proxy.getPlayers().get(0).inventory.setItemStack(ItemStack.EMPTY);
} else {
AppEng.proxy.getPlayers().get(0).inventory.setItemStack(this.slotItem.createItemStack());
}
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.Unpooled;
@@ -55,188 +54,154 @@ import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
import appeng.util.prioritylist.IPartitionList;
public class PacketJEIRecipe extends AppEngPacket {
public class PacketJEIRecipe extends AppEngPacket
{
private ItemStack[][] recipe;
private ItemStack[][] recipe;
public PacketJEIRecipe(final PacketBuffer stream) {
final CompoundNBT comp = stream.readCompoundTag();
if (comp != null) {
this.recipe = new ItemStack[9][];
for (int x = 0; x < this.recipe.length; x++) {
final ListNBT list = comp.getList("#" + x, 10);
if (list.size() > 0) {
this.recipe[x] = new ItemStack[list.size()];
for (int y = 0; y < list.size(); y++) {
this.recipe[x][y] = ItemStack.read(list.getCompound(y));
}
}
}
}
}
public PacketJEIRecipe( final PacketBuffer stream )
{
final CompoundNBT comp = stream.readCompoundTag();
if( comp != null )
{
this.recipe = new ItemStack[9][];
for( int x = 0; x < this.recipe.length; x++ )
{
final ListNBT list = comp.getList( "#" + x, 10 );
if( list.size() > 0 )
{
this.recipe[x] = new ItemStack[list.size()];
for( int y = 0; y < list.size(); y++ )
{
this.recipe[x][y] = ItemStack.read( list.getCompound( y ) );
}
}
}
}
}
// api
public PacketJEIRecipe(final CompoundNBT recipe) {
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
// api
public PacketJEIRecipe( final CompoundNBT recipe )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
data.writeInt(this.getPacketID());
data.writeInt( this.getPacketID() );
data.writeCompoundTag(recipe);
data.writeCompoundTag( recipe );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity pmp = (ServerPlayerEntity) player;
final Container con = pmp.openContainer;
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final ServerPlayerEntity pmp = (ServerPlayerEntity) player;
final Container con = pmp.openContainer;
if (!(con instanceof IContainerCraftingPacket)) {
return;
}
if( !( con instanceof IContainerCraftingPacket ) )
{
return;
}
final IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
final IGridNode node = cct.getNetworkNode();
final IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
final IGridNode node = cct.getNetworkNode();
if (node == null) {
return;
}
if( node == null )
{
return;
}
final IGrid grid = node.getGrid();
if (grid == null) {
return;
}
final IGrid grid = node.getGrid();
if( grid == null )
{
return;
}
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
final IEnergyGrid energy = grid.getCache(IEnergyGrid.class);
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
final ICraftingGrid crafting = grid.getCache(ICraftingGrid.class);
final IItemHandler craftMatrix = cct.getInventoryByName("crafting");
final IItemHandler playerInventory = cct.getInventoryByName("player");
final IStorageGrid inv = grid.getCache( IStorageGrid.class );
final IEnergyGrid energy = grid.getCache( IEnergyGrid.class );
final ISecurityGrid security = grid.getCache( ISecurityGrid.class );
final ICraftingGrid crafting = grid.getCache( ICraftingGrid.class );
final IItemHandler craftMatrix = cct.getInventoryByName( "crafting" );
final IItemHandler playerInventory = cct.getInventoryByName( "player" );
if (inv != null && this.recipe != null && security != null) {
final IMEMonitor<IAEItemStack> storage = inv
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter(cct.getViewCells());
if( inv != null && this.recipe != null && security != null )
{
final IMEMonitor<IAEItemStack> storage = inv.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
for (int x = 0; x < craftMatrix.getSlots(); x++) {
ItemStack currentItem = craftMatrix.getStackInSlot(x);
for( int x = 0; x < craftMatrix.getSlots(); x++ )
{
ItemStack currentItem = craftMatrix.getStackInSlot( x );
// prepare slots
if (!currentItem.isEmpty()) {
// already the correct item?
ItemStack newItem = this.canUseInSlot(x, currentItem);
// prepare slots
if( !currentItem.isEmpty() )
{
// already the correct item?
ItemStack newItem = this.canUseInSlot( x, currentItem );
// put away old item
if (newItem != currentItem && security.hasPermission(player, SecurityPermissions.INJECT)) {
final IAEItemStack in = AEItemStack.fromItemStack(currentItem);
final IAEItemStack out = cct.useRealItems()
? Platform.poweredInsert(energy, storage, in, cct.getActionSource())
: null;
if (out != null) {
currentItem = out.createItemStack();
} else {
currentItem = ItemStack.EMPTY;
}
}
}
// put away old item
if( newItem != currentItem && security.hasPermission( player, SecurityPermissions.INJECT ) )
{
final IAEItemStack in = AEItemStack.fromItemStack( currentItem );
final IAEItemStack out = cct.useRealItems() ? Platform.poweredInsert( energy, storage, in, cct.getActionSource() ) : null;
if( out != null )
{
currentItem = out.createItemStack();
}
else
{
currentItem = ItemStack.EMPTY;
}
}
}
if (currentItem.isEmpty() && this.recipe[x] != null) {
// for each variant
for (int y = 0; y < this.recipe[x].length && currentItem.isEmpty(); y++) {
final IAEItemStack request = AEItemStack.fromItemStack(this.recipe[x][y]);
if (request != null) {
// try ae
if ((filter == null || filter.isListed(request))
&& security.hasPermission(player, SecurityPermissions.EXTRACT)) {
request.setStackSize(1);
IAEItemStack out;
if( currentItem.isEmpty() && this.recipe[x] != null )
{
// for each variant
for( int y = 0; y < this.recipe[x].length && currentItem.isEmpty(); y++ )
{
final IAEItemStack request = AEItemStack.fromItemStack( this.recipe[x][y] );
if( request != null )
{
// try ae
if( ( filter == null || filter.isListed( request ) ) && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
{
request.setStackSize( 1 );
IAEItemStack out;
if (cct.useRealItems()) {
out = Platform.poweredExtraction(energy, storage, request, cct.getActionSource());
} else {
// Query the crafting grid if there is a pattern providing the item
if (!crafting.getCraftingFor(request, null, 0, null).isEmpty()) {
out = request;
} else {
// Fall back using an existing item
out = storage.extractItems(request, Actionable.SIMULATE, cct.getActionSource());
}
}
if( cct.useRealItems() )
{
out = Platform.poweredExtraction( energy, storage, request, cct.getActionSource() );
}
else
{
// Query the crafting grid if there is a pattern providing the item
if( !crafting.getCraftingFor( request, null, 0, null ).isEmpty() )
{
out = request;
}
else
{
// Fall back using an existing item
out = storage.extractItems( request, Actionable.SIMULATE, cct.getActionSource() );
}
}
if (out != null) {
currentItem = out.createItemStack();
}
}
if( out != null )
{
currentItem = out.createItemStack();
}
}
// try inventory
if (currentItem.isEmpty()) {
AdaptorItemHandler ad = new AdaptorItemHandler(playerInventory);
// try inventory
if( currentItem.isEmpty() )
{
AdaptorItemHandler ad = new AdaptorItemHandler( playerInventory );
if (cct.useRealItems()) {
currentItem = ad.removeItems(1, this.recipe[x][y], null);
} else {
currentItem = ad.simulateRemove(1, this.recipe[x][y], null);
}
}
}
}
}
ItemHandlerUtil.setStackInSlot(craftMatrix, x, currentItem);
}
con.onCraftMatrixChanged(new WrapperInvItemHandler(craftMatrix));
}
}
if( cct.useRealItems() )
{
currentItem = ad.removeItems( 1, this.recipe[x][y], null );
}
else
{
currentItem = ad.simulateRemove( 1, this.recipe[x][y], null );
}
}
}
}
}
ItemHandlerUtil.setStackInSlot( craftMatrix, x, currentItem );
}
con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) );
}
}
/**
*
* @param slot
* @param is itemstack
* @return is if it can be used, else EMPTY
*/
private ItemStack canUseInSlot( int slot, ItemStack is )
{
if( this.recipe[slot] != null )
{
for( ItemStack option : this.recipe[slot] )
{
if( is.isItemEqual( option ) )
{
return is;
}
}
}
return ItemStack.EMPTY;
}
/**
*
* @param slot
* @param is itemstack
* @return is if it can be used, else EMPTY
*/
private ItemStack canUseInSlot(int slot, ItemStack is) {
if (this.recipe[slot] != null) {
for (ItemStack option : this.recipe[slot]) {
if (is.isItemEqual(option)) {
return is;
}
}
}
return ItemStack.EMPTY;
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
@@ -33,51 +32,42 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketLightning extends AppEngPacket {
public class PacketLightning extends AppEngPacket
{
private final double x;
private final double y;
private final double z;
private final double x;
private final double y;
private final double z;
public PacketLightning(final PacketBuffer stream) {
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
}
public PacketLightning( final PacketBuffer stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
}
// api
public PacketLightning(final double x, final double y, final double z) {
this.x = x;
this.y = y;
this.z = z;
// api
public PacketLightning( final double x, final double y, final double z )
{
this.x = x;
this.y = y;
this.z = z;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeFloat((float) x);
data.writeFloat((float) y);
data.writeFloat((float) z);
data.writeInt( this.getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
try
{
if( Platform.isClient() && AEConfig.instance().isEnableEffects() )
{
Minecraft.getInstance().world.addParticle( LightningFX.TYPE, this.x, this.y, this.z, 0.0f, 0.0f, 0.0f );
}
}
catch( final Exception ignored )
{
}
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
try {
if (Platform.isClient() && AEConfig.instance().isEnableEffects()) {
Minecraft.getInstance().world.addParticle(LightningFX.TYPE, this.x, this.y, this.z, 0.0f, 0.0f, 0.0f);
}
} catch (final Exception ignored) {
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.annotation.Nullable;
import io.netty.buffer.Unpooled;
@@ -46,163 +46,136 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.util.AEFluidStack;
/**
* @author BrockWS
* @version rv6 - 22/05/2018
* @since rv6 22/05/2018
*/
public class PacketMEFluidInventoryUpdate extends AppEngPacket
{
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
public class PacketMEFluidInventoryUpdate extends AppEngPacket {
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
// input.
@Nullable
private final List<IAEFluidStack> list;
// output...
private final byte ref;
// input.
@Nullable
private final List<IAEFluidStack> list;
// output...
private final byte ref;
@Nullable
private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
@Nullable
private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
private int writtenBytes = 0;
private boolean empty = true;
private int writtenBytes = 0;
private boolean empty = true;
public PacketMEFluidInventoryUpdate( final PacketBuffer stream )
{
this.data = null;
this.compressFrame = null;
this.list = new LinkedList<>();
this.ref = stream.readByte();
public PacketMEFluidInventoryUpdate(final PacketBuffer stream) {
this.data = null;
this.compressFrame = null;
this.list = new LinkedList<>();
this.ref = stream.readByte();
try( final GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
{
@Override
public int read()
{
if( stream.readableBytes() <= 0 )
{
return -1;
}
try (final GZIPInputStream gzReader = new GZIPInputStream(new InputStream() {
@Override
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
return stream.readByte() & STREAM_MASK;
}
} ) )
{
return stream.readByte() & STREAM_MASK;
}
})) {
final PacketBuffer uncompressed = new PacketBuffer( Unpooled.buffer( stream.readableBytes() ) );
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
final PacketBuffer uncompressed = new PacketBuffer(Unpooled.buffer(stream.readableBytes()));
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
while( gzReader.available() != 0 )
{
final int bytes = gzReader.read( tmp );
while (gzReader.available() != 0) {
final int bytes = gzReader.read(tmp);
if( bytes > 0 )
{
uncompressed.writeBytes( tmp, 0, bytes );
}
}
if (bytes > 0) {
uncompressed.writeBytes(tmp, 0, bytes);
}
}
while( uncompressed.readableBytes() > 0 )
{
this.list.add( AEFluidStack.fromPacket( uncompressed ) );
}
}
catch( IOException e )
{
throw new RuntimeException( "Failed to decompress packet.", e );
}
while (uncompressed.readableBytes() > 0) {
this.list.add(AEFluidStack.fromPacket(uncompressed));
}
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
}
this.empty = this.list.isEmpty();
}
this.empty = this.list.isEmpty();
}
// api
public PacketMEFluidInventoryUpdate() throws IOException
{
this( (byte) 0 );
}
// api
public PacketMEFluidInventoryUpdate() throws IOException {
this((byte) 0);
}
// api
public PacketMEFluidInventoryUpdate( final byte ref ) throws IOException
{
this.ref = ref;
this.data = new PacketBuffer( Unpooled.buffer( OPERATION_BYTE_LIMIT ) );
this.data.writeInt( this.getPacketID() );
this.data.writeByte( this.ref );
// api
public PacketMEFluidInventoryUpdate(final byte ref) throws IOException {
this.ref = ref;
this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
this.data.writeInt(this.getPacketID());
this.data.writeByte(this.ref);
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
@Override
public void write( final int value )
{
PacketMEFluidInventoryUpdate.this.data.writeByte( value );
}
} );
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write(final int value) {
PacketMEFluidInventoryUpdate.this.data.writeByte(value);
}
});
this.list = null;
}
this.list = null;
}
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final Screen gs = Minecraft.getInstance().currentScreen;
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final Screen gs = Minecraft.getInstance().currentScreen;
// FIXME if( gs instanceof GuiFluidTerminal )
// FIXME {
// FIXME ( (GuiFluidTerminal) gs ).postUpdate( this.list );
// FIXME }
}
// FIXME if( gs instanceof GuiFluidTerminal )
// FIXME {
// FIXME ( (GuiFluidTerminal) gs ).postUpdate( this.list );
// FIXME }
}
@Nullable
@Override
public IPacket<?> toPacket( NetworkDirection direction )
{
try
{
this.compressFrame.close();
@Nullable
@Override
public IPacket<?> toPacket(NetworkDirection direction) {
try {
this.compressFrame.close();
this.configureWrite( this.data );
return super.toPacket( direction );
}
catch( final IOException e )
{
AELog.debug( e );
}
this.configureWrite(this.data);
return super.toPacket(direction);
} catch (final IOException e) {
AELog.debug(e);
}
return null;
}
return null;
}
public void appendFluid( final IAEFluidStack fs ) throws IOException, BufferOverflowException
{
final PacketBuffer tmp = new PacketBuffer( Unpooled.buffer( OPERATION_BYTE_LIMIT ) );
fs.writeToPacket( tmp );
public void appendFluid(final IAEFluidStack fs) throws IOException, BufferOverflowException {
final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
fs.writeToPacket(tmp);
this.compressFrame.flush();
if( this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT )
{
throw new BufferOverflowException();
}
else
{
this.writtenBytes += tmp.readableBytes();
this.compressFrame.write( tmp.array(), 0, tmp.readableBytes() );
this.empty = false;
}
}
this.compressFrame.flush();
if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) {
throw new BufferOverflowException();
} else {
this.writtenBytes += tmp.readableBytes();
this.compressFrame.write(tmp.array(), 0, tmp.readableBytes());
this.empty = false;
}
}
public int getLength()
{
return this.data.readableBytes();
}
public int getLength() {
return this.data.readableBytes();
}
public boolean isEmpty()
{
return this.empty;
}
public boolean isEmpty() {
return this.empty;
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,12 +26,9 @@ import java.util.ArrayList;
import java.util.List;
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;
@@ -45,179 +41,152 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkDirection;
import appeng.api.storage.data.IAEItemStack;
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 appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketMEInventoryUpdate extends AppEngPacket {
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
public class PacketMEInventoryUpdate extends AppEngPacket
{
private static final int UNCOMPRESSED_PACKET_BYTE_LIMIT = 16 * 1024 * 1024;
private static final int OPERATION_BYTE_LIMIT = 2 * 1024;
private static final int TEMP_BUFFER_SIZE = 1024;
private static final int STREAM_MASK = 0xff;
// input.
@Nullable
private final List<IAEItemStack> list;
// output...
private final byte ref;
// input.
@Nullable
private final List<IAEItemStack> list;
// output...
private final byte ref;
@Nullable
private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
@Nullable
private final PacketBuffer data;
@Nullable
private final GZIPOutputStream compressFrame;
private int writtenBytes = 0;
private boolean empty = true;
private int writtenBytes = 0;
private boolean empty = true;
public PacketMEInventoryUpdate(final PacketBuffer stream) {
this.data = null;
this.compressFrame = null;
this.list = new ArrayList<>();
this.ref = stream.readByte();
public PacketMEInventoryUpdate( final PacketBuffer stream )
{
this.data = null;
this.compressFrame = null;
this.list = new ArrayList<>();
this.ref = stream.readByte();
// int originalBytes = stream.readableBytes();
// int originalBytes = stream.readableBytes();
try (GZIPInputStream gzReader = new GZIPInputStream(new InputStream() {
@Override
public int read() {
if (stream.readableBytes() <= 0) {
return -1;
}
try( GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
{
@Override
public int read()
{
if( stream.readableBytes() <= 0 )
{
return -1;
}
return stream.readByte() & STREAM_MASK;
}
})) {
final PacketBuffer uncompressed = new PacketBuffer(Unpooled.buffer(stream.readableBytes()));
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
return stream.readByte() & STREAM_MASK;
}
} ) )
{
final PacketBuffer uncompressed = new PacketBuffer( Unpooled.buffer( stream.readableBytes() ) );
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
while (gzReader.available() != 0) {
final int bytes = gzReader.read(tmp);
while( gzReader.available() != 0 )
{
final int bytes = gzReader.read( tmp );
if (bytes > 0) {
uncompressed.writeBytes(tmp, 0, bytes);
}
}
if( bytes > 0 )
{
uncompressed.writeBytes( tmp, 0, bytes );
}
}
while (uncompressed.readableBytes() > 0) {
this.list.add(AEItemStack.fromPacket(uncompressed));
}
} catch (IOException e) {
throw new RuntimeException("Failed to decompress packet.", e);
}
while( uncompressed.readableBytes() > 0 )
{
this.list.add( AEItemStack.fromPacket( uncompressed ) );
}
}
catch( IOException e )
{
throw new RuntimeException( "Failed to decompress packet.", e );
}
this.empty = this.list.isEmpty();
}
this.empty = this.list.isEmpty();
}
// api
public PacketMEInventoryUpdate() throws IOException {
this((byte) 0);
}
// api
public PacketMEInventoryUpdate() throws IOException
{
this( (byte) 0 );
}
// api
public PacketMEInventoryUpdate(final byte ref) throws IOException {
this.ref = ref;
this.data = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
this.data.writeInt(this.getPacketID());
this.data.writeByte(this.ref);
// api
public PacketMEInventoryUpdate( final byte ref ) throws IOException
{
this.ref = ref;
this.data = new PacketBuffer( Unpooled.buffer( OPERATION_BYTE_LIMIT ) );
this.data.writeInt( this.getPacketID() );
this.data.writeByte( this.ref );
this.compressFrame = new GZIPOutputStream(new OutputStream() {
@Override
public void write(final int value) {
PacketMEInventoryUpdate.this.data.writeByte(value);
}
});
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
@Override
public void write( final int value )
{
PacketMEInventoryUpdate.this.data.writeByte( value );
}
} );
this.list = null;
}
this.list = null;
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final Screen gs = Minecraft.getInstance().currentScreen;
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final Screen gs = Minecraft.getInstance().currentScreen;
if (gs instanceof GuiCraftConfirm) {
((GuiCraftConfirm) gs).postUpdate(this.list, this.ref);
}
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 GuiCraftingCPU)
{
( (GuiCraftingCPU<?>) gs ).postUpdate( this.list, this.ref );
}
if (gs instanceof GuiMEMonitorable) {
((GuiMEMonitorable<?>) gs).postUpdate(this.list);
}
if( gs instanceof GuiMEMonitorable)
{
( (GuiMEMonitorable<?>) gs ).postUpdate( this.list );
}
if (gs instanceof GuiNetworkStatus) {
((GuiNetworkStatus) gs).postUpdate(this.list);
}
}
if( gs instanceof GuiNetworkStatus)
{
( (GuiNetworkStatus) gs ).postUpdate( this.list );
}
}
@Nullable
@Override
public IPacket<?> toPacket(NetworkDirection direction) {
try {
this.compressFrame.close();
@Nullable
@Override
public IPacket<?> toPacket( NetworkDirection direction )
{
try
{
this.compressFrame.close();
this.configureWrite(this.data);
return super.toPacket(direction);
} catch (final IOException e) {
AELog.debug(e);
}
this.configureWrite( this.data );
return super.toPacket( direction );
}
catch( final IOException e )
{
AELog.debug( e );
}
return null;
}
return null;
}
public void appendItem(final IAEItemStack is) throws IOException, BufferOverflowException {
final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer(OPERATION_BYTE_LIMIT));
is.writeToPacket(tmp);
public void appendItem( final IAEItemStack is ) throws IOException, BufferOverflowException
{
final PacketBuffer tmp = new PacketBuffer( Unpooled.buffer( OPERATION_BYTE_LIMIT ) );
is.writeToPacket( tmp );
this.compressFrame.flush();
if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) {
throw new BufferOverflowException();
} else {
this.writtenBytes += tmp.readableBytes();
this.compressFrame.write(tmp.array(), 0, tmp.readableBytes());
this.empty = false;
}
}
this.compressFrame.flush();
if( this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT )
{
throw new BufferOverflowException();
}
else
{
this.writtenBytes += tmp.readableBytes();
this.compressFrame.write( tmp.array(), 0, tmp.readableBytes() );
this.empty = false;
}
}
public int getLength() {
return this.data.readableBytes();
}
public int getLength()
{
return this.data.readableBytes();
}
public boolean isEmpty()
{
return this.empty;
}
public boolean isEmpty() {
return this.empty;
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
@@ -31,74 +30,68 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketMatterCannon extends AppEngPacket {
public class PacketMatterCannon extends AppEngPacket
{
private final double x;
private final double y;
private final double z;
private final double dx;
private final double dy;
private final double dz;
private final byte len;
private final double x;
private final double y;
private final double z;
private final double dx;
private final double dy;
private final double dz;
private final byte len;
public PacketMatterCannon(final PacketBuffer stream) {
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
this.dx = stream.readFloat();
this.dy = stream.readFloat();
this.dz = stream.readFloat();
this.len = stream.readByte();
}
public PacketMatterCannon( final PacketBuffer stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
this.dx = stream.readFloat();
this.dy = stream.readFloat();
this.dz = stream.readFloat();
this.len = stream.readByte();
}
// api
public PacketMatterCannon(final double x, final double y, final double z, final float dx, final float dy,
final float dz, final byte len) {
final float dl = dx * dx + dy * dy + dz * dz;
final float dlz = (float) Math.sqrt(dl);
// api
public PacketMatterCannon( final double x, final double y, final double z, final float dx, final float dy, final float dz, final byte len )
{
final float dl = dx * dx + dy * dy + dz * dz;
final float dlz = (float) Math.sqrt( dl );
this.x = x;
this.y = y;
this.z = z;
this.dx = dx / dlz;
this.dy = dy / dlz;
this.dz = dz / dlz;
this.len = len;
this.x = x;
this.y = y;
this.z = z;
this.dx = dx / dlz;
this.dy = dy / dlz;
this.dz = dz / dlz;
this.len = len;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeFloat((float) x);
data.writeFloat((float) y);
data.writeFloat((float) z);
data.writeFloat((float) this.dx);
data.writeFloat((float) this.dy);
data.writeFloat((float) this.dz);
data.writeByte(len);
data.writeInt( this.getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
data.writeFloat( (float) this.dx );
data.writeFloat( (float) this.dy );
data.writeFloat( (float) this.dz );
data.writeByte( len );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
try {
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
try
{
final World world = Minecraft.getInstance().world;
for (int a = 1; a < this.len; a++) {
// FIXME final MatterCannonFX fx = new MatterCannonFX( world, this.x + this.dx *
// a, this.y + this.dy * a, this.z + this.dz * a, new ItemStack( Items.DIAMOND )
// );
final World world = Minecraft.getInstance().world;
for( int a = 1; a < this.len; a++ )
{
// FIXME final MatterCannonFX fx = new MatterCannonFX( world, this.x + this.dx * a, this.y + this.dy * a, this.z + this.dz * a, new ItemStack( Items.DIAMOND ) );
// FIXME Minecraft.getInstance().particles.addEffect( fx );
}
}
catch( final Exception ignored )
{
}
}
// FIXME Minecraft.getInstance().particles.addEffect( fx );
}
} catch (final Exception ignored) {
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -32,43 +31,38 @@ import appeng.core.AppEng;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketMockExplosion extends AppEngPacket {
public class PacketMockExplosion extends AppEngPacket
{
private final double x;
private final double y;
private final double z;
private final double x;
private final double y;
private final double z;
public PacketMockExplosion(final PacketBuffer stream) {
this.x = stream.readDouble();
this.y = stream.readDouble();
this.z = stream.readDouble();
}
public PacketMockExplosion( final PacketBuffer stream )
{
this.x = stream.readDouble();
this.y = stream.readDouble();
this.z = stream.readDouble();
}
// api
public PacketMockExplosion(final double x, final double y, final double z) {
this.x = x;
this.y = y;
this.z = z;
// api
public PacketMockExplosion( final double x, final double y, final double z )
{
this.x = x;
this.y = y;
this.z = z;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeDouble(x);
data.writeDouble(y);
data.writeDouble(z);
data.writeInt( this.getPacketID() );
data.writeDouble( x );
data.writeDouble( y );
data.writeDouble( z );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final World world = AppEng.proxy.getWorld();
world.addParticle( ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D );
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final World world = AppEng.proxy.getWorld();
world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D);
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -30,39 +29,34 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
public class PacketPaintedEntity extends AppEngPacket {
public class PacketPaintedEntity extends AppEngPacket
{
private final AEColor myColor;
private final int entityId;
private int ticks;
private final AEColor myColor;
private final int entityId;
private int ticks;
public PacketPaintedEntity(final PacketBuffer stream) {
this.entityId = stream.readInt();
this.myColor = AEColor.values()[stream.readByte()];
this.ticks = stream.readInt();
}
public PacketPaintedEntity( final PacketBuffer stream )
{
this.entityId = stream.readInt();
this.myColor = AEColor.values()[stream.readByte()];
this.ticks = stream.readInt();
}
// api
public PacketPaintedEntity(final int myEntity, final AEColor myColor, final int ticksLeft) {
// api
public PacketPaintedEntity( final int myEntity, final AEColor myColor, final int ticksLeft )
{
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(this.entityId = myEntity);
data.writeByte((this.myColor = myColor).ordinal());
data.writeInt(ticksLeft);
data.writeInt( this.getPacketID() );
data.writeInt( this.entityId = myEntity );
data.writeByte( ( this.myColor = myColor ).ordinal() );
data.writeInt( ticksLeft );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final PlayerColor pc = new PlayerColor( this.entityId, this.myColor, this.ticks );
TickHandler.INSTANCE.getPlayerColors().put( this.entityId, pc );
}
@Override
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final PlayerColor pc = new PlayerColor(this.entityId, this.myColor, this.ticks);
TickHandler.INSTANCE.getPlayerColors().put(this.entityId, pc);
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -33,52 +32,47 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.parts.PartPlacement;
public class PacketPartPlacement extends AppEngPacket {
public class PacketPartPlacement extends AppEngPacket
{
private int x;
private int y;
private int z;
private int face;
private float eyeHeight;
private Hand hand;
private int x;
private int y;
private int z;
private int face;
private float eyeHeight;
private Hand hand;
public PacketPartPlacement(final PacketBuffer stream) {
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
this.face = stream.readByte();
this.eyeHeight = stream.readFloat();
this.hand = Hand.values()[stream.readByte()];
}
public PacketPartPlacement( final PacketBuffer stream )
{
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
this.face = stream.readByte();
this.eyeHeight = stream.readFloat();
this.hand = Hand.values()[stream.readByte()];
}
// api
public PacketPartPlacement(final BlockPos pos, final Direction face, final float eyeHeight, final Hand hand) {
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
// api
public PacketPartPlacement( final BlockPos pos, final Direction face, final float eyeHeight, final Hand hand )
{
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(pos.getX());
data.writeInt(pos.getY());
data.writeInt(pos.getZ());
data.writeByte(face.ordinal());
data.writeFloat(eyeHeight);
data.writeByte(hand.ordinal());
data.writeInt( this.getPacketID() );
data.writeInt( pos.getX() );
data.writeInt( pos.getY() );
data.writeInt( pos.getZ() );
data.writeByte( face.ordinal() );
data.writeFloat( eyeHeight );
data.writeByte( hand.ordinal() );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
AppEng.proxy.updateRenderMode( sender );
PartPlacement.setEyeHeight( this.eyeHeight );
PartPlacement.place( sender.getHeldItem( this.hand ), new BlockPos( this.x, this.y, this.z ), Direction.values()[this.face], sender, this.hand,
sender.world,
PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
AppEng.proxy.updateRenderMode( null );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
AppEng.proxy.updateRenderMode(sender);
PartPlacement.setEyeHeight(this.eyeHeight);
PartPlacement.place(sender.getHeldItem(this.hand), new BlockPos(this.x, this.y, this.z),
Direction.values()[this.face], sender, this.hand, sender.world,
PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0);
AppEng.proxy.updateRenderMode(null);
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.Unpooled;
@@ -36,85 +35,72 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketPatternSlot extends AppEngPacket {
public class PacketPatternSlot extends AppEngPacket
{
public final IAEItemStack slotItem;
public final IAEItemStack slotItem;
public final IAEItemStack[] pattern = new IAEItemStack[9];
public final IAEItemStack[] pattern = new IAEItemStack[9];
public final boolean shift;
public final boolean shift;
public PacketPatternSlot(final PacketBuffer stream) {
public PacketPatternSlot( final PacketBuffer stream )
{
this.shift = stream.readBoolean();
this.shift = stream.readBoolean();
this.slotItem = this.readItem(stream);
this.slotItem = this.readItem( stream );
for (int x = 0; x < 9; x++) {
this.pattern[x] = this.readItem(stream);
}
}
for( int x = 0; x < 9; x++ )
{
this.pattern[x] = this.readItem( stream );
}
}
private IAEItemStack readItem(final PacketBuffer stream) {
final boolean hasItem = stream.readBoolean();
private IAEItemStack readItem( final PacketBuffer stream )
{
final boolean hasItem = stream.readBoolean();
if (hasItem) {
return AEItemStack.fromPacket(stream);
}
if( hasItem )
{
return AEItemStack.fromPacket( stream );
}
return null;
}
return null;
}
// api
public PacketPatternSlot(final IItemHandler pat, final IAEItemStack slotItem, final boolean shift) {
// api
public PacketPatternSlot( final IItemHandler pat, final IAEItemStack slotItem, final boolean shift )
{
this.slotItem = slotItem;
this.shift = shift;
this.slotItem = slotItem;
this.shift = shift;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt( this.getPacketID() );
data.writeBoolean(shift);
data.writeBoolean( shift );
this.writeItem(slotItem, data);
for (int x = 0; x < 9; x++) {
this.pattern[x] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
.createStack(pat.getStackInSlot(x));
this.writeItem(this.pattern[x], data);
}
this.writeItem( slotItem, data );
for( int x = 0; x < 9; x++ )
{
this.pattern[x] = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( pat.getStackInSlot( x ) );
this.writeItem( this.pattern[x], data );
}
this.configureWrite(data);
}
this.configureWrite( data );
}
private void writeItem(final IAEItemStack slotItem, final PacketBuffer data) {
if (slotItem == null) {
data.writeBoolean(false);
} else {
data.writeBoolean(true);
slotItem.writeToPacket(data);
}
}
private void writeItem( final IAEItemStack slotItem, final PacketBuffer data )
{
if( slotItem == null )
{
data.writeBoolean( false );
}
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
if( sender.openContainer instanceof ContainerPatternTerm )
{
final ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer;
patternTerminal.craftOrGetItem( this );
}
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final ServerPlayerEntity sender = (ServerPlayerEntity) player;
if (sender.openContainer instanceof ContainerPatternTerm) {
final ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer;
patternTerminal.craftOrGetItem(this);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -29,51 +28,43 @@ import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketProgressBar extends AppEngPacket {
public class PacketProgressBar extends AppEngPacket
{
private final short id;
private final long value;
private final short id;
private final long value;
public PacketProgressBar(final PacketBuffer stream) {
this.id = stream.readShort();
this.value = stream.readLong();
}
public PacketProgressBar( final PacketBuffer stream )
{
this.id = stream.readShort();
this.value = stream.readLong();
}
// api
public PacketProgressBar(final int shortID, final long value) {
this.id = (short) shortID;
this.value = value;
// api
public PacketProgressBar( final int shortID, final long value )
{
this.id = (short) shortID;
this.value = value;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeShort(shortID);
data.writeLong(value);
data.writeInt( this.getPacketID() );
data.writeShort( shortID );
data.writeLong( value );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final Container c = player.openContainer;
if (c instanceof AEBaseContainer) {
((AEBaseContainer) c).updateFullProgressBar(this.id, this.value);
}
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final Container c = player.openContainer;
if( c instanceof AEBaseContainer )
{
( (AEBaseContainer) c ).updateFullProgressBar( this.id, this.value );
}
}
@Override
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final Container c = player.openContainer;
if( c instanceof AEBaseContainer )
{
( (AEBaseContainer) c ).updateFullProgressBar( this.id, this.value );
}
}
@Override
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final Container c = player.openContainer;
if (c instanceof AEBaseContainer) {
((AEBaseContainer) c).updateFullProgressBar(this.id, this.value);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -28,37 +27,31 @@ import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketSwapSlots extends AppEngPacket {
public class PacketSwapSlots extends AppEngPacket
{
private final int slotA;
private final int slotB;
private final int slotA;
private final int slotB;
public PacketSwapSlots(final PacketBuffer stream) {
this.slotA = stream.readInt();
this.slotB = stream.readInt();
}
public PacketSwapSlots( final PacketBuffer stream )
{
this.slotA = stream.readInt();
this.slotB = stream.readInt();
}
// api
public PacketSwapSlots(final int slotA, final int slotB) {
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
// api
public PacketSwapSlots( final int slotA, final int slotB )
{
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeInt(this.slotA = slotA);
data.writeInt(this.slotB = slotB);
data.writeInt( this.getPacketID() );
data.writeInt( this.slotA = slotA );
data.writeInt( this.slotB = slotB );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
if( player != null && player.openContainer instanceof AEBaseContainer )
{
( (AEBaseContainer) player.openContainer ).swapSlotContents( this.slotA, this.slotB );
}
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
if (player != null && player.openContainer instanceof AEBaseContainer) {
((AEBaseContainer) player.openContainer).swapSlotContents(this.slotA, this.slotB);
}
}
}
@@ -18,8 +18,6 @@
package appeng.core.sync.packets;
import appeng.container.ContainerOpener;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -27,51 +25,44 @@ import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.registries.ForgeRegistries;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
import net.minecraftforge.registries.ForgeRegistries;
public class PacketSwitchGuis extends AppEngPacket {
public class PacketSwitchGuis extends AppEngPacket
{
private final ContainerType<?> newGui;
private final ContainerType<?> newGui;
public PacketSwitchGuis(final PacketBuffer stream) {
this.newGui = ForgeRegistries.CONTAINERS.getValue(stream.readResourceLocation());
}
public PacketSwitchGuis( final PacketBuffer stream )
{
this.newGui = ForgeRegistries.CONTAINERS.getValue(stream.readResourceLocation());
}
// api
public PacketSwitchGuis(final ContainerType<?> newGui) {
this.newGui = newGui;
// api
public PacketSwitchGuis( final ContainerType<?> newGui )
{
this.newGui = newGui;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeResourceLocation(newGui.getRegistryName());
data.writeInt( this.getPacketID() );
data.writeResourceLocation(newGui.getRegistryName());
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final Container c = player.openContainer;
if( c instanceof AEBaseContainer )
{
final AEBaseContainer bc = (AEBaseContainer) c;
final ContainerLocator locator = bc.getLocator();
if( locator != null )
{
ContainerOpener.openContainer(newGui, player, locator);
}
}
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final Container c = player.openContainer;
if (c instanceof AEBaseContainer) {
final AEBaseContainer bc = (AEBaseContainer) c;
final ContainerLocator locator = bc.getLocator();
if (locator != null) {
ContainerOpener.openContainer(newGui, player, locator);
}
}
}
}
@@ -1,93 +1,76 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketBuffer;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.container.ContainerFluidTerminal;
import appeng.fluids.util.AEFluidStack;
/**
* @author BrockWS
* @version rv6 - 23/05/2018
* @since rv6 23/05/2018
*/
public class PacketTargetFluidStack extends AppEngPacket
{
private AEFluidStack stack;
public PacketTargetFluidStack( final PacketBuffer stream )
{
try
{
if( stream.readableBytes() > 0 )
{
this.stack = (AEFluidStack) AEFluidStack.fromPacket( stream );
}
else
{
this.stack = null;
}
}
catch( Exception ex )
{
AELog.debug( ex );
this.stack = null;
}
}
// api
public PacketTargetFluidStack( AEFluidStack stack )
{
this.stack = stack;
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt( this.getPacketID() );
if( stack != null )
{
try
{
stack.writeToPacket( data );
}
catch( Exception ex )
{
AELog.debug( ex );
}
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
if( player.openContainer instanceof ContainerFluidTerminal )
{
( (ContainerFluidTerminal) player.openContainer ).setTargetStack( this.stack );
}
}
}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2018, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketBuffer;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.container.ContainerFluidTerminal;
import appeng.fluids.util.AEFluidStack;
/**
* @author BrockWS
* @version rv6 - 23/05/2018
* @since rv6 23/05/2018
*/
public class PacketTargetFluidStack extends AppEngPacket {
private AEFluidStack stack;
public PacketTargetFluidStack(final PacketBuffer stream) {
try {
if (stream.readableBytes() > 0) {
this.stack = (AEFluidStack) AEFluidStack.fromPacket(stream);
} else {
this.stack = null;
}
} catch (Exception ex) {
AELog.debug(ex);
this.stack = null;
}
}
// api
public PacketTargetFluidStack(AEFluidStack stack) {
this.stack = stack;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
data.writeInt(this.getPacketID());
if (stack != null) {
try {
stack.writeToPacket(data);
} catch (Exception ex) {
AELog.debug(ex);
}
}
this.configureWrite(data);
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
if (player.openContainer instanceof ContainerFluidTerminal) {
((ContainerFluidTerminal) player.openContainer).setTargetStack(this.stack);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.PlayerEntity;
@@ -30,59 +29,43 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketTargetItemStack extends AppEngPacket {
private AEItemStack stack;
public class PacketTargetItemStack extends AppEngPacket
{
private AEItemStack stack;
public PacketTargetItemStack(final PacketBuffer stream) {
try {
if (stream.readableBytes() > 0) {
this.stack = AEItemStack.fromPacket(stream);
} else {
this.stack = null;
}
} catch (Exception ex) {
AELog.debug(ex);
this.stack = null;
}
}
public PacketTargetItemStack( final PacketBuffer stream )
{
try
{
if( stream.readableBytes() > 0 )
{
this.stack = AEItemStack.fromPacket( stream );
}
else
{
this.stack = null;
}
}
catch( Exception ex )
{
AELog.debug( ex );
this.stack = null;
}
}
// api
public PacketTargetItemStack(AEItemStack stack) {
// api
public PacketTargetItemStack( AEItemStack stack )
{
this.stack = stack;
this.stack = stack;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
data.writeInt(this.getPacketID());
if (stack != null) {
try {
stack.writeToPacket(data);
} catch (Exception ex) {
AELog.debug(ex);
}
}
this.configureWrite(data);
}
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt( this.getPacketID() );
if( stack != null )
{
try
{
stack.writeToPacket( data );
}
catch( Exception ex )
{
AELog.debug( ex );
}
}
this.configureWrite( data );
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
if( player.openContainer instanceof AEBaseContainer )
{
( (AEBaseContainer) player.openContainer ).setTargetStack( this.stack );
}
}
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
if (player.openContainer instanceof AEBaseContainer) {
((AEBaseContainer) player.openContainer).setTargetStack(this.stack);
}
}
}
@@ -18,7 +18,6 @@
package appeng.core.sync.packets;
import io.netty.buffer.Unpooled;
import net.minecraft.block.BlockState;
@@ -43,83 +42,78 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketTransitionEffect extends AppEngPacket {
public class PacketTransitionEffect extends AppEngPacket
{
private final boolean mode;
private final double x;
private final double y;
private final double z;
private final AEPartLocation d;
private final boolean mode;
private final double x;
private final double y;
private final double z;
private final AEPartLocation d;
public PacketTransitionEffect(final PacketBuffer stream) {
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
this.d = AEPartLocation.fromOrdinal(stream.readByte());
this.mode = stream.readBoolean();
}
public PacketTransitionEffect( final PacketBuffer stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
this.z = stream.readFloat();
this.d = AEPartLocation.fromOrdinal( stream.readByte() );
this.mode = stream.readBoolean();
}
// api
public PacketTransitionEffect(final double x, final double y, final double z, final AEPartLocation dir,
final boolean wasBlock) {
this.x = x;
this.y = y;
this.z = z;
this.d = dir;
this.mode = wasBlock;
// api
public PacketTransitionEffect( final double x, final double y, final double z, final AEPartLocation dir, final boolean wasBlock )
{
this.x = x;
this.y = y;
this.z = z;
this.d = dir;
this.mode = wasBlock;
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeInt(this.getPacketID());
data.writeFloat((float) x);
data.writeFloat((float) y);
data.writeFloat((float) z);
data.writeByte(this.d.ordinal());
data.writeBoolean(wasBlock);
data.writeInt( this.getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
data.writeByte( this.d.ordinal() );
data.writeBoolean( wasBlock );
this.configureWrite(data);
}
this.configureWrite( data );
}
@Override
@OnlyIn(Dist.CLIENT)
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final World world = AppEng.proxy.getWorld();
@Override
@OnlyIn( Dist.CLIENT )
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final World world = AppEng.proxy.getWorld();
for (int zz = 0; zz < (this.mode ? 32 : 8); zz++) {
if (AppEng.proxy.shouldAddParticles(Platform.getRandom())) {
double x = this.x + (this.mode ? (Platform.getRandomInt() % 100) * 0.01
: (Platform.getRandomInt() % 100) * 0.005 - 0.25);
double y = this.y + (this.mode ? (Platform.getRandomInt() % 100) * 0.01
: (Platform.getRandomInt() % 100) * 0.005 - 0.25);
double z = this.z + (this.mode ? (Platform.getRandomInt() % 100) * 0.01
: (Platform.getRandomInt() % 100) * 0.005 - 0.25);
double speedX = -0.1f * this.d.xOffset;
double speedY = -0.1f * this.d.yOffset;
double speedZ = -0.1f * this.d.zOffset;
for( int zz = 0; zz < ( this.mode ? 32 : 8 ); zz++ )
{
if( AppEng.proxy.shouldAddParticles( Platform.getRandom() ) )
{
double x = this.x + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 );
double y = this.y + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 );
double z = this.z + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 );
double speedX = -0.1f * this.d.xOffset;
double speedY = -0.1f * this.d.yOffset;
double speedZ = -0.1f * this.d.zOffset;
EnergyFx fx = (EnergyFx) Minecraft.getInstance().particles.addParticle(EnergyFx.TYPE, x, y, z, speedX,
speedY, speedZ);
// FIXME: *sigh* custom particle data for this one thing :|
if (!this.mode) {
fx.fromItem(this.d);
}
}
}
EnergyFx fx = (EnergyFx) Minecraft.getInstance().particles.addParticle(EnergyFx.TYPE, x, y, z, speedX, speedY, speedZ);
// FIXME: *sigh* custom particle data for this one thing :|
if( !this.mode )
{
fx.fromItem( this.d );
}
}
}
if (this.mode) {
final BlockPos pos = new BlockPos((int) this.x, (int) this.y, (int) this.z);
final BlockState state = world.getBlockState(pos);
final SoundType sound = state.getSoundType(world, pos, null);
if( this.mode )
{
final BlockPos pos = new BlockPos( (int) this.x, (int) this.y, (int) this.z );
final BlockState state = world.getBlockState( pos );
final SoundType sound = state.getSoundType( world, pos, null );
Minecraft.getInstance()
.getSoundHandler()
.play( new SimpleSound( sound
.getBreakSound(), SoundCategory.BLOCKS, ( sound.getVolume() + 1.0F ) / 2.0F, sound
.getPitch() * 0.8F, (float) this.x + 0.5F, (float) this.y + 0.5F, (float) this.z + 0.5F ) );
}
}
Minecraft.getInstance().getSoundHandler()
.play(new SimpleSound(sound.getBreakSound(), SoundCategory.BLOCKS,
(sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F, (float) this.x + 0.5F,
(float) this.y + 0.5F, (float) this.z + 0.5F));
}
}
}
@@ -18,6 +18,17 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Hand;
import appeng.api.config.FuzzyMode;
import appeng.api.config.Settings;
@@ -41,263 +52,174 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.fluids.container.ContainerFluidLevelEmitter;
import appeng.fluids.container.ContainerFluidStorageBus;
import appeng.helpers.IMouseWheelItem;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Hand;
import java.io.IOException;
public class PacketValueConfig extends AppEngPacket {
private final String Name;
private final String Value;
public class PacketValueConfig extends AppEngPacket
{
public PacketValueConfig(final PacketBuffer stream) {
this.Name = stream.readString();
this.Value = stream.readString();
// dis.close();
}
private final String Name;
private final String Value;
// api
public PacketValueConfig(final String name, final String value) {
this.Name = name;
this.Value = value;
public PacketValueConfig( final PacketBuffer stream )
{
this.Name = stream.readString();
this.Value = stream.readString();
// dis.close();
}
final PacketBuffer data = new PacketBuffer(Unpooled.buffer());
// api
public PacketValueConfig( final String name, final String value )
{
this.Name = name;
this.Value = value;
data.writeInt(this.getPacketID());
final PacketBuffer data = new PacketBuffer( Unpooled.buffer() );
data.writeString(name);
data.writeString(value);
data.writeInt( this.getPacketID() );
this.configureWrite(data);
}
data.writeString( name );
data.writeString( value );
@Override
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
final Container c = player.openContainer;
this.configureWrite( data );
}
if (this.Name.equals("Item") && ((!player.getHeldItem(Hand.MAIN_HAND).isEmpty()
&& player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof IMouseWheelItem)
|| (!player.getHeldItem(Hand.OFF_HAND).isEmpty()
&& player.getHeldItem(Hand.OFF_HAND).getItem() instanceof IMouseWheelItem))) {
final Hand hand;
if (!player.getHeldItem(Hand.MAIN_HAND).isEmpty()
&& player.getHeldItem(Hand.MAIN_HAND).getItem() instanceof IMouseWheelItem) {
hand = Hand.MAIN_HAND;
} else if (!player.getHeldItem(Hand.OFF_HAND).isEmpty()
&& player.getHeldItem(Hand.OFF_HAND).getItem() instanceof IMouseWheelItem) {
hand = Hand.OFF_HAND;
} else {
return;
}
@Override
public void serverPacketData( final INetworkInfo manager, final PlayerEntity player )
{
final Container c = player.openContainer;
final ItemStack is = player.getHeldItem(hand);
final IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel(is, this.Value.equals("WheelUp"));
} else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftingStatus) {
final ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
qk.cycleCpu(this.Value.equals("Next"));
} else if (this.Name.equals("Terminal.Cpu") && c instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.cycleCpu(this.Value.equals("Next"));
} else if (this.Name.equals("Terminal.Start") && c instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
} else if (this.Name.equals("TileCrafting.Cancel") && c instanceof ContainerCraftingCPU) {
final ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
qk.cancelCrafting();
} else if (this.Name.equals("QuartzKnife.Name") && c instanceof ContainerQuartzKnife) {
final ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
qk.setName(this.Value);
} else if (this.Name.equals("TileSecurityStation.ToggleOption") && c instanceof ContainerSecurityStation) {
final ContainerSecurityStation sc = (ContainerSecurityStation) c;
sc.toggleSetting(this.Value, player);
} else if (this.Name.equals("PriorityHost.Priority") && c instanceof ContainerPriority) {
final ContainerPriority pc = (ContainerPriority) c;
pc.setPriority(Integer.parseInt(this.Value), player);
} else if (this.Name.equals("LevelEmitter.Value") && c instanceof ContainerLevelEmitter) {
final ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel(Long.parseLong(this.Value), player);
} else if (this.Name.equals("FluidLevelEmitter.Value") && c instanceof ContainerFluidLevelEmitter) {
final ContainerFluidLevelEmitter lvc = (ContainerFluidLevelEmitter) c;
lvc.setLevel(Long.parseLong(this.Value), player);
} else if (this.Name.startsWith("PatternTerminal.") && c instanceof ContainerPatternTerm) {
final ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if (this.Name.equals("PatternTerminal.CraftMode")) {
cpt.getPatternTerminal().setCraftingRecipe(this.Value.equals("1"));
} else if (this.Name.equals("PatternTerminal.Encode")) {
cpt.encode();
} else if (this.Name.equals("PatternTerminal.Clear")) {
cpt.clear();
} else if (this.Name.equals("PatternTerminal.Substitute")) {
cpt.getPatternTerminal().setSubstitution(this.Value.equals("1"));
}
} else if (this.Name.startsWith("StorageBus.")) {
if (this.Name.equals("StorageBus.Action")) {
if (this.Value.equals("Partition")) {
if (c instanceof ContainerStorageBus) {
((ContainerStorageBus) c).partition();
} else if (c instanceof ContainerFluidStorageBus) {
((ContainerFluidStorageBus) c).partition();
}
} else if (this.Value.equals("Clear")) {
if (c instanceof ContainerStorageBus) {
((ContainerStorageBus) c).clear();
} else if (c instanceof ContainerFluidStorageBus) {
((ContainerFluidStorageBus) c).clear();
}
}
}
} else if (this.Name.startsWith("CellWorkbench.") && c instanceof ContainerCellWorkbench) {
final ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if (this.Name.equals("CellWorkbench.Action")) {
if (this.Value.equals("CopyMode")) {
ccw.nextWorkBenchCopyMode();
} else if (this.Value.equals("Partition")) {
ccw.partition();
} else if (this.Value.equals("Clear")) {
ccw.clear();
}
} else if (this.Name.equals("CellWorkbench.Fuzzy")) {
ccw.setFuzzy(FuzzyMode.valueOf(this.Value));
}
} else if (c instanceof ContainerNetworkTool) {
if (this.Name.equals("NetworkTool") && this.Value.equals("Toggle")) {
((ContainerNetworkTool) c).toggleFacadeMode();
}
} else if (c instanceof IConfigurableObject) {
final IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
if( this.Name.equals( "Item" ) && ( ( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem) || ( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem ) ) )
{
final Hand hand;
if( !player.getHeldItem( Hand.MAIN_HAND ).isEmpty() && player.getHeldItem( Hand.MAIN_HAND ).getItem() instanceof IMouseWheelItem )
{
hand = Hand.MAIN_HAND;
}
else if( !player.getHeldItem( Hand.OFF_HAND ).isEmpty() && player.getHeldItem( Hand.OFF_HAND ).getItem() instanceof IMouseWheelItem )
{
hand = Hand.OFF_HAND;
}
else
{
return;
}
for (final Settings e : cm.getSettings()) {
if (e.name().equals(this.Name)) {
final Enum<?> def = cm.getSetting(e);
final ItemStack is = player.getHeldItem( hand );
final IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel( is, this.Value.equals( "WheelUp" ) );
}
else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus)
{
final ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm )
{
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
{
final ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
}
else if( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
{
final ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
qk.cancelCrafting();
}
else if( this.Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
{
final ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
qk.setName( this.Value );
}
else if( this.Name.equals( "TileSecurityStation.ToggleOption" ) && c instanceof ContainerSecurityStation )
{
final ContainerSecurityStation sc = (ContainerSecurityStation) c;
sc.toggleSetting( this.Value, player );
}
else if( this.Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
{
final ContainerPriority pc = (ContainerPriority) c;
pc.setPriority( Integer.parseInt( this.Value ), player );
}
else if( this.Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
{
final ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel( Long.parseLong( this.Value ), player );
}
else if( this.Name.equals( "FluidLevelEmitter.Value" ) && c instanceof ContainerFluidLevelEmitter)
{
final ContainerFluidLevelEmitter lvc = (ContainerFluidLevelEmitter) c;
lvc.setLevel( Long.parseLong( this.Value ), player );
}
else if( this.Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
{
final ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if( this.Name.equals( "PatternTerminal.CraftMode" ) )
{
cpt.getPatternTerminal().setCraftingRecipe( this.Value.equals( "1" ) );
}
else if( this.Name.equals( "PatternTerminal.Encode" ) )
{
cpt.encode();
}
else if( this.Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
else if( this.Name.equals( "PatternTerminal.Substitute" ) )
{
cpt.getPatternTerminal().setSubstitution( this.Value.equals( "1" ) );
}
}
else if( this.Name.startsWith( "StorageBus." ) )
{
if( this.Name.equals( "StorageBus.Action" ) )
{
if( this.Value.equals( "Partition" ) )
{
if( c instanceof ContainerStorageBus )
{
( (ContainerStorageBus) c ).partition();
}
else if( c instanceof ContainerFluidStorageBus)
{
( (ContainerFluidStorageBus) c ).partition();
}
}
else if( this.Value.equals( "Clear" ) )
{
if( c instanceof ContainerStorageBus )
{
( (ContainerStorageBus) c ).clear();
}
else if( c instanceof ContainerFluidStorageBus )
{
( (ContainerFluidStorageBus) c ).clear();
}
}
}
}
else if( this.Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{
final ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if( this.Name.equals( "CellWorkbench.Action" ) )
{
if( this.Value.equals( "CopyMode" ) )
{
ccw.nextWorkBenchCopyMode();
}
else if( this.Value.equals( "Partition" ) )
{
ccw.partition();
}
else if( this.Value.equals( "Clear" ) )
{
ccw.clear();
}
}
else if( this.Name.equals( "CellWorkbench.Fuzzy" ) )
{
ccw.setFuzzy( FuzzyMode.valueOf( this.Value ) );
}
}
else if( c instanceof ContainerNetworkTool )
{
if( this.Name.equals( "NetworkTool" ) && this.Value.equals( "Toggle" ) )
{
( (ContainerNetworkTool) c ).toggleFacadeMode();
}
}
else if( c instanceof IConfigurableObject)
{
final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager();
try {
cm.putSetting(e, Enum.valueOf(def.getClass(), this.Value));
} catch (final IllegalArgumentException err) {
// :P
}
for( final Settings e : cm.getSettings() )
{
if( e.name().equals( this.Name ) )
{
final Enum<?> def = cm.getSetting( e );
break;
}
}
}
}
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch( final IllegalArgumentException err )
{
// :P
}
@Override
public void clientPacketData(final INetworkInfo network, final PlayerEntity player) {
final Container c = player.openContainer;
break;
}
}
}
}
if (this.Name.equals("CustomName") && c instanceof AEBaseContainer) {
((AEBaseContainer) c).setCustomName(this.Value);
} else if (this.Name.startsWith("SyncDat.")) {
((AEBaseContainer) c).stringSync(Integer.parseInt(this.Name.substring(8)), this.Value);
} else if (this.Name.equals("CraftingStatus") && this.Value.equals("Clear")) {
final Screen gs = Minecraft.getInstance().currentScreen;
if (gs instanceof GuiCraftingCPU) {
((GuiCraftingCPU) gs).clearItems();
}
} else if (c instanceof IConfigurableObject) {
final IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
@Override
public void clientPacketData( final INetworkInfo network, final PlayerEntity player )
{
final Container c = player.openContainer;
for (final Settings e : cm.getSettings()) {
if (e.name().equals(this.Name)) {
final Enum<?> def = cm.getSetting(e);
if( this.Name.equals( "CustomName" ) && c instanceof AEBaseContainer)
{
( (AEBaseContainer) c ).setCustomName( this.Value );
}
else if( this.Name.startsWith( "SyncDat." ) )
{
( (AEBaseContainer) c ).stringSync( Integer.parseInt( this.Name.substring( 8 ) ), this.Value );
}
else if( this.Name.equals( "CraftingStatus" ) && this.Value.equals( "Clear" ) )
{
final Screen gs = Minecraft.getInstance().currentScreen;
if( gs instanceof GuiCraftingCPU)
{
( (GuiCraftingCPU) gs ).clearItems();
}
}
else if( c instanceof IConfigurableObject )
{
final IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager();
try {
cm.putSetting(e, Enum.valueOf(def.getClass(), this.Value));
} catch (final IllegalArgumentException err) {
// :P
}
for( final Settings e : cm.getSettings() )
{
if( e.name().equals( this.Name ) )
{
final Enum<?> def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch( final IllegalArgumentException err )
{
// :P
}
break;
}
}
}
}
break;
}
}
}
}
}