Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -18,6 +18,7 @@
package appeng.core.sync;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
@@ -30,29 +31,29 @@ import appeng.core.features.AEFeature;
import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler;
public abstract class AppEngPacket
{
AppEngPacketHandlerBase.PacketTypes id;
private ByteBuf p;
AppEngPacketHandlerBase.PacketTypes id;
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
throw new RuntimeException( "This packet ( " + this.getPacketID() + " does not implement a server side handler." );
}
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 ( " + this.getPacketID() + " does not implement a server side handler." );
}
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
throw new RuntimeException( "This packet ( " + this.getPacketID() + " does not implement a client side handler." );
}
protected void configureWrite(ByteBuf data)
protected void configureWrite( ByteBuf data )
{
data.capacity( data.readableBytes() );
this.p = data;
@@ -60,15 +61,14 @@ public abstract class AppEngPacket
public FMLProxyPacket getProxy()
{
if ( this.p.array().length > 2 * 1024 * 1024 ) // 2k walking room :)
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!" );
FMLProxyPacket pp = new FMLProxyPacket( this.p, NetworkHandler.instance.getChannel() );
if ( AEConfig.instance.isFeatureEnabled( AEFeature.PacketLogging ) )
if( AEConfig.instance.isFeatureEnabled( AEFeature.PacketLogging ) )
AELog.info( this.getClass().getName() + " : " + pp.payload().readableBytes() );
return pp;
}
}
+229 -225
View File
@@ -123,116 +123,120 @@ import static appeng.core.sync.GuiHostType.ITEM;
import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD;
import static appeng.core.sync.GuiHostType.WORLD;
public enum GuiBridge implements IGuiHandler
{
GUI_Handler(),
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, WORLD, null),
GUI_GRINDER( ContainerGrinder.class, TileGrinder.class, WORLD, null ),
GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD),
GUI_QNB( ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD ),
GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, WORLD, null),
GUI_SKYCHEST( ContainerSkyChest.class, TileSkyChest.class, WORLD, null ),
GUI_CHEST(ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD),
GUI_CHEST( ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD ),
GUI_WIRELESS(ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD),
GUI_WIRELESS( ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD ),
GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null),
GUI_ME( ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null ),
GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, ITEM, null),
GUI_PORTABLE_CELL( ContainerMEPortableCell.class, IPortableCell.class, ITEM, null ),
GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null),
GUI_WIRELESS_TERM( ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null ),
GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null),
GUI_NETWORK_STATUS( ContainerNetworkStatus.class, INetworkTool.class, ITEM, null ),
GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT),
GUI_CRAFTING_CPU( ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT ),
GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null),
GUI_NETWORK_TOOL( ContainerNetworkTool.class, INetworkTool.class, ITEM, null ),
GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null),
GUI_QUARTZ_KNIFE( ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null ),
GUI_DRIVE(ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD),
GUI_DRIVE( ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD ),
GUI_VIBRATION_CHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null),
GUI_VIBRATION_CHAMBER( ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null ),
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, WORLD, null),
GUI_CONDENSER( ContainerCondenser.class, TileCondenser.class, WORLD, null ),
GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD),
GUI_INTERFACE( ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD ),
GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD),
GUI_BUS( ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD ),
GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD),
GUI_IOPORT( ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD ),
GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD),
GUI_STORAGEBUS( ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD ),
GUI_FORMATION_PLANE(ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD),
GUI_FORMATION_PLANE( ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD ),
GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD),
GUI_PRIORITY( ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD ),
GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY),
GUI_SECURITY( ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY ),
GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT),
GUI_CRAFTING_TERMINAL( ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT ),
GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT),
GUI_PATTERN_TERMINAL( ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT ),
// extends (Container/Gui) + Bus
GUI_LEVEL_EMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD),
GUI_LEVEL_EMITTER( ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD ),
GUI_SPATIAL_IO_PORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD),
GUI_SPATIAL_IO_PORT( ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD ),
GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, WORLD, null),
GUI_INSCRIBER( ContainerInscriber.class, TileInscriber.class, WORLD, null ),
GUI_CELL_WORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null),
GUI_CELL_WORKBENCH( ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null ),
GUI_MAC(ContainerMAC.class, TileMolecularAssembler.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_AMOUNT( ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.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_INTERFACE_TERMINAL( ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD ),
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
GUI_CRAFTING_STATUS( ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT );
private final Class Tile;
private Class Gui;
private final Class Container;
private Class Gui;
private GuiHostType type;
private SecurityPermissions requiredPermission;
GuiBridge() {
GuiBridge()
{
this.Tile = null;
this.Gui = null;
this.Container = null;
}
GuiBridge( Class _Container, SecurityPermissions requiredPermission )
{
this.requiredPermission = requiredPermission;
this.Container = _Container;
this.Tile = 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() )
if( Platform.isClient() )
{
final String start = this.Container.getName();
String guiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if ( start.equals( guiClass ) )
if( start.equals( guiClass ) )
throw new RuntimeException( "Unable to find gui class" );
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass );
if ( this.Gui == null )
if( this.Gui == null )
throw new RuntimeException( "Cannot Load class: " + guiClass );
}
}
GuiBridge( Class _Container, SecurityPermissions requiredPermission ) {
this.requiredPermission = requiredPermission;
this.Container = _Container;
this.Tile = null;
this.getGui();
}
GuiBridge( Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission ) {
GuiBridge( Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission )
{
this.requiredPermission = requiredPermission;
this.Container = _Container;
this.type = type;
@@ -240,125 +244,69 @@ public enum GuiBridge implements IGuiHandler
this.getGui();
}
public boolean CorrectTileOrPart(Object tE)
@Override
public Object getServerGuiElement( int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z )
{
if ( this.Tile == null )
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 4];
boolean stem = ( ( ID_ORDINAL >> 3 ) & 1 ) == 1;
if( ID.type.isItem() && stem )
{
ItemStack it = player.inventory.getCurrentItem();
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() )
{
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 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( 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;
}
public boolean CorrectTileOrPart( Object tE )
{
if( this.Tile == null )
throw new RuntimeException( "This Gui Cannot use the standard Handler." );
return this.Tile.isInstance( tE );
}
public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE)
private Object updateGui( Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem )
{
try
{
Constructor[] c = this.Container.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
Constructor target = this.findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.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();
final IMaterials materials = AEApi.instance().definitions().materials();
this.addPressAchievementToPlayer( is, materials, inventory.player );
}
}
}
return o;
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
private void addPressAchievementToPlayer( ItemStack newItem, IMaterials possibleMaterials, EntityPlayer player )
{
final IComparableDefinition logic = possibleMaterials.logicProcessorPress();
final IComparableDefinition eng = possibleMaterials.engProcessorPress();
final IComparableDefinition calc = possibleMaterials.calcProcessorPress();
final IComparableDefinition silicon = possibleMaterials.siliconPress();
final List<IComparableDefinition> presses = Lists.newArrayList( logic, eng, calc, silicon );
for ( IComparableDefinition press : presses )
{
if ( press.isSameAs( newItem ) )
{
Achievements.Presses.addToPlayer( player );
return;
}
}
}
public Object ConstructGui(InventoryPlayer inventory, ForgeDirection side, Object tE)
{
try
{
Constructor[] c = this.Gui.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
Constructor target = this.findConstructor( c, inventory, tE );
if ( target == null )
{
throw new RuntimeException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.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 )
if( newContainer instanceof AEBaseContainer )
{
AEBaseContainer bc = (AEBaseContainer) newContainer;
bc.openContext = new ContainerOpenContext( myItem );
@@ -372,87 +320,120 @@ public enum GuiBridge implements IGuiHandler
return newContainer;
}
@Override
public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
public Object ConstructContainer( InventoryPlayer inventory, ForgeDirection side, Object tE )
{
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 4];
boolean stem = ((ID_ORDINAL >> 3) & 1) == 1;
if ( ID.type.isItem() && stem )
try
{
ItemStack it = player.inventory.getCurrentItem();
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 );
}
Constructor[] c = this.Container.getConstructors();
if( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
if ( ID.type.isTile() )
Constructor target = this.findConstructor( c, inventory, tE );
if( target == null )
{
throw new RuntimeException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.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();
final IMaterials materials = AEApi.instance().definitions().materials();
this.addPressAchievementToPlayer( is, materials, inventory.player );
}
}
}
return o;
}
catch( Throwable t )
{
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 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 );
}
throw new RuntimeException( t );
}
return new ContainerNull();
}
private Object getGuiObject(ItemStack it, EntityPlayer player, World w, int x, int y, int z)
private Constructor findConstructor( Constructor[] c, InventoryPlayer inventory, Object tE )
{
if ( it != null )
for( Constructor con : c )
{
if ( it.getItem() instanceof IGuiItem )
Class[] types = con.getParameterTypes();
if( types.length == 2 )
{
return ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z );
if( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
return con;
}
IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
if ( wh != null )
return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z );
}
return null;
}
private String typeName( Object inventory )
{
if( inventory == null )
return "NULL";
return inventory.getClass().getName();
}
private void addPressAchievementToPlayer( ItemStack newItem, IMaterials possibleMaterials, EntityPlayer player )
{
final IComparableDefinition logic = possibleMaterials.logicProcessorPress();
final IComparableDefinition eng = possibleMaterials.engProcessorPress();
final IComparableDefinition calc = possibleMaterials.calcProcessorPress();
final IComparableDefinition silicon = possibleMaterials.siliconPress();
final List<IComparableDefinition> presses = Lists.newArrayList( logic, eng, calc, silicon );
for( IComparableDefinition press : presses )
{
if( press.isSameAs( newItem ) )
{
Achievements.Presses.addToPlayer( player );
return;
}
}
}
@Override
public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
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 stem = ((ID_ORDINAL >> 3) & 1) == 1;
boolean stem = ( ( ID_ORDINAL >> 3 ) & 1 ) == 1;
if ( ID.type.isItem() && stem )
if( ID.type.isItem() && stem )
{
ItemStack it = player.inventory.getCurrentItem();
Object myItem = this.getGuiObject( it, player, w, x, y, z );
if ( ID.CorrectTileOrPart( myItem ) )
if( ID.CorrectTileOrPart( myItem ) )
return ID.ConstructGui( player.inventory, side, myItem );
}
if ( ID.type.isTile() )
if( ID.type.isTile() )
{
TileEntity TE = w.getTileEntity( x, y, z );
if ( TE instanceof IPartHost )
if( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart( side );
if ( ID.CorrectTileOrPart( part ) )
( (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 ) )
if( ID.CorrectTileOrPart( TE ) )
return ID.ConstructGui( player.inventory, side, TE );
}
}
@@ -460,38 +441,61 @@ public enum GuiBridge implements IGuiHandler
return new GuiNull( new ContainerNull() );
}
public boolean hasPermissions(TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player)
public Object ConstructGui( InventoryPlayer inventory, ForgeDirection side, Object tE )
{
try
{
Constructor[] c = this.Gui.getConstructors();
if( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
Constructor target = this.findConstructor( c, inventory, tE );
if( target == null )
{
throw new RuntimeException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.typeName( tE ) + " )" );
}
return target.newInstance( inventory, tE );
}
catch( Throwable t )
{
throw new RuntimeException( t );
}
}
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( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.worldObj, x, y, z ), player ) )
{
if ( this.type.isItem() )
if( this.type.isItem() )
{
ItemStack it = player.inventory.getCurrentItem();
if ( it != null && it.getItem() instanceof IGuiItem )
if( it != null && it.getItem() instanceof IGuiItem )
{
Object myItem = ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z );
if ( this.CorrectTileOrPart( myItem ) )
Object myItem = ( (IGuiItem) it.getItem() ).getGuiObject( it, w, x, y, z );
if( this.CorrectTileOrPart( myItem ) )
{
return true;
}
}
}
if ( this.type.isTile() )
if( this.type.isTile() )
{
TileEntity TE = w.getTileEntity( x, y, z );
if ( TE instanceof IPartHost )
if( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart( side );
if ( this.CorrectTileOrPart( part ) )
( (IPartHost) TE ).getPart( side );
IPart part = ( (IPartHost) TE ).getPart( side );
if( this.CorrectTileOrPart( part ) )
return this.securityCheck( part, player );
}
else
{
if ( this.CorrectTileOrPart( TE ) )
if( this.CorrectTileOrPart( TE ) )
return this.securityCheck( TE, player );
}
}
@@ -499,29 +503,29 @@ public enum GuiBridge implements IGuiHandler
return false;
}
private boolean securityCheck(Object te, EntityPlayer player)
private boolean securityCheck( Object te, EntityPlayer player )
{
if ( te instanceof IActionHost && this.requiredPermission != null )
if( te instanceof IActionHost && this.requiredPermission != null )
{
boolean requirePower = false;
IGridNode gn = ((IActionHost) te).getActionableNode();
if ( gn != null )
IGridNode gn = ( (IActionHost) te ).getActionableNode();
if( gn != null )
{
IGrid g = gn.getGrid();
if ( g != null )
if( g != null )
{
if ( requirePower )
if( requirePower )
{
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
if ( !eg.isNetworkPowered() )
if( !eg.isNetworkPowered() )
{
return false;
}
}
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
if ( sg.hasPermission( player, this.requiredPermission ) )
if( sg.hasPermission( player, this.requiredPermission ) )
return true;
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync;
public enum GuiHostType
{
ITEM_OR_WORLD, ITEM, WORLD;
@@ -18,6 +18,7 @@
package appeng.core.sync.network;
import java.lang.reflect.InvocationTargetException;
import io.netty.buffer.ByteBuf;
@@ -31,11 +32,12 @@ import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkInfo network, FMLProxyPacket packet, EntityPlayer player)
public void onPacketData( INetworkInfo network, FMLProxyPacket packet, EntityPlayer player )
{
ByteBuf stream = packet.payload();
int packetType = -1;
@@ -48,22 +50,21 @@ public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implement
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.clientPacketData( network, pack, player );
}
catch (InstantiationException e)
catch( InstantiationException e )
{
AELog.error( e );
}
catch (IllegalAccessException e)
catch( IllegalAccessException e )
{
AELog.error( e );
}
catch (IllegalArgumentException e)
catch( IllegalArgumentException e )
{
AELog.error( e );
}
catch (InvocationTargetException e)
catch( InvocationTargetException e )
{
AELog.error( e );
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.network;
import java.lang.reflect.InvocationTargetException;
import io.netty.buffer.ByteBuf;
@@ -30,11 +31,12 @@ import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkInfo manager, FMLProxyPacket packet, EntityPlayer player)
public void onPacketData( INetworkInfo manager, FMLProxyPacket packet, EntityPlayer player )
{
ByteBuf stream = packet.payload();
int packetType = -1;
@@ -45,22 +47,21 @@ public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase imp
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.serverPacketData( manager, pack, player );
}
catch (InstantiationException e)
catch( InstantiationException e )
{
AELog.error( e );
}
catch (IllegalAccessException e)
catch( IllegalAccessException e )
{
AELog.error( e );
}
catch (IllegalArgumentException e)
catch( IllegalArgumentException e )
{
AELog.error( e );
}
catch (InvocationTargetException e)
catch( InvocationTargetException e )
{
AELog.error( e );
}
}
}
@@ -18,13 +18,14 @@
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);
void onPacketData( INetworkInfo manager, FMLProxyPacket packet, EntityPlayer player );
}
@@ -34,6 +34,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import appeng.core.WorldSettings;
import appeng.core.sync.AppEngPacket;
public class NetworkHandler
{
@@ -45,7 +46,8 @@ public class NetworkHandler
final IPacketHandler clientHandler;
final IPacketHandler serveHandler;
public NetworkHandler(String channelName) {
public NetworkHandler( String channelName )
{
FMLCommonHandler.instance().bus().register( this );
this.ec = NetworkRegistry.INSTANCE.newEventDrivenChannel( this.myChannelName = channelName );
this.ec.register( this );
@@ -54,55 +56,55 @@ public class NetworkHandler
this.serveHandler = this.createServerSide();
}
private IPacketHandler createServerSide()
{
try
{
return new AppEngServerPacketHandler();
}
catch (Throwable t)
{
return null;
}
}
private IPacketHandler createClientSide()
{
try
{
return new AppEngClientPacketHandler();
}
catch (Throwable t)
catch( Throwable t )
{
return null;
}
}
private IPacketHandler createServerSide()
{
try
{
return new AppEngServerPacketHandler();
}
catch( Throwable t )
{
return null;
}
}
@SubscribeEvent
public void newConnection(ServerConnectionFromClientEvent ev)
public void newConnection( ServerConnectionFromClientEvent ev )
{
WorldSettings.getInstance().sendToPlayer( ev.manager );
}
@SubscribeEvent
public void newConnection(PlayerLoggedInEvent loginEvent)
public void newConnection( PlayerLoggedInEvent loginEvent )
{
if ( loginEvent.player instanceof EntityPlayerMP )
if( loginEvent.player instanceof EntityPlayerMP )
WorldSettings.getInstance().sendToPlayer( null );
}
@SubscribeEvent
public void serverPacket(ServerCustomPacketEvent ev)
public void serverPacket( ServerCustomPacketEvent ev )
{
NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.packet.handler();
if ( this.serveHandler != null )
if( this.serveHandler != null )
this.serveHandler.onPacketData( null, ev.packet, srv.playerEntity );
}
@SubscribeEvent
public void clientPacket(ClientCustomPacketEvent ev)
public void clientPacket( ClientCustomPacketEvent ev )
{
if ( this.clientHandler != null )
if( this.clientHandler != null )
this.clientHandler.onPacketData( null, ev.packet, null );
}
@@ -111,29 +113,28 @@ public class NetworkHandler
return this.myChannelName;
}
public void sendToAll(AppEngPacket message)
public void sendToAll( AppEngPacket message )
{
this.ec.sendToAll( message.getProxy() );
}
public void sendTo(AppEngPacket message, EntityPlayerMP player)
public void sendTo( AppEngPacket message, EntityPlayerMP player )
{
this.ec.sendTo( message.getProxy(), player );
}
public void sendToAllAround(AppEngPacket message, NetworkRegistry.TargetPoint point)
public void sendToAllAround( AppEngPacket message, NetworkRegistry.TargetPoint point )
{
this.ec.sendToAllAround( message.getProxy(), point );
}
public void sendToDimension(AppEngPacket message, int dimensionId)
public void sendToDimension( AppEngPacket message, int dimensionId )
{
this.ec.sendToDimension( message.getProxy(), dimensionId );
}
public void sendToServer(AppEngPacket message)
public void sendToServer( AppEngPacket message )
{
this.ec.sendToServer( message.getProxy() );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
@@ -35,6 +36,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketAssemblerAnimation extends AppEngPacket
{
@@ -45,7 +47,8 @@ public class PacketAssemblerAnimation extends AppEngPacket
final public IAEItemStack is;
// automatic.
public PacketAssemblerAnimation(ByteBuf stream) throws IOException {
public PacketAssemblerAnimation( ByteBuf stream ) throws IOException
{
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
@@ -53,19 +56,9 @@ public class PacketAssemblerAnimation extends AppEngPacket
this.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(), this.x + d0, this.y + d1, this.z + d2, this );
}
// api
public PacketAssemblerAnimation(int x, int y, int z, byte rate, IAEItemStack is) throws IOException {
public PacketAssemblerAnimation( int x, int y, int z, byte rate, IAEItemStack is ) throws IOException
{
ByteBuf data = Unpooled.buffer();
@@ -79,4 +72,15 @@ public class PacketAssemblerAnimation extends AppEngPacket
this.configureWrite( data );
}
@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(), this.x + d0, this.y + d1, this.z + d2, this );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -34,6 +35,7 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.items.tools.ToolNetworkTool;
import appeng.items.tools.powered.ToolColorApplicator;
public class PacketClick extends AppEngPacket
{
@@ -46,7 +48,8 @@ public class PacketClick extends AppEngPacket
final float hitZ;
// automatic.
public PacketClick(ByteBuf stream) {
public PacketClick( ByteBuf stream )
{
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
@@ -56,39 +59,9 @@ public class PacketClick extends AppEngPacket
this.hitZ = stream.readFloat();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
ItemStack is = player.inventory.getCurrentItem();
final IItems items = AEApi.instance().definitions().items();
final IComparableDefinition maybeMemoryCard = items.memoryCard();
final IComparableDefinition maybeColorApplicator = items.colorApplicator();
if ( is != null )
{
if ( is.getItem() instanceof ToolNetworkTool )
{
ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
tnt.serverSideToolLogic( is, player, player.worldObj, this.x, this.y, this.z, this.side, this.hitX, this.hitY, this.hitZ );
}
else if ( maybeMemoryCard.isSameAs( is ) )
{
IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
is.setTagCompound( null );
}
else if ( maybeColorApplicator.isSameAs( 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) {
public PacketClick( int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{
ByteBuf data = Unpooled.buffer();
@@ -103,4 +76,35 @@ public class PacketClick extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
ItemStack is = player.inventory.getCurrentItem();
final IItems items = AEApi.instance().definitions().items();
final IComparableDefinition maybeMemoryCard = items.memoryCard();
final IComparableDefinition maybeColorApplicator = items.colorApplicator();
if( is != null )
{
if( is.getItem() instanceof ToolNetworkTool )
{
ToolNetworkTool tnt = (ToolNetworkTool) is.getItem();
tnt.serverSideToolLogic( is, player, player.worldObj, this.x, this.y, this.z, this.side, this.hitX, this.hitY, this.hitZ );
}
else if( maybeMemoryCard.isSameAs( is ) )
{
IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
is.setTagCompound( null );
}
else if( maybeColorApplicator.isSameAs( is ) )
{
ToolColorApplicator mem = (ToolColorApplicator) is.getItem();
mem.cycleColors( is, mem.getColor( is ), 1 );
}
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -31,6 +32,7 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler;
import appeng.services.compass.ICompassCallback;
public class PacketCompassRequest extends AppEngPacket implements ICompassCallback
{
@@ -42,30 +44,17 @@ public class PacketCompassRequest extends AppEngPacket implements ICompassCallba
EntityPlayer talkBackTo;
// automatic.
public PacketCompassRequest(ByteBuf stream) {
public PacketCompassRequest( ByteBuf stream )
{
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
this.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) this.talkBackTo );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
this.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) {
public PacketCompassRequest( long attunement, int cx, int cz, int cdy )
{
ByteBuf data = Unpooled.buffer();
@@ -76,6 +65,20 @@ public class PacketCompassRequest extends AppEngPacket implements ICompassCallba
data.writeInt( this.cdy = cdy );
this.configureWrite( data );
}
@Override
public void calculatedDirection( boolean hasResult, boolean spin, double radians, double dist )
{
NetworkHandler.instance.sendTo( new PacketCompassResponse( this, hasResult, spin, radians ), (EntityPlayerMP) this.talkBackTo );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
this.talkBackTo = player;
DimensionalCoord loc = new DimensionalCoord( player.worldObj, this.cx << 4, this.cdy << 5, this.cz << 4 );
WorldSettings.getInstance().getCompass().getCompassDirection( loc, 174, this );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -28,6 +29,7 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.CompassManager;
import appeng.hooks.CompassResult;
public class PacketCompassResponse extends AppEngPacket
{
@@ -39,7 +41,8 @@ public class PacketCompassResponse extends AppEngPacket
public CompassResult cr;
// automatic.
public PacketCompassResponse(ByteBuf stream) {
public PacketCompassResponse( ByteBuf stream )
{
this.attunement = stream.readLong();
this.cx = stream.readInt();
this.cz = stream.readInt();
@@ -48,14 +51,9 @@ public class PacketCompassResponse extends AppEngPacket
this.cr = new CompassResult( stream.readBoolean(), stream.readBoolean(), stream.readDouble() );
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
CompassManager.INSTANCE.postResult( this.attunement, this.cx << 4, this.cdy << 5, this.cz << 4, this.cr );
}
// api
public PacketCompassResponse(PacketCompassRequest req, boolean hasResult, boolean spin, double radians) {
public PacketCompassResponse( PacketCompassRequest req, boolean hasResult, boolean spin, double radians )
{
ByteBuf data = Unpooled.buffer();
@@ -70,6 +68,11 @@ public class PacketCompassResponse extends AppEngPacket
data.writeDouble( radians );
this.configureWrite( data );
}
@Override
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
CompassManager.INSTANCE.postResult( this.attunement, this.cx << 4, this.cdy << 5, this.cz << 4, this.cr );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -42,36 +43,35 @@ import appeng.client.gui.implementations.GuiInterfaceTerminal;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketCompressedNBT extends AppEngPacket
{
// input.
final NBTTagCompound in;
// 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 {
public PacketCompressedNBT( final ByteBuf stream ) throws IOException
{
this.data = null;
this.compressFrame = null;
GZIPInputStream gzReader = new GZIPInputStream( new InputStream() {
GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
{
@Override
public int read() throws IOException
{
if ( stream.readableBytes() <= 0 )
if( stream.readableBytes() <= 0 )
return -1;
return stream.readByte() & 0xff;
}
} );
DataInputStream inStream = new DataInputStream( gzReader );
@@ -79,33 +79,23 @@ public class PacketCompressedNBT extends AppEngPacket
inStream.close();
}
@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( this.in );
}
// api
public PacketCompressedNBT(NBTTagCompound din) throws IOException {
public PacketCompressedNBT( NBTTagCompound din ) throws IOException
{
this.data = Unpooled.buffer( 2048 );
this.data.writeInt( this.getPacketID() );
this.in = din;
this.compressFrame = new GZIPOutputStream( new OutputStream() {
this.compressFrame = new GZIPOutputStream( new OutputStream()
{
@Override
public void write(int value) throws IOException
public void write( int value ) throws IOException
{
PacketCompressedNBT.this.data.writeByte( value );
}
} );
CompressedStreamTools.write( din, new DataOutputStream( this.compressFrame ) );
@@ -114,4 +104,13 @@ public class PacketCompressedNBT extends AppEngPacket
this.configureWrite( this.data );
}
@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( this.in );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -32,6 +33,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketConfigButton extends AppEngPacket
{
@@ -39,26 +41,15 @@ public class PacketConfigButton extends AppEngPacket
final public boolean rotationDirection;
// automatic.
public PacketConfigButton(ByteBuf stream) {
public PacketConfigButton( ByteBuf stream )
{
this.option = Settings.values()[stream.readInt()];
this.rotationDirection = stream.readBoolean();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if ( baseContainer.getTarget() instanceof IConfigurableObject )
{
IConfigManager cm = ((IConfigurableObject) baseContainer.getTarget()).getConfigManager();
Enum newState = Platform.rotateEnum( cm.getSetting( this.option ), this.rotationDirection, this.option.getPossibleValues() );
cm.putSetting( this.option, newState );
}
}
// api
public PacketConfigButton(Settings option, boolean rotationDirection) {
public PacketConfigButton( Settings option, boolean rotationDirection )
{
this.option = option;
this.rotationDirection = rotationDirection;
@@ -70,4 +61,17 @@ public class PacketConfigButton extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if( baseContainer.getTarget() instanceof IConfigurableObject )
{
IConfigManager cm = ( (IConfigurableObject) baseContainer.getTarget() ).getConfigManager();
Enum newState = Platform.rotateEnum( cm.getSetting( this.option ), this.rotationDirection, this.option.getPossibleValues() );
cm.putSetting( this.option, newState );
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.util.concurrent.Future;
import io.netty.buffer.ByteBuf;
@@ -41,6 +42,7 @@ import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketCraftRequest extends AppEngPacket
{
@@ -48,66 +50,13 @@ public class PacketCraftRequest extends AppEngPacket
final public boolean heldShift;
// automatic.
public PacketCraftRequest(ByteBuf stream)
public PacketCraftRequest( ByteBuf stream )
{
this.heldShift = stream.readBoolean();
this.amount = stream.readLong();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
if ( player.openContainer instanceof ContainerCraftAmount )
{
ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
Object target = cca.getTarget();
if ( target instanceof IGridHost )
{
IGridHost gh = (IGridHost) target;
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( this.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 = this.heldShift;
ccc.job = futureJob;
cca.detectAndSendChanges();
}
}
}
catch (Throwable e)
{
if ( futureJob != null )
futureJob.cancel( true );
AELog.error( e );
}
}
}
}
public PacketCraftRequest(int craftAmt, boolean shift)
public PacketCraftRequest( int craftAmt, boolean shift )
{
this.amount = craftAmt;
this.heldShift = shift;
@@ -121,4 +70,55 @@ public class PacketCraftRequest extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
if( player.openContainer instanceof ContainerCraftAmount )
{
ContainerCraftAmount cca = (ContainerCraftAmount) player.openContainer;
Object target = cca.getTarget();
if( target instanceof IGridHost )
{
IGridHost gh = (IGridHost) target;
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( this.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 = this.heldShift;
ccc.job = futureJob;
cca.detectAndSendChanges();
}
}
}
catch( Throwable e )
{
if( futureJob != null )
futureJob.cancel( true );
AELog.error( e );
}
}
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
@@ -39,6 +40,7 @@ import appeng.helpers.InventoryAction;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class PacketInventoryAction extends AppEngPacket
{
@@ -48,37 +50,87 @@ public class PacketInventoryAction extends AppEngPacket
final public IAEItemStack slotItem;
// automatic.
public PacketInventoryAction(ByteBuf stream) throws IOException {
public PacketInventoryAction( ByteBuf stream ) throws IOException
{
this.action = InventoryAction.values()[stream.readInt()];
this.slot = stream.readInt();
this.id = stream.readLong();
boolean hasItem = stream.readBoolean();
if ( hasItem )
if( hasItem )
this.slotItem = AEItemStack.loadItemStackFromPacket( stream );
else
this.slotItem = null;
}
// 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( 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 );
}
this.configureWrite( data );
}
// api
public PacketInventoryAction( InventoryAction action, int slot, long id )
{
this.action = action;
this.slot = slot;
this.id = id;
this.slotItem = null;
ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( id );
data.writeBoolean( false );
this.configureWrite( data );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
EntityPlayerMP sender = (EntityPlayerMP) player;
if ( sender.openContainer instanceof AEBaseContainer )
if( sender.openContainer instanceof AEBaseContainer )
{
AEBaseContainer baseContainer = (AEBaseContainer) sender.openContainer;
if ( this.action == InventoryAction.AUTO_CRAFT )
if( this.action == InventoryAction.AUTO_CRAFT )
{
ContainerOpenContext context = baseContainer.openContext;
if ( context != null )
if( context != null )
{
TileEntity te = context.getTile();
Platform.openGUI( sender, te, baseContainer.openContext.side, GuiBridge.GUI_CRAFTING_AMOUNT );
if ( sender.openContainer instanceof ContainerCraftAmount )
if( sender.openContainer instanceof ContainerCraftAmount )
{
ContainerCraftAmount cca = (ContainerCraftAmount) sender.openContainer;
if ( baseContainer.getTargetStack() != null )
if( baseContainer.getTargetStack() != null )
{
cca.craftingItem.putStack( baseContainer.getTargetStack().getItemStack() );
cca.whatToMake = baseContainer.getTargetStack();
@@ -96,62 +148,14 @@ public class PacketInventoryAction extends AppEngPacket
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
if ( this.action == InventoryAction.UPDATE_HAND )
if( this.action == InventoryAction.UPDATE_HAND )
{
if ( this.slotItem == null )
if( this.slotItem == null )
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( null );
else
ClientHelper.proxy.getPlayers().get( 0 ).inventory.setItemStack( this.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( 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 );
}
this.configureWrite( data );
}
// api
public PacketInventoryAction(InventoryAction action, int slot, long id)
{
this.action = action;
this.slot = slot;
this.id = id;
this.slotItem = null;
ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
data.writeLong( id );
data.writeBoolean( false );
this.configureWrite( data );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -34,6 +35,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketLightning extends AppEngPacket
{
@@ -42,31 +44,15 @@ public class PacketLightning extends AppEngPacket
final double z;
// automatic.
public PacketLightning(ByteBuf stream) {
public PacketLightning( ByteBuf stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
this.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(), this.x, this.y, this.z, 0.0f, 0.0f, 0.0f );
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
}
catch (Exception ignored)
{
}
}
// api
public PacketLightning(double x, double y, double z)
public PacketLightning( double x, double y, double z )
{
this.x = x;
this.y = y;
@@ -82,4 +68,20 @@ public class PacketLightning extends AppEngPacket
this.configureWrite( data );
}
@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(), this.x, this.y, this.z, 0.0f, 0.0f, 0.0f );
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
}
catch( Exception ignored )
{
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -34,6 +35,7 @@ import appeng.client.render.effects.MatterCannonFX;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketMatterCannon extends AppEngPacket
{
@@ -46,7 +48,7 @@ public class PacketMatterCannon extends AppEngPacket
final byte len;
// automatic.
public PacketMatterCannon(ByteBuf stream)
public PacketMatterCannon( ByteBuf stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
@@ -57,28 +59,8 @@ public class PacketMatterCannon extends AppEngPacket
this.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 < this.len; a++)
{
MatterCannonFX fx = new MatterCannonFX( world, this.x + this.dx * a, this.y + this.dy * a, this.z + this.dz * a, Items.diamond );
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
}
catch (Exception ignored)
{
}
}
// api
public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len)
public PacketMatterCannon( double x, double y, double z, float dx, float dy, float dz, byte len )
{
float dl = dx * dx + dy * dy + dz * dz;
float dlz = (float) Math.sqrt( dl );
@@ -105,4 +87,23 @@ public class PacketMatterCannon extends AppEngPacket
this.configureWrite( data );
}
@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 < this.len; a++ )
{
MatterCannonFX fx = new MatterCannonFX( world, this.x + this.dx * a, this.y + this.dy * a, this.z + this.dz * a, Items.diamond );
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
}
catch( Exception ignored )
{
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -31,6 +32,7 @@ import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketMockExplosion extends AppEngPacket
{
@@ -38,16 +40,8 @@ public class PacketMockExplosion extends AppEngPacket
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)
public PacketMockExplosion( ByteBuf stream )
{
this.x = stream.readDouble();
this.y = stream.readDouble();
@@ -55,7 +49,7 @@ public class PacketMockExplosion extends AppEngPacket
}
// api
public PacketMockExplosion(double x, double y, double z)
public PacketMockExplosion( double x, double y, double z )
{
this.x = x;
this.y = y;
@@ -71,4 +65,11 @@ public class PacketMockExplosion extends AppEngPacket
this.configureWrite( data );
}
@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 );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -31,25 +32,15 @@ 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)
public PacketMultiPart( ByteBuf stream )
{
}
@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 posts this event.
}
}
// api
public PacketMultiPart()
{
@@ -60,4 +51,14 @@ public class PacketMultiPart extends AppEngPacket
this.configureWrite( data );
}
@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 posts this event.
}
}
}
@@ -69,16 +69,16 @@ public class PacketNEIRecipe extends AppEngPacket
ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() );
bytes.skip( stream.readerIndex() );
NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes );
if ( comp != null )
if( comp != null )
{
this.recipe = new ItemStack[9][];
for ( int x = 0; x < this.recipe.length; x++ )
for( int x = 0; x < this.recipe.length; x++ )
{
NBTTagList list = comp.getTagList( "#" + x, 10 );
if ( list.tagCount() > 0 )
if( list.tagCount() > 0 )
{
this.recipe[x] = new ItemStack[list.tagCount()];
for ( int y = 0; y < list.tagCount(); y++ )
for( int y = 0; y < list.tagCount(); y++ )
{
this.recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt( y ) );
}
@@ -87,20 +87,36 @@ public class PacketNEIRecipe extends AppEngPacket
}
}
// api
public PacketNEIRecipe( NBTTagCompound recipe ) throws IOException
{
ByteBuf data = Unpooled.buffer();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream( bytes );
data.writeInt( this.getPacketID() );
CompressedStreamTools.writeCompressed( recipe, outputStream );
data.writeBytes( bytes.toByteArray() );
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
EntityPlayerMP pmp = ( EntityPlayerMP ) player;
EntityPlayerMP pmp = (EntityPlayerMP) player;
Container con = pmp.openContainer;
if ( con instanceof IContainerCraftingPacket )
if( con instanceof IContainerCraftingPacket )
{
IContainerCraftingPacket cct = ( IContainerCraftingPacket ) con;
IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
IGridNode node = cct.getNetworkNode();
if ( node != null )
if( node != null )
{
IGrid grid = node.getGrid();
if ( grid == null )
if( grid == null )
return;
IStorageGrid inv = grid.getCache( IStorageGrid.class );
@@ -111,12 +127,12 @@ public class PacketNEIRecipe extends AppEngPacket
Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;
if ( inv != null && this.recipe != null && security != null )
if( inv != null && this.recipe != null && security != null )
{
InventoryCrafting testInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
for ( int x = 0; x < 9; x++ )
for( int x = 0; x < 9; x++ )
{
if ( this.recipe[x] != null && this.recipe[x].length > 0 )
if( this.recipe[x] != null && this.recipe[x].length > 0 )
{
testInv.setInventorySlotContents( x, this.recipe[x][0] );
}
@@ -124,35 +140,34 @@ public class PacketNEIRecipe extends AppEngPacket
IRecipe r = Platform.findMatchingRecipe( testInv, pmp.worldObj );
if ( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
if( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
{
ItemStack is = r.getCraftingResult( testInv );
if ( is != null )
if( is != null )
{
IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
IItemList all = storage.getStorageList();
IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
for ( int x = 0; x < craftMatrix.getSizeInventory(); x++ )
for( int x = 0; x < craftMatrix.getSizeInventory(); x++ )
{
ItemStack PatternItem = testInv.getStackInSlot( x );
ItemStack currentItem = craftMatrix.getStackInSlot( x );
if ( currentItem != null )
if( currentItem != null )
{
testInv.setInventorySlotContents( x, currentItem );
ItemStack newItemStack = r.matches( testInv, pmp.worldObj ) ? r.getCraftingResult( testInv ) : null;
testInv.setInventorySlotContents( x, PatternItem );
if ( newItemStack == null || !Platform.isSameItemPrecise( newItemStack, is ) )
if( newItemStack == null || !Platform.isSameItemPrecise( newItemStack, is ) )
{
IAEItemStack in = AEItemStack.create( currentItem );
if ( in != null )
if( in != null )
{
IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert( energy, storage, in,
cct.getSource() );
if ( out != null )
IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert( energy, storage, in, cct.getSource() );
if( out != null )
craftMatrix.setInventorySlotContents( x, out.getItemStack() );
else
craftMatrix.setInventorySlotContents( x, null );
@@ -163,26 +178,25 @@ public class PacketNEIRecipe extends AppEngPacket
}
// True if we need to fetch an item for the recipe
if ( PatternItem != null && currentItem == null )
if( PatternItem != null && currentItem == null )
{
// Grab from network by recipe
ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), storage, player.worldObj, r, is, testInv,
PatternItem, x, all, realForFake, filter );
ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), storage, player.worldObj, r, is, testInv, PatternItem, x, all, realForFake, filter );
// If that doesn't get it, grab exact items from network (?)
// TODO see if this code is necessary
if ( whichItem == null )
if( whichItem == null )
{
for ( int y = 0; y < this.recipe[x].length; y++ )
for( int y = 0; y < this.recipe[x].length; y++ )
{
IAEItemStack request = AEItemStack.create( this.recipe[x][y] );
if ( request != null )
if( request != null )
{
if ( filter == null || filter.isListed( request ) )
if( filter == null || filter.isListed( request ) )
{
request.setStackSize( 1 );
IAEItemStack out = Platform.poweredExtraction( energy, storage, request, cct.getSource() );
if ( out != null )
if( out != null )
{
whichItem = out.getItemStack();
break;
@@ -193,18 +207,18 @@ public class PacketNEIRecipe extends AppEngPacket
}
// If that doesn't work, grab from the player's inventory
if ( whichItem == null && playerInventory != null )
if( whichItem == null && playerInventory != null )
{
for ( int y = 0; y < this.recipe[x].length; y++ )
for( int y = 0; y < this.recipe[x].length; y++ )
{
ItemStack playerItemStack = null;
for ( int i = 0; i < playerInventory.getSizeInventory(); i++ )
for( int i = 0; i < playerInventory.getSizeInventory(); i++ )
{
// check if the item in slot y matches the required item.
playerItemStack = playerInventory.getStackInSlot( i );
if ( playerItemStack != null && this.recipe[x][y] != null && playerItemStack.getItem() == this.recipe[x][y].getItem() )
if( playerItemStack != null && this.recipe[x][y] != null && playerItemStack.getItem() == this.recipe[x][y].getItem() )
{
if ( realForFake == Actionable.SIMULATE )
if( realForFake == Actionable.SIMULATE )
{
whichItem = playerInventory.getStackInSlot( i ).copy();
whichItem.stackSize = 1;
@@ -229,20 +243,4 @@ public class PacketNEIRecipe extends AppEngPacket
}
}
}
// api
public PacketNEIRecipe( NBTTagCompound recipe ) throws IOException
{
ByteBuf data = Unpooled.buffer();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream( bytes );
data.writeInt( this.getPacketID() );
CompressedStreamTools.writeCompressed( recipe, outputStream );
data.writeBytes( bytes.toByteArray() );
this.configureWrite( data );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -31,33 +32,20 @@ import appeng.core.AEConfig;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketNewStorageDimension extends AppEngPacket
{
final int newDim;
// automatic.
public PacketNewStorageDimension(ByteBuf stream)
public PacketNewStorageDimension( ByteBuf stream )
{
this.newDim = stream.readInt();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
try
{
DimensionManager.registerDimension( this.newDim, AEConfig.instance.storageProviderID );
}
catch (IllegalArgumentException iae)
{
// ok!
}
}
// api
public PacketNewStorageDimension(int newDim)
public PacketNewStorageDimension( int newDim )
{
this.newDim = newDim;
@@ -69,4 +57,17 @@ public class PacketNewStorageDimension extends AppEngPacket
this.configureWrite( data );
}
@Override
@SideOnly( Side.CLIENT )
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
try
{
DimensionManager.registerDimension( this.newDim, AEConfig.instance.storageProviderID );
}
catch( IllegalArgumentException iae )
{
// ok!
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -29,6 +30,7 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.TickHandler;
import appeng.hooks.TickHandler.PlayerColor;
public class PacketPaintedEntity extends AppEngPacket
{
@@ -37,30 +39,31 @@ public class PacketPaintedEntity extends AppEngPacket
private int ticks;
// automatic.
public PacketPaintedEntity(ByteBuf stream)
public PacketPaintedEntity( ByteBuf stream )
{
this.entityId = stream.readInt();
this.myColor = AEColor.values()[stream.readByte()];
this.ticks = stream.readInt();
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
PlayerColor pc = new PlayerColor( this.entityId, this.myColor, this.ticks );
TickHandler.INSTANCE.getPlayerColors().put( this.entityId, pc );
}
// api
public PacketPaintedEntity(int myEntity, AEColor myColor, int ticksLeft) {
public PacketPaintedEntity( int myEntity, AEColor myColor, int ticksLeft )
{
ByteBuf data = Unpooled.buffer();
data.writeInt( this.getPacketID() );
data.writeInt( this.entityId = myEntity );
data.writeByte( (this.myColor = myColor).ordinal() );
data.writeByte( ( this.myColor = myColor ).ordinal() );
data.writeInt( ticksLeft );
this.configureWrite( data );
}
@Override
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
PlayerColor pc = new PlayerColor( this.entityId, this.myColor, this.ticks );
TickHandler.INSTANCE.getPlayerColors().put( this.entityId, pc );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -29,6 +30,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.parts.PartPlacement;
public class PacketPartPlacement extends AppEngPacket
{
@@ -39,7 +41,7 @@ public class PacketPartPlacement extends AppEngPacket
float eyeHeight;
// automatic.
public PacketPartPlacement(ByteBuf stream)
public PacketPartPlacement( ByteBuf stream )
{
this.x = stream.readInt();
this.y = stream.readInt();
@@ -48,18 +50,8 @@ public class PacketPartPlacement extends AppEngPacket
this.eyeHeight = stream.readFloat();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
CommonHelper.proxy.updateRenderMode( sender );
PartPlacement.eyeHeight = this.eyeHeight;
PartPlacement.place( sender.getHeldItem(), this.x, this.y, this.z, this.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 )
public PacketPartPlacement( int x, int y, int z, int face, float eyeHeight )
{
ByteBuf data = Unpooled.buffer();
@@ -73,4 +65,13 @@ public class PacketPartPlacement extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
EntityPlayerMP sender = (EntityPlayerMP) player;
CommonHelper.proxy.updateRenderMode( sender );
PartPlacement.eyeHeight = this.eyeHeight;
PartPlacement.place( sender.getHeldItem(), this.x, this.y, this.z, this.face, sender, sender.worldObj, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
CommonHelper.proxy.updateRenderMode( null );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -27,6 +28,7 @@ import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketPartialItem extends AppEngPacket
{
@@ -34,28 +36,19 @@ public class PacketPartialItem extends AppEngPacket
final byte[] data;
// automatic.
public PacketPartialItem(ByteBuf stream)
public PacketPartialItem( ByteBuf stream )
{
this.pageNum = stream.readShort();
stream.readBytes( this.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)
public PacketPartialItem( int page, int maxPages, byte[] buf )
{
ByteBuf data = Unpooled.buffer();
this.pageNum = (short) (page | (maxPages << 8));
this.pageNum = (short) ( page | ( maxPages << 8 ) );
this.data = buf;
data.writeInt( this.getPacketID() );
data.writeShort( this.pageNum );
@@ -64,6 +57,15 @@ public class PacketPartialItem extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
if( player.openContainer instanceof AEBaseContainer )
{
( (AEBaseContainer) player.openContainer ).postPartial( this );
}
}
public int getPageCount()
{
return this.pageNum >> 8;
@@ -74,7 +76,7 @@ public class PacketPartialItem extends AppEngPacket
return this.data.length;
}
public int write(byte[] buffer, int cursor)
public int write( byte[] buffer, int cursor )
{
System.arraycopy( this.data, 0, buffer, cursor, this.data.length );
return cursor + this.data.length;
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
@@ -34,6 +35,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.item.AEItemStack;
public class PacketPatternSlot extends AppEngPacket
{
@@ -43,51 +45,31 @@ public class PacketPatternSlot extends AppEngPacket
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 {
public PacketPatternSlot( ByteBuf stream ) throws IOException
{
this.shift = stream.readBoolean();
this.slotItem = this.readItem( stream );
for (int x = 0; x < 9; x++)
for( int x = 0; x < 9; x++ )
this.pattern[x] = this.readItem( stream );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
public IAEItemStack readItem( ByteBuf stream ) throws IOException
{
EntityPlayerMP sender = (EntityPlayerMP) player;
if ( sender.openContainer instanceof ContainerPatternTerm )
{
ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer;
patternTerminal.craftOrGetItem( this );
}
}
boolean hasItem = stream.readBoolean();
private void writeItem(IAEItemStack slotItem, ByteBuf data) throws IOException
{
if ( slotItem == null )
data.writeBoolean( false );
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
if( hasItem )
return AEItemStack.loadItemStackFromPacket( stream );
return null;
}
// api
public PacketPatternSlot(IInventory pat, IAEItemStack slotItem, boolean shift) throws IOException {
public PacketPatternSlot( IInventory pat, IAEItemStack slotItem, boolean shift ) throws IOException
{
this.slotItem = slotItem;
this.shift = shift;
@@ -99,7 +81,7 @@ public class PacketPatternSlot extends AppEngPacket
data.writeBoolean( shift );
this.writeItem( slotItem, data );
for (int x = 0; x < 9; x++)
for( int x = 0; x < 9; x++ )
{
this.pattern[x] = AEApi.instance().storage().createItemStack( pat.getStackInSlot( x ) );
this.writeItem( this.pattern[x], data );
@@ -108,4 +90,25 @@ public class PacketPatternSlot extends AppEngPacket
this.configureWrite( data );
}
private void writeItem( IAEItemStack slotItem, ByteBuf data ) throws IOException
{
if( slotItem == null )
data.writeBoolean( false );
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
EntityPlayerMP sender = (EntityPlayerMP) player;
if( sender.openContainer instanceof ContainerPatternTerm )
{
ContainerPatternTerm patternTerminal = (ContainerPatternTerm) sender.openContainer;
patternTerminal.craftOrGetItem( this );
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -28,6 +29,7 @@ import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketProgressBar extends AppEngPacket
{
@@ -35,30 +37,14 @@ public class PacketProgressBar extends AppEngPacket
final long value;
// automatic.
public PacketProgressBar(ByteBuf stream)
public PacketProgressBar( ByteBuf stream )
{
this.id = stream.readShort();
this.value = stream.readLong();
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( c instanceof AEBaseContainer )
((AEBaseContainer) c).updateFullProgressBar( this.id, this.value );
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( c instanceof AEBaseContainer )
((AEBaseContainer) c).updateFullProgressBar( this.id, this.value );
}
// api
public PacketProgressBar(int short_id, long value)
public PacketProgressBar( int short_id, long value )
{
this.id = (short) short_id;
this.value = value;
@@ -71,4 +57,20 @@ public class PacketProgressBar extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
Container c = player.openContainer;
if( c instanceof AEBaseContainer )
( (AEBaseContainer) c ).updateFullProgressBar( this.id, this.value );
}
@Override
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
Container c = player.openContainer;
if( c instanceof AEBaseContainer )
( (AEBaseContainer) c ).updateFullProgressBar( this.id, this.value );
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -27,6 +28,7 @@ import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
public class PacketSwapSlots extends AppEngPacket
{
@@ -34,23 +36,14 @@ public class PacketSwapSlots extends AppEngPacket
final int slotB;
// automatic.
public PacketSwapSlots(ByteBuf stream)
public PacketSwapSlots( ByteBuf stream )
{
this.slotA = stream.readInt();
this.slotB = stream.readInt();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
if ( player != null && player.openContainer instanceof AEBaseContainer )
{
((AEBaseContainer) player.openContainer).swapSlotContents( this.slotA, this.slotB );
}
}
// api
public PacketSwapSlots(int slotA, int slotB)
public PacketSwapSlots( int slotA, int slotB )
{
ByteBuf data = Unpooled.buffer();
@@ -60,4 +53,13 @@ public class PacketSwapSlots extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
if( player != null && player.openContainer instanceof AEBaseContainer )
{
( (AEBaseContainer) player.openContainer ).swapSlotContents( this.slotA, this.slotB );
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -33,45 +34,24 @@ 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)
public PacketSwitchGuis( ByteBuf stream )
{
this.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, this.newGui );
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
AEBaseGui.switchingGuis = true;
}
// api
public PacketSwitchGuis(GuiBridge newGui)
public PacketSwitchGuis( GuiBridge newGui )
{
this.newGui = newGui;
if ( Platform.isClient() )
if( Platform.isClient() )
AEBaseGui.switchingGuis = true;
ByteBuf data = Unpooled.buffer();
@@ -81,4 +61,26 @@ public class PacketSwitchGuis extends AppEngPacket
this.configureWrite( data );
}
@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, this.newGui );
}
}
}
@Override
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
AEBaseGui.switchingGuis = true;
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -40,17 +41,18 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
public class PacketTransitionEffect extends AppEngPacket
{
final public boolean mode;
final double x;
final double y;
final double z;
final ForgeDirection d;
final public boolean mode;
// automatic.
public PacketTransitionEffect(ByteBuf stream)
public PacketTransitionEffect( ByteBuf stream )
{
this.x = stream.readFloat();
this.y = stream.readFloat();
@@ -59,44 +61,8 @@ public class PacketTransitionEffect extends AppEngPacket
this.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 < (this.mode ? 32 : 8); zz++)
if ( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) )
{
EnergyFx fx = new EnergyFx( world, this.x + (this.mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), this.y
+ (this.mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), this.z
+ (this.mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), Items.diamond );
if ( !this.mode )
fx.fromItem( this.d );
fx.motionX = -0.1 * this.d.offsetX;
fx.motionY = -0.1 * this.d.offsetY;
fx.motionZ = -0.1 * this.d.offsetZ;
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
if ( this.mode )
{
Block block = world.getBlock( (int) this.x, (int) this.y, (int) this.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) this.x + 0.5F, (float) this.y + 0.5F, (float) this.z + 0.5F ) );
}
}
// api
public PacketTransitionEffect(double x, double y, double z, ForgeDirection dir, boolean wasBlock)
public PacketTransitionEffect( double x, double y, double z, ForgeDirection dir, boolean wasBlock )
{
this.x = x;
this.y = y;
@@ -116,4 +82,32 @@ public class PacketTransitionEffect extends AppEngPacket
this.configureWrite( data );
}
@Override
@SideOnly( Side.CLIENT )
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
World world = ClientHelper.proxy.getWorld();
for( int zz = 0; zz < ( this.mode ? 32 : 8 ); zz++ )
if( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) )
{
EnergyFx fx = new EnergyFx( world, this.x + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), this.y + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), this.z + ( this.mode ? ( Platform.getRandomInt() % 100 ) * 0.01 : ( Platform.getRandomInt() % 100 ) * 0.005 - 0.25 ), Items.diamond );
if( !this.mode )
fx.fromItem( this.d );
fx.motionX = -0.1 * this.d.offsetX;
fx.motionY = -0.1 * this.d.offsetY;
fx.motionZ = -0.1 * this.d.offsetZ;
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
}
if( this.mode )
{
Block block = world.getBlock( (int) this.x, (int) this.y, (int) this.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) this.x + 0.5F, (float) this.y + 0.5F, (float) this.z + 0.5F ) );
}
}
}
@@ -18,6 +18,7 @@
package appeng.core.sync.packets;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
@@ -54,6 +55,7 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.IMouseWheelItem;
public class PacketValueConfig extends AppEngPacket
{
@@ -61,198 +63,17 @@ public class PacketValueConfig extends AppEngPacket
final public String Value;
// automatic.
public PacketValueConfig(ByteBuf stream) throws IOException {
public PacketValueConfig( ByteBuf stream ) throws IOException
{
DataInputStream dis = new DataInputStream( new ByteArrayInputStream( stream.array(), stream.readerIndex(), stream.readableBytes() ) );
this.Name = dis.readUTF();
this.Value = dis.readUTF();
// dis.close();
}
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( this.Name.equals( "Item" ) && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IMouseWheelItem )
{
ItemStack is = player.getHeldItem();
IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel( is, this.Value.equals( "WheelUp" ) );
}
else if ( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus )
{
ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if ( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if ( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
}
else if ( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
{
ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
qk.cancelCrafting();
}
else if ( this.Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
{
ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
qk.setName( this.Value );
}
else if ( this.Name.equals( "TileSecurity.ToggleOption" ) && c instanceof ContainerSecurity )
{
ContainerSecurity sc = (ContainerSecurity) c;
sc.toggleSetting( this.Value, player );
}
else if ( this.Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
{
ContainerPriority pc = (ContainerPriority) c;
pc.setPriority( Integer.parseInt( this.Value ), player );
}
else if ( this.Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
{
ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel( Long.parseLong( this.Value ), player );
}
else if ( this.Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
{
ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if ( this.Name.equals( "PatternTerminal.CraftMode" ) )
{
cpt.ct.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.startsWith( "StorageBus." ) && c instanceof ContainerStorageBus )
{
ContainerStorageBus ccw = (ContainerStorageBus) c;
if ( this.Name.equals( "StorageBus.Action" ) )
{
if ( this.Value.equals( "Partition" ) )
{
ccw.partition();
}
else if ( this.Value.equals( "Clear" ) )
{
ccw.clear();
}
}
}
else if ( this.Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{
ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if ( this.Name.equals( "CellWorkbench.Action" ) )
{
if ( this.Value.equals( "CopyMode" ) )
{
ccw.nextCopyMode();
}
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 )
{
IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
for (Settings e : cm.getSettings())
{
if ( e.name().equals( this.Name ) )
{
Enum<?> def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch (IllegalArgumentException err)
{
// :P
}
break;
}
}
}
}
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
Container c = player.openContainer;
if ( this.Name.equals( "CustomName" ) && c instanceof AEBaseContainer )
{
((AEBaseContainer) c).customName = 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" ) )
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiCraftingCPU )
((GuiCraftingCPU) gs).clearItems();
}
else if ( c instanceof IConfigurableObject )
{
IConfigManager cm = ((IConfigurableObject) c).getConfigManager();
for (Settings e : cm.getSettings())
{
if ( e.name().equals( this.Name ) )
{
Enum<?> def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch (IllegalArgumentException err)
{
// :P
}
break;
}
}
}
}
// api
public PacketValueConfig(String Name, String Value) throws IOException {
public PacketValueConfig( String Name, String Value ) throws IOException
{
this.Name = Name;
this.Value = Value;
@@ -270,4 +91,185 @@ public class PacketValueConfig extends AppEngPacket
this.configureWrite( data );
}
@Override
public void serverPacketData( INetworkInfo manager, AppEngPacket packet, EntityPlayer player )
{
Container c = player.openContainer;
if( this.Name.equals( "Item" ) && player.getHeldItem() != null && player.getHeldItem().getItem() instanceof IMouseWheelItem )
{
ItemStack is = player.getHeldItem();
IMouseWheelItem si = (IMouseWheelItem) is.getItem();
si.onWheel( is, this.Value.equals( "WheelUp" ) );
}
else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftingStatus )
{
ContainerCraftingStatus qk = (ContainerCraftingStatus) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if( this.Name.equals( "Terminal.Cpu" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.cycleCpu( this.Value.equals( "Next" ) );
}
else if( this.Name.equals( "Terminal.Start" ) && c instanceof ContainerCraftConfirm )
{
ContainerCraftConfirm qk = (ContainerCraftConfirm) c;
qk.startJob();
}
else if( this.Name.equals( "TileCrafting.Cancel" ) && c instanceof ContainerCraftingCPU )
{
ContainerCraftingCPU qk = (ContainerCraftingCPU) c;
qk.cancelCrafting();
}
else if( this.Name.equals( "QuartzKnife.Name" ) && c instanceof ContainerQuartzKnife )
{
ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
qk.setName( this.Value );
}
else if( this.Name.equals( "TileSecurity.ToggleOption" ) && c instanceof ContainerSecurity )
{
ContainerSecurity sc = (ContainerSecurity) c;
sc.toggleSetting( this.Value, player );
}
else if( this.Name.equals( "PriorityHost.Priority" ) && c instanceof ContainerPriority )
{
ContainerPriority pc = (ContainerPriority) c;
pc.setPriority( Integer.parseInt( this.Value ), player );
}
else if( this.Name.equals( "LevelEmitter.Value" ) && c instanceof ContainerLevelEmitter )
{
ContainerLevelEmitter lvc = (ContainerLevelEmitter) c;
lvc.setLevel( Long.parseLong( this.Value ), player );
}
else if( this.Name.startsWith( "PatternTerminal." ) && c instanceof ContainerPatternTerm )
{
ContainerPatternTerm cpt = (ContainerPatternTerm) c;
if( this.Name.equals( "PatternTerminal.CraftMode" ) )
{
cpt.ct.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.startsWith( "StorageBus." ) && c instanceof ContainerStorageBus )
{
ContainerStorageBus ccw = (ContainerStorageBus) c;
if( this.Name.equals( "StorageBus.Action" ) )
{
if( this.Value.equals( "Partition" ) )
{
ccw.partition();
}
else if( this.Value.equals( "Clear" ) )
{
ccw.clear();
}
}
}
else if( this.Name.startsWith( "CellWorkbench." ) && c instanceof ContainerCellWorkbench )
{
ContainerCellWorkbench ccw = (ContainerCellWorkbench) c;
if( this.Name.equals( "CellWorkbench.Action" ) )
{
if( this.Value.equals( "CopyMode" ) )
{
ccw.nextCopyMode();
}
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 )
{
IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager();
for( Settings e : cm.getSettings() )
{
if( e.name().equals( this.Name ) )
{
Enum<?> def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch( IllegalArgumentException err )
{
// :P
}
break;
}
}
}
}
@Override
public void clientPacketData( INetworkInfo network, AppEngPacket packet, EntityPlayer player )
{
Container c = player.openContainer;
if( this.Name.equals( "CustomName" ) && c instanceof AEBaseContainer )
{
( (AEBaseContainer) c ).customName = 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" ) )
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if( gs instanceof GuiCraftingCPU )
( (GuiCraftingCPU) gs ).clearItems();
}
else if( c instanceof IConfigurableObject )
{
IConfigManager cm = ( (IConfigurableObject) c ).getConfigManager();
for( Settings e : cm.getSettings() )
{
if( e.name().equals( this.Name ) )
{
Enum<?> def = cm.getSetting( e );
try
{
cm.putSetting( e, Enum.valueOf( def.getClass(), this.Value ) );
}
catch( IllegalArgumentException err )
{
// :P
}
break;
}
}
}
}
}