Search in sources :

Example 71 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class DenseDeposit method afterGen.

/**
 * Handles what to do after the world has generated
 */
@Override
public void afterGen(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
    // Debug the pluton
    if (CommonConfig.DEBUG_WORLD_GEN.get()) {
        Geolosys.getInstance().LOGGER.debug("Generated {} in Chunk {} (Pos [{} {} {}])", this.toString(), new ChunkPos(pos), pos.getX(), pos.getY(), pos.getZ());
    }
    ChunkPos thisChunk = new ChunkPos(pos);
    int maxSampleCnt = Math.min(CommonConfig.MAX_SAMPLES_PER_CHUNK.get(), (this.size / CommonConfig.MAX_SAMPLES_PER_CHUNK.get()) + (this.size % CommonConfig.MAX_SAMPLES_PER_CHUNK.get()));
    for (int i = 0; i < maxSampleCnt; i++) {
        BlockPos samplePos = SampleUtils.getSamplePosition(reader, new ChunkPos(pos));
        BlockState tmp = this.getSample();
        if (tmp == null) {
            continue;
        }
        if (samplePos == null || SampleUtils.inNonWaterFluid(reader, samplePos)) {
            continue;
        }
        if (SampleUtils.isInWater(reader, samplePos) && tmp.hasProperty(BlockStateProperties.WATERLOGGED)) {
            tmp = tmp.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true));
        }
        FeatureUtils.tryPlaceBlock(reader, thisChunk, samplePos, tmp, cap);
        FeatureUtils.fixSnowyBlock(reader, samplePos);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 72 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class DenseDeposit method generate.

/**
 * Handles full-on generation of this type of pluton. Requires 0 arguments as
 * everything is self-contained in this class
 *
 * @return (int) the number of pluton resource blocks placed. If 0 -- this
 *         should be evaluted as a false for use of Mojang's sort-of sketchy
 *         generation code in
 *         {@link DepositFeature#generate(net.minecraft.world.ISeedReader, net.minecraft.world.gen.ChunkGenerator, java.util.Random, net.minecraft.util.math.BlockPos, net.minecraft.world.gen.feature.NoFeatureConfig)}
 */
