changed getPacket to getTilePacket for tileEntity requests

keep calling its overload by mistake
This commit is contained in:
Robert 2013-11-12 21:43:25 -05:00
parent cc9b26b021
commit ce4c40c0fb
10 changed files with 128 additions and 32 deletions

View file

@ -71,7 +71,7 @@ public class TileEntityGasBlock extends TileEntity implements ISimplePacketRecei
{ {
if (this.stack != null) if (this.stack != null)
{ {
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, "Desc", this.stack.writeToNBT(new NBTTagCompound())); return PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, "Desc", this.stack.writeToNBT(new NBTTagCompound()));
} }
return null; return null;
} }

View file

@ -55,7 +55,7 @@ public class TileEntityBatteryBox extends TileEntityEnergyMachine
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.instance().getPacket(this.getChannel(), this, "energy", this.getEnergyStored()); return PacketHandler.instance().getTilePacket(this.getChannel(), this, "energy", this.getEnergyStored());
} }
@Override @Override

View file

@ -105,7 +105,7 @@ public class TileEntityCoalGenerator extends TileEntityEnergyMachine
{ {
if (entity != null) if (entity != null)
{ {
PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getPacket(this.getChannel(), this, "gen", this.generateWatts, this.itemCookTime), (Player) entity); PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getTilePacket(this.getChannel(), this, "gen", this.generateWatts, this.itemCookTime), (Player) entity);
} }
} }

View file

@ -95,7 +95,7 @@ public class TileEntityElectricFurnace extends TileEntityEnergyMachine
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.instance().getPacket(this.getChannel(), this, "processTicks", this.processTicks); return PacketHandler.instance().getTilePacket(this.getChannel(), this, "processTicks", this.processTicks);
} }
@Override @Override

View file

@ -22,13 +22,13 @@ public interface IDamageableTile extends IBlockActivated
public boolean isAlive(); public boolean isAlive();
/** Current health of the tile */ /** Current health of the tile */
public float health(); public float getDamage();
/** Sets the tiles heath /** Sets the tiles heath
* *
* @param health - amount hit points * @param health - amount hit points
* @param increase - increase instead of replace */ * @param increase - increase instead of replace */
public void setHealth(float health); public void setDamage(float health);
/** Max hit points of the object */ /** Max hit points of the object */
public float getMaxHealth(); public float getMaxHealth();

View file

@ -178,7 +178,7 @@ public class PacketHandler implements IPacketHandler, IPacketReceiver
* *
* @return */ * @return */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public Packet getPacket(String channelName, TileEntity sender, Object... sendData) public Packet getTilePacket(String channelName, TileEntity sender, Object... sendData)
{ {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes); DataOutputStream data = new DataOutputStream(bytes);

View file

@ -198,7 +198,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
{ {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
this.writeToNBT(tag); this.writeToNBT(tag);
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(this.getChannel(), this, SimplePacketTypes.NBT.name, tag), worldObj, new Vector3(this), 64); PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.NBT.name, tag), worldObj, new Vector3(this), 64);
} }
} }
@ -207,7 +207,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
{ {
if (!this.worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getPacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning), worldObj, new Vector3(this), 64); PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning), worldObj, new Vector3(this), 64);
} }
} }
@ -236,7 +236,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return PacketHandler.instance().getPacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning); return PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning);
} }
/** NetworkMod channel name */ /** NetworkMod channel name */

View file

@ -54,7 +54,7 @@ public class TileEntityMulti extends TileEntity implements IPacketReceiver
this.channel = ((BlockMulti) this.getBlockType()).channel; this.channel = ((BlockMulti) this.getBlockType()).channel;
} }
return PacketHandler.instance().getPacket(this.channel, this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); return PacketHandler.instance().getTilePacket(this.channel, this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
} }

View file

