Added to TileMechanical packet system
This commit is contained in:
parent
2772d4add6
commit
ac4d930aac
1 changed files with 30 additions and 4 deletions
|
@ -1,11 +1,15 @@
|
||||||
package resonantinduction.mechanical.energy.grid;
|
package resonantinduction.mechanical.energy.grid;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonant.api.grid.INode;
|
import resonant.api.grid.INode;
|
||||||
import resonant.api.grid.INodeProvider;
|
import resonant.api.grid.INodeProvider;
|
||||||
|
import resonant.lib.References;
|
||||||
import resonant.lib.content.module.TileBase;
|
import resonant.lib.content.module.TileBase;
|
||||||
import resonant.lib.network.IPacketReceiver;
|
import resonant.lib.network.IPacketReceiver;
|
||||||
import resonant.lib.network.IPacketReceiverWithID;
|
import resonant.lib.network.IPacketReceiverWithID;
|
||||||
|
@ -21,6 +25,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
* @author Calclavia */
|
* @author Calclavia */
|
||||||
public abstract class TileMechanical extends TileBase implements INodeProvider, IPacketReceiverWithID
|
public abstract class TileMechanical extends TileBase implements INodeProvider, IPacketReceiverWithID
|
||||||
{
|
{
|
||||||
|
protected static final int PACKET_NBT = 0;
|
||||||
protected static final int PACKET_VELOCITY = 1;
|
protected static final int PACKET_VELOCITY = 1;
|
||||||
|
|
||||||
/** Node that handles most mechanical actions */
|
/** Node that handles most mechanical actions */
|
||||||
|
@ -75,6 +80,14 @@ public abstract class TileMechanical extends TileBase implements INodeProvider,
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet getDescriptionPacket()
|
||||||
|
{
|
||||||
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
|
writeToNBT(tag);
|
||||||
|
return References.PACKET_TILE.getPacketWithID(PACKET_NBT, this, tag);
|
||||||
|
}
|
||||||
|
|
||||||
private void sendRotationPacket()
|
private void sendRotationPacket()
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity), worldObj, new Vector3(this), 20);
|
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
|
@Override
|
||||||
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
public boolean onReceivePacket(int id, ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!world().isRemote)
|
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();
|
mechanicalNode.angularVelocity = data.readDouble();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue