Packet handling change

see DarksCoreMachine for more info
This commit is contained in:
DarkGuardsman 2013-08-24 08:02:49 -04:00
parent ee742fc624
commit 8be2ac3665
6 changed files with 27 additions and 124 deletions

View file

@ -162,10 +162,8 @@ public class AssemblyLine extends ModPrefab
AssemblyLine.REQUIRE_NO_POWER = !CONFIGURATION.get("general", "requirePower", true).getBoolean(true);
AssemblyLine.VINALLA_RECIPES = CONFIGURATION.get("general", "Vinalla_Recipes", false).getBoolean(false);
if (CONFIGURATION.hasChanged())
{
CONFIGURATION.save();
}
CONFIGURATION.save();
}

View file

@ -288,15 +288,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
return delta;
}
/** Data */
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbt = new NBTTagCompound();
this.writeToNBT(nbt);
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT, nbt);
}
/** Inventory */
@Override
public int getSizeInventory()

View file

@ -98,22 +98,6 @@ public abstract class TileEntityFilterable extends TileEntityAssembly implements
this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 3);
}
/** Don't override this! Override getPackData() instead! */
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT.ordinal(), this.getPacketData().toArray());
}
public ArrayList getPacketData()
{
ArrayList array = new ArrayList();
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
array.add(tag);
return array;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
@ -121,7 +105,9 @@ public abstract class TileEntityFilterable extends TileEntityAssembly implements
NBTTagCompound filter = new NBTTagCompound();
if (getFilter() != null)
{
getFilter().writeToNBT(filter);
}
nbt.setTag("filter", filter);
nbt.setBoolean("inverted", inverted);
}

View file

@ -3,6 +3,7 @@ package dark.assembly.common.machine;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.World;
import universalelectricity.core.UniversalElectricity;
import cpw.mods.fml.relauncher.Side;
@ -12,7 +13,7 @@ import dark.assembly.common.TabAssemblyLine;
import dark.assembly.common.imprinter.prefab.BlockImprintable;
/** A block that manipulates item movement between inventories.
*
*
* @author Calclavia */
public class BlockManipulator extends BlockImprintable
{
@ -36,13 +37,14 @@ public class BlockManipulator extends BlockImprintable
if (tileEntity instanceof TileEntityManipulator)
{
((TileEntityManipulator) tileEntity).setSelfPulse(!((TileEntityManipulator) tileEntity).isSelfPulse());
entityPlayer.sendChatToPlayer(ChatMessageComponent.func_111066_d("Manip. set to " + (((TileEntityManipulator) tileEntity).isSelfPulse() ? "auto pulse" : "not pulse")));
}
return true;
}
@Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
@ -69,6 +71,8 @@ public class BlockManipulator extends BlockImprintable
manip.toggleOutput();
manip.toggleInversion();
}
entityPlayer.sendChatToPlayer(ChatMessageComponent.func_111066_d("Manip. outputing = "+manip.isOutput()));
}
return true;

View file

@ -1,26 +1,15 @@
package dark.assembly.common.machine;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput;
import dark.api.INetworkPart;
import dark.assembly.common.AssemblyLine;
import dark.core.blocks.TileEntityMachine;
@ -32,20 +21,6 @@ import dark.core.tile.network.NetworkTileEntities;
* @author DarkGuardsman */
public abstract class TileEntityAssembly extends TileEntityMachine implements INetworkPart, IPacketReceiver, IConductor
{
public TileEntityAssembly(float wattsPerTick)
{
super(wattsPerTick);
}
public TileEntityAssembly(float wattsPerTick, float maxEnergy)
{
super(wattsPerTick, maxEnergy);
}
/** Is the tile currently powered allowing it to run */
public boolean running = false;
private boolean prevRun = false;
/** Network used to link assembly machines together */
private NetworkAssembly assemblyNetwork;
/** Tiles that are connected to this */
@ -55,10 +30,14 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
/** Random rate by which this tile updates its connections */
private int updateTick = 1;
public static enum AssemblyTilePacket
public TileEntityAssembly(float wattsPerTick)
{
POWER(),
NBT();
super(wattsPerTick);
}
public TileEntityAssembly(float wattsPerTick, float maxEnergy)
{
super(wattsPerTick, maxEnergy);
}
@Override
@ -77,7 +56,7 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
{
if (!this.worldObj.isRemote)
{
this.prevRun = this.running;
this.prevRunning = this.running;
super.updateEntity();
if (ticks % updateTick == 0)
{
@ -85,16 +64,21 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
this.refresh();
}
this.running = this.canRun();
if (running != prevRun)
if (running != prevRunning)
{
Packet packet = PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.POWER.ordinal(), this.running);
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 64);
this.sendPowerUpdate();
}
}
this.onUpdate();
}
@Override
public String getChannel()
{
return AssemblyLine.CHANNEL;
}
@Override
public boolean canRun()
{
@ -180,67 +164,6 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
return "[AssemblyTile]@" + (new Vector3(this).toString());
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
boolean packetSize = false;
try
{
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
DataInputStream dis = new DataInputStream(bis);
int id = dis.readInt();
int x = dis.readInt();
int y = dis.readInt();
int z = dis.readInt();
int pId = dis.readInt();
this.simplePacket(pId, dis, player);
/** DEBUG PACKET SIZE AND INFO */
if (packetSize)
{
System.out.println("TileEntityAssembly>" + new Vector3(this) + ">>>Debug>>Packet" + pId + ">>Size>>bytes>>" + packet.data.length);
}
}
catch (Exception e)
{
System.out.println("Error Reading Packet for a TileEntityAssembly");
e.printStackTrace();
}
}
/** Handles reduced data from the main packet method
*
* @param id - packet ID
* @param dis - data
* @param player - player
* @return true if the packet was used */
public boolean simplePacket(int id, DataInputStream dis, EntityPlayer player)
{
try
{
if (this.worldObj.isRemote)
{
if (id == AssemblyTilePacket.POWER.ordinal())
{
this.running = dis.readBoolean();
return true;
}
if (id == AssemblyTilePacket.NBT.ordinal())
{
this.readFromNBT(Packet.readNBTTagCompound(dis));
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}
@Override
public IElectricityNetwork getNetwork()
{

View file

@ -122,4 +122,5 @@ public class TileEntityDetector extends TileEntityFilterable
// TODO Auto-generated method stub
}
}