@Override
public int generate(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
    /* Check biome allowance */
    if (!DepositUtils.canPlaceInBiome(reader.getBiome(pos), this.biomeFilter, this.biomeTypeFilter, this.isBiomeFilterBl)) {
        return 0;
    }
    int totlPlaced = 0;
    ChunkPos thisChunk = new ChunkPos(pos);
    int randY = this.yMin + reader.getRandom().nextInt(this.yMax - this.yMin);
    int max = Utils.getTopSolidBlock(reader, pos).getY();
    if (randY > max) {
        randY = Math.max(yMin, max);
    }
    float ranFlt = reader.getRandom().nextFloat() * (float) Math.PI;
    double x1 = (float) (pos.getX() + 8) + MathHelper.sin(ranFlt) * (float) this.size / 8.0F;
    double x2 = (float) (pos.getX() + 8) - MathHelper.sin(ranFlt) * (float) this.size / 8.0F;
    double z1 = (float) (pos.getZ() + 8) + MathHelper.cos(ranFlt) * (float) this.size / 8.0F;
    double z2 = (float) (pos.getZ() + 8) - MathHelper.cos(ranFlt) * (float) this.size / 8.0F;
    double y1 = randY + reader.getRandom().nextInt(3) - 2;
    double y2 = randY + reader.getRandom().nextInt(3) - 2;
    for (int i = 0; i < this.size; ++i) {
        float radScl = (float) i / (float) this.size;
        double xn = x1 + (x2 - x1) * (double) radScl;
        double yn = y1 + (y2 - y1) * (double) radScl;
        double zn = z1 + (z2 - z1) * (double) radScl;
        double noise = reader.getRandom().nextDouble() * (double) this.size / 16.0D;
        double radius = (double) (MathHelper.sin((float) Math.PI * radScl) + 1.0F) * noise + 1.0D;
        int xmin = MathHelper.floor(xn - radius / 2.0D);
        int ymin = MathHelper.floor(yn - radius / 2.0D);
        int zmin = MathHelper.floor(zn - radius / 2.0D);
        int xmax = MathHelper.floor(xn + radius / 2.0D);
        int ymax = MathHelper.floor(yn + radius / 2.0D);
        int zmax = MathHelper.floor(zn + radius / 2.0D);
        for (int x = xmin; x <= xmax; ++x) {
            double layerRadX = ((double) x + 0.5D - xn) / (radius / 2.0D);
            if (layerRadX * layerRadX < 1.0D) {
                for (int y = ymin; y <= ymax; ++y) {
                    double layerRadY = ((double) y + 0.5D - yn) / (radius / 2.0D);
                    if (layerRadX * layerRadX + layerRadY * layerRadY < 1.0D) {
                        for (int z = zmin; z <= zmax; ++z) {
                            double layerRadZ = ((double) z + 0.5D - zn) / (radius / 2.0D);
                            if (layerRadX * layerRadX + layerRadY * layerRadY + layerRadZ * layerRadZ < 1.0D) {
                                BlockPos placePos = new BlockPos(x, y, z);
                                BlockState tmp = this.getOre();
                                if (tmp == null) {
                                    continue;
                                }
                                // Skip this block if it can't replace the target block
                                if (!this.getBlockStateMatchers().contains(FeatureUtils.tryGetBlockState(reader, thisChunk, placePos))) {
                                    continue;
                                }
                                if (FeatureUtils.tryPlaceBlock(reader, new ChunkPos(pos), placePos, tmp, cap)) {
                                    totlPlaced++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return totlPlaced;
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 73 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class TopLayerDeposit method generate.

/**
 * Handles full-on generation of this type of pluton. Requires 0 arguments as
 * everything is self-contained in this class
 *
 * @return (int) the number of pluton resource blocks placed. If 0 -- this
 *         should be evaluted as a false for use of Mojang's sort-of sketchy
 *         generation code in
 *         {@link DepositFeature#generate(net.minecraft.world.ISeedReader, net.minecraft.world.gen.ChunkGenerator, java.util.Random, net.minecraft.util.math.BlockPos, net.minecraft.world.gen.feature.NoFeatureConfig)}
 */
@Override
public int generate(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
    /* Check biome allowance */
    if (!DepositUtils.canPlaceInBiome(reader.getBiome(pos), this.biomeFilter, this.biomeTypeFilter, this.isBiomeFilterBl)) {
        return 0;
    }
    int totlPlaced = 0;
    ChunkPos thisChunk = new ChunkPos(pos);
    int x = ((thisChunk.getXStart() + thisChunk.getXEnd()) / 2) - reader.getRandom().nextInt(8) + reader.getRandom().nextInt(16);
    int z = ((thisChunk.getZStart() + thisChunk.getZEnd()) / 2) - reader.getRandom().nextInt(8) + reader.getRandom().nextInt(16);
    int radX = (this.radius / 2) + reader.getRandom().nextInt(this.radius / 2);
    int radZ = (this.radius / 2) + reader.getRandom().nextInt(this.radius / 2);
    BlockPos basePos = new BlockPos(x, 0, z);
    for (int dX = -radX; dX <= radX; dX++) {
        for (int dZ = -radZ; dZ <= radZ; dZ++) {
            if (((dX * dX) + (dZ * dZ)) > this.radius + reader.getRandom().nextInt(Math.max(1, this.radius / 2))) {
                continue;
            }
            BlockPos baseForXZ = Utils.getTopSolidBlock(reader, basePos.add(dX, 0, dZ));
            for (int i = 0; i < this.depth; i++) {
                BlockPos placePos = baseForXZ.down(i);
                BlockState tmp = this.getOre();
                boolean isTop = i == 0;
                if (tmp == null) {
                    continue;
                } else if (tmp.hasProperty(BlockStateProperties.BOTTOM)) {
                    tmp = tmp.with(BlockStateProperties.BOTTOM, !isTop);
                }
                // Skip this block if it can't replace the target block
                if (!this.getBlockStateMatchers().contains(FeatureUtils.tryGetBlockState(reader, thisChunk, placePos))) {
                    continue;
                }
                if (FeatureUtils.tryPlaceBlock(reader, thisChunk, placePos, tmp, cap)) {
                    totlPlaced++;
                    if (isTop && reader.getRandom().nextFloat() <= this.sampleChance) {
                        BlockState smpl = this.getSample();
                        if (smpl != null) {
                            FeatureUtils.tryPlaceBlock(reader, thisChunk, placePos.up(), smpl, cap);
                            FeatureUtils.fixSnowyBlock(reader, placePos);
                        }
                    }
                }
            }
        }
    }
    return totlPlaced;
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 74 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class DikeDeposit method afterGen.

/**
 * Handles what to do after the world has generated
 */
@Override
public void afterGen(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
    // Debug the pluton
    if (CommonConfig.DEBUG_WORLD_GEN.get()) {
        Geolosys.getInstance().LOGGER.debug("Generated {} in Chunk {} (Pos [{} {} {}])", this.toString(), new ChunkPos(pos), pos.getX(), pos.getY(), pos.getZ());
    }
    ChunkPos thisChunk = new ChunkPos(pos);
    int maxSampleCnt = Math.min(CommonConfig.MAX_SAMPLES_PER_CHUNK.get(), (this.baseRadius / CommonConfig.MAX_SAMPLES_PER_CHUNK.get()) + (this.baseRadius % CommonConfig.MAX_SAMPLES_PER_CHUNK.get()));
    maxSampleCnt = Math.max(maxSampleCnt, 1);
    for (int i = 0; i < maxSampleCnt; i++) {
        BlockPos samplePos = SampleUtils.getSamplePosition(reader, new ChunkPos(pos));
        BlockState tmp = this.getSample();
        if (tmp == null) {
            continue;
        }
        if (samplePos == null || SampleUtils.inNonWaterFluid(reader, samplePos)) {
            continue;
        }
        if (SampleUtils.isInWater(reader, samplePos) && tmp.hasProperty(BlockStateProperties.WATERLOGGED)) {
            tmp = tmp.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true));
        }
        FeatureUtils.tryPlaceBlock(reader, thisChunk, samplePos, tmp, cap);
        FeatureUtils.fixSnowyBlock(reader, samplePos);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 75 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class SerializerUtils method deconstructMultiBlockMap.

public static JsonArray deconstructMultiBlockMap(HashMap<BlockState, Float> in) {
    JsonArray ret = new JsonArray();
    for (Entry<BlockState, Float> e : in.entrySet()) {
        JsonObject obj = new JsonObject();
        obj.addProperty("block", e.getKey().getBlock().getRegistryName().toString());
        obj.addProperty("chance", e.getValue());
        ret.add(obj);
    }
    return ret;
}
Also used : JsonArray(com.google.gson.JsonArray) BlockState(net.minecraft.block.BlockState) JsonObject(com.google.gson.JsonObject)

Aggregations

BlockState (net.minecraft.block.BlockState)79 BlockPos (net.minecraft.util.math.BlockPos)32 TileEntity (net.minecraft.tileentity.TileEntity)19 Direction (net.minecraft.util.Direction)16 Nonnull (javax.annotation.Nonnull)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 World (net.minecraft.world.World)12 ChunkPos (net.minecraft.util.math.ChunkPos)11 Block (net.minecraft.block.Block)10 Nullable (javax.annotation.Nullable)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashSet (java.util.HashSet)4 Blocks (net.minecraft.block.Blocks)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 IForgeBlockState (net.minecraftforge.common.extensions.IForgeBlockState)4 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3