Search in sources :

Example 1 with BlockState

use of net.minecraft.block.BlockState in project Bookshelf by Darkhax-Minecraft.

the class SerializerBlockState method read.

@Override
public BlockState read(JsonElement json) {
    if (json.isJsonObject()) {
        final JsonObject obj = json.getAsJsonObject();
        final Block block = Serializers.BLOCK.read(obj, "block");
        BlockState state = block.defaultBlockState();
        if (obj.has("properties")) {
            final JsonElement properties = obj.get("properties");
            for (final Entry<String, JsonElement> property : properties.getAsJsonObject().entrySet()) {
                state = this.readProperty(state, property.getKey(), property.getValue());
            }
        }
        return state;
    } else {
        throw new JsonParseException("Expected properties to be an object. Recieved " + JSONUtils.getType(json));
    }
}
Also used : BlockState(net.minecraft.block.BlockState) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Block(net.minecraft.block.Block) JsonParseException(com.google.gson.JsonParseException)

Example 2 with BlockState

use of net.minecraft.block.BlockState in project Bookshelf by Darkhax-Minecraft.

the class TileEntityBasic method sync.

/**
 * Synchronizes the server state of the tile with all clients tracking it.
 *
 * @param renderUpdate Whether or not a render update should happen as well. Only use this
 *        if you need to change the block model.
 */
public void sync(boolean renderUpdate) {
    if (renderUpdate) {
        this.setChanged();
        final BlockState state = this.getState();
        this.level.sendBlockUpdated(this.worldPosition, state, state, BlockFlags.DEFAULT_AND_RERENDER);
    } else if (this.level instanceof ServerWorld) {
        final IPacket<?> packet = this.getUpdatePacket();
        WorldUtils.sendToTracking((ServerWorld) this.level, this.getChunkPos(), packet, false);
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IPacket(net.minecraft.network.IPacket) BlockState(net.minecraft.block.BlockState)

Example 3 with BlockState

use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.

the class NetherSurfaceBuilderWrapper method buildSurface.

@Override
public void buildSurface(Random random, IChunk chunk, Biome biome, int chunkX, int chunkZ, int startHeight, double noise, BlockState defaultState, BlockState defaultLiquid, int seaLevel, long seed, Config config) {
    if (seaLevel != 32) {
        config.getOriginalBuilder().buildSurface(random, chunk, biome, chunkX, chunkZ, startHeight, noise, defaultState, defaultLiquid, seaLevel, seed);
    } else {
        int posX = chunkX & 15;
        int posZ = chunkZ & 15;
        BlockPos.Mutable mutablePos = new BlockPos.Mutable();
        boolean wasLastBlockNonSolid = false;
        for (int posY = 127; posY >= 0; posY--) {
            mutablePos = mutablePos.setPos(posX, posY, posZ);
            BlockState checkState = chunk.getBlockState(mutablePos);
            if (checkState.isAir(chunk, mutablePos)) {
                wasLastBlockNonSolid = true;
            } else if (checkState == defaultState) {
                if (wasLastBlockNonSolid) {
                    if (posY < seaLevel) {
                        chunk.setBlockState(mutablePos, config.getLiquid(), false);
                    } else {
                        chunk.setBlockState(mutablePos, config.getTop(), false);
                    }
                } else {
                    chunk.setBlockState(mutablePos, config.getUnder(), false);
                }
                wasLastBlockNonSolid = false;
            } else if (checkState == defaultLiquid) {
                chunk.setBlockState(mutablePos, config.getLiquid(), false);
                wasLastBlockNonSolid = true;
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockState

use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.

the class EnokiStemBlock method isValidPosition.

@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
    BlockState upState = world.getBlockState(pos.up());
    boolean flag = !world.getBlockState(pos.down()).isAir() && !upState.isAir();
    for (Direction direction : Direction.Plane.HORIZONTAL) {
        BlockPos offsetPos = pos.offset(direction);
        Block block = world.getBlockState(offsetPos).getBlock();
        if (block == this) {
            if (flag) {
                return false;
            }
            Block upBlock = world.getBlockState(offsetPos.up()).getBlock();
            if (upBlock == this || upBlock == NetherExBlocks.LIVELY_NETHERRACK.get()) {
                return true;
            }
        }
    }
    Block upBlock = upState.getBlock();
    return upBlock == this || upBlock == NetherExBlocks.LIVELY_NETHERRACK.get();
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) SixWayBlock(net.minecraft.block.SixWayBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 5 with BlockState

use of net.minecraft.block.BlockState in project NetherEx by LogicTechCorp.

the class NetherCaveCarverOverride method func_225556_a_.

@Override
protected boolean func_225556_a_(IChunk chunk, Function<BlockPos, Biome> posBiomeFunction, BitSet carvingMask, Random random, BlockPos.Mutable mutablePos, BlockPos.Mutable mutablePosUp, BlockPos.Mutable mutablePosDown, int minY, int minX, int minZ, int posX, int posZ, int p_222703_12_, int posY, int p_222703_14_, AtomicBoolean isDefaultTopBlock) {
    int bitIndex = p_222703_12_ | p_222703_14_ << 4 | posY << 8;
    if (carvingMask.get(bitIndex)) {
        return false;
    } else {
        carvingMask.set(bitIndex);
        mutablePos.setPos(posX, posY, posZ);
        mutablePosUp.setPos(mutablePos).move(Direction.UP);
        if (this.canCarveBlock(chunk.getBlockState(mutablePos), chunk.getBlockState(mutablePosUp))) {
            BlockState state;
            if (posY <= 31) {
                state = LAVA.getBlockState();
                BiomeData biomeData = NetherEx.BIOME_DATA_MANAGER.getBiomeData(posBiomeFunction.apply(mutablePos));
                if (biomeData != BiomeData.EMPTY) {
                    state = biomeData.getBiomeBlock(BiomeData.BlockType.LIQUID_BLOCK);
                }
            } else {
                state = CAVE_AIR;
            }
            chunk.setBlockState(mutablePos, state, false);
            return true;
        } else {
            return false;
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BiomeData(logictechcorp.libraryex.world.biome.BiomeData)

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