update for packet handling

This commit is contained in:
DarkGuardsman 2013-09-27 18:58:31 -04:00
parent e5e212dec9
commit 74fb3882a6
11 changed files with 73 additions and 84 deletions

View file

@ -54,7 +54,7 @@ public class RenderArmbot extends TileEntitySpecialRenderer
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).renderYaw, ((TileEntityArmbot) tileEntity).renderPitch);
MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).actualYaw, ((TileEntityArmbot) tileEntity).actualPitch);
GL11.glPopMatrix();

View file

@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
@ -16,12 +18,12 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.network.IPacketReceiver;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
@ -43,9 +45,10 @@ import dark.core.common.DarkMain;
import dark.core.network.PacketHandler;
import dark.core.prefab.IMultiBlock;
import dark.core.prefab.helpers.ItemWorldHelper;
import dark.core.prefab.helpers.MathHelper;
import dark.core.prefab.machine.BlockMulti;
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IPacketReceiver, IArmbot, IPeripheral
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IArmbot, IPeripheral
{
private final CommandManager commandManager = new CommandManager();
/** The items this container contains. */
@ -55,8 +58,8 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
/** The rotation of the arms. In Degrees. */
public float rotationPitch = 0;
public float rotationYaw = 0;
public float renderPitch = 0;
public float renderYaw = 0;
public float actualPitch = 0;
public float actualYaw = 0;
public final float ROTATION_SPEED = 2.0f;
private String displayText = "";
@ -168,12 +171,12 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
// System.out.println("Ren: " + this.renderYaw + "; Rot: " +
// this.rotationYaw);
if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f)
if (Math.abs(this.actualYaw - this.rotationYaw) > 0.001f)
{
float speedYaw;
if (this.renderYaw > this.rotationYaw)
if (this.actualYaw > this.rotationYaw)
{
if (Math.abs(this.renderYaw - this.rotationYaw) >= 180)
if (Math.abs(this.actualYaw - this.rotationYaw) >= 180)
{
speedYaw = this.ROTATION_SPEED;
}
@ -184,7 +187,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
else
{
if (Math.abs(this.renderYaw - this.rotationYaw) >= 180)
if (Math.abs(this.actualYaw - this.rotationYaw) >= 180)
{
speedYaw = -this.ROTATION_SPEED;
}
@ -194,17 +197,9 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
}
this.renderYaw += speedYaw;
this.actualYaw += speedYaw;
// keep it within 0 - 360 degrees so ROTATE commands work properly
while (this.renderYaw < 0)
{
this.renderYaw += 360;
}
while (this.renderYaw > 360)
{
this.renderYaw -= 360;
}
this.rotationYaw = MathHelper.clampAngleTo360(this.rotationYaw);
if (this.ticks % 5 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
@ -212,21 +207,21 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 0.4f, 1.7f, true);
}
if (Math.abs(this.renderYaw - this.rotationYaw) < this.ROTATION_SPEED + 0.1f)
if (Math.abs(this.actualYaw - this.rotationYaw) < this.ROTATION_SPEED + 0.1f)
{
this.renderYaw = this.rotationYaw;
this.actualYaw = this.rotationYaw;
}
for (Entity e : (ArrayList<Entity>) this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord + 2, this.zCoord, this.xCoord + 1, this.yCoord + 3, this.zCoord + 1)))
{
e.rotationYaw = this.renderYaw;
e.rotationYaw = this.actualYaw;
}
}
if (Math.abs(this.renderPitch - this.rotationPitch) > 0.001f)
if (Math.abs(this.actualPitch - this.rotationPitch) > 0.001f)
{
float speedPitch;
if (this.renderPitch > this.rotationPitch)
if (this.actualPitch > this.rotationPitch)
{
speedPitch = -this.ROTATION_SPEED;
}
@ -235,51 +230,28 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
speedPitch = this.ROTATION_SPEED;
}
this.renderPitch += speedPitch;
this.actualPitch += speedPitch;
//Clamp pitch between 0 - 60
while (this.renderPitch < 0)
{
this.renderPitch += 60;
}
while (this.renderPitch > 60)
{
this.renderPitch -= 60;
}
this.rotationPitch = MathHelper.clampAngle(this.rotationPitch, 0, 60);
if (this.ticks % 4 == 0 && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
this.worldObj.playSound(this.xCoord, this.yCoord, this.zCoord, "mods.assemblyline.conveyor", 2f, 2.5f, true);
}
if (Math.abs(this.renderPitch - this.rotationPitch) < this.ROTATION_SPEED + 0.1f)
if (Math.abs(this.actualPitch - this.rotationPitch) < this.ROTATION_SPEED + 0.1f)
{
this.renderPitch = this.rotationPitch;
this.actualPitch = this.rotationPitch;
}
for (Entity e : (ArrayList<Entity>) this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord + 2, this.zCoord, this.xCoord + 1, this.yCoord + 3, this.zCoord + 1)))
{
e.rotationPitch = this.renderPitch;
e.rotationPitch = this.actualPitch;
}
}
//Clamp angles between 0 - 360
while (this.rotationYaw < 0)
{
this.rotationYaw += 360;
}
while (this.rotationYaw > 360)
{
this.rotationYaw -= 360;
}
while (this.rotationPitch < 0)
{
this.rotationPitch += 60;
}
while (this.rotationPitch > 60)
{
this.rotationPitch -= 60;
}
this.rotationYaw = MathHelper.clampAngleTo360(this.rotationYaw);
this.rotationPitch = MathHelper.clampAngle(this.rotationPitch, 0, 60);
//TODO reduce this to an event based system were it only updates the client when something changes
if (!this.worldObj.isRemote && this.ticks % 20 == 0)
@ -312,12 +284,12 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
double distance = 1f;
Vector3 delta = new Vector3();
// The delta Y of the hand.
delta.y = Math.sin(Math.toRadians(this.renderPitch)) * distance * 2;
delta.y = Math.sin(Math.toRadians(this.actualPitch)) * distance * 2;
// The horizontal delta of the hand.
double dH = Math.cos(Math.toRadians(this.renderPitch)) * distance;
double dH = Math.cos(Math.toRadians(this.actualPitch)) * distance;
// The delta X and Z.
delta.x = Math.sin(Math.toRadians(-this.renderYaw)) * dH;
delta.z = Math.cos(Math.toRadians(-this.renderYaw)) * dH;
delta.x = Math.sin(Math.toRadians(-this.actualYaw)) * dH;
delta.z = Math.cos(Math.toRadians(-this.actualYaw)) * dH;
return delta;
}
@ -523,7 +495,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
@Override
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
@ -544,7 +516,7 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
}
}
}
catch (IOException e)
catch (Exception e)
{
e.printStackTrace();
}

