use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class StructureRenderHandler method renderComponentInWorld.
private static boolean renderComponentInWorld(Level world, BuildBlock buildBlock, MultiBufferSource.BufferSource entityVertexConsumer, PoseStack matrixStack, BlockPos pos) {
// Don't render this block if it's going to overlay a non-air/water block.
BlockState targetBlock = world.getBlockState(pos);
if (targetBlock.getMaterial() != Material.AIR && targetBlock.getMaterial() != Material.WATER) {
return false;
}
StructureRenderHandler.doRenderComponent(world, buildBlock, pos, entityVertexConsumer, matrixStack);
if (buildBlock.getSubBlock() != null) {
Block foundBlock = Registry.BLOCK.get(buildBlock.getSubBlock().getResourceLocation());
BlockState blockState = foundBlock.defaultBlockState();
BuildBlock subBlock = BuildBlock.SetBlockState(StructureRenderHandler.currentConfiguration, StructureRenderHandler.currentConfiguration.pos, buildBlock.getSubBlock(), foundBlock, blockState, StructureRenderHandler.currentStructure.getClearSpace().getShape().getDirection());
BlockPos subBlockPos = subBlock.getStartingPosition().getRelativePosition(StructureRenderHandler.currentConfiguration.pos, StructureRenderHandler.currentStructure.getClearSpace().getShape().getDirection(), StructureRenderHandler.currentConfiguration.houseFacing);
RenderShape subBlockRenderType = subBlock.getBlockState().getRenderShape();
return StructureRenderHandler.renderComponentInWorld(world, subBlock, entityVertexConsumer, matrixStack, subBlockPos);
}
return true;
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class StructureRenderHandler method renderPlayerLook.
/**
* This is to render the currently bound structure.
*
* @param player The player to render the structure for.
* @param src The ray trace for where the player is currently looking.
*/
public static void renderPlayerLook(Player player, HitResult src, PoseStack matrixStack) {
if (StructureRenderHandler.currentStructure != null && StructureRenderHandler.dimension == player.level.dimensionType().logicalHeight() && StructureRenderHandler.currentConfiguration != null && CommonProxy.proxyConfiguration.serverConfiguration.enableStructurePreview) {
rendering = true;
MultiBufferSource.BufferSource entityVertexConsumer = Minecraft.getInstance().renderBuffers().bufferSource();
Frustum frustum = new Frustum(matrixStack.last().pose(), RenderSystem.getProjectionMatrix());
BlockPos cameraPos = player.eyeBlockPosition();
frustum.prepare(cameraPos.getX(), cameraPos.getY(), cameraPos.getZ());
for (BuildBlock buildBlock : StructureRenderHandler.currentStructure.getBlocks()) {
Block foundBlock = Registry.BLOCK.get(buildBlock.getResourceLocation());
if (foundBlock != null) {
// In order to get the proper relative position I also need the structure's original facing.
BlockPos pos = buildBlock.getStartingPosition().getRelativePosition(StructureRenderHandler.currentConfiguration.pos, StructureRenderHandler.currentStructure.getClearSpace().getShape().getDirection(), StructureRenderHandler.currentConfiguration.houseFacing);
// Don't render the block if it isn't visible (cull)
AABB box = new AABB(pos.getX() - 0.5, pos.getY() - 0.5, pos.getZ() - 0.5, pos.getX() + 1.5, pos.getY() + 1.5, pos.getZ() + 1.5);
if (!frustum.isVisible(box)) {
continue;
}
// Get the unique block state for this block.
BlockState blockState = foundBlock.defaultBlockState();
buildBlock = BuildBlock.SetBlockState(StructureRenderHandler.currentConfiguration, StructureRenderHandler.currentConfiguration.pos, buildBlock, foundBlock, blockState, StructureRenderHandler.currentStructure.getClearSpace().getShape().getDirection());
StructureRenderHandler.renderComponentInWorld(player.level, buildBlock, entityVertexConsumer, matrixStack, pos);
}
}
// Draw function.
entityVertexConsumer.endBatch(Sheets.translucentItemSheet());
if (!StructureRenderHandler.showedMessage) {
Minecraft mc = Minecraft.getInstance();
// Stop narrator from continuing narrating what was in the structure GUI
Narrator.getNarrator().clear();
TranslatableComponent message = new TranslatableComponent(GuiLangKeys.GUI_PREVIEW_NOTICE);
message.setStyle(Style.EMPTY.withColor(ChatFormatting.GREEN));
mc.gui.handleChat(ChatType.CHAT, message, Util.NIL_UUID);
message = new TranslatableComponent(GuiLangKeys.GUI_BLOCK_CLICKED);
message.setStyle(Style.EMPTY.withColor(ChatFormatting.YELLOW));
mc.gui.handleChat(ChatType.CHAT, message, Util.NIL_UUID);
StructureRenderHandler.showedMessage = true;
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class IGrassSpreadable method DetermineGrassSpread.
/**
* Determines if grass should spread to this block.
*
* @param state The state of the current block.
* @param worldIn The server world the block resides in.
* @param pos The position of the block.
* @param random The random value used for checking.
*/
default void DetermineGrassSpread(BlockState state, ServerLevel worldIn, BlockPos pos, Random random) {
if (!worldIn.isClientSide) {
// This is equivalent to light level 9.
if (worldIn.getBrightness(pos.above()) >= 0.2727273) {
for (int i = 0; i < 4; ++i) {
BlockPos blockpos = pos.offset(random.nextInt(3) - 1, random.nextInt(5) - 3, random.nextInt(3) - 1);
if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isLoaded(blockpos)) {
return;
}
BlockState iblockstate1 = worldIn.getBlockState(blockpos);
if ((iblockstate1.getBlock() == Blocks.GRASS_BLOCK || iblockstate1.getBlock() == ModRegistry.GrassStairs.get() || iblockstate1.getBlock() == ModRegistry.GrassWall.get() || iblockstate1.getBlock() == ModRegistry.GrassSlab.get()) && // This equivalent to light level 4.
worldIn.getBrightness(blockpos.above()) >= 0.08333334) {
BlockState grassState = this.getGrassBlockState(state);
worldIn.setBlock(pos, grassState, 3);
}
}
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project MC-Prefab by Brian-Wuest.
the class BlockPhasing method findNeighborPhasicBlocks.
/**
* Sets the powered status and updates the block's neighbor.
*
* @param worldIn The world where the block resides.
* @param pos The position of the block.
* @param desiredBlockState The current state of the block at the position.
* @param cascadeCount The number of times it has cascaded.
* @param cascadedBlockPos The list of cascaded block positions, this is used to determine if this block should
* be processed again.
* @param setCurrentBlock Determines if the current block should be set.
*/
private int findNeighborPhasicBlocks(Level worldIn, BlockPos pos, BlockState desiredBlockState, int cascadeCount, ArrayList<BlockPos> cascadedBlockPos, boolean setCurrentBlock) {
cascadeCount++;
if (cascadeCount > 100) {
return cascadeCount;
}
if (setCurrentBlock) {
cascadedBlockPos.add(pos);
}
for (Direction facing : Direction.values()) {
Block neighborBlock = worldIn.getBlockState(pos.relative(facing)).getBlock();
if (neighborBlock instanceof BlockPhasing) {
BlockState blockState = worldIn.getBlockState(pos.relative(facing));
// If the block is already in the correct state or was already checked, there is no need to cascade to
// it's neighbors.
EnumPhasingProgress progress = blockState.getValue(Phasing_Progress);
if (cascadedBlockPos.contains(pos.relative(facing)) || progress == desiredBlockState.getValue(Phasing_Progress)) {
continue;
}
setCurrentBlock = true;
cascadeCount = this.findNeighborPhasicBlocks(worldIn, pos.relative(facing), desiredBlockState, cascadeCount, cascadedBlockPos, setCurrentBlock);
if (cascadeCount > 100) {
break;
}
}
}
return cascadeCount;
}
use of net.minecraft.world.level.block.state.BlockState in project MinecraftForge by MinecraftForge.
the class ForgeEventFactory method onBlockPlace.
public static boolean onBlockPlace(@Nullable Entity entity, @Nonnull BlockSnapshot blockSnapshot, @Nonnull Direction direction) {
BlockState placedAgainst = blockSnapshot.getLevel().getBlockState(blockSnapshot.getPos().relative(direction.getOpposite()));
EntityPlaceEvent event = new BlockEvent.EntityPlaceEvent(blockSnapshot, placedAgainst, entity);
return MinecraftForge.EVENT_BUS.post(event);
}
Aggregations