Search in sources :

Example 1 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class RayTrace method rayTraceBlocks.

// From World.rayTraceBlocks()
@Nullable
public static RayTraceResult rayTraceBlocks(@Nonnull final World world, Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) {
    final BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos();
    final IBlockAccessEx provider = WorldUtils.getDefaultBlockStateProvider();
    if (!Double.isNaN(vec31.x) && !Double.isNaN(vec31.y) && !Double.isNaN(vec31.z)) {
        if (!Double.isNaN(vec32.x) && !Double.isNaN(vec32.y) && !Double.isNaN(vec32.z)) {
            final int i = MathStuff.floor(vec32.x);
            final int j = MathStuff.floor(vec32.y);
            final int k = MathStuff.floor(vec32.z);
            int l = MathStuff.floor(vec31.x);
            int i1 = MathStuff.floor(vec31.y);
            int j1 = MathStuff.floor(vec31.z);
            blockpos.setPos(l, i1, j1);
            IBlockState iblockstate = provider.getBlockState(blockpos);
            Block block = iblockstate.getBlock();
            if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(world, blockpos) != Block.NULL_AABB) && block.canCollideCheck(iblockstate, stopOnLiquid)) {
                final RayTraceResult raytraceresult = iblockstate.collisionRayTrace(world, blockpos, vec31, vec32);
                if (raytraceresult != null) {
                    return raytraceresult;
                }
            }
            RayTraceResult raytraceresult2 = null;
            int k1 = 200;
            while (k1-- >= 0) {
                if (Double.isNaN(vec31.x) || Double.isNaN(vec31.y) || Double.isNaN(vec31.z)) {
                    return null;
                }
                if (l == i && i1 == j && j1 == k) {
                    return returnLastUncollidableBlock ? raytraceresult2 : null;
                }
                boolean flag2 = true;
                boolean flag = true;
                boolean flag1 = true;
                double d0 = 999.0D;
                double d1 = 999.0D;
                double d2 = 999.0D;
                if (i > l) {
                    d0 = l + 1.0D;
                } else if (i < l) {
                    d0 = l + 0.0D;
                } else {
                    flag2 = false;
                }
                if (j > i1) {
                    d1 = i1 + 1.0D;
                } else if (j < i1) {
                    d1 = i1 + 0.0D;
                } else {
                    flag = false;
                }
                if (k > j1) {
                    d2 = j1 + 1.0D;
                } else if (k < j1) {
                    d2 = j1 + 0.0D;
                } else {
                    flag1 = false;
                }
                double d3 = 999.0D;
                double d4 = 999.0D;
                double d5 = 999.0D;
                final double d6 = vec32.x - vec31.x;
                final double d7 = vec32.y - vec31.y;
                final double d8 = vec32.z - vec31.z;
                if (flag2) {
                    d3 = (d0 - vec31.x) / d6;
                }
                if (flag) {
                    d4 = (d1 - vec31.y) / d7;
                }
                if (flag1) {
                    d5 = (d2 - vec31.z) / d8;
                }
                if (d3 == -0.0D) {
                    d3 = -1.0E-4D;
                }
                if (d4 == -0.0D) {
                    d4 = -1.0E-4D;
                }
                if (d5 == -0.0D) {
                    d5 = -1.0E-4D;
                }
                EnumFacing enumfacing;
                if (d3 < d4 && d3 < d5) {
                    enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
                    vec31 = new Vec3d(d0, vec31.y + d7 * d3, vec31.z + d8 * d3);
                } else if (d4 < d5) {
                    enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
                    vec31 = new Vec3d(vec31.x + d6 * d4, d1, vec31.z + d8 * d4);
                } else {
                    enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
                    vec31 = new Vec3d(vec31.x + d6 * d5, vec31.y + d7 * d5, d2);
                }
                l = MathStuff.floor(vec31.x) - (enumfacing == EnumFacing.EAST ? 1 : 0);
                i1 = MathStuff.floor(vec31.y) - (enumfacing == EnumFacing.UP ? 1 : 0);
                j1 = MathStuff.floor(vec31.z) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
                blockpos.setPos(l, i1, j1);
                iblockstate = provider.getBlockState(blockpos);
                block = iblockstate.getBlock();
                if (!ignoreBlockWithoutBoundingBox || iblockstate.getMaterial() == Material.PORTAL || iblockstate.getCollisionBoundingBox(world, blockpos) != Block.NULL_AABB) {
                    if (block.canCollideCheck(iblockstate, stopOnLiquid)) {
                        final RayTraceResult raytraceresult1 = iblockstate.collisionRayTrace(world, blockpos, vec31, vec32);
                        if (raytraceresult1 != null) {
                            return raytraceresult1;
                        }
                    } else {
                        raytraceresult2 = new RayTraceResult(RayTraceResult.Type.MISS, vec31, enumfacing, blockpos);
                    }
                }
            }
            return returnLastUncollidableBlock ? raytraceresult2 : null;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) Nullable(javax.annotation.Nullable)

