AE2 First Commit, the dawn of 1.7 hast arrived.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( packet.data ) );
|
||||
// Determine packet type and coordinates of affected tile entity
|
||||
int packetType = -1;
|
||||
|
||||
try
|
||||
{
|
||||
packetType = stream.readInt();
|
||||
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
|
||||
pack.clientPacketData( network, pack, player );
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraft.network.packet.Packet1Login;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import appeng.core.WorldSettings;
|
||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class AppEngConnectionHandler implements IConnectionHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
WorldSettings.getInstance().sendToPlayer( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import appeng.core.Configuration;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public abstract class AppEngPacket
|
||||
{
|
||||
|
||||
private Packet250CustomPayload p;
|
||||
protected boolean isChunkDataPacket;
|
||||
|
||||
AppEngPacketHandlerBase.PacketTypes id;
|
||||
|
||||
final public int getPacketID()
|
||||
{
|
||||
return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
|
||||
}
|
||||
|
||||
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
|
||||
{
|
||||
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a server side handler." );
|
||||
}
|
||||
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a client side handler." );
|
||||
}
|
||||
|
||||
public Packet250CustomPayload getPacket()
|
||||
{
|
||||
// / += p.getPacketSize();
|
||||
return p;
|
||||
}
|
||||
|
||||
protected void configureWrite(byte[] par2ArrayOfByte)
|
||||
{
|
||||
p = new Packet250CustomPayload( Configuration.PACKET_CHANNEL, par2ArrayOfByte );
|
||||
p.isChunkDataPacket = isChunkDataPacket;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.core.sync.packets.PacketConfigButton;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.sync.packets.PacketLightning;
|
||||
import appeng.core.sync.packets.PacketLocalizedChatMsg;
|
||||
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
||||
import appeng.core.sync.packets.PacketMatterCannon;
|
||||
import appeng.core.sync.packets.PacketMockExplosion;
|
||||
import appeng.core.sync.packets.PacketMultiPart;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
|
||||
public class AppEngPacketHandlerBase
|
||||
{
|
||||
|
||||
public static Map<Class, PacketTypes> reverseLookup = new HashMap<Class, AppEngPacketHandlerBase.PacketTypes>();
|
||||
|
||||
public enum PacketTypes
|
||||
{
|
||||
PACKET_INVENTORY_ACTION(PacketInventoryAction.class),
|
||||
|
||||
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class),
|
||||
|
||||
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
|
||||
|
||||
PACKET_MULTIPART(PacketMultiPart.class),
|
||||
|
||||
PACKET_PARTPLACEMENT(PacketPartPlacement.class),
|
||||
|
||||
PACKET_LIGHTNING(PacketLightning.class),
|
||||
|
||||
PACKET_MATTERCANNON(PacketMatterCannon.class),
|
||||
|
||||
PACKET_MOCKEXPLOSION(PacketMockExplosion.class),
|
||||
|
||||
PACKET_LOCALIZED_CHATMSG(PacketLocalizedChatMsg.class);
|
||||
|
||||
final public Class pc;
|
||||
final public Constructor con;
|
||||
|
||||
private PacketTypes(Class c) {
|
||||
pc = c;
|
||||
|
||||
Constructor x = null;
|
||||
try
|
||||
{
|
||||
x = pc.getConstructor( DataInputStream.class );
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
}
|
||||
|
||||
con = x;
|
||||
AppEngPacketHandlerBase.reverseLookup.put( pc, this );
|
||||
|
||||
if ( con == null )
|
||||
throw new RuntimeException( "Invalid Packet Class, must be constructable on DataInputStream" );
|
||||
}
|
||||
|
||||
AppEngPacket parsePacket(DataInputStream in) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
||||
{
|
||||
return (AppEngPacket) con.newInstance( in );
|
||||
}
|
||||
|
||||
public static PacketTypes getPacket(int id)
|
||||
{
|
||||
return (values())[id];
|
||||
}
|
||||
|
||||
public static PacketTypes getID(Class<? extends AppEngPacket> c)
|
||||
{
|
||||
return AppEngPacketHandlerBase.reverseLookup.get( c );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( packet.data ) );
|
||||
// Determine packet type and coordinates of affected tile entity
|
||||
int packetType = -1;
|
||||
|
||||
try
|
||||
{
|
||||
packetType = stream.readInt();
|
||||
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
|
||||
pack.serverPacketData( manager, pack, player );
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package appeng.core.sync;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.exceptions.AppEngException;
|
||||
import appeng.api.implementations.IStorageMonitorable;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.client.gui.GuiNull;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.implementations.ContainerChest;
|
||||
import appeng.container.implementations.ContainerCondenser;
|
||||
import appeng.container.implementations.ContainerDrive;
|
||||
import appeng.container.implementations.ContainerGrinder;
|
||||
import appeng.container.implementations.ContainerMEMonitorable;
|
||||
import appeng.container.implementations.ContainerVibrationChamber;
|
||||
import appeng.tile.grindstone.TileGrinder;
|
||||
import appeng.tile.misc.TileCondenser;
|
||||
import appeng.tile.misc.TileVibrationChamber;
|
||||
import appeng.tile.storage.TileChest;
|
||||
import appeng.tile.storage.TileDrive;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public enum GuiBridge implements IGuiHandler
|
||||
{
|
||||
GUI_Handler(),
|
||||
|
||||
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class),
|
||||
|
||||
GUI_CHEST(ContainerChest.class, TileChest.class),
|
||||
|
||||
GUI_ME(ContainerMEMonitorable.class, IStorageMonitorable.class),
|
||||
|
||||
GUI_DRIVE(ContainerDrive.class, TileDrive.class),
|
||||
|
||||
GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class),
|
||||
|
||||
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class);
|
||||
|
||||
private Class Tile;
|
||||
private Class Gui;
|
||||
private Class Container;
|
||||
|
||||
private GuiBridge() {
|
||||
Tile = null;
|
||||
Gui = null;
|
||||
Container = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server
|
||||
* Exploding.
|
||||
*/
|
||||
private void getGui()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
{
|
||||
String start = Container.getName();
|
||||
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
|
||||
if ( start.equals( GuiClass ) )
|
||||
throw new RuntimeException( "Unable to find gui class" );
|
||||
Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
|
||||
if ( Gui == null )
|
||||
throw new RuntimeException( "Cannot Load class: " + GuiClass );
|
||||
}
|
||||
}
|
||||
|
||||
private GuiBridge(Class _Container) {
|
||||
Container = _Container;
|
||||
Tile = null;
|
||||
getGui();
|
||||
}
|
||||
|
||||
private GuiBridge(Class _Container, Class _Tile) {
|
||||
Container = _Container;
|
||||
Tile = _Tile;
|
||||
getGui();
|
||||
}
|
||||
|
||||
public boolean CorrectTileOrPart(Object tE)
|
||||
{
|
||||
if ( Tile == null )
|
||||
throw new RuntimeException( "This Gui Cannot use the standard Handler." );
|
||||
|
||||
return Tile.isInstance( tE );
|
||||
}
|
||||
|
||||
public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE)
|
||||
{
|
||||
try
|
||||
{
|
||||
Constructor[] c = Container.getConstructors();
|
||||
if ( c.length == 0 )
|
||||
throw new AppEngException( "Invalid Gui Class" );
|
||||
return c[0].newInstance( inventory, tE );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
}
|
||||
|
||||
public Object ConstructGui(InventoryPlayer inventory,ForgeDirection side, Object tE)
|
||||
{
|
||||
try
|
||||
{
|
||||
Constructor[] c = Gui.getConstructors();
|
||||
if ( c.length == 0 )
|
||||
throw new AppEngException( "Invalid Gui Class" );
|
||||
return c[0].newInstance( inventory, tE );
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
throw new RuntimeException( t );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL& 0x07 );
|
||||
GuiBridge ID = values()[ID_ORDINAL >> 3];
|
||||
|
||||
TileEntity TE = w.getBlockTileEntity( x, y, z );
|
||||
|
||||
if ( TE instanceof IPartHost )
|
||||
{
|
||||
((IPartHost) TE).getPart( side );
|
||||
IPart part = ((IPartHost) TE).getPart(side);
|
||||
if ( ID.CorrectTileOrPart(part) )
|
||||
return ID.ConstructContainer( player.inventory, side, part );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ID.CorrectTileOrPart( TE ) )
|
||||
return ID.ConstructContainer( player.inventory, side, TE );
|
||||
}
|
||||
|
||||
return new ContainerNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL& 0x07 );
|
||||
GuiBridge ID = values()[ID_ORDINAL >> 3];
|
||||
|
||||
TileEntity TE = w.getBlockTileEntity( x, y, z );
|
||||
|
||||
if ( TE instanceof IPartHost )
|
||||
{
|
||||
((IPartHost) TE).getPart( side );
|
||||
IPart part = ((IPartHost) TE).getPart(side);
|
||||
if ( ID.CorrectTileOrPart(part) )
|
||||
return ID.ConstructGui( player.inventory, side, part );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ID.CorrectTileOrPart( TE ) )
|
||||
return ID.ConstructGui( player.inventory, side, TE );
|
||||
}
|
||||
|
||||
return new GuiNull( new ContainerNull() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigureableObject;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketConfigButton extends AppEngPacket
|
||||
{
|
||||
|
||||
final public Settings option;
|
||||
|
||||
// automatic.
|
||||
public PacketConfigButton(DataInputStream stream) throws IOException {
|
||||
option = Settings.values()[stream.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
|
||||
{
|
||||
EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
|
||||
TileEntity bt = aebc.getTileEntity();
|
||||
if ( bt instanceof IConfigureableObject )
|
||||
{
|
||||
IConfigManager cm = ((IConfigureableObject) bt).getConfigManager();
|
||||
Enum newState = Platform.nextEnum( cm.getSetting( option ) );
|
||||
cm.putSetting( option, newState );
|
||||
}
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketConfigButton(Settings option) throws IOException {
|
||||
this.option = option;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeInt( option.ordinal() );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketInventoryAction extends AppEngPacket
|
||||
{
|
||||
|
||||
final public InventoryAction action;
|
||||
final public int slot;
|
||||
final public IAEItemStack slotItem;
|
||||
|
||||
// automatic.
|
||||
public PacketInventoryAction(DataInputStream stream) throws IOException {
|
||||
action = InventoryAction.values()[stream.readInt()];
|
||||
slot = stream.readInt();
|
||||
boolean hasItem = stream.readBoolean();
|
||||
if ( hasItem )
|
||||
slotItem = AEItemStack.loadItemStackFromPacket( stream );
|
||||
else
|
||||
slotItem = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
|
||||
{
|
||||
EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
|
||||
aebc.doAction( sender, action, slot, slotItem );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketInventoryAction(InventoryAction action, int slot, IAEItemStack slotItem) throws IOException {
|
||||
this.action = action;
|
||||
this.slot = slot;
|
||||
this.slotItem = slotItem;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeInt( action.ordinal() );
|
||||
data.writeInt( slot );
|
||||
|
||||
if ( slotItem == null )
|
||||
data.writeBoolean( false );
|
||||
else
|
||||
{
|
||||
data.writeBoolean( true );
|
||||
slotItem.writeToPacket( data );
|
||||
}
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.client.render.effects.LightningEffect;
|
||||
import appeng.core.Configuration;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketLightning extends AppEngPacket
|
||||
{
|
||||
|
||||
final double x;
|
||||
final double y;
|
||||
final double z;
|
||||
|
||||
// automatic.
|
||||
public PacketLightning(DataInputStream stream) throws IOException {
|
||||
x = stream.readFloat();
|
||||
y = stream.readFloat();
|
||||
z = stream.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( Platform.isClient() && Configuration.instance.enableEffects )
|
||||
{
|
||||
LightningEffect fx = new LightningEffect( ClientHelper.proxy.getWorld(), x, y, z, 0.0f, 0.0f, 0.0f );
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketLightning(double x, double y, double z) throws IOException {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeFloat( (float) x );
|
||||
data.writeFloat( (float) y );
|
||||
data.writeFloat( (float) z );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketLocalizedChatMsg extends AppEngPacket
|
||||
{
|
||||
|
||||
final public String msg;
|
||||
|
||||
// automatic.
|
||||
public PacketLocalizedChatMsg(DataInputStream stream) throws IOException {
|
||||
msg = stream.readUTF();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
((EntityPlayer) player).sendChatToPlayer( ChatMessageComponent.createFromTranslationWithSubstitutions( msg ) );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketLocalizedChatMsg(String msg) throws IOException {
|
||||
this.msg = msg;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeUTF( msg );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.implementations.GuiMEMonitorable;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketMEInventoryUpdate extends AppEngPacket
|
||||
{
|
||||
|
||||
// output...
|
||||
final private ByteArrayOutputStream bytes;
|
||||
final private DataOutputStream data;
|
||||
boolean empty = true;
|
||||
|
||||
// input.
|
||||
final List<IAEItemStack> list;
|
||||
|
||||
// automatic.
|
||||
public PacketMEInventoryUpdate(DataInputStream stream) throws IOException {
|
||||
bytes = null;
|
||||
data = null;
|
||||
list = new LinkedList();
|
||||
while (stream.available() > 0)
|
||||
list.add( AEItemStack.loadItemStackFromPacket( stream ) );
|
||||
empty = list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
||||
if ( gs instanceof GuiMEMonitorable )
|
||||
{
|
||||
((GuiMEMonitorable) gs).postUpdate( list );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet250CustomPayload getPacket()
|
||||
{
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
return super.getPacket();
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketMEInventoryUpdate() throws IOException {
|
||||
bytes = new ByteArrayOutputStream();
|
||||
data = new DataOutputStream( bytes );
|
||||
list = null;
|
||||
data.writeInt( getPacketID() );
|
||||
}
|
||||
|
||||
public void appendItem(IAEItemStack is) throws IOException
|
||||
{
|
||||
is.writeToPacket( data );
|
||||
empty = false;
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return empty;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.client.render.effects.MatterCannonEffect;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketMatterCannon extends AppEngPacket
|
||||
{
|
||||
|
||||
final double x;
|
||||
final double y;
|
||||
final double z;
|
||||
final double dx;
|
||||
final double dy;
|
||||
final double dz;
|
||||
final byte len;
|
||||
|
||||
// automatic.
|
||||
public PacketMatterCannon(DataInputStream stream) throws IOException {
|
||||
x = stream.readFloat();
|
||||
y = stream.readFloat();
|
||||
z = stream.readFloat();
|
||||
dx = stream.readFloat();
|
||||
dy = stream.readFloat();
|
||||
dz = stream.readFloat();
|
||||
len = stream.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
World world = FMLClientHandler.instance().getClient().theWorld;
|
||||
for (int a = 1; a < len; a++)
|
||||
{
|
||||
MatterCannonEffect fx = new MatterCannonEffect( world, x + dx * a, y + dy * a, z + dz * a, Item.diamond );
|
||||
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
|
||||
}
|
||||
} catch (Exception err)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len) throws IOException {
|
||||
float dl = dx * dx + dy * dy + dz * dz;
|
||||
float dlz = (float) Math.sqrt( dl );
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.dx = dx / dlz;
|
||||
this.dy = dy / dlz;
|
||||
this.dz = dz / dlz;
|
||||
this.len = len;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeFloat( (float) x );
|
||||
data.writeFloat( (float) y );
|
||||
data.writeFloat( (float) z );
|
||||
data.writeFloat( (float) this.dx );
|
||||
data.writeFloat( (float) this.dy );
|
||||
data.writeFloat( (float) this.dz );
|
||||
data.writeByte( len );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketMockExplosion extends AppEngPacket
|
||||
{
|
||||
|
||||
final public double x;
|
||||
final public double y;
|
||||
final public double z;
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
|
||||
{
|
||||
World world = CommonHelper.proxy.getWorld();
|
||||
world.spawnParticle( "largeexplode", this.x, this.y, this.z, 1.0D, 0.0D, 0.0D );
|
||||
}
|
||||
|
||||
// automatic.
|
||||
public PacketMockExplosion(DataInputStream stream) throws IOException {
|
||||
x = stream.readDouble();
|
||||
y = stream.readDouble();
|
||||
z = stream.readDouble();
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketMockExplosion(double x, double y, double z) throws IOException {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeDouble( x );
|
||||
data.writeDouble( y );
|
||||
data.writeDouble( z );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.integration.modules.helpers.FMPPacketEvent;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketMultiPart extends AppEngPacket
|
||||
{
|
||||
|
||||
// automatic.
|
||||
public PacketMultiPart(DataInputStream stream) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
|
||||
{
|
||||
EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
MinecraftForge.EVENT_BUS.post( new FMPPacketEvent( sender ) );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketMultiPart() throws IOException {
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package appeng.core.sync.packets;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.helpers.PartPlacement;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketPartPlacement extends AppEngPacket
|
||||
{
|
||||
|
||||
int x, y, z, face;
|
||||
|
||||
// automatic.
|
||||
public PacketPartPlacement(DataInputStream stream) throws IOException {
|
||||
x = stream.readInt();
|
||||
y = stream.readInt();
|
||||
z = stream.readInt();
|
||||
face = stream.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
|
||||
{
|
||||
EntityPlayerMP sender = (EntityPlayerMP) player;
|
||||
PartPlacement.place( sender.getHeldItem(), x, y, z, face, sender, sender.worldObj, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketPartPlacement(int x, int y, int z, int face) throws IOException {
|
||||
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream( bytes );
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeInt( x );
|
||||
data.writeInt( y );
|
||||
data.writeInt( z );
|
||||
data.writeByte( face );
|
||||
|
||||
isChunkDataPacket = false;
|
||||
configureWrite( bytes.toByteArray() );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user