Changed EntityDrivable into a prefab

It was designed to be one anyways but during testing it was treated as
an actual entity.
This commit is contained in:
Robert 2013-11-10 11:54:21 -05:00
parent 81cac14c90
commit 0f9721e0c2
6 changed files with 62 additions and 18 deletions

View file

@ -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

View file

@ -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)
{

View file

@ -5,14 +5,15 @@ 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)
{

View file

@ -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()
{

View file

@ -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);
}
}

View file

@ -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())