From 0f9721e0c20e6d6ea43d27d4aae3437b64c2eb2b Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 10 Nov 2013 11:54:21 -0500 Subject: [PATCH] Changed EntityDrivable into a prefab It was designed to be one anyways but during testing it was treated as an actual entity. --- src/dark/core/client/ClientProxy.java | 3 +- .../core/client/renders/RenderTestCar.java | 2 +- src/dark/core/prefab/EntityAdvanced.java | 9 +++--- .../core/prefab/vehicles/EntityDrivable.java | 32 ++++++++++++------- .../core/prefab/vehicles/EntityTestCar.java | 32 +++++++++++++++++++ .../prefab/vehicles/ItemVehicleSpawn.java | 2 +- 6 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 src/dark/core/prefab/vehicles/EntityTestCar.java diff --git a/src/dark/core/client/ClientProxy.java b/src/dark/core/client/ClientProxy.java index 39bf905b..537b2c75 100644 --- a/src/dark/core/client/ClientProxy.java +++ b/src/dark/core/client/ClientProxy.java @@ -22,6 +22,7 @@ import dark.core.common.machines.TileEntityCoalGenerator; import dark.core.common.machines.TileEntityElectricFurnace; import dark.core.prefab.ModPrefab; import dark.core.prefab.vehicles.EntityDrivable; +import dark.core.prefab.vehicles.EntityTestCar; @SideOnly(Side.CLIENT) public class ClientProxy extends CommonProxy @@ -48,7 +49,7 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerBlockHandler(new BlockRenderingHandler()); //MinecraftForge.EVENT_BUS.register(SoundHandler.INSTANCE); - RenderingRegistry.registerEntityRenderingHandler(EntityDrivable.class, new RenderTestCar()); + RenderingRegistry.registerEntityRenderingHandler(EntityTestCar.class, new RenderTestCar()); } @Override diff --git a/src/dark/core/client/renders/RenderTestCar.java b/src/dark/core/client/renders/RenderTestCar.java index 47a8b85f..35a11521 100644 --- a/src/dark/core/client/renders/RenderTestCar.java +++ b/src/dark/core/client/renders/RenderTestCar.java @@ -34,7 +34,7 @@ public class RenderTestCar extends Render { GL11.glPushMatrix(); - GL11.glTranslatef((float) rx, (float) ry, (float) rz); + GL11.glTranslatef((float) rx, (float) ry + .8f, (float) rz); GL11.glRotatef(180.0F - rYaw, 0.0F, 1.0F, 0.0F); if (entity instanceof EntityAdvanced) { diff --git a/src/dark/core/prefab/EntityAdvanced.java b/src/dark/core/prefab/EntityAdvanced.java index 43f4da92..82c67837 100644 --- a/src/dark/core/prefab/EntityAdvanced.java +++ b/src/dark/core/prefab/EntityAdvanced.java @@ -5,18 +5,19 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -/** Extended version of the entity +/** Extended version of the entity, used in the case that an entity needs to be created that can't + * extend entity living base * * @author DarkGuardsman */ public abstract class EntityAdvanced extends Entity { - protected float maxDamage = 20; + protected float maxDamage = 50; protected long ticks = 1; - protected static final int DAMAGE_ID = 6, HIT_TICK_ID = 7, ROLL_DIRECTION_ID = 8, ROLL_AMP_ID = 9, FORWARD_DIRECTION_ID = 10; + protected static final int DAMAGE_ID = 6, HIT_TICK_ID = 7, ROLL_DIRECTION_ID = 8, ROLL_AMP_ID = 9, FORWARD_DIRECTION_ID = 10; public EntityAdvanced(World world) { - super(world); + super(world); this.setHealth(this.getMaxHealth()); } diff --git a/src/dark/core/prefab/vehicles/EntityDrivable.java b/src/dark/core/prefab/vehicles/EntityDrivable.java index 5b53b47a..0dd1ea7d 100644 --- a/src/dark/core/prefab/vehicles/EntityDrivable.java +++ b/src/dark/core/prefab/vehicles/EntityDrivable.java @@ -23,11 +23,11 @@ import dark.core.network.PacketManagerEntity; import dark.core.network.PacketManagerKeyEvent; import dark.core.prefab.EntityAdvanced; -public class EntityDrivable extends EntityAdvanced implements IControlReceiver, ISimplePacketReceiver +public abstract class EntityDrivable extends EntityAdvanced implements IControlReceiver, ISimplePacketReceiver { //1m/tick is 80km/h or 50mi/h //0.5/tick is 40km/h - public double speed = 0.0, maxSpeed = 0.32; + public double speed = 0.0, maxSpeed = 0.32, turnRate = 3, acceration = .1; public double boatX, boatY, boatZ, boatYaw, boatPitch; public int boatPosRotationIncrements; @@ -165,8 +165,11 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, if (this.worldObj.isRemote) { - this.motionX = -(this.speed * Math.cos((this.rotationYaw - 90F) * Math.PI / 180.0D)); - this.motionZ = -(this.speed * Math.sin((this.rotationYaw - 90F) * Math.PI / 180.0D)); + if (this.canMove()) + { + this.motionX = -(this.speed * Math.cos((this.rotationYaw - 90F) * Math.PI / 180.0D)); + this.motionZ = -(this.speed * Math.sin((this.rotationYaw - 90F) * Math.PI / 180.0D)); + } this.moveEntity(this.motionX, this.motionY, this.motionZ); } @@ -187,12 +190,15 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, } else { - //TODO send generic vehicle settings to clients + this.updateClients(); } } } + /** Called to update all the clients with new information */ + public abstract void updateClients(); + @Override public boolean simplePacket(String id, ByteArrayDataInput data, Player player) { @@ -257,7 +263,7 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, { if (forward) { - this.speed += 1; + this.speed += this.acceration; if (this.speed > this.maxSpeed) { this.speed = this.maxSpeed; @@ -266,7 +272,7 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, } else { - this.speed -= 1; + this.speed -= this.acceration; if (this.speed < -this.maxSpeed) { this.speed = -this.maxSpeed; @@ -279,11 +285,11 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, { if (left) { - this.rotationYaw -= 6; + this.rotationYaw -= this.turnRate; } else { - this.rotationYaw += 6; + this.rotationYaw += this.turnRate; } } @@ -359,7 +365,7 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, this.setBeenAttacked(); boolean flag = source.getEntity() instanceof EntityPlayer && ((EntityPlayer) source.getEntity()).capabilities.isCreativeMode; - if (flag || this.getHealth() > 40.0F) + if (flag || this.getHealth() > this.maxDamage) { if (this.riddenByEntity != null) { @@ -368,7 +374,8 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, if (!flag) { - this.dropItemWithOffset(CoreRecipeLoader.itemVehicleTest.itemID, 1, 0.0F); + //this.dropItemWithOffset(CoreRecipeLoader.itemVehicleTest.itemID, 1, 0.0F); + this.dropAsItem(); } this.setDead(); @@ -382,6 +389,9 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver, } } + /** Called whe the vehicle is destory and should be dropped */ + public abstract void dropAsItem(); + /** Checks if the vehicle can move, use this to check for fuel */ public boolean canMove() { diff --git a/src/dark/core/prefab/vehicles/EntityTestCar.java b/src/dark/core/prefab/vehicles/EntityTestCar.java new file mode 100644 index 00000000..6da4d6df --- /dev/null +++ b/src/dark/core/prefab/vehicles/EntityTestCar.java @@ -0,0 +1,32 @@ +package dark.core.prefab.vehicles; + +import dark.core.common.CoreRecipeLoader; +import net.minecraft.world.World; + +public class EntityTestCar extends EntityDrivable +{ + + public EntityTestCar(World world) + { + super(world); + } + + public EntityTestCar(World world, float xx, float yy, float zz) + { + super(world, xx, yy, zz); + } + + @Override + public void updateClients() + { + // TODO Auto-generated method stub + + } + + @Override + public void dropAsItem() + { + this.dropItemWithOffset(CoreRecipeLoader.itemVehicleTest.itemID, 1, 0.0F); + } + +} diff --git a/src/dark/core/prefab/vehicles/ItemVehicleSpawn.java b/src/dark/core/prefab/vehicles/ItemVehicleSpawn.java index 9c4dc681..ed758877 100644 --- a/src/dark/core/prefab/vehicles/ItemVehicleSpawn.java +++ b/src/dark/core/prefab/vehicles/ItemVehicleSpawn.java @@ -97,7 +97,7 @@ public class ItemVehicleSpawn extends Item --y; } - EntityDrivable spawnedEntity = new EntityDrivable(world, hitObj.blockX + 0.5F, y + 1.0F, hitObj.blockZ + 0.5F); + EntityDrivable spawnedEntity = new EntityTestCar(world, hitObj.blockX + 0.5F, y + 1.0F, hitObj.blockZ + 0.5F); //Last collision check using the entities collision box if (!world.getCollidingBoundingBoxes(spawnedEntity, spawnedEntity.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())