Search in sources :

Example 86 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project TUMAT by canitzp.

the class RenderOverlay method createRayTraceForDistance.

private static RayTraceResult createRayTraceForDistance(World world, EntityPlayer player, double maxDistance, float partialTicks) {
    Entity pointedEntity;
    RayTraceResult traceResult = null;
    if (player != null) {
        if (world != null) {
            traceResult = player.rayTrace(maxDistance, partialTicks);
            Vec3d eyeVec = player.getPositionEyes(partialTicks);
            double currentDistance = maxDistance;
            if (traceResult != null) {
                currentDistance = traceResult.hitVec.distanceTo(eyeVec);
            }
            Vec3d lookVec = player.getLook(partialTicks);
            Vec3d lookingEyeVec = eyeVec.addVector(lookVec.x * maxDistance, lookVec.y * maxDistance, lookVec.z * maxDistance);
            pointedEntity = null;
            Vec3d calcVec = null;
            List<Entity> list = world.getEntitiesInAABBexcluding(player, player.getEntityBoundingBox().grow(lookVec.x * maxDistance, lookVec.y * maxDistance, lookVec.z * maxDistance).expand(1.0D, 1.0D, 1.0D), entity -> entity != null && (!(entity instanceof EntityItem) || ConfigBoolean.SHOW_DROPPED_ITEMS.value) && !ignoredEntities.contains(entity.getClass().getName()));
            double d2 = currentDistance;
            for (Entity entity : list) {
                double collisionBorder = entity.getCollisionBorderSize();
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand(collisionBorder, collisionBorder + (entity instanceof EntityItem ? 0.35 : 0), collisionBorder);
                RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(eyeVec, lookingEyeVec);
                if (axisalignedbb.contains(eyeVec)) {
                    if (d2 >= 0.0D) {
                        pointedEntity = entity;
                        calcVec = raytraceresult == null ? eyeVec : raytraceresult.hitVec;
                        d2 = 0.0D;
                    }
                } else if (raytraceresult != null) {
                    double d3 = eyeVec.distanceTo(raytraceresult.hitVec);
                    if (d3 < d2 || d2 == 0.0D) {
                        if (entity.getLowestRidingEntity() == player.getLowestRidingEntity() && !player.canRiderInteract()) {
                            if (d2 == 0.0D) {
                                pointedEntity = entity;
                                calcVec = raytraceresult.hitVec;
                            }
                        } else {
                            pointedEntity = entity;
                            calcVec = raytraceresult.hitVec;
                            d2 = d3;
                        }
                    }
                }
            }
            if (pointedEntity != null && (d2 < currentDistance || traceResult == null)) {
                traceResult = new RayTraceResult(pointedEntity, calcVec);
            }
        }
    }
    return traceResult;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) EntityItem(net.minecraft.entity.item.EntityItem)

Example 87 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Tropicraft by Tropicraft.

the class EntityFishHook method onUpdate.

/**
 * Called to update the entity's position/logic.
 */