Example 2 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class CuboidScanner method updateScan.

protected void updateScan(@Nonnull final Cuboid newVolume, @Nonnull final Cuboid oldVolume, @Nonnull final Cuboid intersect) {
    final IBlockAccessEx provider = this.locus.getWorld();
    if (doBlockUnscan()) {
        final ComplementsPointIterator newOutOfRange = new ComplementsPointIterator(oldVolume, intersect);
        // Notify on the blocks going out of range
        for (BlockPos point = newOutOfRange.next(); point != null; point = newOutOfRange.next()) {
            if (point.getY() > 0) {
                final IBlockState state = provider.getBlockState(point);
                if (interestingBlock(state))
                    blockUnscan(state, point, this.random);
            }
        }
    }
    // Notify on blocks coming into range
    final ComplementsPointIterator newInRange = new ComplementsPointIterator(newVolume, intersect);
    for (BlockPos point = newInRange.next(); point != null; point = newInRange.next()) {
        if (point.getY() > 0) {
            final IBlockState state = provider.getBlockState(point);
            if (interestingBlock(state))
                blockScan(state, point, this.random);
        }
    }
    this.scanFinished = true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class CuboidScanner method nextPos.

@Override
@Nullable
protected BlockPos nextPos(@Nonnull final BlockPos.MutableBlockPos workingPos, @Nonnull final Random rand) {
    if (this.scanFinished)
        return null;
    final IBlockAccessEx provider = this.locus.getWorld();
    int checked = 0;
    BlockPos point = null;
    while ((point = this.fullRange.peek()) != null) {
        // Chunk not loaded we need to skip this tick
        if (!provider.isAvailable(point))
            return null;
        // Consume the point
        this.fullRange.next();
        // be returned.
        if (point.getY() > 0) {
            return point;
        }
        // to examine the next point.
        if (++checked >= this.blocksPerTick)
            return null;
    }
    this.scanFinished = true;
    return null;
}
Also used : IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 4 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class LightLevelHUD method updateLightInfo.

protected static void updateLightInfo(@Nonnull final RenderManager manager, final double x, final double y, final double z) {
    font = Minecraft.getMinecraft().fontRenderer;
    final boolean isThirdPerson = manager.options.thirdPersonView == 2;
    // Position frustum behind the player in order to reduce
    // clipping of nearby light level textures. Purpose of the
    // frustum is to reduce processing requirements and does
    // not have to be perfect.
    final EntityPlayer player = EnvironState.getPlayer();
    final Vec3d lookVec = player.getLookVec();
    final double fX, fY, fZ;
    if (isThirdPerson) {
        fX = x + lookVec.x * 2D;
        fY = y + lookVec.y * 2D;
        fZ = z + lookVec.z * 2D;
    } else {
        fX = x - lookVec.x * 2D;
        fY = y - lookVec.y * 2D;
        fZ = z - lookVec.z * 2D;
    }
    frustum.setPosition(fX, fY, fZ);
    nextCoord = 0;
    final ColorSet colors = ColorSet.getStyle(ModOptions.lightlevel.llColors);
    final Mode displayMode = Mode.getMode(ModOptions.lightlevel.llDisplayMode);
    final int skyLightSub = EnvironState.getWorld().calculateSkylightSubtracted(1.0F);
    final int rangeXZ = ModOptions.lightlevel.llBlockRange * 2 + 1;
    final int rangeY = ModOptions.lightlevel.llBlockRange + 1;
    final int originX = MathStuff.floor(x) - (rangeXZ / 2);
    final int originZ = MathStuff.floor(z) - (rangeXZ / 2);
    final int originY = MathStuff.floor(y) - (rangeY - 3);
    final IBlockAccessEx blocks = ClientChunkCache.INSTANCE;
    for (int dX = 0; dX < rangeXZ; dX++) for (int dZ = 0; dZ < rangeXZ; dZ++) {
        final int trueX = originX + dX;
        final int trueZ = originZ + dZ;
        if (!blocks.isAvailable(trueX, trueZ))
            return;
        IBlockState lastState = null;
        for (int dY = 0; dY < rangeY; dY++) {
            final int trueY = originY + dY;
            if (trueY < 1 || !inFrustum(trueX, trueY, trueZ))
                continue;
            final IBlockState state = blocks.getBlockState(trueX, trueY, trueZ);
            if (lastState == null)
                lastState = blocks.getBlockState(trueX, trueY - 1, trueZ);
            if (renderLightLevel(state, lastState)) {
                mutable.setPos(trueX, trueY, trueZ);
                final boolean mobSpawn = canMobSpawn(mutable);
                if (mobSpawn || !ModOptions.lightlevel.llHideSafe) {
                    final int blockLight = blocks.getLightFor(EnumSkyBlock.BLOCK, mutable);
                    final int skyLight = blocks.getLightFor(EnumSkyBlock.SKY, mutable) - skyLightSub;
                    final int effective = Math.max(blockLight, skyLight);
                    final int result = displayMode == Mode.BLOCK_SKY ? effective : blockLight;
                    Color color = colors.safe;
                    if (!mobSpawn) {
                        color = colors.noSpawn;
                    } else if (blockLight <= ModOptions.lightlevel.llSpawnThreshold) {
                        if (effective > ModOptions.lightlevel.llSpawnThreshold)
                            color = colors.caution;
                        else
                            color = colors.hazard;
                    }
                    if (!(color == colors.safe && ModOptions.lightlevel.llHideSafe)) {
                        final LightCoord coord = nextCoord();
                        coord.x = trueX;
                        coord.y = trueY + heightAdjustment(state, lastState, mutable);
                        coord.z = trueZ;
                        coord.lightLevel = result;
                        coord.color = color;
                    }
                }
            }
            lastState = state;
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) Color(org.blockartistry.lib.Color) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with IBlockAccessEx

use of org.blockartistry.lib.chunk.IBlockAccessEx in project DynamicSurroundings by OreCruncher.

the class Scanner method update.

@Override
public void update() {
    preScan();
    final IBlockAccessEx provider = this.locus.getWorld();
    for (int count = 0; count < this.blocksPerTick; count++) {
        final BlockPos pos = nextPos(this.workingPos, this.random);
        if (pos == null)
            break;
        final IBlockState state = provider.getBlockState(pos);
        if (interestingBlock(state)) {
            blockScan(state, pos, this.random);
        }
    }
    postScan();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockAccessEx(org.blockartistry.lib.chunk.IBlockAccessEx) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IBlockAccessEx (org.blockartistry.lib.chunk.IBlockAccessEx)10 BlockPos (net.minecraft.util.math.BlockPos)7 IBlockState (net.minecraft.block.state.IBlockState)4 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Vec3d (net.minecraft.util.math.Vec3d)2 BlockEffect (org.blockartistry.DynSurround.client.fx.BlockEffect)2 BiomeInfo (org.blockartistry.DynSurround.registry.BiomeInfo)2 Color (org.blockartistry.lib.Color)2 TObjectIntCustomHashMap (gnu.trove.map.custom_hash.TObjectIntCustomHashMap)1 Block (net.minecraft.block.Block)1 GameSettings (net.minecraft.client.settings.GameSettings)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 World (net.minecraft.world.World)1 Biome (net.minecraft.world.biome.Biome)1 SoundEffect (org.blockartistry.DynSurround.client.sound.SoundEffect)1