Search in sources :

Example 81 with AxisAlignedBB

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

the class EntityButterfly method getBlockPathWeight.

@Override
public float getBlockPathWeight(BlockPos pos) {
    if (!world.isBlockLoaded(pos)) {
        return -100f;
    }
    float weight = 0.0f;
    double distanceToHome = getHomePosition().distanceSq(pos);
    if (!isWithinHomeDistanceFromPosition(distanceToHome)) {
        weight -= 7.5f + 0.005 * (distanceToHome / 4);
    }
    if (!getButterfly().isAcceptedEnvironment(world, pos.getX(), pos.getY(), pos.getZ())) {
        weight -= 15.0f;
    }
    if (!world.getEntitiesWithinAABB(EntityButterfly.class, new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1)).isEmpty()) {
        weight -= 1.0f;
    }
    int depth = getFluidDepth(pos);
    if (depth > 0) {
        weight -= 0.1f * depth;
    } else {
        IBlockState blockState = world.getBlockState(pos);
        Block block = blockState.getBlock();
        if (block instanceof BlockFlower) {
            weight += 2.0f;
        } else if (block instanceof IPlantable) {
            weight += 1.5f;
        } else if (block instanceof IGrowable) {
            weight += 1.0f;
        } else if (blockState.getMaterial() == Material.PLANTS) {
            weight += 1.0f;
        }
        BlockPos posBelow = pos.down();
        IBlockState blockStateBelow = world.getBlockState(posBelow);
        Block blockBelow = blockStateBelow.getBlock();
        if (blockBelow.isLeaves(blockStateBelow, world, posBelow)) {
            weight += 2.5f;
        } else if (blockBelow instanceof BlockFence) {
            weight += 1.0f;
        } else if (blockBelow instanceof BlockWall) {
            weight += 1.0f;
        }
    }
    weight += world.getLightBrightness(pos);
    return weight;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockWall(net.minecraft.block.BlockWall) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockFence(net.minecraft.block.BlockFence) BlockFlower(net.minecraft.block.BlockFlower)

Example 82 with AxisAlignedBB

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

the class MultiblockEventHandlerClient method onWorldRenderLast.

@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
    if (GeneticsUtil.hasNaturalistEye(Minecraft.getMinecraft().player)) {
        try {
            World world = Minecraft.getMinecraft().world;
            Set<IMultiblockControllerInternal> controllers = MultiblockRegistry.getControllersFromWorld(world);
            if (!controllers.isEmpty()) {
                float partialTicks = event.getPartialTicks();
                EntityPlayer player = Minecraft.getMinecraft().player;
                double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
                double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
                double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
                GlStateManager.pushMatrix();
                GlStateManager.enableBlend();
                GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
                GlStateManager.disableTexture2D();
                GlStateManager.glLineWidth(2.0F);
                GlStateManager.depthMask(false);
                for (IMultiblockController controller : controllers) {
                    if (controller != null) {
                        BlockPos lastErrorPosition = controller.getLastValidationErrorPosition();
                        if (lastErrorPosition != null) {
                            if (world.isBlockLoaded(lastErrorPosition) && player.getDistanceSq(lastErrorPosition) < 64F) {
                                AxisAlignedBB box = Block.FULL_BLOCK_AABB.offset(lastErrorPosition.getX() - playerX, lastErrorPosition.getY() - playerY, lastErrorPosition.getZ() - playerZ);
                                RenderGlobal.drawSelectionBoundingBox(box, 1.0F, 0.0F, 0.0F, 0.25F);
                                RenderGlobal.renderFilledBox(box, 1.0F, 0.0F, 0.0F, 0.125F);
                            }
                        }
                    }
                }
                GlStateManager.depthMask(true);
                GlStateManager.enableTexture2D();
                GlStateManager.disableBlend();
                GlStateManager.popMatrix();
            }
        } catch (Exception e) {
            Log.error("Failed to render the position of a multiblock exception.", e);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IMultiblockController(forestry.api.multiblock.IMultiblockController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 83 with AxisAlignedBB

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

the class ParticleHelper method addBlockHitEffects.

@SideOnly(Side.CLIENT)
public static boolean addBlockHitEffects(World world, BlockPos pos, EnumFacing side, ParticleManager effectRenderer, Callback callback) {
    IBlockState iblockstate = world.getBlockState(pos);
    if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE) {
        int x = pos.getX();
        int y = pos.getY();
        int z = pos.getZ();
        float f = 0.1F;
        AxisAlignedBB axisalignedbb = iblockstate.getBoundingBox(world, pos);
        double px = x + world.rand.nextDouble() * (axisalignedbb.maxX - axisalignedbb.minX - f * 2.0F) + f + axisalignedbb.minX;
        double py = y + world.rand.nextDouble() * (axisalignedbb.maxY - axisalignedbb.minY - f * 2.0F) + f + axisalignedbb.minY;
        double pz = z + world.rand.nextDouble() * (axisalignedbb.maxZ - axisalignedbb.minZ - f * 2.0F) + f + axisalignedbb.minZ;
        if (side == EnumFacing.DOWN) {
            py = y + axisalignedbb.minY - f;
        }
        if (side == EnumFacing.UP) {
            py = y + axisalignedbb.maxY + f;
        }
        if (side == EnumFacing.NORTH) {
            pz = z + axisalignedbb.minZ - f;
        }
        if (side == EnumFacing.SOUTH) {
            pz = z + axisalignedbb.maxZ + f;
        }
        if (side == EnumFacing.WEST) {
            px = x + axisalignedbb.minX - f;
        }
        if (side == EnumFacing.EAST) {
            px = x + axisalignedbb.maxX + f;
        }
        ParticleDigging fx = (ParticleDigging) effectRenderer.spawnEffectParticle(EnumParticleTypes.BLOCK_DUST.getParticleID(), px, py, pz, 0.0D, 0.0D, 0.0D, Block.getStateId(iblockstate));
        if (fx != null) {
            callback.addHitEffects(fx, world, pos, iblockstate);
            effectRenderer.addEffect(fx.setBlockPos(new BlockPos(x, y, z)).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) ParticleDigging(net.minecraft.client.particle.ParticleDigging) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 84 with AxisAlignedBB

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

the class WallBlockHandler method isAirBlock.

/**
 * Same as {@link World#isAirBlock(BlockPos)} but faster
 */
private boolean isAirBlock(World world, BlockPos pos) {
    IBlockState blockState = world.getBlockState(pos);
    AxisAlignedBB collisionBB = blockState.getCollisionBoundingBox(world, pos);
    return collisionBB == null || collisionBB.equals(Block.NULL_AABB) || blockState.getBlock().isLeaves(blockState, world, pos);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState)

Example 85 with AxisAlignedBB

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

the class GreenhouseProviderServer method getHeight.

public int getHeight(BlockPos pos, int maximalHeight) {
    int worldHeight = world.getHeight();
    BlockPos.MutableBlockPos position = new BlockPos.MutableBlockPos(pos);
    int height = -1;
    while (position.getY() <= worldHeight && position.getY() <= maximalHeight && height == -1) {
        IBlockState blockState = world.getBlockState(position);
        AxisAlignedBB collisionBB = blockState.getCollisionBoundingBox(world, pos);
        if (collisionBB == null || collisionBB.equals(Block.NULL_AABB) || blockState.getBlock().isLeaves(blockState, world, pos)) {
            position.move(EnumFacing.UP);
        } else {
            height = position.down().getY();
        }
    }
    return height;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

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