View file

@ -75,11 +75,11 @@ public class CommandRotateBy extends Command
this.tileEntity.rotationPitch = this.targetRotationPitch;
// if (this.ticks < this.totalTicks) { return true; }
if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f)
if (Math.abs(this.tileEntity.actualPitch - this.tileEntity.rotationPitch) > 0.001f)
{
return true;
}
if (Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f)
if (Math.abs(this.tileEntity.actualYaw - this.tileEntity.rotationYaw) > 0.001f)
{
return true;
}

View file

@ -46,8 +46,8 @@ public class CommandRotateTo extends Command
while (this.targetRotationPitch > 60)
this.targetRotationPitch -= 60;
int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.renderYaw) / this.tileEntity.ROTATION_SPEED);
int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.renderPitch) / this.tileEntity.ROTATION_SPEED);
int totalTicksYaw = (int) (Math.abs(this.targetRotationYaw - this.tileEntity.actualYaw) / this.tileEntity.ROTATION_SPEED);
int totalTicksPitch = (int) (Math.abs(this.targetRotationPitch - this.tileEntity.actualPitch) / this.tileEntity.ROTATION_SPEED);
this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch);
}
@ -71,11 +71,11 @@ public class CommandRotateTo extends Command
this.tileEntity.rotationPitch = this.targetRotationPitch;
// if (this.ticks < this.totalTicks) { return true; }
if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f)
if (Math.abs(this.tileEntity.actualPitch - this.tileEntity.rotationPitch) > 0.001f)
{
return true;
}
if (Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f)
if (Math.abs(this.tileEntity.actualYaw - this.tileEntity.rotationYaw) > 0.001f)
{
return true;
}

