Search in sources :

Example 41 with BlockState

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

the class ProPickItem method prospect.

private boolean prospect(PlayerEntity player, ItemStack stack, World world, BlockPos pos, Direction facing, int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd) {
    HashSet<BlockState> foundBlocks = new HashSet<BlockState>();
    HashSet<BlockPos> foundBlockPos = new HashSet<BlockPos>();
    HashSet<BlockState> depositBlocks = Prospecting.getDepositBlocks();
    for (int x = xStart; x <= xEnd; x++) {
        for (int y = yStart; y <= yEnd; y++) {
            for (int z = zStart; z <= zEnd; z++) {
                BlockPos tmpPos = pos.add(x, y, z);
                BlockState state = world.getBlockState(tmpPos);
                if (depositBlocks.contains(state)) {
                    foundBlocks.add(state);
                    foundBlockPos.add(tmpPos);
                }
            }
        }
    }
    if (!foundBlocks.isEmpty()) {
        Geolosys.proxy.sendProspectingMessage(player, foundBlocks, facing.getOpposite());
        foundBlockPos.forEach((_pos) -> {
            world.playSound(null, _pos, SoundEvents.BLOCK_ANVIL_PLACE, SoundCategory.PLAYERS, 0.15F, 2F);
        });
        return true;
    }
    return prospectChunk(world, stack, pos, player);
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 42 with BlockState

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

the class SampleUtils method canReplace.

/**
 * @param reader an ISeedReader instance
 * @param pos    A BlockPos to check in and around
 * @return true if the block at pos is replaceable
 */
public static boolean canReplace(ISeedReader reader, BlockPos pos) {
    BlockState state = reader.getBlockState(pos);
    Material mat = state.getMaterial();
    return BlockTags.LEAVES.contains(state.getBlock()) || mat.isReplaceable();
}
Also used : BlockState(net.minecraft.block.BlockState) Material(net.minecraft.block.material.Material)

Example 43 with BlockState

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

the class DepositFeature method placePendingBlocks.

private boolean placePendingBlocks(ISeedReader reader, IDepositCapability cap, BlockPos pos) {
    boolean placedAny = false;
    for (Entry<BlockPos, BlockState> e : cap.getPendingBlocks().entrySet()) {
        if (FeatureUtils.isInChunk(new ChunkPos(pos), e.getKey())) {
            if (reader.setBlockState(e.getKey(), e.getValue(), 2 | 16)) {
                placedAny = true;
                cap.getPendingBlocks().remove(e.getKey());
                if (CommonConfig.ADVANCED_DEBUG_WORLD_GEN.get()) {
                    Geolosys.getInstance().LOGGER.debug("Generated pending block " + e.getValue().getBlock().getRegistryName().toString() + " at " + e.getKey());
                }
            } else {
                if (CommonConfig.DEBUG_WORLD_GEN.get()) {
                    Geolosys.getInstance().LOGGER.error("FAILED to generate pending block " + e.getValue().getBlock().getRegistryName().toString() + " at " + e.getKey());
                }
            }
        }
    }
    return placedAny;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 44 with BlockState

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

the class InventoryUtils method getInventory.

/**
 * Gets an inventory from a position within the world. If no tile exists or the tile does
 * not have the inventory capability the empty inventory handler will be returned.
 *
 * @param world The world instance.
 * @param pos The position of the expected tile entity.
 * @param side The side to access the inventory from.
 * @return The inventory handler. Will be empty if none was found.
 */
public static IItemHandler getInventory(World world, BlockPos pos, Direction side) {
    final TileEntity tileEntity = world.getBlockEntity(pos);
    if (tileEntity != null) {
        final LazyOptional<IItemHandler> inventoryCap = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
        return inventoryCap.orElse(EmptyHandler.INSTANCE);
    } else {
        // Some blocks like composters are not tile entities so their inv can not be
        // accessed through the normal capability system.
        final BlockState state = world.getBlockState(pos);
        if (state.getBlock() instanceof ISidedInventoryProvider) {
            final ISidedInventoryProvider inventoryProvider = (ISidedInventoryProvider) state.getBlock();
            final ISidedInventory inventory = inventoryProvider.getContainer(state, world, pos);
            if (inventory != null) {
                return new SidedInvWrapper(inventory, side);
            }
        }
    }
    return EmptyHandler.INSTANCE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory) ISidedInventoryProvider(net.minecraft.inventory.ISidedInventoryProvider) BlockState(net.minecraft.block.BlockState) IItemHandler(net.minecraftforge.items.IItemHandler) SidedInvWrapper(net.minecraftforge.items.wrapper.SidedInvWrapper)

Example 45 with BlockState

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

the class PacketUtils method deserializeBlockState.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static BlockState deserializeBlockState(PacketBuffer buffer) {
    final ResourceLocation id = buffer.readResourceLocation();
    final Block block = ForgeRegistries.BLOCKS.getValue(id);
    if (block != null) {
        final int size = buffer.readInt();
        BlockState state = block.defaultBlockState();
        for (int i = 0; i < size; i++) {
            final String propName = buffer.readUtf();
            final String value = buffer.readUtf();
            // Check the block for the property. Keys = property names.
            final Property blockProperty = block.getStateDefinition().getProperty(propName);
            if (blockProperty != null) {
                // Attempt to parse the value with the the property.
                final Optional<Comparable> propValue = blockProperty.getValue(value);
                if (propValue.isPresent()) {
                    // Update the state with the new property.
                    try {
                        state = state.setValue(blockProperty, propValue.get());
                    } catch (final Exception e) {
                        Bookshelf.LOG.error("Failed to read state for block {}. The mod that adds this block has issues.", block.getRegistryName());
                        Bookshelf.LOG.catching(e);
                    }
                }
            }
        }
        return state;
    }
    return Blocks.AIR.defaultBlockState();
}
Also used : BlockState(net.minecraft.block.BlockState) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) Property(net.minecraft.state.Property)

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