Added to TileMechanical packet system

This commit is contained in:
Robert S 2014-06-10 09:53:46 -04:00
parent 2772d4add6
commit ac4d930aac

View file

@ -1,11 +1,15 @@
package resonantinduction.mechanical.energy.grid;
import java.io.IOException;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonant.lib.References;
import resonant.lib.content.module.TileBase;
import resonant.lib.network.IPacketReceiver;
import resonant.lib.network.IPacketReceiverWithID;
@ -21,6 +25,7 @@ import com.google.common.io.ByteArrayDataInput;
* @author Calclavia */
public abstract class TileMechanical extends TileBase implements INodeProvider, IPacketReceiverWithID
{
protected static final int PACKET_NBT = 0;
protected static final int PACKET_VELOCITY = 1;
/** Node that handles most mechanical actions */
@ -75,6 +80,14 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
return null;
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return References.PACKET_TILE.getPacketWithID(PACKET_NBT, this, tag);
}
private void sendRotationPacket()
{
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity), worldObj, new Vector3(this), 20);
@ -82,15 +95,28 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
@Override
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
if (!world().isRemote)
{
if (id == PACKET_VELOCITY)
if (id == PACKET_NBT)
{
readFromNBT(PacketHandler.readNBTTagCompound(data));
return true;
}
else if (id == PACKET_VELOCITY)
{
mechanicalNode.angularVelocity = data.readDouble();
return true;
}
}
}
catch (IOException e)
{
e.printStackTrace();
return true;
}
return false;
}