View file

@ -11,7 +11,7 @@ import dark.assembly.api.IFilterable;
import dark.assembly.common.imprinter.ItemImprinter;
import dark.assembly.common.machine.TileEntityAssembly;
public abstract class TileEntityFilterable extends TileEntityAssembly implements IRotatable, IFilterable, IPacketReceiver
public abstract class TileEntityFilterable extends TileEntityAssembly implements IRotatable, IFilterable
{
private ItemStack filterItem;

View file

@ -193,10 +193,4 @@ public abstract class TileEntityAssembly extends TileEntityEnergyMachine impleme
{
return INFINITE_EXTENT_AABB;
}
@Override
public String toString()
{
return "[AssemblyTile]@" + (new Vector3(this).toString());
}
}

View file

@ -4,6 +4,10 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -111,7 +115,8 @@ public class TileEntityDetector extends TileEntityFilterable
return PacketHandler.instance().getPacket(this.getChannel(), this, "detector", this.functioning, this.isInverted());
}
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
@ -125,7 +130,7 @@ public class TileEntityDetector extends TileEntityFilterable
}
}
}
catch (IOException e)
catch (Exception e)
{
e.printStackTrace();
}

View file

@ -4,6 +4,10 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -184,7 +188,8 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
return PacketHandler.instance().getPacket(this.getChannel(), this, "manipulator", this.functioning, this.isInverted(), this.isSelfPulse(), this.isOutput());
}
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
@ -200,7 +205,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
}
}
catch (IOException e)
catch (Exception e)
{
e.printStackTrace();
}

View file

@ -4,6 +4,10 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -109,7 +113,8 @@ public class TileEntityRejector extends TileEntityFilterable
return PacketHandler.instance().getPacket(this.getChannel(), this, "rejector", this.functioning, this.isInverted(), this.firePiston);
}
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
@ -124,7 +129,7 @@ public class TileEntityRejector extends TileEntityFilterable
}
}
}
catch (IOException e)
catch (Exception e)
{
e.printStackTrace();
}

View file

@ -6,6 +6,10 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
@ -25,7 +29,7 @@ import dark.core.network.PacketHandler;
/** Conveyer belt TileEntity that allows entities of all kinds to be moved
*
* @author DarkGuardsman */
public class TileEntityConveyorBelt extends TileEntityAssembly implements IPacketReceiver, IBelt, IRotatable
public class TileEntityConveyorBelt extends TileEntityAssembly implements IBelt, IRotatable
{
public enum SlantType
@ -176,7 +180,7 @@ public class TileEntityConveyorBelt extends TileEntityAssembly implements IPacke
}
@Override
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
if (!super.simplePacket(id, dis, player) && this.worldObj.isRemote)
{

View file

@ -3,6 +3,10 @@ package dark.assembly.common.machine.processor;
import java.io.DataInputStream;
import java.io.IOException;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
@ -280,7 +284,7 @@ public class TileEntityProcessor extends TileEntityEnergyMachine
}
@Override
public boolean simplePacket(String id, DataInputStream dis, EntityPlayer player)
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
if (!super.simplePacket(id, dis, player))
{
@ -297,7 +301,7 @@ public class TileEntityProcessor extends TileEntityEnergyMachine
}
}
}
catch (IOException e)
catch (Exception e)
{
e.printStackTrace();
}