@Override
public void onUpdate() {
    super.onUpdate();
    if (this.angler == null) {
        if (this.ticksExisted > 40) {
            setDead();
        }
        return;
    }
    if (this.world.isRemote) {
        int i = ((Integer) this.getDataManager().get(DATA_HOOKED_ENTITY)).intValue();
        if (i > 0 && this.caughtEntity == null) {
            this.caughtEntity = this.world.getEntityByID(i - 1);
        }
    } else {
        ItemStack itemstack = this.angler.getHeldItemMainhand();
        if (this.angler.isDead || !this.angler.isEntityAlive() || itemstack.isEmpty() || itemstack.getItem() != Items.FISHING_ROD || this.getDistanceSq(this.angler) > 1024.0D) {
            this.setDead();
            this.angler.setLure(null);
            return;
        }
    }
    if (this.caughtEntity != null) {
        if (!this.caughtEntity.isDead) {
            this.posX = this.caughtEntity.posX;
            double d17 = (double) this.caughtEntity.height;
            this.posY = this.caughtEntity.getEntityBoundingBox().minY + d17 * 0.8D;
            this.posZ = this.caughtEntity.posZ;
            return;
        }
        this.caughtEntity = null;
    }
    if (this.fishPosRotationIncrements > 0) {
        double d3 = this.posX + (this.fishX - this.posX) / (double) this.fishPosRotationIncrements;
        double d4 = this.posY + (this.fishY - this.posY) / (double) this.fishPosRotationIncrements;
        double d6 = this.posZ + (this.fishZ - this.posZ) / (double) this.fishPosRotationIncrements;
        double d8 = MathHelper.wrapDegrees(this.fishYaw - (double) this.rotationYaw);
        this.rotationYaw = (float) ((double) this.rotationYaw + d8 / (double) this.fishPosRotationIncrements);
        this.rotationPitch = (float) ((double) this.rotationPitch + (this.fishPitch - (double) this.rotationPitch) / (double) this.fishPosRotationIncrements);
        --this.fishPosRotationIncrements;
        this.setPosition(d3, d4, d6);
        this.setRotation(this.rotationYaw, this.rotationPitch);
    } else {
        if (this.inGround) {
            if (this.world.getBlockState(this.pos).getBlock() == this.inTile) {
                ++this.ticksInGround;
                if (this.ticksInGround == 1200) {
                    this.setDead();
                }
                return;
            }
            this.inGround = false;
            this.motionX *= (double) (this.rand.nextFloat() * 0.2F);
            this.motionY *= (double) (this.rand.nextFloat() * 0.2F);
            this.motionZ *= (double) (this.rand.nextFloat() * 0.2F);
            this.ticksInGround = 0;
            this.ticksInAir = 0;
        } else {
            ++this.ticksInAir;
        }
        if (!this.world.isRemote) {
            Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
            Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
            RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d);
            vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
            vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
            if (raytraceresult != null) {
                vec3d = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
            }
            Entity entity = null;
            List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
            double d0 = 0.0D;
            for (int j = 0; j < list.size(); ++j) {
                Entity entity1 = (Entity) list.get(j);
                if (this.canBeHooked(entity1) && (entity1 != this.angler || this.ticksInAir >= 5)) {
                    AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
                    RayTraceResult raytraceresult1 = axisalignedbb1.calculateIntercept(vec3d1, vec3d);
                    if (raytraceresult1 != null) {
                        double d1 = vec3d1.squareDistanceTo(raytraceresult1.hitVec);
                        if (d1 < d0 || d0 == 0.0D) {
                            entity = entity1;
                            d0 = d1;
                        }
                    }
                }
            }
            if (entity != null) {
                raytraceresult = new RayTraceResult(entity);
            }
            if (raytraceresult != null) {
                if (raytraceresult.entityHit != null) {
                    this.caughtEntity = raytraceresult.entityHit;
                    this.getDataManager().set(DATA_HOOKED_ENTITY, Integer.valueOf(this.caughtEntity.getEntityId() + 1));
                } else {
                    this.inGround = true;
                }
            }
        }
        if (!this.inGround) {
            this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
            float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
            this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
            for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, (double) f2) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
                ;
            }
            while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
                this.prevRotationPitch += 360.0F;
            }
            while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
                this.prevRotationYaw -= 360.0F;
            }
            while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
                this.prevRotationYaw += 360.0F;
            }
            this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
            this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
            float f3 = 0.92F;
            if (this.onGround || this.collidedHorizontally) {
                f3 = 0.5F;
            }
            int k = 5;
            double d5 = 0.0D;
            for (int l = 0; l < 5; ++l) {
                AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
                double d9 = axisalignedbb.maxY - axisalignedbb.minY;
                double d10 = axisalignedbb.minY + d9 * (double) l / 5.0D;
                double d11 = axisalignedbb.minY + d9 * (double) (l + 1) / 5.0D;
                AxisAlignedBB axisalignedbb2 = new AxisAlignedBB(axisalignedbb.minX, d10, axisalignedbb.minZ, axisalignedbb.maxX, d11, axisalignedbb.maxZ);
                if (this.world.isMaterialInBB(axisalignedbb2, Material.WATER)) {
                    d5 += 0.2D;
                }
            }
            if (!this.world.isRemote && d5 > 0.0D) {
                WorldServer worldserver = (WorldServer) this.world;
                int i1 = 1;
                BlockPos blockpos = (new BlockPos(this)).up();
                if (this.rand.nextFloat() < 0.25F && this.world.isRainingAt(blockpos)) {
                    i1 = 2;
                }
                if (this.rand.nextFloat() < 0.5F && !this.world.canSeeSky(blockpos)) {
                    --i1;
                }
                if (this.ticksCatchable > 0) {
                    --this.ticksCatchable;
                    if (this.ticksCatchable <= 0) {
                        this.ticksCaughtDelay = 0;
                        this.ticksCatchableDelay = 0;
                    }
                } else if (this.ticksCatchableDelay > 0) {
                    this.ticksCatchableDelay -= i1;
                    if (this.ticksCatchableDelay <= 0) {
                        this.motionY -= 0.20000000298023224D;
                        this.playSound(SoundEvents.ENTITY_BOBBER_SPLASH, 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
                        float f6 = (float) MathHelper.floor(this.getEntityBoundingBox().minY);
                        worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX, (double) (f6 + 1.0F), this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D, new int[0]);
                        worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, this.posX, (double) (f6 + 1.0F), this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D, new int[0]);
                        this.ticksCatchable = MathHelper.getInt(this.rand, 10, 30);
                    } else {
                        this.fishApproachAngle = (float) ((double) this.fishApproachAngle + this.rand.nextGaussian() * 4.0D);
                        float f5 = this.fishApproachAngle * 0.017453292F;
                        float f8 = MathHelper.sin(f5);
                        float f10 = MathHelper.cos(f5);
                        double d13 = this.posX + (double) (f8 * (float) this.ticksCatchableDelay * 0.1F);
                        double d15 = (double) ((float) MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
                        double d16 = this.posZ + (double) (f10 * (float) this.ticksCatchableDelay * 0.1F);
                        Block block1 = worldserver.getBlockState(new BlockPos((int) d13, (int) d15 - 1, (int) d16)).getBlock();
                        if (block1 == Blocks.WATER || block1 == Blocks.FLOWING_WATER) {
                            if (this.rand.nextFloat() < 0.15F) {
                                worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, d13, d15 - 0.10000000149011612D, d16, 1, (double) f8, 0.1D, (double) f10, 0.0D, new int[0]);
                            }
                            float f = f8 * 0.04F;
                            float f1 = f10 * 0.04F;
                            worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d13, d15, d16, 0, (double) f1, 0.01D, (double) (-f), 1.0D, new int[0]);
                            worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d13, d15, d16, 0, (double) (-f1), 0.01D, (double) f, 1.0D, new int[0]);
                        }
                    }
                } else if (this.ticksCaughtDelay > 0) {
                    this.ticksCaughtDelay -= i1;
                    float f4 = 0.15F;
                    if (this.ticksCaughtDelay < 20) {
                        f4 = (float) ((double) f4 + (double) (20 - this.ticksCaughtDelay) * 0.05D);
                    } else if (this.ticksCaughtDelay < 40) {
                        f4 = (float) ((double) f4 + (double) (40 - this.ticksCaughtDelay) * 0.02D);
                    } else if (this.ticksCaughtDelay < 60) {
                        f4 = (float) ((double) f4 + (double) (60 - this.ticksCaughtDelay) * 0.01D);
                    }
                    if (this.rand.nextFloat() < f4) {
                        float f7 = MathHelper.nextFloat(this.rand, 0.0F, 360.0F) * 0.017453292F;
                        float f9 = MathHelper.nextFloat(this.rand, 25.0F, 60.0F);
                        double d12 = this.posX + (double) (MathHelper.sin(f7) * f9 * 0.1F);
                        double d14 = (double) ((float) MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
                        double d2 = this.posZ + (double) (MathHelper.cos(f7) * f9 * 0.1F);
                        Block block = worldserver.getBlockState(new BlockPos((int) d12, (int) d14 - 1, (int) d2)).getBlock();
                        if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
                            worldserver.spawnParticle(EnumParticleTypes.WATER_SPLASH, d12, d14, d2, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D, new int[0]);
                        }
                    }
                    if (this.ticksCaughtDelay <= 0) {
                        this.fishApproachAngle = MathHelper.nextFloat(this.rand, 0.0F, 360.0F);
                        this.ticksCatchableDelay = MathHelper.getInt(this.rand, 20, 80);
                    }
                } else {
                    this.ticksCaughtDelay = MathHelper.getInt(this.rand, 100, 900);
                    this.ticksCaughtDelay -= EnchantmentHelper.getFishingSpeedBonus(EnchantmentHelper.getEnchantedItem(Enchantments.LURE, this.angler)) * 20 * 5;
                }
                if (this.ticksCatchable > 0) {
                    this.motionY -= (double) (this.rand.nextFloat() * this.rand.nextFloat() * this.rand.nextFloat()) * 0.2D;
                }
            }
            double d7 = d5 * 2.0D - 1.0D;
            this.motionY += 0.03999999910593033D * d7;
            if (d5 > 0.0D) {
                f3 = (float) ((double) f3 * 0.9D);
                this.motionY *= 0.8D;
            }
            this.motionX *= (double) f3;
            this.motionY *= (double) f3;
            this.motionZ *= (double) f3;
            this.setPosition(this.posX, this.posY, this.posZ);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 88 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Tropicraft by Tropicraft.

the class EntityChair method onUpdate.

/**
 * Called to update the entity's position/logic.
 */
@Override
public void onUpdate() {
    super.onUpdate();
    if (this.getTimeSinceHit() > 0) {
        this.setTimeSinceHit(this.getTimeSinceHit() - 1);
    }
    if (this.getDamage() > 0.0F) {
        this.setDamage(this.getDamage() - 1.0F);
    }
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    byte b0 = 5;
    double d0 = 0.0D;
    if (this.getComeSailAway())
        for (int i = 0; i < b0; ++i) {
            double d1 = this.getEntityBoundingBox().minY + (this.getEntityBoundingBox().maxY - this.getEntityBoundingBox().minY) * (double) (i + 0) / (double) b0 - 0.125D;
            double d3 = this.getEntityBoundingBox().minY + (this.getEntityBoundingBox().maxY - this.getEntityBoundingBox().minY) * (double) (i + 1) / (double) b0 - 0.125D;
            AxisAlignedBB axisalignedbb = new AxisAlignedBB(this.getEntityBoundingBox().minX, d1, this.getEntityBoundingBox().minZ, this.getEntityBoundingBox().maxX, d3, this.getEntityBoundingBox().maxZ);
            if (this.world.isMaterialInBB(axisalignedbb, Material.WATER)) {
                d0 += 1.0D / (double) b0;
            }
        }
    double d10 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
    double d2;
    double d4;
    int j;
    if (/*this.getComeSailAway() && */
    d10 > 0.26249999999999996D) {
        d2 = Math.cos((double) this.rotationYaw * Math.PI / 180.0D);
        d4 = Math.sin((double) this.rotationYaw * Math.PI / 180.0D);
        if (this.getComeSailAway())
            for (j = 0; (double) j < 1.0D + d10 * 60.0D; ++j) {
                double d5 = (double) (this.rand.nextFloat() * 2.0F - 1.0F);
                double d6 = (double) (this.rand.nextInt(2) * 2 - 1) * 0.7D;
                double d8;
                double d9;
                if (this.rand.nextBoolean()) {
                    d8 = this.posX - d2 * d5 * 0.8D + d4 * d6;
                    d9 = this.posZ - d4 * d5 * 0.8D - d2 * d6;
                    this.world.spawnParticle(EnumParticleTypes.WATER_SPLASH, d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
                } else {
                    d8 = this.posX + d2 + d4 * d5 * 0.7D;
                    d9 = this.posZ + d4 - d2 * d5 * 0.7D;
                    this.world.spawnParticle(EnumParticleTypes.WATER_SPLASH, d8, this.posY - 0.125D, d9, this.motionX, this.motionY, this.motionZ);
                }
            }
    }
    double d11;
    double d12;
    if (this.world.isRemote && this.isChairEmpty) {
        if (this.chairPosRotationIncrements > 0) {
            d2 = this.posX + (this.chairX - this.posX) / (double) this.chairPosRotationIncrements;
            d4 = this.posY + (this.chairY - this.posY) / (double) this.chairPosRotationIncrements;
            d11 = this.posZ + (this.chairZ - this.posZ) / (double) this.chairPosRotationIncrements;
            d12 = MathHelper.wrapDegrees(this.chairYaw - (double) this.rotationYaw);
            this.rotationYaw = (float) ((double) this.rotationYaw + d12 / (double) this.chairPosRotationIncrements);
            this.rotationPitch = (float) ((double) this.rotationPitch + (this.chairPitch - (double) this.rotationPitch) / (double) this.chairPosRotationIncrements);
            --this.chairPosRotationIncrements;
            this.setPosition(d2, d4, d11);
            this.setRotation(this.rotationYaw, this.rotationPitch);
        } else {
            d2 = this.posX + this.motionX;
            d4 = this.posY + this.motionY;
            d11 = this.posZ + this.motionZ;
            this.setPosition(d2, d4, d11);
            if (this.onGround) {
                this.motionX *= 0.5D;
                this.motionY *= 0.5D;
                this.motionZ *= 0.5D;
            }
            this.motionX *= 0.9900000095367432D;
            this.motionY *= 0.949999988079071D;
            this.motionZ *= 0.9900000095367432D;
        }
    } else {
        if (d0 < 1.0D) {
            d2 = d0 * 2.0D - 1.0D;
            this.motionY += 0.03999999910593033D * d2;
        } else {
            if (this.motionY < 0.0D) {
                this.motionY /= 2.0D;
            }
            this.motionY += 0.007000000216066837D;
        }
        if (this.getComeSailAway() && this.getControllingPassenger() != null && this.getControllingPassenger() instanceof EntityLivingBase) {
            EntityLivingBase entitylivingbase = (EntityLivingBase) this.getControllingPassenger();
            float f = this.getControllingPassenger().rotationYaw + -entitylivingbase.moveStrafing * 90.0F;
            this.motionX += -Math.sin((double) (f * (float) Math.PI / 180.0F)) * this.speedMultiplier * (double) entitylivingbase.moveForward * 0.05000000074505806D;
            this.motionZ += Math.cos((double) (f * (float) Math.PI / 180.0F)) * this.speedMultiplier * (double) entitylivingbase.moveForward * 0.05000000074505806D;
        }
        d2 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        if (d2 > 0.45D) {
            d4 = 0.45D / d2;
            this.motionX *= d4;
            this.motionZ *= d4;
            d2 = 0.45D;
        }
        if (d2 > d10 && this.speedMultiplier < 0.45D) {
            this.speedMultiplier += (0.45D - this.speedMultiplier) / 45.0D;
            if (this.speedMultiplier > 0.45D) {
                this.speedMultiplier = 0.45D;
            }
        } else {
            this.speedMultiplier -= (this.speedMultiplier - 0.10D) / 45.0D;
            if (this.speedMultiplier < 0.10D) {
                this.speedMultiplier = 0.10D;
            }
        }
        int l;
        if (this.getComeSailAway())
            for (l = 0; l < 4; ++l) {
                int i1 = MathHelper.floor(this.posX + ((double) (l % 2) - 0.5D) * 0.8D);
                j = MathHelper.floor(this.posZ + ((double) (l / 2) - 0.5D) * 0.8D);
                for (int j1 = 0; j1 < 2; ++j1) {
                    int k = MathHelper.floor(this.posY) + j1;
                    Block block = this.world.getBlockState(new BlockPos(i1, k, j)).getBlock();
                    BlockPos pos = new BlockPos(i1, k, j);
                    if (block == Blocks.SNOW_LAYER) {
                        this.world.setBlockToAir(pos);
                        this.collidedHorizontally = false;
                    } else if (block == Blocks.WATERLILY) {
                        this.world.setBlockToAir(pos);
                        this.collidedHorizontally = false;
                    }
                }
            }
        if (this.getComeSailAway() && this.onGround) {
            this.motionX *= 0.5D;
            this.motionY *= 0.5D;
            this.motionZ *= 0.5D;
        } else if (this.onGround) {
            this.motionX = 0;
            this.motionY = 0;
            this.motionZ = 0;
        }
        this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
        // In other words, when come sail away, there is no stopping this sucker
        if (this.getComeSailAway()) {
            this.motionX *= 0.9900000095367432D;
            this.motionY *= 0.949999988079071D;
            this.motionZ *= 0.9900000095367432D;
        }
        this.rotationPitch = 0.0F;
        d4 = (double) this.rotationYaw;
        d11 = this.prevPosX - this.posX;
        d12 = this.prevPosZ - this.posZ;
        if (d11 * d11 + d12 * d12 > 0.001D) {
            d4 = (double) ((float) (Math.atan2(d12, d11) * 180.0D / Math.PI));
        }
        double d7 = MathHelper.wrapDegrees(d4 - (double) this.rotationYaw);
        if (d7 > 20.0D) {
            d7 = 20.0D;
        }
        if (d7 < -20.0D) {
            d7 = -20.0D;
        }
        this.rotationYaw = (float) ((double) this.rotationYaw + d7);
        this.setRotation(this.rotationYaw, this.rotationPitch);
        if (!this.world.isRemote) {
            List<?> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D));
            if (list != null && !list.isEmpty()) {
                for (int k1 = 0; k1 < list.size(); ++k1) {
                    Entity entity = (Entity) list.get(k1);
                    if (entity != this.getControllingPassenger() && entity.canBePushed() && entity instanceof EntityChair) {
                        entity.applyEntityCollision(this);
                    }
                }
            }
            if (this.getControllingPassenger() != null && this.getControllingPassenger().isDead) {
                this.removePassengers();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 89 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Tropicraft by Tropicraft.

the class EntityEchinoderm method findMate.

private EntityEchinoderm findMate() {
    int neighbors = 0;
    EntityEchinoderm closestMate = null;
    double closestSqDist = -1f;
    AxisAlignedBB aabb = this.getEntityBoundingBox().grow(NEIGHBORHOOD_SIZE, NEIGHBORHOOD_SIZE, NEIGHBORHOOD_SIZE);
    for (Object obj : world.getEntitiesWithinAABB(getClass(), aabb)) {
        // don't masturbate
        if (obj == this) {
            continue;
        }
        neighbors++;
        EntityEchinoderm other = (EntityEchinoderm) obj;
        if (!isPotentialMate(other)) {
            continue;
        }
        double sqDist = getDistanceSq(other);
        if (sqDist < BREEDING_PROXIMITY && (closestSqDist == -1f || sqDist < closestSqDist)) {
            closestMate = other;
            closestSqDist = sqDist;
        }
    }
    if (neighbors > MAX_NEIGHBORS) {
        return null;
    } else {
        return closestMate;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB)

Example 90 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project Tropicraft by Tropicraft.

the class EntityTropicraftWaterBase method onLivingUpdate.

@Override
public void onLivingUpdate() {
    super.onLivingUpdate();
    // Remove this entity if difficulty is peaceful and it is capable of harming a player
    if (this instanceof IPredatorDiet && world.getDifficulty().equals(EnumDifficulty.PEACEFUL)) {
        boolean hasPlayer = false;
        Class[] prey = ((IPredatorDiet) this).getPreyClasses();
        for (Class c : prey) {
            if (c.getName().equals(EntityPlayer.class.getName())) {
                hasPlayer = true;
                break;
            }
        }
        if (hasPlayer) {
            this.setDead();
        }
    }
    // Client Side
    if (world.isRemote) {
        if (!(this instanceof IAmphibian)) {
            this.rotationPitch = -this.swimPitch;
            this.rotationYaw = -this.swimYaw;
            this.rotationYawHead = -this.swimYaw;
            this.prevRotationYawHead = -this.prevSwimYaw;
            this.renderYawOffset = 0;
            this.cameraPitch = -this.swimPitch;
            this.prevRotationPitch = -this.prevSwimPitch;
            this.prevRotationYaw = -this.prevSwimYaw;
            double x = (this.posX - this.prevPosX);
            double y = (this.posY - this.prevPosY);
            double z = (this.posZ - this.prevPosZ);
            float yaw;
            float pitch;
            this.prevSwimYaw = this.swimYaw;
            this.prevSwimPitch = this.swimPitch;
            if (this.posX == this.prevPosX && this.posZ == this.prevPosZ) {
                yaw = this.swimYaw;
            } else {
                yaw = (float) ((Math.atan2(z, x) * 180D) / Math.PI) - 90f;
            }
            if (this.posY == this.prevPosY) {
                pitch = this.swimPitch;
            } else {
                pitch = (float) (-((Math.atan2(y, MathHelper.sqrt(x * x + z * z)) * 180D) / Math.PI));
            }
            this.swimYaw = lerp(swimYaw, (int) -yaw, this.swimSpeedTurn * 4);
            this.swimPitch = lerp(swimPitch, (int) -pitch, this.swimSpeedTurn * 4);
            this.motionX *= 0.98f;
            this.motionY *= 0.98f;
            this.motionZ *= 0.98f;
            if (this.isAIDisabled() && this.isInWater()) {
                motionY = 0;
                fallVelocity = 0f;
                motionX = 0;
                motionZ = 0;
                swimSpeedCurrent = 0;
            }
        } else {
            this.rotationPitch = -this.swimPitch;
            if (this.isInWater()) {
                this.rotationYaw = -this.swimYaw;
                this.rotationYawHead = -this.swimYaw;
                this.prevRotationYawHead = -this.prevSwimYaw;
                this.renderYawOffset = 0;
                this.prevRotationYaw = -this.prevSwimYaw;
            } else {
                // this.prevSwimYaw = this.swimYaw;
                // this.swimYaw = -this.rotationYaw;
                this.rotationYawHead = this.rotationYaw;
            }
            this.cameraPitch = -this.swimPitch;
            this.prevRotationPitch = -this.prevSwimPitch;
            double x = (this.posX - this.prevPosX);
            double y = (this.posY - this.prevPosY);
            double z = (this.posZ - this.prevPosZ);
            float yaw;
            float pitch;
            if (this.posX == this.prevPosX && this.posZ == this.prevPosZ) {
                yaw = this.swimYaw;
            } else {
                yaw = (float) ((Math.atan2(z, x) * 180D) / Math.PI) - 90f;
            }
            if (this.posY == this.prevPosY) {
                pitch = this.swimPitch;
            } else {
                pitch = (float) (-((Math.atan2(y, MathHelper.sqrt(x * x + z * z)) * 180D) / Math.PI));
            }
            if (this.onGround && !this.isInWater()) {
                yaw = -this.rotationYawHead;
            }
            this.prevSwimYaw = this.swimYaw;
            this.prevSwimPitch = this.swimPitch;
            this.swimYaw = lerp(swimYaw, (int) -yaw, this.swimSpeedTurn * 2);
            this.swimPitch = lerp(swimPitch, (int) -pitch, this.swimSpeedTurn * 2);
        // this.motionX *= 0.98f;
        // this.motionY *= 0.98f;
        // this.motionZ *= 0.98f;
        }
        return;
    }
    if (((this instanceof IAmphibian) && this.isInWater()) || !(this instanceof IAmphibian)) {
        if (this.getHook() != null) {
            if (this.getHook().isDead || !world.loadedEntityList.contains(this.getHook())) {
                this.setHook(null);
            }
        }
        if (this.isInWater()) {
            // Yaw/Pitch lerp
            // *(1 + (swimSpeedCurrent/5));
            float swimSpeedTurn = this.swimSpeedTurn;
            if (this.isMovingAwayFromWall) {
                swimSpeedTurn *= 1.8f;
            }
            if (this.isFishable() && (this.ticksExisted + this.getEntityId()) % 80 == 0 && rand.nextInt(35) == 0) {
                List<EntityHook> ents = world.getEntitiesWithinAABB(EntityHook.class, new AxisAlignedBB(this.getPosition()).grow(16, 8, 16));
                for (int i = 0; i < ents.size(); i++) {
                    EntityHook h = ents.get(i);
                    if (this.canEntityBeSeen(h)) {
                        if (h.getHooked() == null && h.isInWater()) {
                            this.hookTarget = h;
                        }
                    }
                }
            }
            if (this.hookTarget != null) {
                if (this.hookTarget.isDead || !world.loadedEntityList.contains(this.hookTarget) || this.hookTarget.getHooked() != null) {
                    this.hookTarget = null;
                    this.setRandomTargetHeadingForce(10);
                } else {
                    if (this.ticksExisted % 20 == 0) {
                        this.setTargetHeading(hookTarget.posX, hookTarget.posY, hookTarget.posZ, false);
                    }
                    if (this.getDistanceSq(this.hookTarget) < 2D) {
                        if (this.hookTarget.getHooked() == null) {
                            this.hookTarget.setHooked(this);
                            this.hookTarget = null;
                        }
                    }
                }
            }
            if (getHook() != null) {
                // swimSpeedTurn *= 2f;
                EntityHook hook = (EntityHook) getHook();
                if (hook.getHooked() != null) {
                    if (!hook.getHooked().equals(this)) {
                        this.setHook(null);
                    } else {
                        EntityPlayer angler = hook.getAngler();
                        if (angler != null) {
                            if (this.getDistance(angler) > 2D) {
                                this.setTargetHeading(angler.posX, angler.posY, angler.posZ, false);
                            } else {
                                hook.bringInHookedEntity();
                                return;
                            }
                        } else {
                            hook.setHooked(null);
                            this.aggressTarget = null;
                            this.setRandomTargetHeadingForce(5);
                        }
                    }
                }
            }
            if (this.targetVectorHeading != null) {
                this.swimYaw = lerp(this.swimYaw, -this.targetVectorHeading.x, swimSpeedTurn);
                this.swimPitch = lerp(this.swimPitch, -this.targetVectorHeading.y, swimSpeedTurn);
            }
        }
        // Out of water
        if (!this.isInWater() && !(this instanceof IAmphibian)) {
            this.setTargetHeading(posX, posY - 1, posZ, false);
        }
        // Move speed
        float currentSpeed = this.swimSpeedCurrent;
        float desiredSpeed = this.swimSpeedDefault;
        if (this.aggressTarget != null) {
            if (this.getDistanceSq(this.aggressTarget) < 10f) {
                desiredSpeed = this.swimSpeedCharging;
            } else {
                desiredSpeed = this.swimSpeedChasing;
            }
        }
        if (this.hookTarget != null) {
            desiredSpeed = this.swimSpeedChasing;
        }
        if (this.isPanicking) {
            desiredSpeed = this.swimSpeedPanic;
        }
        if (this.ticksExisted % 50 < 30) {
            desiredSpeed *= 0.8f;
        }
        if (this.getIsLeader()) {
            desiredSpeed *= 0.95f;
        }
        if (this.isMovingAwayFromWall) {
            desiredSpeed *= 0.6f;
            currentSpeed *= 0.8f;
        }
        if (this.swimSpeedCurrent < desiredSpeed) {
            this.swimSpeedCurrent += this.swimAccelRate;
        }
        if (this.swimSpeedCurrent > desiredSpeed) {
            this.swimSpeedCurrent -= this.swimDecelRate;
        }
        // speed scaled down 1/10th
        currentSpeed *= 0.1f;
        // In water motion
        if (this.isInWater()) {
            motionX = currentSpeed * Math.sin(this.swimYaw * (Math.PI / 180.0));
            motionZ = currentSpeed * Math.cos(this.swimYaw * (Math.PI / 180.0));
            motionY = currentSpeed * Math.sin(this.swimPitch * (Math.PI / 180.0));
            fallVelocity = 0f;
        }
        if (this.isAIDisabled() && this.isInWater()) {
            motionY = 0;
            fallVelocity = 0f;
            motionX = 0;
            motionZ = 0;
            swimSpeedCurrent = 0;
        }
        // out of water motion
        if (!this.isInWater() && !(this instanceof IAmphibian)) {
            if (this.onGround) {
                if (rand.nextInt(6) == 0) {
                    this.motionX += rand.nextBoolean() ? rand.nextFloat() / 8 : -rand.nextFloat() / 8;
                    this.motionZ += rand.nextBoolean() ? rand.nextFloat() / 8 : -rand.nextFloat() / 8;
                }
                this.motionX *= 0.5f;
                this.motionZ *= 0.5f;
                if (this.ticksExisted % 4 == 0)
                    this.fallVelocity = -.02f;
                if (rand.nextInt(20) == 0 || this.hurtTime > 0) {
                    this.fallVelocity = -.03f;
                    this.swimPitch = 25f;
                }
            }
            if (this.swimPitch > 0f) {
                this.swimPitch -= 5f;
            }
            if (this.ticksExisted % 20 == 0) {
                this.outOfWaterAngle = rand.nextInt(360);
            }
            float turnSpeed = 5f;
            if (this.hurtTime > 0) {
                turnSpeed = 15f;
            }
            if (this.swimYaw > this.outOfWaterAngle) {
                this.swimYaw -= turnSpeed;
            }
            if (this.swimYaw < this.outOfWaterAngle) {
                this.swimYaw += turnSpeed;
            }
            float vel = this.fallVelocity;
            if (this.getPassengers().size() > 0) {
                vel *= 0.5f;
            }
            this.motionY -= vel;
            this.fallVelocity += (this.fallGravity / 10);
        }
        if (!this.isInWater() && (this instanceof IAmphibian)) {
            if (!onGround) {
                this.motionY -= this.fallVelocity;
                this.fallVelocity += (this.fallGravity / 10);
            } else {
                this.fallVelocity = 0f;
            }
        }
        if (swimPitch > 45f) {
            swimPitch = 45f;
        }
    } else {
        super.onLivingUpdate();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)597 BlockPos (net.minecraft.util.math.BlockPos)194 Entity (net.minecraft.entity.Entity)133 EntityPlayer (net.minecraft.entity.player.EntityPlayer)119 IBlockState (net.minecraft.block.state.IBlockState)110 Vec3d (net.minecraft.util.math.Vec3d)95 EntityLivingBase (net.minecraft.entity.EntityLivingBase)93 EnumFacing (net.minecraft.util.EnumFacing)88 ItemStack (net.minecraft.item.ItemStack)77 World (net.minecraft.world.World)69 TileEntity (net.minecraft.tileentity.TileEntity)67 List (java.util.List)48 ArrayList (java.util.ArrayList)47 RayTraceResult (net.minecraft.util.math.RayTraceResult)45 EntityItem (net.minecraft.entity.item.EntityItem)43 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)41 Block (net.minecraft.block.Block)36 PotionEffect (net.minecraft.potion.PotionEffect)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)25 Nullable (javax.annotation.Nullable)24