Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityAirplane extends Entity {
- @SideOnly(Side.CLIENT)
- private SoundY sy = new SoundY();
- private BlockPos startPoint = null;
- private double distanceToFly = Double.MAX_VALUE;
- private boolean hasDropped = false;
- private final float FLY_SPEED = 0.5F;
- private final double Y_HEIGHT = 200;
- private ChunkCoordIntPair chunk;
- private Ticket ticket;
- public EntityAirplane(World worldIn) {
- super(worldIn);
- this.noClip = true;
- this.height = 1.5F;
- this.width = 7F;
- this.renderDistanceWeight = 40.0D;
- int x = (int) (this.posX / 16);
- int z = (int) (this.posZ / 16);
- if (!worldObj.isRemote && (ticket == null || chunk == null || chunk.chunkXPos != x || chunk.chunkZPos != z)) {
- ticket = ForgeChunkManager.requestTicket(SevenDaysToMine.instance, this.worldObj,
- ForgeChunkManager.Type.NORMAL);
- chunk = new ChunkCoordIntPair(x, z);
- ForgeChunkManager.forceChunk(ticket, chunk);
- }
- }
- public EntityAirplane(World worldIn, double x, double y, double z) {
- this(worldIn);
- setPosition(x, y, z);
- }
- public EntityAirplane(World worldIn, BlockPos pos) {
- this(worldIn, pos.getX(), pos.getY(), pos.getZ());
- }
- public EntityAirplane(World world, BlockPos start, BlockPos center, double distance) {
- this(world);
- this.startPoint = start;
- this.distanceToFly = distance;
- Vec3 vec = new Vec3(center.subtract(start));
- vec.normalize();
- setPosition(start.getX(), Y_HEIGHT, start.getZ());
- setThrowableHeading((double) vec.xCoord, Y_HEIGHT, (double) vec.zCoord, FLY_SPEED, 0f);
- Utils.getLogger().info(new BlockPos(this));
- }
- @Override
- protected void entityInit() {
- }
- @Override
- protected void readEntityFromNBT(NBTTagCompound tagCompund) {
- distanceToFly = tagCompund.getDouble("distance");
- startPoint = BlockPos.fromLong(tagCompund.getLong("start"));
- hasDropped = tagCompund.getBoolean("hasDropped");
- }
- @Override
- protected void writeEntityToNBT(NBTTagCompound tagCompound) {
- tagCompound.setDouble("distance", distanceToFly);
- tagCompound.setLong("start", startPoint.toLong());
- tagCompound.setBoolean("hasDropped", hasDropped);
- }
- @Override
- public void onUpdate() {
- super.onUpdate();
- this.posY = Y_HEIGHT;
- this.posX += this.motionX;
- this.posZ += this.motionZ;
- }
- @Override
- public void onEntityUpdate() {
- super.onEntityUpdate();
- Utils.getLogger().info("Update");
- if (!worldObj.isRemote) {
- if (startPoint == null) {
- this.setDead();
- Utils.getLogger().info(
- "EntityAirplane with id " + this.getEntityId() + " has null startPoint. Removing the entity!");
- }
- if (!hasDropped && worldObj.rand.nextDouble() * distanceToFly <= 1d) {
- drop();
- }
- if (Utils.getDistance(new BlockPos(posX, posY, posZ), startPoint) >= distanceToFly) {
- if (!hasDropped) {
- drop();
- }
- this.setDead();
- }
- }
- if (worldObj.isRemote) {
- if (worldObj.rand.nextInt(3) == 0) {
- sy.volume = 15;
- sy.playSirene(new ResourceLocation(SevenDaysToMine.MODID + ":mod.airplane.engine"), new BlockPos(this));
- }
- }
- int x = (int) (this.posX / 16);
- int z = (int) (this.posZ / 16);
- if (!worldObj.isRemote && (ticket == null || chunk == null || chunk.chunkXPos != x || chunk.chunkZPos != z)) {
- if (ticket != null && chunk != null) {
- ForgeChunkManager.unforceChunk(ticket, chunk);
- }
- ticket = ForgeChunkManager.requestTicket(SevenDaysToMine.instance, this.worldObj,
- ForgeChunkManager.Type.NORMAL);
- if (ticket != null) {
- NBTTagCompound nbt = ticket.getModData();
- nbt.setLong("UUIDMost", this.getUniqueID().getMostSignificantBits());
- nbt.setLong("UUIDLeast", this.getUniqueID().getLeastSignificantBits());
- chunk = new ChunkCoordIntPair(x, z);
- ForgeChunkManager.forceChunk(ticket, chunk);
- }
- }
- }
- public void drop() {
- Utils.getLogger().info("Drop!");
- hasDropped = true;
- EntityAirdrop airdrop = new EntityAirdrop(worldObj, new BlockPos(this));
- airdrop.copyLocationAndAnglesFrom(this);
- if (!worldObj.isRemote) {
- worldObj.spawnEntityInWorld(airdrop);
- }
- }
- public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) {
- float f = MathHelper.sqrt_double(x * x + y * y + z * z);
- x = x / (double) f;
- y = y / (double) f;
- z = z / (double) f;
- x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
- y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
- z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
- x = x * (double) velocity;
- y = y * (double) velocity;
- z = z * (double) velocity;
- double maxMotion = Math.abs(Math.max(Math.abs(x), Math.abs(z)));
- this.motionX = (x / maxMotion) * FLY_SPEED;
- // this.motionY = (y / maxMotion) * FLY_SPEED;
- this.motionZ = (z / maxMotion) * FLY_SPEED;
- float f1 = MathHelper.sqrt_double(x * x + z * z);
- this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(x, z) * 180.0D / Math.PI);
- this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * 180.0D / Math.PI);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment