Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package simcraft.entity.trucks;
- import java.util.List;
- import org.lwjgl.input.Keyboard;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import simcraft.core.SimCraft;
- import simcraft.core.sound.SoundSource;
- import simcraft.core.sound.SoundsManager;
- import simcraft.entity.KeyConfig;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityBoat;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- public class EntityTrucks extends Entity
- {
- public boolean field_70279_a;
- public double speedMultiplier;
- public int vehiclePosRotationIncrements;
- public double vehicleX;
- public double vehicleY;
- public double vehicleZ;
- public double vehicleYaw;
- public double vehiclePitch;
- @SideOnly(Side.CLIENT)
- public double velocityX;
- @SideOnly(Side.CLIENT)
- public double velocityY;
- @SideOnly(Side.CLIENT)
- public double velocityZ;
- public double turnLeftModifier;
- public double turnRightModifier;
- public double acceleration;
- public double decceleration;
- public double maxSpeed;
- public double engineSpeed;
- public float rotationRoll;
- public float wheelYaw;
- public double playerXOffset;
- public double playerYOffset;
- public double playerZOffset;
- public double theta;
- public int vehicleMaxHealth;
- public int vehicleHealth;
- public int vehicleMaxFuel;
- public int vehicleFuel;
- public EntityTrucks(World par1World)
- {
- super(par1World);
- this.field_70279_a = true;
- this.speedMultiplier = 0.07D;
- this.preventEntitySpawning = true;
- this.setSize(1.5F, 0.6F);
- this.yOffset = this.height - 0.17F;
- this.playerXOffset = 0.0D;
- this.playerYOffset = 0.0D;
- this.playerZOffset = 0.0D;
- this.wheelYaw = 0.0F;
- this.vehicleHealth = 0;
- this.vehicleMaxHealth = 0;
- this.vehicleMaxFuel = 0;
- this.vehicleFuel = 0;
- }
- public EntityTrucks(World world, double d, double d1, double d2)
- {
- this(world);
- this.setPosition(d, d1 + (double)yOffset, d2);
- this.motionX = 0.0D;
- this.motionY = 0.0D;
- this.motionZ = 0.0D;
- this.prevPosX = d;
- this.prevPosY = d1;
- this.prevPosZ = d2;
- }
- public EntityTrucks(World world, double d, double d1, double d2,
- EntityPlayer entityplayer, int i)
- {
- this(world);
- this.setPosition(d, d1 + (double)yOffset, d2);
- this.motionX = 0.0D;
- this.motionY = 0.0D;
- this.motionZ = 0.0D;
- this.rotationYaw = entityplayer.rotationYaw;
- this.prevPosX = d;
- this.prevPosY = d1;
- this.prevPosZ = d2;
- }
- /**
- * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
- * prevent them from trampling crops
- */
- protected boolean canTriggerWalking()
- {
- return false;
- }
- protected void entityInit()
- {
- this.dataWatcher.addObject(17, new Integer(0));
- this.dataWatcher.addObject(18, new Integer(1));
- this.dataWatcher.addObject(19, new Float(0.0F));
- }
- /**
- * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
- * pushable on contact, like boats or minecarts.
- */
- public AxisAlignedBB getCollisionBox(Entity par1Entity)
- {
- return par1Entity.boundingBox;
- }
- /**
- * returns the bounding box for this entity
- */
- public AxisAlignedBB getBoundingBox()
- {
- return this.boundingBox;
- }
- /**
- * Returns true if this entity should push and be pushed by other entities when colliding.
- */
- public boolean canBePushed()
- {
- return false;
- }
- /**
- * Returns the Y offset from the entity's position for any entity riding this one.
- */
- public double getMountedYOffset()
- {
- return playerYOffset;
- }
- /**
- * Sets The position of the Vehicle.
- */
- public void setPosition(double d, double d1, double d2)
- {
- this.posX = d;
- this.posY = d1;
- this.posZ = d2;
- float f = width / 2.0F;
- float f1 = height;
- this.boundingBox.setBounds(d - (double)f, (d1 - (double)this.yOffset) + (double)this.ySize, d2 - (double)f, d + (double)f, (d1 - (double)this.yOffset) + (double)this.ySize + (double)f1, d2 + (double)f);
- }
- /**
- * Called when the entity is attacked.
- */
- public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
- {
- if (this.isEntityInvulnerable())
- {
- return false;
- }
- else if (!this.worldObj.isRemote && !this.isDead)
- {
- this.setForwardDirection(-this.getForwardDirection());
- this.setTimeSinceHit(10);
- this.setDamageTaken(this.getDamageTaken() + par2 * 10.0F);
- this.setBeenAttacked();
- boolean flag = par1DamageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)par1DamageSource.getEntity()).capabilities.isCreativeMode;
- if (flag || this.getDamageTaken() > 40.0F)
- {
- if (this.riddenByEntity != null)
- {
- this.riddenByEntity.mountEntity(this);
- }
- if (!flag)
- {
- this.dropItemWithOffset(Item.boat.itemID, 1, 0.0F);
- }
- this.destroyVehicle();
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- /**
- * Destroys the vehicle.
- */
- public void destroyVehicle()
- {
- if (!worldObj.isRemote)
- {
- this.setDead();
- this.spawnExplosionParticle();
- }
- }
- /**
- * Spawns an explosion particle around the Entity's location
- */
- public void spawnExplosionParticle()
- {
- for (int i = 0; i < 20; ++i)
- {
- double d0 = this.rand.nextGaussian() * 0.02D;
- double d1 = this.rand.nextGaussian() * 0.02D;
- double d2 = this.rand.nextGaussian() * 0.02D;
- double d3 = 10.0D;
- this.worldObj.spawnParticle("explode", this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d0 * d3, this.posY + (double)(this.rand.nextFloat() * this.height) - d1 * d3, this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width - d2 * d3, d0, d1, d2);
- }
- }
- @SideOnly(Side.CLIENT)
- /**
- * Setups the entity to do the hurt animation. Only used by packets in multiplayer.
- */
- public void performHurtAnimation()
- {
- this.setForwardDirection(-this.getForwardDirection());
- this.setTimeSinceHit(10);
- this.setDamageTaken(this.getDamageTaken() * 11.0F);
- if (this.getForwardDirection() > 0)
- {
- this.worldObj.playSoundAtEntity(this, "impactA", 1.0F, 1.0F);
- }
- else
- {
- this.worldObj.playSoundAtEntity(this, "impactB", 1.0F, 1.0F);
- }
- }
- /**
- * Returns true if other Entities should be prevented from moving through this Entity.
- */
- public boolean canBeCollidedWith()
- {
- return !this.isDead;
- }
- @SideOnly(Side.CLIENT)
- /**
- * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
- * posY, posZ, yaw, pitch
- */
- public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
- {
- if (this.field_70279_a)
- {
- this.vehiclePosRotationIncrements = par9 + 5;
- }
- else
- {
- double d3 = par1 - this.posX;
- double d4 = par3 - this.posY;
- double d5 = par5 - this.posZ;
- double d6 = d3 * d3 + d4 * d4 + d5 * d5;
- if (d6 <= 1.0D)
- {
- return;
- }
- this.vehiclePosRotationIncrements = 3;
- }
- this.vehicleX = par1;
- this.vehicleY = par3;
- this.vehicleZ = par5;
- this.vehicleYaw = (double)par7;
- this.vehiclePitch = (double)par8;
- this.motionX = this.velocityX;
- this.motionY = this.velocityY;
- this.motionZ = this.velocityZ;
- }
- @SideOnly(Side.CLIENT)
- /**
- * Sets the velocity to the args. Args: x, y, z
- */
- public void setVelocity(double par1, double par3, double par5)
- {
- this.velocityX = this.motionX = par1;
- this.velocityY = this.motionY = par3;
- this.velocityZ = this.motionZ = par5;
- }
- public double getSpeed()
- {
- return Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
- }
- public void onUpdate()
- {
- this.pressKeyClient();
- /** Last Time Entity was Hit **/
- if (this.getTimeSinceHit() > 0)
- {
- this.setTimeSinceHit(this.getTimeSinceHit() - 1);
- }
- /** Last TDamage Taken **/
- if (this.getDamageTaken() > 0.0F)
- {
- this.setDamageTaken(this.getDamageTaken() - 1.0F);
- }
- /** Update current position and recalculate fuel and health **/
- this.prevPosX = this.posX;
- this.prevPosY = this.posY;
- this.prevPosZ = this.posZ;
- this.vehicleFuel = Math.max(0, Math.min(this.vehicleFuel, this.vehicleMaxFuel));
- this.vehicleFuel = 10 * this.vehicleFuel < this.vehicleMaxFuel ? this.vehicleFuel - 1 : this.vehicleFuel;
- this.vehicleHealth = Math.max(0, Math.min(this.vehicleHealth, this.vehicleMaxHealth));
- this.vehicleHealth = 10 * this.vehicleHealth < this.vehicleMaxHealth ? this.vehicleHealth - 1 : this.vehicleHealth;
- /**Vehicle Health **/
- if (this.vehicleHealth <= 0)
- {
- this.destroyVehicle();
- }
- /** Vehicle Fuel deducted while moving**/
- if (this.vehicleFuel > 0 && getSpeed() > 0.02D)
- {
- this.vehicleFuel--;
- }
- /** Vehicle Health Below 150 **/
- if (this.vehicleHealth < 150)
- {
- this.worldObj.spawnParticle("smoke", posX + 2.5D * Math.cos(((double)this.rotationYaw * Math.PI) / 180D) + (0.80000000000000004D * (double)rand.nextFloat() - 0.40000000000000002D), posY + 1.2D, posZ + 2.5D * Math.sin(((double)this.rotationYaw * Math.PI) / 180D) + (0.80000000000000004D * (double)rand.nextFloat() - 0.40000000000000002D), this.motionX, 0.10000000000000001D, this.motionZ);
- }
- /** Vehicle Health Below 50 **/
- if (this.vehicleHealth < 50)
- {
- this.worldObj.spawnParticle("flame", posX + 2.5D * Math.cos(((double)this.rotationYaw * Math.PI) / 180D) + (0.59999999999999998D * (double)rand.nextFloat() - 0.29999999999999999D), posY + 1.2D, posZ + 2.5D * Math.sin(((double)this.rotationYaw * Math.PI) / 180D) + (0.59999999999999998D * (double)rand.nextFloat() - 0.29999999999999999D), this.motionX, 0.050000000000000003D, this.motionZ);
- }
- /** Bounding Box around Entity **/
- this.prevPosX = this.posX;
- this.prevPosY = this.posY;
- this.prevPosZ = this.posZ;
- byte b0 = 5;
- double d0 = 0.0D;
- for (int i = 0; i < b0; ++i)
- {
- double d1 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 0) / (double)b0 - 0.125D;
- double d2 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(i + 1) / (double)b0 - 0.125D;
- AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB(this.boundingBox.minX, d1, this.boundingBox.minZ, this.boundingBox.maxX, d2, this.boundingBox.maxZ);
- if (this.worldObj.isAABBInMaterial(axisalignedbb, Material.water))
- {
- d0 += 1.0D / (double)b0;
- }
- }
- double d3 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
- double d4;
- double d5;
- if (d3 > 0.26249999999999996D)
- {
- d4 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D);
- d5 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D);
- for (int j = 0; (double)j < 1.0D + d3 * 60.0D; ++j)
- {
- double d6 = (double)(this.rand.nextFloat() * 2.0F - 1.0F);
- double d7 = (double)(this.rand.nextInt(2) * 2 - 1) * 0.7D;
- double d8;
- double d9;
- if (this.rand.nextBoolean())
- {
- d8 = this.posX - d4 * d6 * 0.8D + d5 * d7;
- d9 = this.posZ - d5 * d6 * 0.8D - d4 * d7;
- this.worldObj.spawnParticle("smoke", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
- }
- else
- {
- d8 = this.posX + d4 + d5 * d6 * 0.7D;
- d9 = this.posZ + d5 - d4 * d6 * 0.7D;
- this.worldObj.spawnParticle("smoke", d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
- }
- }
- }
- double d10;
- double d11;
- if (this.worldObj.isRemote && this.field_70279_a)
- {
- if (this.vehiclePosRotationIncrements > 0)
- {
- d4 = this.posX + (this.vehicleX - this.posX) / (double)this.vehiclePosRotationIncrements;
- d5 = this.posY + (this.vehicleY - this.posY) / (double)this.vehiclePosRotationIncrements;
- d11 = this.posZ + (this.vehicleZ - this.posZ) / (double)this.vehiclePosRotationIncrements;
- d10 = MathHelper.wrapAngleTo180_double(this.vehicleYaw - (double)this.rotationYaw);
- double d12;
- for (d12 = vehicleYaw - (double)rotationYaw; d12 < -180D; d12 += 360D) { }
- for (; d12 >= 180D; d12 -= 360D) { }
- this.rotationYaw += d12 / (double)this.vehiclePosRotationIncrements;
- this.rotationPitch += (this.vehiclePitch - (double)this.rotationPitch) / (double)this.vehiclePosRotationIncrements;
- vehiclePosRotationIncrements--;
- this.setPosition(d4, d5, d11);
- this.setRotation(this.rotationYaw, this.rotationPitch);
- }
- else
- {
- d4 = this.posX + this.motionX;
- d5 = this.posY + this.motionY;
- d11 = this.posZ + this.motionZ;
- this.setPosition(d4, d5, d11);
- if (this.onGround)
- {
- this.motionX *= 0.5D;
- this.motionY *= 0.5D;
- this.motionZ *= 0.5D;
- }
- this.motionX *= 0.94999999999999996D;
- this.motionY *= 0.94999999999999996D;
- this.motionZ *= 0.94999999999999996D;
- }
- return;
- }
- /** movement of Entity **/
- if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase)
- {
- double d = this.engineSpeed;
- if (d < 0.0D)
- {
- d = 0.0D;
- }
- double dmotionX = this.riddenByEntity.motionX;
- double dmotionY = this.riddenByEntity.motionY;
- double dmotionZ = this.riddenByEntity.motionZ;
- double d15 = Math.sqrt(dmotionX * dmotionX + dmotionY * dmotionY + dmotionZ * dmotionZ);
- this.engineSpeed += d15;
- double d16 = this.riddenByEntity.rotationYaw;
- double d17 = this.riddenByEntity.rotationPitch;
- if (d16 - (double)this.rotationYaw > 1.0D)
- {
- this.rotationYaw += d / 3D;
- }
- if (d16 - (double)this.rotationYaw < 1.0D)
- {
- this.rotationYaw -= d / 3D;
- }
- if (d17 - (double)this.rotationPitch > 1.0D)
- {
- this.rotationPitch += d / 3D;
- }
- if (d17 - (double)this.rotationPitch < 1.0D)
- {
- this.rotationPitch -= d / 3D;
- }
- }
- /** Wheel Yaw **/
- this.wheelYaw = Math.max(-60F, Math.min(60F, this.wheelYaw));
- this.wheelYaw *= 0.80000000000000004D;
- if ((getSpeed() * 10D <= (double)this.wheelYaw || this.wheelYaw <= 0.0F) && (getSpeed() * 5D <= (double)(-this.wheelYaw) || this.wheelYaw >= 0.0F) && getSpeed() > 0.0D)
- {
- this.theta = (Math.atan2(this.motionZ, this.motionX) * 180D) / Math.PI;
- for (this.theta = (Math.atan2(this.motionZ, this.motionX) * 180D) / Math.PI; this.theta <= 0.0D; this.theta += 360D) { }
- for (; this.theta > 360D; this.theta -= 360D) { }
- double d1;
- for (d1 = this.rotationYaw; d1 <= 0.0D; d1 += 360D) { }
- for (; d1 > 360D; d1 -= 360D) { }
- double d6 = Math.abs(this.theta - d1);
- if (d6 < 90D || d6 > 270D)
- {
- this.rotationYaw += 0.40000000000000002D * (double)this.wheelYaw * Math.sqrt(getSpeed() / this.maxSpeed);
- }
- else
- {
- this.rotationYaw -= 0.59999999999999998D * (double)this.wheelYaw * Math.sqrt(getSpeed() / this.maxSpeed);
- }
- if (this.wheelYaw > 0.0F)
- {
- this.motionX += getSpeed() * 0.02D * this.acceleration * Math.cos(((this.rotationYaw + 90F) * (float)Math.PI) / 180F);
- this.motionZ += getSpeed() * 0.02D * this.acceleration * Math.sin(((this.rotationYaw + 90F) * (float)Math.PI) / 180F);
- }
- else
- {
- this.motionX += getSpeed() * 0.02D * this.acceleration * Math.cos(((this.rotationYaw - 90F) * (float)Math.PI) / 180F);
- this.motionZ += getSpeed() * 0.02D * this.acceleration * Math.sin(((this.rotationYaw - 90F) * (float)Math.PI) / 180F);
- }
- }
- if (getSpeed() > this.maxSpeed)
- {
- this.motionX *= this.maxSpeed / getSpeed();
- this.motionY *= this.maxSpeed / getSpeed();
- this.motionZ *= this.maxSpeed / getSpeed();
- }
- if (this.onGround && this.riddenByEntity == null)
- {
- this.motionX = 0.0D;
- this.motionY = 0.0D;
- this.motionZ = 0.0D;
- this.rotationPitch *= 0.90000000000000002D;
- this.engineSpeed *= 0.90000000000000002D;
- }
- if (!this.onGround)
- {
- //motionY--;
- }
- this.motionX *= 0.94999999999999996D;
- this.motionY *= 0.94999999999999996D;
- this.motionZ *= 0.94999999999999996D;
- moveEntity(this.motionX, this.motionY, this.motionZ);
- int j = (int)Math.floor(this.posX);
- int k = (int)Math.floor(this.posY + 0.5D);
- int l = (int)Math.floor(this.posZ);
- byte byte0 = 0;
- byte byte1 = 0;
- float f;
- for (f = this.rotationYaw; f <= -45F; f += 360F) { }
- for (; f > 315F; f -= 360F) { }
- if (f > -45F && f <= 45F)
- {
- byte0 = 1;
- byte1 = 0;
- }
- if (f > 45F && f <= 135F)
- {
- byte0 = 0;
- byte1 = 1;
- }
- if (f > 135F && f <= 225F)
- {
- byte0 = -1;
- byte1 = 0;
- }
- if (f > 225F && f <= 315F)
- {
- byte0 = 0;
- byte1 = -1;
- }
- boolean flag = false;
- /** Collision of Blocks **/
- if (!this.worldObj.isRemote)
- {
- List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
- int li;
- if (list != null && !list.isEmpty())
- {
- for (li = 0; li < list.size(); ++li)
- {
- Entity entity = (Entity)list.get(li);
- if (entity != this.riddenByEntity && entity instanceof EntityTrucks)
- {
- entity.applyEntityCollision(this);
- }
- }
- }
- for (li = 0; li < 4; ++li)
- {
- int i1 = MathHelper.floor_double(this.posX + ((double)(li % 2) - 0.5D) * 0.8D);
- int j1 = MathHelper.floor_double(this.posZ + ((double)(li / 2) - 0.5D) * 0.8D);
- for (int k1 = 0; k1 < 2; ++k1)
- {
- int l1 = MathHelper.floor_double(this.posY) + k1;
- int i2 = this.worldObj.getBlockId(i1, l1, j1);
- if (i2 == Block.leaves.blockID)
- {
- this.worldObj.setBlockToAir(i1, l1, j1);
- }
- else if (i2 == Block.glass.blockID)
- {
- this.worldObj.destroyBlock(i1, l1, j1, true);
- }
- }
- }
- rotationPitch = flag ? ((rotationPitch + 5F) * 8F) / 10F : rotationPitch * 0.8F;
- rotationRoll *= 0.8F;
- if (riddenByEntity != null)
- {
- riddenByEntity.fallDistance = 0.0F;
- List list1 = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.10000000000000001D, 0.0D, 0.10000000000000001D));
- if (list1 != null && list1.size() > 0)
- {
- for (int i2 = 0; i2 < list1.size(); i2++)
- {
- Entity entity = (Entity)list1.get(i2);
- boolean flag2 = true;
- if (flag2 && entity != riddenByEntity && entity.canBePushed())
- {
- entity.applyEntityCollision(this);
- }
- }
- }
- }
- if (this.riddenByEntity != null && this.riddenByEntity.isDead)
- {
- this.riddenByEntity = null;
- }
- }
- }
- public void updateRiderPosition()
- {
- if (this.riddenByEntity != null)
- {
- double d = this.playerXOffset + 0.05D;
- double d1 = getMountedYOffset() + this.riddenByEntity.getYOffset() - 1.5D;
- double d2 = this.playerZOffset + 0.05D;
- double d3 = Math.cos(((double)(-this.rotationYaw) / 180D) * 3.1415926535897931D);
- double d4 = Math.sin(((double)(-this.rotationYaw) / 180D) * 3.1415926535897931D);
- //double d5 = Math.cos(((double)this.rotationPitch / 180D) * 3.1415926535897931D);
- // double d6 = Math.sin(((double)this.rotationPitch / 180D) * 3.1415926535897931D);
- double d7 = Math.cos(((double)this.rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
- double d8 = Math.sin(((double)this.rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
- double d9 = (d - d1 ) * d3 + d2 * d4;
- double d10 = d + d1;
- double d11 = (d1 - d) * d4 + d2 * d3;
- this.riddenByEntity.setPosition(this.posX + d9 + d7, this.posY + d10, this.posZ + d11 + d8);
- return;
- }
- else
- {
- return;
- }
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
- @SideOnly(Side.CLIENT)
- public float getShadowSize()
- {
- return 0.0F;
- }
- public boolean func_130002_c(EntityPlayer par1EntityPlayer)
- {
- if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer)
- {
- return true;
- }
- else
- {
- if (!this.worldObj.isRemote)
- {
- par1EntityPlayer.mountEntity(this);
- }
- return true;
- }
- }
- public void pressKey(int i)
- {
- double d = getSpeed();
- if (d < 0.0D)
- {
- d = 0.0D;
- }
- if (vehicleFuel > 0 || this.worldObj.isRemote)
- {
- switch (i)
- {
- case 0:
- this.motionX += 0.02D * this.acceleration * Math.cos((this.rotationYaw * (float)Math.PI) / 180F);
- this.motionZ += 0.02D * this.acceleration * Math.sin((this.rotationYaw * (float)Math.PI) / 180F);
- if (getSpeed() / this.maxSpeed < 0.75D)
- {
- this.rotationPitch += 2D * (1.0D - Math.sqrt(getSpeed() / this.maxSpeed));
- }
- break;
- case 1:
- this.motionX -= 0.02D * this.acceleration * Math.cos((this.rotationYaw * (float)Math.PI) / 180F);
- this.motionZ -= 0.02D * this.acceleration * Math.sin((this.rotationYaw * (float)Math.PI) / 180F);
- if (getSpeed() / this.maxSpeed > 0.25D)
- {
- this.rotationPitch -= 2D * (getSpeed() / this.maxSpeed);
- }
- break;
- case 2:
- this.wheelYaw += 2D * ((this.maxSpeed * 2D - d) * this.turnRightModifier);
- if (getSpeed() / this.maxSpeed > 0.5D)
- {
- this.rotationRoll -= 3D * (getSpeed() / this.maxSpeed - 0.20000000000000001D);
- }
- break;
- case 3:
- this.wheelYaw -= 2D * ((this.maxSpeed * 2D - d) * this.turnLeftModifier);
- if (getSpeed() / this.maxSpeed > 0.20000000000000001D)
- {
- this.rotationRoll += 3D * (getSpeed() / this.maxSpeed - 0.20000000000000001D);
- }
- break;
- }
- }
- }
- public void pressKeyClient(int i)
- {
- SimCraft.network.initiateKeyUpdate(i);
- }
- public void pressKeyClient()
- {
- if (this.riddenByEntity != null && this.riddenByEntity.ridingEntity != null && this.riddenByEntity.ridingEntity == this)
- {
- try
- {
- if (Class.forName("org.lwjgl.input.Keyboard") != null && Keyboard.isCreated())
- {
- if (Keyboard.isKeyDown(KeyConfig.KEY_ACC))
- {
- this.pressKeyClient(0);
- }
- if (Keyboard.isKeyDown(KeyConfig.KEY_DEC))
- {
- this.pressKeyClient(1);
- }
- if (Keyboard.isKeyDown(KeyConfig.KEY_TURNRIGHT))
- {
- this.pressKeyClient(2);
- }
- if (Keyboard.isKeyDown(KeyConfig.KEY_TURNLEFT))
- {
- this.pressKeyClient(3);
- }
- }
- }
- catch (ClassNotFoundException var2)
- {
- ;
- }
- }
- }
- /** DataWatchers **/
- /**
- * Sets the damage taken from the last hit.
- */
- public void setDamageTaken(float par1)
- {
- this.dataWatcher.updateObject(19, Float.valueOf(par1));
- }
- /**
- * Gets the damage taken from the last hit.
- */
- public float getDamageTaken()
- {
- return this.dataWatcher.func_111145_d(19);
- }
- /**
- * Sets the time to count down from since the last time entity was hit.
- */
- public void setTimeSinceHit(int par1)
- {
- this.dataWatcher.updateObject(17, Integer.valueOf(par1));
- }
- /**
- * Gets the time since the last hit.
- */
- public int getTimeSinceHit()
- {
- return this.dataWatcher.getWatchableObjectInt(17);
- }
- /**
- * Sets the forward direction of the entity.
- */
- public void setForwardDirection(int par1)
- {
- this.dataWatcher.updateObject(18, Integer.valueOf(par1));
- }
- /**
- * Gets the forward direction of the entity.
- */
- public int getForwardDirection()
- {
- return this.dataWatcher.getWatchableObjectInt(18);
- }
- @SideOnly(Side.CLIENT)
- public void func_70270_d(boolean par1)
- {
- this.field_70279_a = par1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement