Search in sources :

Example 91 with AxisAlignedBB

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

the class EntityHook method onUpdate.

/**
 * Called to update the entity's position/logic.
 */
@Override
public void onUpdate() {
    super.onUpdate();
    if (world.isRemote) {
        this.angler = this.getAngler();
    }
    if (this.angler == null) {
        setDead();
        return;
    }
    if (!world.isRemote) {
        ItemStack itemstack = this.angler.getHeldItemMainhand();
        if (this.angler.isDead || !this.angler.isEntityAlive() || itemstack.isEmpty() || itemstack.getItem() != ItemRegistry.fishingRod || this.getDistanceSq(this.angler) > 1024.0D) {
            this.setDead();
            // this.angler.setLure(null);
            return;
        }
    }
    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 result = 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 (result != null) {
            vec3d = new Vec3d(result.hitVec.x, result.hitVec.y, result.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) {
            result = new RayTraceResult(entity);
        }
        if (result != null) {
            if (result.entityHit != null) {
                if (this.getHooked() == null)
                    this.setHooked(result.entityHit);
            } else {
                this.inGround = true;
            }
        }
    }
    if (!this.inGround) {
        if (this.world.isMaterialInBB(this.getEntityBoundingBox().offset(0, 0.0D, 0), Material.WATER)) {
            if (this.motionY < -.05f) {
                this.motionY = -.05f;
            }
            this.motionY += 0.01D;
        } else {
            if (this.motionY > 0) {
                this.motionY *= 0.9D;
            }
            this.motionY -= 0.02D;
        }
        this.motionX *= 0.9D;
        this.motionZ *= 0.9D;
        this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
        this.setPosition(this.posX, this.posY, this.posZ);
        if (this.getHooked() != null) {
            this.setPosition(this.getHooked().posX, this.getHooked().posY + (this.getHooked().height * 0.5f), this.getHooked().posZ);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 92 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class TravelController method canTeleportTo.

private boolean canTeleportTo(@Nonnull EntityPlayer player, @Nonnull TravelSource source, @Nonnull BlockPos bc, @Nonnull World w) {
    if (bc.getY() < 1) {
        return false;
    }
    if (source == TravelSource.STAFF_BLINK && !Config.travelStaffBlinkThroughSolidBlocksEnabled) {
        Vec3d start = Util.getEyePosition(player);
        Vec3d target = new Vec3d(bc.getX() + 0.5f, bc.getY() + 0.5f, bc.getZ() + 0.5f);
        if (!canBlinkTo(bc, w, start, target)) {
            return false;
        }
    }
    IBlockState bs = w.getBlockState(bc);
    Block block = bs.getBlock();
    if (block.isAir(bs, w, bc)) {
        return true;
    }
    final AxisAlignedBB aabb = bs.getBoundingBox(w, bc);
    return aabb.getAverageEdgeLength() < 0.7;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d)

Example 93 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method getSelectedBoundingBox.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
    TileConduitBundle te = getTileEntity(world, pos);
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (te == null) {
        // FIXME is this valid?
        return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
    }
    IConduitBundle con = te;
    BoundingBox minBB = null;
    if (!YetaUtil.isSolidFacadeRendered(con, player)) {
        List<RaytraceResult> results = doRayTraceAll(world, pos, player);
        Iterator<RaytraceResult> iter = results.iterator();
        while (iter.hasNext()) {
            CollidableComponent component = iter.next().component;
            if (component != null && component.conduitType == null && component.data != ConduitConnectorType.EXTERNAL) {
                iter.remove();
            }
        }
        // This is an ugly special case, TODO fix this
        for (RaytraceResult hit : results) {
            IRedstoneConduit cond = con.getConduit(IRedstoneConduit.class);
            CollidableComponent component = hit.component;
            EnumFacing dir = component == null ? null : component.dir;
            if (cond != null && component != null && dir != null && cond.getExternalConnections().contains(dir) && component.data == InsulatedRedstoneConduit.COLOR_CONTROLLER_ID) {
                minBB = component.bound;
            }
        }
        if (minBB == null) {
            RaytraceResult hit = RaytraceResult.getClosestHit(Util.getEyePosition(player), results);
            CollidableComponent component = hit == null ? null : hit.component;
            if (component != null) {
                EnumFacing dir = component.dir;
                minBB = component.bound;
                if (dir != null && component.conduitType == null) {
                    dir = dir.getOpposite();
                    float trans = 0.0125f;
                    minBB = minBB.translate(dir.getFrontOffsetX() * trans, dir.getFrontOffsetY() * trans, dir.getFrontOffsetZ() * trans);
                    float scale = 0.7f;
                    minBB = minBB.scale(1 + Math.abs(dir.getFrontOffsetX()) * scale, 1 + Math.abs(dir.getFrontOffsetY()) * scale, 1 + Math.abs(dir.getFrontOffsetZ()) * scale);
                } else {
                    minBB = minBB.scale(1.09, 1.09, 1.09);
                }
            }
        }
    } else {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    if (minBB == null) {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    return new AxisAlignedBB(pos.getX() + minBB.minX, pos.getY() + minBB.minY, pos.getZ() + minBB.minZ, pos.getX() + minBB.maxX, pos.getY() + minBB.maxY, pos.getZ() + minBB.maxZ);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IRedstoneConduit(crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 94 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class ItemDarkSteelShears method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(@Nonnull ItemStack itemstack, @Nonnull EntityPlayer player, @Nonnull EntityLivingBase entity, @Nonnull EnumHand hand) {
    if (entity.world.isRemote) {
        return false;
    }
    int powerStored = getStoredPower(player);
    if (powerStored < Config.darkSteelShearsPowerUsePerDamagePoint) {
        return super.itemInteractionForEntity(itemstack, player, entity, hand);
    }
    if (entity instanceof IShearable) {
        AxisAlignedBB bb = new AxisAlignedBB(entity.posX - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ - Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posX + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posY + Config.darkSteelShearsEntityAreaBoostWhenPowered, entity.posZ + Config.darkSteelShearsEntityAreaBoostWhenPowered);
        List<Entity> sortedTargets = new ArrayList<Entity>(entity.world.getEntitiesWithinAABB(Entity.class, bb, selectShearable));
        entityComparator.refPoint = entity;
        Collections.sort(sortedTargets, entityComparator);
        boolean result = false;
        int maxSheep = Math.min(sortedTargets.size(), powerStored / Config.darkSteelShearsPowerUsePerDamagePoint);
        for (int i = 0; i < maxSheep; i++) {
            Entity entity2 = sortedTargets.get(i);
            if (entity2 instanceof EntityLivingBase && super.itemInteractionForEntity(itemstack, player, (EntityLivingBase) entity2, hand)) {
                result = true;
            }
        }
        return result;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IShearable(net.minecraftforge.common.IShearable) ArrayList(java.util.ArrayList) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 95 with AxisAlignedBB

use of net.minecraft.util.math.AxisAlignedBB in project EnderIO by SleepyTrousers.

the class TeleportEntityRenderHandler method onEntityRender.

/*
   * gl flags when this is called: GL_ALPHA_TEST GL_COLOR_MATERIAL GL_CULL_FACE GL_DEPTH_TEST GL_DITHER GL_FOG GL_LIGHTING GL_TEXTURE_2D
   */
@SubscribeEvent
public static void onEntityRender(RenderLivingEvent.Post<EntityLivingBase> event) {
    EntityLivingBase e = event.getEntity();
    if (e.getEntityData().getBoolean("eio_needs_pop")) {
        GlStateManager.popMatrix();
        e.getEntityData().removeTag("eio_needs_pop");
    }
    if (e.getEntityData().getBoolean(TileTelePad.TELEPORTING_KEY)) {
        final float progress = e.getEntityData().getFloat(TileTelePad.PROGRESS_KEY);
        final float speed = progress * 1.2f;
        final float rot = (e.getEntityData().getFloat("eio_teleportrotation")) + speed;
        e.getEntityData().setFloat("eio_teleportrotation", rot);
        AxisAlignedBB bb = e.getRenderBoundingBox();
        if (NullHelper.untrust(bb) == null || bb.getAverageEdgeLength() < .2) {
            float radius = e.width / 2.0F;
            bb = new AxisAlignedBB(-radius, 0, -radius, radius, e.height, radius).offset(e.posX, e.posY, e.posZ);
        }
        bb = bb.setMaxY(bb.maxY + 1.25 - progress / 2).expand(0.5 - progress / 5, 0, 0.5 - progress / 5);
        GlStateManager.pushMatrix();
        GlStateManager.disableTexture2D();
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE);
        GlStateManager.disableAlpha();
        GlStateManager.disableCull();
        GlStateManager.disableLighting();
        GlStateManager.depthMask(false);
        GlStateManager.translate(event.getX(), event.getY(), event.getZ());
        GlStateManager.rotate(rot + Minecraft.getMinecraft().getRenderPartialTicks() + e.ticksExisted, 0, 1, 0);
        Tessellator tes = Tessellator.getInstance();
        BufferBuilder vertexBuffer = tes.getBuffer();
        vertexBuffer.setTranslation(-e.posX, -e.posY, -e.posZ);
        vertexBuffer.begin(GL11.GL_QUAD_STRIP, DefaultVertexFormats.POSITION_COLOR);
        vertexBuffer.pos(bb.maxX, bb.maxY, bb.maxZ).color(COL_TOP.x, COL_TOP.y, COL_TOP.z, COL_TOP.w).endVertex();
        vertexBuffer.pos(bb.maxX, bb.minY, bb.maxZ).color(COL_BOT.x, COL_BOT.y, COL_BOT.z, COL_BOT.w).endVertex();
        vertexBuffer.pos(bb.minX, bb.maxY, bb.maxZ).color(COL_TOP.x, COL_TOP.y, COL_TOP.z, COL_TOP.w).endVertex();
        vertexBuffer.pos(bb.minX, bb.minY, bb.maxZ).color(COL_BOT.x, COL_BOT.y, COL_BOT.z, COL_BOT.w).endVertex();
        vertexBuffer.pos(bb.minX, bb.maxY, bb.minZ).color(COL_TOP.x, COL_TOP.y, COL_TOP.z, COL_TOP.w).endVertex();
        vertexBuffer.pos(bb.minX, bb.minY, bb.minZ).color(COL_BOT.x, COL_BOT.y, COL_BOT.z, COL_BOT.w).endVertex();
        vertexBuffer.pos(bb.maxX, bb.maxY, bb.minZ).color(COL_TOP.x, COL_TOP.y, COL_TOP.z, COL_TOP.w).endVertex();
        vertexBuffer.pos(bb.maxX, bb.minY, bb.minZ).color(COL_BOT.x, COL_BOT.y, COL_BOT.z, COL_BOT.w).endVertex();
        vertexBuffer.pos(bb.maxX, bb.maxY, bb.maxZ).color(COL_TOP.x, COL_TOP.y, COL_TOP.z, COL_TOP.w).endVertex();
        vertexBuffer.pos(bb.maxX, bb.minY, bb.maxZ).color(COL_BOT.x, COL_BOT.y, COL_BOT.z, COL_BOT.w).endVertex();
        tes.draw();
        GlStateManager.enableTexture2D();
        GlStateManager.disableBlend();
        GlStateManager.enableAlpha();
        GlStateManager.enableCull();
        GlStateManager.enableLighting();
        GlStateManager.depthMask(true);
        GlStateManager.popMatrix();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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