Relocate Source to proper directory.

This commit is contained in:
AlgorithmX2
2014-09-23 19:26:27 -05:00
parent fe927ce65d
commit 386d18a059
785 changed files with 35585 additions and 35580 deletions
@@ -0,0 +1,53 @@
package appeng.core.sync;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.features.AEFeature;
import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public abstract class AppEngPacket
{
private ByteBuf p;
AppEngPacketHandlerBase.PacketTypes id;
final public int getPacketID()
{
return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
}
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a server side handler." );
}
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a client side handler." );
}
protected void configureWrite(ByteBuf data)
{
data.capacity( data.readableBytes() );
p = data;
}
public FMLProxyPacket getProxy()
{
if ( p.array().length > 2 * 1024 * 1024 ) // 2k walking room :)
throw new IllegalArgumentException( "Sorry AE2 made a " + p.array().length + " byte packet by accident!" );
FMLProxyPacket pp = new FMLProxyPacket( p, NetworkHandler.instance.getChannel() );
if ( AEConfig.instance.isFeatureEnabled( AEFeature.PacketLogging ) )
AELog.info( getClass().getName() + " : " + pp.payload().readableBytes() );
return pp;
}
}
@@ -0,0 +1,132 @@
package appeng.core.sync;
import io.netty.buffer.ByteBuf;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import appeng.core.sync.packets.PacketAssemblerAnimation;
import appeng.core.sync.packets.PacketClick;
import appeng.core.sync.packets.PacketCompassRequest;
import appeng.core.sync.packets.PacketCompassResponse;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketCraftRequest;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketLightning;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketMatterCannon;
import appeng.core.sync.packets.PacketMockExplosion;
import appeng.core.sync.packets.PacketMultiPart;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.core.sync.packets.PacketNewStorageDimension;
import appeng.core.sync.packets.PacketPaintedEntity;
import appeng.core.sync.packets.PacketPartPlacement;
import appeng.core.sync.packets.PacketPartialItem;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.core.sync.packets.PacketProgressBar;
import appeng.core.sync.packets.PacketSwapSlots;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.core.sync.packets.PacketValueConfig;
public class AppEngPacketHandlerBase
{
public static Map<Class, PacketTypes> reverseLookup = new HashMap<Class, AppEngPacketHandlerBase.PacketTypes>();
public enum PacketTypes
{
PACKET_COMPASS_REQUEST(PacketCompassRequest.class),
PACKET_COMPASS_RESPONSE(PacketCompassResponse.class),
PACKET_INVENTORY_ACTION(PacketInventoryAction.class),
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class),
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
PACKET_MULTIPART(PacketMultiPart.class),
PACKET_PARTPLACEMENT(PacketPartPlacement.class),
PACKET_LIGHTNING(PacketLightning.class),
PACKET_MATTERCANNON(PacketMatterCannon.class),
PACKET_MOCKEXPLOSION(PacketMockExplosion.class),
PACKET_VALUE_CONFIG(PacketValueConfig.class),
PACKET_TRANSITION_EFFECT(PacketTransitionEffect.class),
PACKET_PROGRESS_VALUE(PacketProgressBar.class),
PACKET_CLICK(PacketClick.class),
PACKET_NEW_STORAGE_DIMENSION(PacketNewStorageDimension.class),
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
PACKET_SWAP_SLOTS(PacketSwapSlots.class),
PACKET_PATTERN_SLOT(PacketPatternSlot.class),
PACKET_RECIPE_NEI(PacketNEIRecipe.class),
PACKET_PARTIAL_ITEM(PacketPartialItem.class),
PACKET_CRAFTING_REQUEST(PacketCraftRequest.class),
PACKET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class),
PACKET_COMPRESSED_NBT(PacketCompressedNBT.class),
PACKET_PAINTED_ENTITY(PacketPaintedEntity.class);
final public Class pc;
final public Constructor con;
private PacketTypes(Class c) {
pc = c;
Constructor x = null;
try
{
x = pc.getConstructor( ByteBuf.class );
}
catch (NoSuchMethodException e)
{
}
catch (SecurityException e)
{
}
con = x;
AppEngPacketHandlerBase.reverseLookup.put( pc, this );
if ( con == null )
throw new RuntimeException( "Invalid Packet Class, must be constructable on DataInputStream" );
}
public AppEngPacket parsePacket(ByteBuf in) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
return (AppEngPacket) con.newInstance( in );
}
public static PacketTypes getPacket(int id)
{
return (values())[id];
}
public static PacketTypes getID(Class<? extends AppEngPacket> c)
{
return AppEngPacketHandlerBase.reverseLookup.get( c );
}
};
}
@@ -0,0 +1,497 @@
package appeng.core.sync;
import static appeng.core.sync.GuiHostType.ITEM;
import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD;
import static appeng.core.sync.GuiHostType.WORLD;
import java.lang.reflect.Constructor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.definitions.Materials;
import appeng.api.exceptions.AppEngException;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.storage.ITerminalHost;
import appeng.api.util.DimensionalCoord;
import appeng.client.gui.GuiNull;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerNull;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.container.implementations.ContainerChest;
import appeng.container.implementations.ContainerCondenser;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.container.implementations.ContainerCraftingStatus;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.container.implementations.ContainerDrive;
import appeng.container.implementations.ContainerFormationPlane;
import appeng.container.implementations.ContainerGrinder;
import appeng.container.implementations.ContainerIOPort;
import appeng.container.implementations.ContainerInscriber;
import appeng.container.implementations.ContainerInterface;
import appeng.container.implementations.ContainerInterfaceTerminal;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerMAC;
import appeng.container.implementations.ContainerMEMonitorable;
import appeng.container.implementations.ContainerMEPortableCell;
import appeng.container.implementations.ContainerNetworkStatus;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.implementations.ContainerPriority;
import appeng.container.implementations.ContainerQNB;
import appeng.container.implementations.ContainerQuartzKnife;
import appeng.container.implementations.ContainerSecurity;
import appeng.container.implementations.ContainerSkyChest;
import appeng.container.implementations.ContainerSpatialIOPort;
import appeng.container.implementations.ContainerStorageBus;
import appeng.container.implementations.ContainerUpgradeable;
import appeng.container.implementations.ContainerVibrationChamber;
import appeng.container.implementations.ContainerWireless;
import appeng.container.implementations.ContainerWirelessTerm;
import appeng.core.stats.Achievements;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.IPriorityHost;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.items.contents.QuartzKnifeObj;
import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.misc.PartStorageBus;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartMonitor;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.crafting.TileCraftingTile;
import appeng.tile.crafting.TileMolecularAssembler;
import appeng.tile.grindstone.TileGrinder;
import appeng.tile.misc.TileCellWorkbench;
import appeng.tile.misc.TileCondenser;
import appeng.tile.misc.TileInscriber;
import appeng.tile.misc.TileSecurity;
import appeng.tile.misc.TileVibrationChamber;
import appeng.tile.networking.TileWireless;
import appeng.tile.qnb.TileQuantumBridge;
import appeng.tile.spatial.TileSpatialIOPort;
import appeng.tile.storage.TileChest;
import appeng.tile.storage.TileDrive;
import appeng.tile.storage.TileIOPort;
import appeng.tile.storage.TileSkyChest;
import appeng.util.Platform;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
public enum GuiBridge implements IGuiHandler
{
GUI_Handler(),
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, WORLD, null),
GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD),
GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, WORLD, null),
GUI_CHEST(ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD),
GUI_WIRELESS(ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD),
GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null),
GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, ITEM, null),
GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null),
GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null),
GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT),
GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null),
GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null),
GUI_DRIVE(ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD),
GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null),
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, WORLD, null),
GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD),
GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD),
GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD),
GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD),
GUI_FPLANE(ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD),
GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD),
GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY),
GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT),
GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT),
// extends (Container/Gui) + Bus
GUI_LEVELEMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD),
GUI_SPATIALIOPORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD),
GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, WORLD, null),
GUI_CELLWORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null),
GUI_MAC(ContainerMAC.class, TileMolecularAssembler.class, WORLD, null),
GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD),
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
private Class Tile;
private Class Gui;
private Class Container;
private GuiHostType type;
private SecurityPermissions requiredPermission;
private GuiBridge() {
Tile = null;
Gui = null;
Container = null;
}
/**
* 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() )
{
String start = Container.getName();
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if ( start.equals( GuiClass ) )
throw new RuntimeException( "Unable to find gui class" );
Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
if ( Gui == null )
throw new RuntimeException( "Cannot Load class: " + GuiClass );
}
}
private GuiBridge(Class _Container, SecurityPermissions requiredPermission) {
this.requiredPermission = requiredPermission;
Container = _Container;
Tile = null;
getGui();
}
private GuiBridge(Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission) {
this.requiredPermission = requiredPermission;
Container = _Container;
this.type = type;
Tile = _Tile;
getGui();
}
public boolean CorrectTileOrPart(Object tE)
{
if ( Tile == null )
throw new RuntimeException( "This Gui Cannot use the standard Handler." );
return Tile.isInstance( tE );
}
public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE)
{
try
{
Constructor[] c = Container.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
Constructor target = findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
}
Object o = target.newInstance( inventory, tE );
/**
* triggers achievement when the player sees presses.
*/
if ( o instanceof AEBaseContainer )
{
AEBaseContainer bc = (AEBaseContainer) o;
for (Object so : bc.inventorySlots)
{
if ( so instanceof Slot )
{
ItemStack is = ((Slot) so).getStack();
Materials m = AEApi.instance().materials();
if ( m.materialLogicProcessorPress.sameAsStack( is ) || m.materialEngProcessorPress.sameAsStack( is )
|| m.materialCalcProcessorPress.sameAsStack( is ) || m.materialSiliconPress.sameAsStack( is ) )
{
Achievements.Presses.addToPlayer( inventory.player );
}
}
}
}
return o;
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
public Object ConstructGui(InventoryPlayer inventory, ForgeDirection side, Object tE)
{
try
{
Constructor[] c = Gui.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
Constructor target = findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
private String typeName(Object inventory)
{
if ( inventory == null )
return "NULL";
return inventory.getClass().getName();
}
private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object tE)
{
for (Constructor con : c)
{
Class[] types = con.getParameterTypes();
if ( types.length == 2 )
{
if ( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
return con;
}
}
return null;
}
private Object updateGui(Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem)
{
if ( newContainer instanceof AEBaseContainer )
{
AEBaseContainer bc = (AEBaseContainer) newContainer;
bc.openContext = new ContainerOpenContext( myItem );
bc.openContext.w = w;
bc.openContext.x = x;
bc.openContext.y = y;
bc.openContext.z = z;
bc.openContext.side = side;
}
return newContainer;
}
@Override
public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
{
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 4];
boolean istem = ((ID_ORDINAL >> 3) & 1) == 1;
if ( ID.type.isItem() && istem )
{
ItemStack it = player.inventory.getCurrentItem();
Object myItem = getGuiObject( it, player, w, x, y, z );
if ( myItem != null && ID.CorrectTileOrPart( myItem ) )
return updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem );
}
if ( ID.type.isTile() )
{
TileEntity TE = w.getTileEntity( x, y, z );
if ( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart( side );
if ( ID.CorrectTileOrPart( part ) )
return updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part );
}
else
{
if ( ID.CorrectTileOrPart( TE ) )
return updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE );
}
}
return new ContainerNull();
}
private Object getGuiObject(ItemStack it, EntityPlayer player, World w, int x, int y, int z)
{
if ( it != null )
{
if ( it.getItem() instanceof IGuiItem )
{
return ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z );
}
IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
if ( wh != null )
return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z );
}
return null;
}
@Override
public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
{
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 4];
boolean istem = ((ID_ORDINAL >> 3) & 1) == 1;
if ( ID.type.isItem() && istem )
{
ItemStack it = player.inventory.getCurrentItem();
Object myItem = getGuiObject( it, player, w, x, y, z );
if ( ID.CorrectTileOrPart( myItem ) )
return ID.ConstructGui( player.inventory, side, myItem );
}
if ( ID.type.isTile() )
{
TileEntity TE = w.getTileEntity( x, y, z );
if ( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
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 new GuiNull( new ContainerNull() );
}
public boolean hasPermissions(TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player)
{
World w = player.getEntityWorld();
if ( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.worldObj, x, y, z ), player ) )
{
if ( type.isItem() )
{
ItemStack it = player.inventory.getCurrentItem();
if ( it != null && it.getItem() instanceof IGuiItem )
{
Object myItem = ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z );
if ( CorrectTileOrPart( myItem ) )
{
return true;
}
}
}
if ( type.isTile() )
{
TileEntity TE = w.getTileEntity( x, y, z );
if ( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart( side );
if ( CorrectTileOrPart( part ) )
return securityCheck( part, player );
}
else
{
if ( CorrectTileOrPart( TE ) )
return securityCheck( TE, player );
}
}
}
return false;
}
private boolean securityCheck(Object te, EntityPlayer player)
{
if ( te instanceof IActionHost && requiredPermission != null )
{
boolean requirePower = false;
IGridNode gn = ((IActionHost) te).getActionableNode();
if ( gn != null )
{
IGrid g = gn.getGrid();
if ( g != null )
{
if ( requirePower )
{
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
if ( !eg.isNetworkPowered() )
{
return false;
}
}
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
if ( sg.hasPermission( player, requiredPermission ) )
return true;
}
}
return false;
}
return true;
}
public GuiHostType getType()
{
return type;
}
}
@@ -0,0 +1,16 @@
package appeng.core.sync;
public enum GuiHostType
{
ITEM_OR_WORLD, ITEM, WORLD;
public boolean isItem()
{
return this != WORLD;
}
public boolean isTile()
{
return this != ITEM;
}
}
@@ -0,0 +1,49 @@
package appeng.core.sync.network;
import io.netty.buffer.ByteBuf;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkInfo network, FMLProxyPacket packet, EntityPlayer player)
{
ByteBuf stream = packet.payload();
int packetType = -1;
player = Minecraft.getMinecraft().thePlayer;
try
{
packetType = stream.readInt();
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.clientPacketData( network, pack, player );
}
catch (InstantiationException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (InvocationTargetException e)
{
AELog.error( e );
}
}
}
@@ -0,0 +1,46 @@
package appeng.core.sync.network;
import io.netty.buffer.ByteBuf;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkInfo manager, FMLProxyPacket packet, EntityPlayer player)
{
ByteBuf stream = packet.payload();
int packetType = -1;
try
{
packetType = stream.readInt();
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.serverPacketData( manager, pack, (EntityPlayer) player );
}
catch (InstantiationException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (InvocationTargetException e)
{
AELog.error( e );
}
}
}
@@ -0,0 +1,7 @@
package appeng.core.sync.network;
public interface INetworkInfo
{
}
@@ -0,0 +1,11 @@
package appeng.core.sync.network;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public interface IPacketHandler
{
void onPacketData(INetworkInfo manager, FMLProxyPacket packet, EntityPlayer player);
}
@@ -0,0 +1,118 @@
package appeng.core.sync.network;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import appeng.core.WorldSettings;
import appeng.core.sync.AppEngPacket;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerConnectionFromClientEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
public class NetworkHandler
{
public static NetworkHandler instance;
final FMLEventChannel ec;
final String myChannelName;
final IPacketHandler clientHandler;
final IPacketHandler serveHandler;
public NetworkHandler(String channelName) {
FMLCommonHandler.instance().bus().register( this );
ec = NetworkRegistry.INSTANCE.newEventDrivenChannel( myChannelName = channelName );
ec.register( this );
clientHandler = createClientSide();
serveHandler = createServerSide();
}
private IPacketHandler createServerSide()
{
try
{
return new AppEngServerPacketHandler();
}
catch (Throwable t)
{
return null;
}
}
private IPacketHandler createClientSide()
{
try
{
return new AppEngClientPacketHandler();
}
catch (Throwable t)
{
return null;
}
}
@SubscribeEvent
public void newConnection(ServerConnectionFromClientEvent ev)
{
WorldSettings.getInstance().sendToPlayer( ev.manager, null );
}
@SubscribeEvent
public void newConnection(PlayerLoggedInEvent loginEvent)
{
if ( loginEvent.player instanceof EntityPlayerMP )
WorldSettings.getInstance().sendToPlayer( null, (EntityPlayerMP) loginEvent.player );
}
@SubscribeEvent
public void serverPacket(ServerCustomPacketEvent ev)
{
NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.packet.handler();
if ( serveHandler != null )
serveHandler.onPacketData( null, ev.packet, srv.playerEntity );
}
@SubscribeEvent
public void clientPacket(ClientCustomPacketEvent ev)
{
if ( clientHandler != null )
clientHandler.onPacketData( null, ev.packet, null );
}
public String getChannel()
{
return myChannelName;
}
public void sendToAll(AppEngPacket message)
{
ec.sendToAll( message.getProxy() );
}
public void sendTo(AppEngPacket message, EntityPlayerMP player)
{
ec.sendTo( message.getProxy(), player );
}
public void sendToAllAround(AppEngPacket message, NetworkRegistry.TargetPoint point)
{
ec.sendToAllAround( message.getProxy(), point );
}
public void sendToDimension(AppEngPacket message, int dimensionId)
{
ec.sendToDimension( message.getProxy(), dimensionId );
}
public void sendToServer(AppEngPacket message)
{
ec.sendToServer( message.getProxy() );
}
}
@@ -0,0 +1,60 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.EffectType;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketAssemblerAnimation extends AppEngPacket
{
final public int x, y, z;
final public byte rate;
final public IAEItemStack is;
// automatic.
public PacketAssemblerAnimation(ByteBuf stream) throws IOException {
x = stream.readInt();
y = stream.readInt();
z = stream.readInt();
rate = stream.readByte();
is = AEItemStack.loadItemStackFromPacket( stream );
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
double d0 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
double d1 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
double d2 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
CommonHelper.proxy.spawnEffect( EffectType.Assembler, player.getEntityWorld(), x + d0, y + d1, z + d2, this );
}
// api
public PacketAssemblerAnimation(int x, int y, int z, byte rate, IAEItemStack is) throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( this.x = x );
data.writeInt( this.y = y );
data.writeInt( this.z = z );
data.writeByte( this.rate = rate );
is.writeToPacket( data );
this.is = is;
configureWrite( data );
}
}
@@ -0,0 +1,73 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.implementations.items.IMemoryCard;
import appeng.api.implementations.items.MemoryCardMessages;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.items.tools.ToolNetworkTool;
import appeng.items.tools.powered.ToolColorApplicator;
public class PacketClick extends AppEngPacket
{
int x, y, z, side;
float hitX, hitY, hitZ;
// automatic.
public PacketClick(ByteBuf stream) throws IOException {
x = stream.readInt();
y = stream.readInt();
z = stream.readInt();
side = stream.readInt();
hitX = stream.readFloat();
hitY = stream.readFloat();
hitZ = stream.readFloat();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
ItemStack is = player.inventory.getCurrentItem();
if ( is != null && is.getItem() instanceof ToolNetworkTool )
{
ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
tnt.serverSideToolLogic( is, player, player.worldObj, x, y, z, side, hitX, hitY, hitZ );
}
else if ( is != null && AEApi.instance().items().itemMemoryCard.sameAsStack( is ) )
{
IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
is.setTagCompound( null );
}
else if ( is != null && AEApi.instance().items().itemColorApplicator.sameAsStack( is ) )
{
ToolColorApplicator mem = (ToolColorApplicator) is.getItem();
mem.cycleColors( is, mem.getColor( is ), 1 );
}
}
// api
public PacketClick(int x, int y, int z, int side, float hitX, float hitY, float hitZ) throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( this.x = x );
data.writeInt( this.y = y );
data.writeInt( this.z = z );
data.writeInt( this.side = side );
data.writeFloat( this.hitX = hitX );
data.writeFloat( this.hitY = hitY );
data.writeFloat( this.hitZ = hitZ );
configureWrite( data );
}
}
@@ -0,0 +1,62 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.api.util.DimensionalCoord;
import appeng.core.WorldSettings;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler;
import appeng.services.helpers.ICompassCallback;
public class PacketCompassRequest extends AppEngPacket implements ICompassCallback
{
final public long attunement;
final public int cx, cz, cdy;
EntityPlayer talkBackTo;
// automatic.
public PacketCompassRequest(ByteBuf stream) throws IOException {
attunement = stream.readLong();
cx = stream.readInt();
cz = stream.readInt();
cdy = stream.readInt();
}
@Override
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
{
NetworkHandler.instance.sendTo( new PacketCompassResponse( this, hasResult, spin, radians ), (EntityPlayerMP) talkBackTo );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
talkBackTo = player;
DimensionalCoord loc = new DimensionalCoord( player.worldObj, this.cx << 4, this.cdy << 5, this.cz << 4 );
WorldSettings.getInstance().getCompass().getCompassDirection( loc, 174, this );
}
// api
public PacketCompassRequest(long attunement, int cx, int cz, int cdy) throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeLong( this.attunement = attunement );
data.writeInt( this.cx = cx );
data.writeInt( this.cz = cz );
data.writeInt( this.cdy = cdy );
configureWrite( data );
}
}
@@ -0,0 +1,56 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
public class PacketCompassResponse extends AppEngPacket
{
final public long attunement;
final public int cx, cz, cdy;
public CompassResult cr;
// automatic.
public PacketCompassResponse(ByteBuf stream) throws IOException {
attunement = stream.readLong();
cx = stream.readInt();
cz = stream.readInt();
cdy = stream.readInt();
cr = new CompassResult( stream.readBoolean(), stream.readBoolean(), stream.readDouble() );
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
CompassManager.instance.postResult( attunement, cx << 4, cdy << 5, cz << 4, cr );
}
// api
public PacketCompassResponse(PacketCompassRequest req, boolean hasResult, boolean spin, double radians) {
ByteBuf data = Unpooled.buffer();
data.writeInt( 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 );
configureWrite( data );
}
}
@@ -0,0 +1,95 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import appeng.client.gui.implementations.GuiInterfaceTerminal;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketCompressedNBT extends AppEngPacket
{
// output...
final private ByteBuf data;
final private GZIPOutputStream compressFrame;
int writtenBytes = 0;
boolean empty = true;
// input.
final NBTTagCompound in;
// automatic.
public PacketCompressedNBT(final ByteBuf stream) throws IOException {
data = null;
compressFrame = null;
GZIPInputStream gzReader = new GZIPInputStream( new InputStream() {
@Override
public int read() throws IOException
{
if ( stream.readableBytes() <= 0 )
return -1;
return (int) stream.readByte() & 0xff;
}
} );
in = CompressedStreamTools.read( new DataInputStream( gzReader ) );
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiInterfaceTerminal )
((GuiInterfaceTerminal) gs).postUpdate( in );
}
// api
public PacketCompressedNBT(NBTTagCompound din) throws IOException {
data = Unpooled.buffer( 2048 );
data.writeInt( getPacketID() );
in = din;
compressFrame = new GZIPOutputStream( new OutputStream() {
@Override
public void write(int value) throws IOException
{
data.writeByte( value );
}
} );
CompressedStreamTools.write( din, new DataOutputStream( compressFrame ) );
compressFrame.close();
configureWrite( data );
}
}
@@ -0,0 +1,56 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.api.config.Settings;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketConfigButton extends AppEngPacket
{
final public Settings option;
final public boolean rotationDirection;
// automatic.
public PacketConfigButton(ByteBuf stream) throws IOException {
option = Settings.values()[stream.readInt()];
rotationDirection = stream.readBoolean();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
if ( aebc.getTarget() instanceof IConfigurableObject )
{
IConfigManager cm = ((IConfigurableObject) aebc.getTarget()).getConfigManager();
Enum newState = Platform.rotateEnum( cm.getSetting( option ), rotationDirection, option.getPossibleValues() );
cm.putSetting( option, newState );
}
}
// api
public PacketConfigButton(Settings option, boolean rotationDirection) throws IOException {
this.option = option;
this.rotationDirection = rotationDirection;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( option.ordinal() );
data.writeBoolean( rotationDirection );
configureWrite( data );
}
}
@@ -0,0 +1,105 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.concurrent.Future;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketCraftRequest extends AppEngPacket
{
final public long amount;
final public boolean heldShift;
// automatic.
public PacketCraftRequest(ByteBuf stream) throws IOException {
heldShift = stream.readBoolean();
amount = stream.readLong();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
if ( player.openContainer instanceof ContainerCraftAmount )
{
ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
Object targ = cca.getTarget();
if ( targ instanceof IGridHost )
{
IGridHost gh = (IGridHost) targ;
IGridNode gn = gh.getGridNode( ForgeDirection.UNKNOWN );
if ( gn == null )
return;
IGrid g = gn.getGrid();
if ( g == null || cca.whatToMake == null )
return;
Future<ICraftingJob> futureJob = null;
cca.whatToMake.setStackSize( amount );
try
{
ICraftingGrid cg = g.getCache( ICraftingGrid.class );
futureJob = cg.beginCraftingJob( cca.getWorld(), cca.getGrid(), cca.getActionSrc(), cca.whatToMake, null );
ContainerOpenContext context = cca.openContext;
if ( context != null )
{
TileEntity te = context.getTile();
Platform.openGUI( player, te, cca.openContext.side, GuiBridge.GUI_CRAFTING_CONFIRM );
if ( player.openContainer instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.autoStart = heldShift;
ccc.job = futureJob;
cca.detectAndSendChanges();
}
}
}
catch (Throwable e)
{
if ( futureJob != null )
futureJob.cancel( true );
AELog.error( e );
}
}
}
}
public PacketCraftRequest(int craftAmt, boolean shift) throws IOException {
this.amount = craftAmt;
this.heldShift = shift;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeBoolean( shift );
data.writeLong( amount );
configureWrite( data );
}
}
@@ -0,0 +1,138 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.ClientHelper;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.InventoryAction;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class PacketInventoryAction extends AppEngPacket
{
final public InventoryAction action;
final public int slot;
final public long id;
final public IAEItemStack slotItem;
// automatic.
public PacketInventoryAction(ByteBuf stream) throws IOException {
action = InventoryAction.values()[stream.readInt()];
slot = stream.readInt();
id = stream.readLong();
boolean hasItem = stream.readBoolean();
if ( hasItem )
slotItem = AEItemStack.loadItemStackFromPacket( stream );
else
slotItem = null;
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
if ( sender.openContainer instanceof AEBaseContainer )
{
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
if ( action == InventoryAction.AUTOCRAFT )
{
ContainerOpenContext context = aebc.openContext;
if ( context != null )
{
TileEntity te = context.getTile();
Platform.openGUI( sender, te, aebc.openContext.side, GuiBridge.GUI_CRAFTING_AMOUNT );
if ( sender.openContainer instanceof ContainerCraftAmount )
{
ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
if ( aebc.getTargetStack() != null )
{
cca.craftingItem.putStack( aebc.getTargetStack().getItemStack() );
cca.whatToMake = aebc.getTargetStack();
}
cca.detectAndSendChanges();
}
}
}
else
{
aebc.doAction( sender, action, slot, id );
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
if ( action == InventoryAction.UPDATE_HAND )
{
if ( slotItem == null )
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( null );
else
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( slotItem.getItemStack() );
}
}
// api
public PacketInventoryAction(InventoryAction action, int slot, IAEItemStack slotItem) throws IOException {
if ( Platform.isClient() )
throw new RuntimeException( "invalid packet, client cannot post inv actions with stacks." );
this.action = action;
this.slot = slot;
this.id = 0;
this.slotItem = slotItem;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( id );
if ( slotItem == null )
data.writeBoolean( false );
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
configureWrite( data );
}
// api
public PacketInventoryAction(InventoryAction action, int slot, long id) throws IOException {
this.action = action;
this.slot = slot;
this.id = id;
this.slotItem = null;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( id );
data.writeBoolean( false );
configureWrite( data );
}
}
@@ -0,0 +1,68 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import appeng.client.ClientHelper;
import appeng.client.render.effects.LightningFX;
import appeng.core.AEConfig;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketLightning extends AppEngPacket
{
final double x;
final double y;
final double z;
// automatic.
public PacketLightning(ByteBuf stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
try
{
if ( Platform.isClient() && AEConfig.instance.enableEffects )
{
LightningFX fx = new LightningFX( ClientHelper.proxy.getWorld(), x, y, z, 0.0f, 0.0f, 0.0f );
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
}
catch (Exception err)
{
}
}
// api
public PacketLightning(double x, double y, double z) throws IOException {
this.x = x;
this.y = y;
this.z = z;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
configureWrite( data );
}
}
@@ -0,0 +1,175 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.BufferOverflowException;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
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;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMEInventoryUpdate extends AppEngPacket
{
// output...
final private byte ref;
final private ByteBuf data;
final private GZIPOutputStream compressFrame;
int writtenBytes = 0;
boolean empty = true;
// input.
final List<IAEItemStack> list;
// automatic.
public PacketMEInventoryUpdate(final ByteBuf stream) throws IOException {
data = null;
compressFrame = null;
list = new LinkedList();
ref = stream.readByte();
// int originalBytes = stream.readableBytes();
GZIPInputStream gzReader = new GZIPInputStream( new InputStream() {
@Override
public int read() throws IOException
{
if ( stream.readableBytes() <= 0 )
return -1;
return (int) stream.readByte() & 0xff;
}
} );
ByteBuf uncompressed = Unpooled.buffer( stream.readableBytes() );
byte tmp[] = new byte[1024];
while (gzReader.available() != 0)
{
int bytes = gzReader.read( tmp );
if ( bytes > 0 )
uncompressed.writeBytes( tmp, 0, bytes );
}
gzReader.close();
// int uncompressedBytes = uncompressed.readableBytes();
// AELog.info( "Recv: " + originalBytes + " -> " + uncompressedBytes );
while (uncompressed.readableBytes() > 0)
list.add( AEItemStack.loadItemStackFromPacket( uncompressed ) );
empty = list.isEmpty();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiCraftConfirm )
((GuiCraftConfirm) gs).postUpdate( list, ref );
if ( gs instanceof GuiCraftingCPU )
((GuiCraftingCPU) gs).postUpdate( list, ref );
if ( gs instanceof GuiMEMonitorable )
((GuiMEMonitorable) gs).postUpdate( list );
if ( gs instanceof GuiNetworkStatus )
((GuiNetworkStatus) gs).postUpdate( list );
}
@Override
public FMLProxyPacket getProxy()
{
try
{
compressFrame.close();
configureWrite( data );
return super.getProxy();
}
catch (IOException e)
{
AELog.error( e );
}
return null;
}
// api
public PacketMEInventoryUpdate() throws IOException {
this( (byte) 0 );
}
// api
public PacketMEInventoryUpdate(byte ref) throws IOException {
data = Unpooled.buffer( 2048 );
data.writeInt( getPacketID() );
data.writeByte( this.ref = ref );
compressFrame = new GZIPOutputStream( new OutputStream() {
@Override
public void write(int value) throws IOException
{
data.writeByte( value );
}
} );
list = null;
}
public void appendItem(IAEItemStack is) throws IOException, BufferOverflowException
{
ByteBuf tmp = Unpooled.buffer( 2048 );
is.writeToPacket( tmp );
compressFrame.flush();
if ( writtenBytes + tmp.readableBytes() > 2 * 1024 * 1024 ) // 2mb!
throw new BufferOverflowException();
else
{
writtenBytes += tmp.readableBytes();
compressFrame.write( tmp.array(), 0, tmp.readableBytes() );
empty = false;
}
}
public int getLength()
{
return data.readableBytes();
}
public boolean isEmpty()
{
return empty;
}
}
@@ -0,0 +1,89 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.world.World;
import appeng.client.render.effects.MatterCannonFX;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMatterCannon extends AppEngPacket
{
final double x;
final double y;
final double z;
final double dx;
final double dy;
final double dz;
final byte len;
// automatic.
public PacketMatterCannon(ByteBuf stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
dx = stream.readFloat();
dy = stream.readFloat();
dz = stream.readFloat();
len = stream.readByte();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
try
{
World world = FMLClientHandler.instance().getClient().theWorld;
for (int a = 1; a < len; a++)
{
MatterCannonFX fx = new MatterCannonFX( world, x + dx * a, y + dy * a, z + dz * a, Items.diamond );
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
}
catch (Exception err)
{
}
}
// api
public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len) throws IOException {
float dl = dx * dx + dy * dy + dz * dz;
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;
ByteBuf data = Unpooled.buffer();
data.writeInt( 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 );
configureWrite( data );
}
}
@@ -0,0 +1,54 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMockExplosion extends AppEngPacket
{
final public double x;
final public double y;
final public double z;
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
World world = CommonHelper.proxy.getWorld();
world.spawnParticle( "largeexplode", this.x, this.y, this.z, 1.0D, 0.0D, 0.0D );
}
// automatic.
public PacketMockExplosion(ByteBuf stream) throws IOException {
x = stream.readDouble();
y = stream.readDouble();
z = stream.readDouble();
}
// api
public PacketMockExplosion(double x, double y, double z) throws IOException {
this.x = x;
this.y = y;
this.z = z;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeDouble( x );
data.writeDouble( y );
data.writeDouble( z );
configureWrite( data );
}
}
@@ -0,0 +1,46 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.MinecraftForge;
import appeng.core.AppEng;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IFMP;
public class PacketMultiPart extends AppEngPacket
{
// automatic.
public PacketMultiPart(ByteBuf stream) throws IOException {
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
IFMP fmp = (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP );
if ( fmp != null )
{
EntityPlayerMP sender = (EntityPlayerMP) player;
MinecraftForge.EVENT_BUS.post( fmp.newFMPPacketEvent( sender ) ); // when received it just pots this event.
}
}
// api
public PacketMultiPart() throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
configureWrite( data );
}
}
@@ -0,0 +1,195 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import appeng.util.prioitylist.IPartitionList;
public class PacketNEIRecipe extends AppEngPacket
{
ItemStack[][] recipe;
// automatic.
public PacketNEIRecipe(ByteBuf stream) throws IOException
{
ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() );
bytes.skip( stream.readerIndex() );
NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes );
if ( comp != null )
{
recipe = new ItemStack[9][];
for (int x = 0; x < recipe.length; x++)
{
NBTTagList list = comp.getTagList( "#" + x, 10 );
if ( list.tagCount() > 0 )
{
recipe[x] = new ItemStack[list.tagCount()];
for (int y = 0; y < list.tagCount(); y++)
{
recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt( y ) );
}
}
}
}
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP pmp = (EntityPlayerMP) player;
Container con = pmp.openContainer;
if ( con != null && con instanceof IContainerCraftingPacket )
{
IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
IGridNode node = cct.getNetworkNode();
if ( node != null )
{
IGrid grid = node.getGrid();
if ( grid == null )
return;
IStorageGrid inv = grid.getCache( IStorageGrid.class );
IEnergyGrid energy = grid.getCache( IEnergyGrid.class );
ISecurityGrid security = grid.getCache( ISecurityGrid.class );
IInventory craftMatrix = cct.getInventoryByName( "crafting" );
Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;
if ( inv != null && recipe != null && security != null )
{
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
for (int x = 0; x < 9; x++)
{
if ( recipe[x] != null && recipe[x].length > 0 )
{
ic.setInventorySlotContents( x, recipe[x][0] );
}
}
IRecipe r = Platform.findMatchingRecipe( ic, pmp.worldObj );
if ( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
{
ItemStack is = r.getCraftingResult( ic );
if ( is != null )
{
IMEMonitor<IAEItemStack> stor = inv.getItemInventory();
IItemList all = stor.getStorageList();
IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
for (int x = 0; x < craftMatrix.getSizeInventory(); x++)
{
ItemStack PatternItem = ic.getStackInSlot( x );
ItemStack currentItem = craftMatrix.getStackInSlot( x );
if ( currentItem != null )
{
ic.setInventorySlotContents( x, currentItem );
ItemStack newis = r.matches( ic, pmp.worldObj ) ? r.getCraftingResult( ic ) : null;
ic.setInventorySlotContents( x, PatternItem );
if ( newis == null || !Platform.isSameItemPrecise( newis, is ) )
{
IAEItemStack in = AEItemStack.create( currentItem );
if ( in != null )
{
IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert( energy, stor, in,
cct.getSource() );
if ( out != null )
craftMatrix.setInventorySlotContents( x, out.getItemStack() );
else
craftMatrix.setInventorySlotContents( x, null );
currentItem = craftMatrix.getStackInSlot( x );
}
}
}
if ( PatternItem != null && currentItem == null )
{
ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, is, ic,
PatternItem, x, all, realForFake, filter );
if ( whichItem == null )
{
for (int y = 0; y < recipe[x].length; y++)
{
IAEItemStack request = AEItemStack.create( recipe[x][y] );
if ( request != null )
{
if ( filter == null || filter.isListed( request ) )
{
request.setStackSize( 1 );
IAEItemStack out = Platform.poweredExtraction( energy, stor, request, cct.getSource() );
if ( out != null )
{
whichItem = out.getItemStack();
break;
}
}
}
}
}
craftMatrix.setInventorySlotContents( x, whichItem );
}
}
con.onCraftMatrixChanged( craftMatrix );
}
}
}
}
}
}
// api
public PacketNEIRecipe(NBTTagCompound recipe) throws IOException
{
ByteBuf data = Unpooled.buffer();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream datao = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
CompressedStreamTools.writeCompressed( recipe, datao );
data.writeBytes( bytes.toByteArray() );
configureWrite( data );
}
}
@@ -0,0 +1,53 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.DimensionManager;
import appeng.core.AEConfig;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketNewStorageDimension extends AppEngPacket
{
final int newDim;
// automatic.
public PacketNewStorageDimension(ByteBuf stream) throws IOException {
newDim = stream.readInt();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
try
{
DimensionManager.registerDimension( newDim, AEConfig.instance.storageProviderID );
}
catch (IllegalArgumentException iae)
{
// ok!
}
}
// api
public PacketNewStorageDimension(int newDim) throws IOException {
this.newDim = newDim;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( newDim );
configureWrite( data );
}
}
@@ -0,0 +1,48 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.api.util.AEColor;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
public class PacketPaintedEntity extends AppEngPacket
{
private AEColor myColor;
private int entityId;
private int ticks;
// automatic.
public PacketPaintedEntity(ByteBuf stream) throws IOException {
entityId = stream.readInt();
myColor = AEColor.values()[stream.readByte()];
ticks = stream.readInt();
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
PlayerColor pc = new PlayerColor( entityId, myColor, ticks );
TickHandler.instance.getPlayerColors().put( entityId, pc );
}
// api
public PacketPaintedEntity(int myEntity, AEColor myColor, int ticksLeft) {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( this.entityId = myEntity );
data.writeByte( (this.myColor = myColor).ordinal() );
data.writeInt( ticksLeft );
configureWrite( data );
}
}
@@ -0,0 +1,55 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.parts.PartPlacement;
public class PacketPartPlacement extends AppEngPacket
{
int x, y, z, face;
float eyeHeight;
// automatic.
public PacketPartPlacement(ByteBuf stream) throws IOException {
x = stream.readInt();
y = stream.readInt();
z = stream.readInt();
face = stream.readByte();
eyeHeight = stream.readFloat();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
CommonHelper.proxy.updateRenderMode( sender );
PartPlacement.eyeHeight = eyeHeight;
PartPlacement.place( sender.getHeldItem(), x, y, z, face, sender, sender.worldObj, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
CommonHelper.proxy.updateRenderMode( null );
}
// api
public PacketPartPlacement(int x, int y, int z, int face, float eyeHeight ) throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( x );
data.writeInt( y );
data.writeInt( z );
data.writeByte( face );
data.writeFloat( eyeHeight );
configureWrite( data );
}
}
@@ -0,0 +1,63 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketPartialItem extends AppEngPacket
{
short pageNum;
byte[] data;
// automatic.
public PacketPartialItem(ByteBuf stream) throws IOException {
pageNum = stream.readShort();
stream.readBytes( data = new byte[stream.readableBytes()] );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
if ( player.openContainer instanceof AEBaseContainer )
{
((AEBaseContainer) player.openContainer).postPartial( this );
}
}
// api
public PacketPartialItem(int page, int maxPages, byte[] buf) throws IOException {
ByteBuf data = Unpooled.buffer();
pageNum = (short) (page | (maxPages << 8));
this.data = buf;
data.writeInt( getPacketID() );
data.writeShort( pageNum );
data.writeBytes( buf );
configureWrite( data );
}
public int getPageCount()
{
return pageNum >> 8;
}
public int getSize()
{
return data.length;
}
public int write(byte[] buffer, int cursor)
{
System.arraycopy( data, 0, buffer, cursor, data.length );
return cursor + data.length;
}
}
@@ -0,0 +1,92 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import appeng.api.AEApi;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketPatternSlot extends AppEngPacket
{
final public IAEItemStack slotItem;
final public IAEItemStack pattern[] = new IAEItemStack[9];
final public boolean shift;
public IAEItemStack readItem(ByteBuf stream) throws IOException
{
boolean hasItem = stream.readBoolean();
if ( hasItem )
return AEItemStack.loadItemStackFromPacket( stream );
return null;
}
// automatic.
public PacketPatternSlot(ByteBuf stream) throws IOException {
shift = stream.readBoolean();
slotItem = readItem( stream );
for (int x = 0; x < 9; x++)
pattern[x] = readItem( stream );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
if ( sender.openContainer instanceof ContainerPatternTerm )
{
ContainerPatternTerm aebc = (ContainerPatternTerm) sender.openContainer;
aebc.craftOrGetItem( this );
}
}
private void writeItem(IAEItemStack slotItem, ByteBuf data) throws IOException
{
if ( slotItem == null )
data.writeBoolean( false );
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
}
// api
public PacketPatternSlot(IInventory pat, IAEItemStack slotItem, boolean shift) throws IOException {
this.slotItem = slotItem;
this.shift = shift;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeBoolean( shift );
writeItem( slotItem, data );
for (int x = 0; x < 9; x++)
{
pattern[x] = AEApi.instance().storage().createItemStack( pat.getStackInSlot( x ) );
writeItem( pattern[x], data );
}
configureWrite( data );
}
}
@@ -0,0 +1,56 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketProgressBar extends AppEngPacket
{
short id;
long value;
// automatic.
public PacketProgressBar(ByteBuf stream) throws IOException {
id = stream.readShort();
value = stream.readLong();
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( c instanceof AEBaseContainer )
((AEBaseContainer) c).updateFullProgressBar( id, value );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( c instanceof AEBaseContainer )
((AEBaseContainer) c).updateFullProgressBar( id, value );
}
// api
public PacketProgressBar(int short_id, long value) throws IOException {
this.id = (short) short_id;
this.value = value;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeShort( short_id );
data.writeLong( value );
configureWrite( data );
}
}
@@ -0,0 +1,44 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketSwapSlots extends AppEngPacket
{
int slotA, slotB;
// automatic.
public PacketSwapSlots(ByteBuf stream) throws IOException {
slotA = stream.readInt();
slotB = stream.readInt();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
if ( player != null && player.openContainer instanceof AEBaseContainer )
{
((AEBaseContainer) player.openContainer).swapSlotContents( slotA, slotB );
}
}
// api
public PacketSwapSlots(int slotA, int slotB) throws IOException {
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( this.slotA = slotA );
data.writeInt( this.slotB = slotB );
configureWrite( data );
}
}
@@ -0,0 +1,66 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketSwitchGuis extends AppEngPacket
{
final GuiBridge newGui;
// automatic.
public PacketSwitchGuis(ByteBuf stream) throws IOException {
newGui = GuiBridge.values()[stream.readInt()];
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( c instanceof AEBaseContainer )
{
AEBaseContainer bc = (AEBaseContainer) c;
ContainerOpenContext context = bc.openContext;
if ( context != null )
{
TileEntity te = context.getTile();
Platform.openGUI( player, te, context.side, newGui );
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
AEBaseGui.switchingGuis = true;
}
// api
public PacketSwitchGuis(GuiBridge newGui) throws IOException {
this.newGui = newGui;
if ( Platform.isClient() )
AEBaseGui.switchingGuis = true;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( newGui.ordinal() );
configureWrite( data );
}
}
@@ -0,0 +1,101 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.client.ClientHelper;
import appeng.client.render.effects.EnergyFx;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketTransitionEffect extends AppEngPacket
{
final double x;
final double y;
final double z;
final ForgeDirection d;
final public boolean mode;
// automatic.
public PacketTransitionEffect(ByteBuf stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
d = ForgeDirection.getOrientation( stream.readByte() );
mode = stream.readBoolean();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
World world = ClientHelper.proxy.getWorld();
for (int zz = 0; zz < (mode ? 32 : 8); zz++)
if ( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) )
{
EnergyFx fx = new EnergyFx( world, x + (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), y
+ (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), z
+ (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), Items.diamond );
if ( !mode )
fx.fromItem( d );
fx.motionX = -0.1 * d.offsetX;
fx.motionY = -0.1 * d.offsetY;
fx.motionZ = -0.1 * d.offsetZ;
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
if ( mode )
{
Block block = world.getBlock( (int) x, (int) y, (int) z );
Minecraft
.getMinecraft()
.getSoundHandler()
.playSound(
new PositionedSoundRecord( new ResourceLocation( block.stepSound.getBreakSound() ), (block.stepSound.getVolume() + 1.0F) / 2.0F,
block.stepSound.getPitch() * 0.8F, (float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F ) );
}
}
// api
public PacketTransitionEffect(double x, double y, double z, ForgeDirection dir, boolean wasBlock) throws IOException {
this.x = x;
this.y = y;
this.z = z;
this.d = dir;
this.mode = wasBlock;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
data.writeByte( this.d.ordinal() );
data.writeBoolean( wasBlock );
configureWrite( data );
}
}
@@ -0,0 +1,263 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import appeng.api.config.FuzzyMode;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.implementations.GuiCraftingCPU;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerCellWorkbench;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerCraftingCPU;
import appeng.container.implementations.ContainerCraftingStatus;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerNetworkTool;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.implementations.ContainerPriority;
import appeng.container.implementations.ContainerQuartzKnife;
import appeng.container.implementations.ContainerSecurity;
import appeng.container.implementations.ContainerStorageBus;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.IMouseWheelItem;
public class PacketValueConfig extends AppEngPacket
{
final public String Name;
final public String Value;
// automatic.
public PacketValueConfig(ByteBuf stream) throws IOException {
DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) );
Name = dis.readUTF();
Value = dis.readUTF();
// dis.close();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( Name.equals( "Item" ) && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IMouseWheelItem )
{
ItemStack is = player.getHeldItem();
IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel( is, Value.equals( "WheelUp" ) );
return;
}
else if ( Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus )
{
ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
qk.cycleCpu( Value.equals( "Next" ) );
return;
}
else if ( Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.cycleCpu( Value.equals( "Next" ) );
return;
}
else if ( Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
return;
}
else if ( Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
{
ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
qk.cancelCrafting();
return;
}
else if ( Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
{
ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
qk.setName( Value );
return;
}
else if ( Name.equals( "TileSecurity.ToggleOption" ) && c instanceof ContainerSecurity )
{
ContainerSecurity sc = (ContainerSecurity) c;
sc.toggleSetting( Value, player );
return;
}
else if ( Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
{
ContainerPriority pc = (ContainerPriority) c;
pc.setPriority( Integer.parseInt( Value ), player );
return;
}
else if ( Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
{
ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel( Long.parseLong( Value ), player );
return;
}
else if ( Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
{
ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if ( Name.equals( "PatternTerminal.CraftMode" ) )
{
cpt.ct.setCraftingRecipe( Value.equals( "1" ) );
}
else if ( Name.equals( "PatternTerminal.Encode" ) )
{
cpt.encode();
}
else if ( Name.equals( "PatternTerminal.Clear" ) )
{
cpt.clear();
}
}
else if ( Name.startsWith( "StorageBus." ) && c instanceof ContainerStorageBus )
{
ContainerStorageBus ccw = (ContainerStorageBus) c;
if ( Name.equals( "StorageBus.Action" ) )
{
if ( Value.equals( "Partition" ) )
{
ccw.partition();
}
else if ( Value.equals( "Clear" ) )
{
ccw.clear();
}
}
}
else if ( Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{
ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if ( Name.equals( "CellWorkbench.Action" ) )
{
if ( Value.equals( "CopyMode" ) )
{
ccw.nextCopyMode();
}
else if ( Value.equals( "Partition" ) )
{
ccw.partition();
}
else if ( Value.equals( "Clear" ) )
{
ccw.clear();
}
}
else if ( Name.equals( "CellWorkbench.Fuzzy" ) )
{
ccw.setFuzzy( FuzzyMode.valueOf( Value ) );
}
}
else if ( c instanceof ContainerNetworkTool )
{
if ( Name.equals( "NetworkTool" ) && Value.equals( "Toggle" ) )
{
((ContainerNetworkTool) c).toggleFacadeMode();
}
}
else if ( c instanceof IConfigurableObject )
{
IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
for (Enum e : cm.getSettings())
{
if ( e.name().equals( Name ) )
{
Enum def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), Value ) );
}
catch (IllegalArgumentException err)
{
// :P
}
break;
}
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( Name.equals( "CustomName" ) && c instanceof AEBaseContainer )
{
((AEBaseContainer) c).customName = Value;
}
else if ( Name.startsWith( "SyncDat." ) )
{
((AEBaseContainer) c).stringSync( Integer.parseInt( Name.substring( 8 ) ), Value );
}
else if ( Name.equals( "CraftingStatus" ) && Value.equals( "Clear" ) )
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiCraftingCPU )
((GuiCraftingCPU) gs).clearItems();
return;
}
else if ( c instanceof IConfigurableObject )
{
IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
for (Enum e : cm.getSettings())
{
if ( e.name().equals( Name ) )
{
Enum def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), Value ) );
}
catch (IllegalArgumentException err)
{
// :P
}
break;
}
}
}
}
// api
public PacketValueConfig(String Name, String Value) throws IOException {
this.Name = Name;
this.Value = Value;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream( bos );
dos.writeUTF( Name );
dos.writeUTF( Value );
// dos.close();
data.writeBytes( bos.toByteArray() );
configureWrite( data );
}
}