@ -1,13 +1,15 @@
package dark.core.prefab.sentry; package dark.core.prefab.sentry;
import java.util.ArrayList; import java.io.IOException;
import java.util.List; import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler; import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
@ -15,9 +17,13 @@ import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import dark.api.ISentryGun; import dark.api.ISentryGun;
import dark.core.common.DarkMain;
import dark.core.helpers.MathHelper; import dark.core.helpers.MathHelper;
import dark.core.helpers.RayTraceHelper;
import dark.core.network.PacketHandler;
import dark.core.prefab.EntityTileDamage; import dark.core.prefab.EntityTileDamage;
import dark.core.prefab.machine.TileEntityMachine; import dark.core.prefab.machine.TileEntityMachine;
import dark.core.prefab.machine.TileEntityMachine.SimplePacketTypes;
/** Prefab tileEntity for creating senty guns that can be of type aimed, mounted, or automated. /** Prefab tileEntity for creating senty guns that can be of type aimed, mounted, or automated.
* Contains most of the code for a sentry gun to operate short of aiming and operating logic. This * Contains most of the code for a sentry gun to operate short of aiming and operating logic. This
@ -36,7 +42,7 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
private float damage = 0.0f; private float damage = 0.0f;
private final float maxDamage; private final float maxDamage;
private Vector3 rotation = new Vector3(), newRotation = new Vector3(), prevRotation = new Vector3(); private Vector3 rotation = new Vector3(), targetRotation = new Vector3(), prevRotation = new Vector3();
protected float roationSpeed = 10f, minPitch = -30, maxPitch = 30, minYaw = -180, maxYaw = 180, size = 1.0f; protected float roationSpeed = 10f, minPitch = -30, maxPitch = 30, minYaw = -180, maxYaw = 180, size = 1.0f;
public TileEntitySentry(float maxDamage) public TileEntitySentry(float maxDamage)
@ -98,15 +104,15 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
public void updateRotation() public void updateRotation()
{ {
this.prevRotation = this.getRotation(); this.prevRotation = this.getRotation();
this.rotation.x = MathHelper.clamp((float) MathHelper.updateRotation(this.rotation.x, this.newRotation.x, this.roationSpeed), this.minPitch, this.maxPitch); this.rotation.x = MathHelper.clamp((float) MathHelper.updateRotation(this.rotation.x, this.targetRotation.x, this.roationSpeed), this.minPitch, this.maxPitch);
this.rotation.y = MathHelper.clamp((float) MathHelper.updateRotation(this.rotation.y, this.newRotation.y, this.roationSpeed), this.minYaw, this.maxYaw); this.rotation.y = MathHelper.clamp((float) MathHelper.updateRotation(this.rotation.y, this.targetRotation.y, this.roationSpeed), this.minYaw, this.maxYaw);
} }
@Override @Override
public Vector3 getLook() public Vector3 getLook()
{ {
// TODO Auto-generated method stub //TODO store this value so a new vector is not created each call
return null; return new Vector3(RayTraceHelper.getLook(this.worldObj, this.getRotation().floatX(), this.getRotation().floatY(), this.size));
} }
@Override @Override
@ -122,13 +128,13 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
@Override @Override
public void updateRotation(float pitch, float yaw, float roll) public void updateRotation(float pitch, float yaw, float roll)
{ {
if (this.newRotation == null) if (this.targetRotation == null)
{ {
this.newRotation = this.getRotation(); this.targetRotation = this.getRotation();
} }
this.newRotation.x += pitch; this.targetRotation.x += pitch;
this.newRotation.y += yaw; this.targetRotation.y += yaw;
this.newRotation.z += roll; this.targetRotation.z += roll;
} }
@Override @Override
@ -146,7 +152,31 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
@Override @Override
public boolean onDamageTaken(DamageSource source, float ammount) public boolean onDamageTaken(DamageSource source, float ammount)
{ {
// TODO Auto-generated method stub if (source != null && ammount > 0)
{
if (source.equals(DamageSource.onFire))
{
//TODO cause heat damage slowly but not right away
//TODO check for heat sources around the sentry
//TODO mess with the sentries abilities when over heated
return false;
}
else
{
this.setDamage(this.getDamage() - ammount);
if (this.getDamage() <= 0)
{
this.isAlive = false;
if (this.entitySentry != null)
{
this.entitySentry.setDead();
}
this.entitySentry = null;
}
return true;
}
}
return false; return false;
} }
@ -157,13 +187,13 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
} }
@Override @Override
public float health() public float getDamage()
{ {
return this.damage; return this.damage;
} }
@Override @Override
public void setHealth(float health) public void setDamage(float health)
{ {
this.damage = health; this.damage = health;
} }
@ -171,7 +201,6 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
@Override @Override
public float getMaxHealth() public float getMaxHealth()
{ {
return this.maxDamage; return this.maxDamage;
} }
@ -225,4 +254,71 @@ public abstract class TileEntitySentry extends TileEntityMachine implements ISen
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
/* ******************************************************
* Save/Load/PacketHandling
* ****************************************************** */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.getRotation() != null)
{
nbt.setFloat("pitch", this.getRotation().floatX());
nbt.setFloat("yaw", this.getRotation().floatY());
nbt.setFloat("roll", this.getRotation().floatZ());
}
if (this.targetRotation != null)
{
nbt.setFloat("npitch", this.targetRotation.floatX());
nbt.setFloat("nyaw", this.targetRotation.floatY());
nbt.setFloat("nroll", this.targetRotation.floatZ());
}
nbt.setFloat("damage", this.getDamage());
nbt.setByte("mountSide", (byte) this.mountingSide.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.getRotation().x = nbt.getFloat("pitch");
this.getRotation().y = nbt.getFloat("yaw");
this.getRotation().z = nbt.getFloat("roll");
this.targetRotation = new Vector3();
this.targetRotation.x = nbt.getFloat("pitch");
this.targetRotation.y = nbt.getFloat("yaw");
this.targetRotation.z = nbt.getFloat("roll");
this.setDamage(nbt.getFloat("damage"));
this.mountingSide = ForgeDirection.getOrientation(nbt.getByte("mountSide"));
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, "Desc", this.isRunning, this.rotation);
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
if (this.worldObj.isRemote && !super.simplePacket(id, dis, player))
{
if (id.equalsIgnoreCase("Desc"))
{
this.functioning = dis.readBoolean();
this.rotation = PacketHandler.readVector3(dis);
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
} }

