Search in sources :

Example 36 with BlockState

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

the class SparseDeposit 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()))) * ((int) (spread / 16));
    for (int i = 0; i < maxSampleCnt; i++) {
        BlockPos samplePos = SampleUtils.getSamplePosition(reader, new ChunkPos(pos), this.spread);
        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 37 with BlockState

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

the class SampleBlock method randomTick.

public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
    if (!worldIn.isAreaLoaded(pos, 1)) {
        return;
    }
    BlockState[] neighbors = new BlockState[] { worldIn.getBlockState(pos.add(1, 0, 0)), worldIn.getBlockState(pos.add(-1, 0, 0)), worldIn.getBlockState(pos.add(0, 0, 1)), worldIn.getBlockState(pos.add(0, 0, -1)) };
    int waterNeighbors = 0;
    for (BlockState b : neighbors) {
        if (b.getFluidState() == Fluids.WATER.getStillFluidState(false)) {
            waterNeighbors++;
        }
    }
    if (waterNeighbors > 1) {
        worldIn.setBlockState(pos, state.with(WATERLOGGED, Boolean.TRUE), 2 | 16);
    }
}
Also used : BlockState(net.minecraft.block.BlockState)

Example 38 with BlockState

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

the class DikeDeposit 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;
    }
    ChunkPos thisChunk = new ChunkPos(pos);
    int height = Math.abs((this.yMax - this.yMin));
    int x = thisChunk.getXStart() + reader.getRandom().nextInt(16);
    int z = thisChunk.getZStart() + reader.getRandom().nextInt(16);
    int yMin = this.yMin + reader.getRandom().nextInt(height / 4);
    int yMax = this.yMax - reader.getRandom().nextInt(height / 4);
    int max = Utils.getTopSolidBlock(reader, pos).getY();
    if (yMin > max) {
        yMin = Math.max(yMin, max);
    } else if (yMin == yMax) {
        yMax = this.yMax;
    }
    BlockPos basePos = new BlockPos(x, yMin, z);
    int totlPlaced = 0;
    int htRnd = Math.abs((yMax - yMin));
    int rad = this.baseRadius / 2;
    boolean shouldSub = false;
    for (int dY = yMin; dY <= yMax; dY++) {
        for (int dX = -rad; dX <= rad; dX++) {
            for (int dZ = -rad; dZ <= rad; dZ++) {
                float dist = (dX * dX) + (dZ * dZ);
                if (dist > rad) {
                    continue;
                }
                BlockPos placePos = new BlockPos(basePos.getX() + dX, dY, basePos.getZ() + dZ);
                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++;
                }
            }
        }
        // flip at around the halfway point.
        if (yMin + (htRnd / 2) <= dY) {
            shouldSub = true;
        }
        if (reader.getWorld().getRandom().nextInt(3) == 0) {
            rad += shouldSub ? -1 : 1;
            if (rad <= 0) {
                return totlPlaced;
            }
        }
    }
    return totlPlaced;
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 39 with BlockState

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

the class PacketHelpers method messagify.

public static String messagify(HashSet<BlockState> blocks) {
    StringBuilder sb = new StringBuilder();
    // I hate old for-loops but I need the index.
    int idx = 0;
    for (BlockState b : blocks) {
        sb.append((new ItemStack(b.getBlock())).getDisplayName().getString());
        if ((idx + 2) == blocks.size()) {
            sb.append(" & ");
        } else if ((idx + 1) != blocks.size()) {
            sb.append(", ");
        }
        idx++;
    }
    return sb.toString();
}
Also used : BlockState(net.minecraft.block.BlockState) ItemStack(net.minecraft.item.ItemStack)

Example 40 with BlockState

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

the class PacketHelpers method encodeBlocks.

public static CompoundNBT encodeBlocks(HashSet<BlockState> blocks) {
    CompoundNBT comp = new CompoundNBT();
    ListNBT list = new ListNBT();
    for (BlockState b : blocks) {
        list.add(NBTUtil.writeBlockState(b));
    }
    comp.put(BLOCK_NBT_NAME, list);
    return comp;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT)

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