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);
}
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();
}
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;
}
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;
}
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();
}
Aggregations