View file

@ -58,7 +58,7 @@ public abstract class TileEntityTerminal extends TileEntityEnergyMachine impleme
{ {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
this.writeToNBT(nbt); this.writeToNBT(nbt);
return PacketHandler.instance().getPacket(this.getChannel(), this, SimplePacketTypes.NBT.name, nbt); return PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.NBT.name, nbt);
} }
/** Sends all Terminal data Server -> Client */ /** Sends all Terminal data Server -> Client */
@ -69,7 +69,7 @@ public abstract class TileEntityTerminal extends TileEntityEnergyMachine impleme
data.add(this.getTerminalOuput().size()); data.add(this.getTerminalOuput().size());
data.addAll(this.getTerminalOuput()); data.addAll(this.getTerminalOuput());
Packet packet = PacketHandler.instance().getPacket(this.getChannel(), this, data.toArray()); Packet packet = PacketHandler.instance().getTilePacket(this.getChannel(), this, data.toArray());
for (Object entity : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - 10, yCoord - 10, zCoord - 10, xCoord + 10, yCoord + 10, zCoord + 10))) for (Object entity : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - 10, yCoord - 10, zCoord - 10, xCoord + 10, yCoord + 10, zCoord + 10)))
{ {
@ -85,7 +85,7 @@ public abstract class TileEntityTerminal extends TileEntityEnergyMachine impleme
{ {
if (this.worldObj.isRemote) if (this.worldObj.isRemote)
{ {
Packet packet = PacketHandler.instance().getPacket(this.getChannel(), this, SimplePacketTypes.GUI_COMMAND.name, entityPlayer.username, cmdInput); Packet packet = PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.GUI_COMMAND.name, entityPlayer.username, cmdInput);
PacketDispatcher.sendPacketToServer(packet); PacketDispatcher.sendPacketToServer(packet);
} }
} }