Jump to content

[1.16.5] Block Heightmap Problem


dun

Recommended Posts

For some reason, my block does is not considered to 'block motion' when utilizing the MOTION_BLOCKING_NO_LEAVES Heightmap. 

I have a spell that allows me to summon mobs near the player, and on the highest non motion blocking/non leaf block. But for some reason, this block is not considered non-motion blocking despite the fact that it's using a non-motion blocking Material and has no collision. I could just make the spell to not use the Heightmap, but I also wanted to fix this to prevent other problems.

Here's the block:

package com.Polarice3.Goety.common.blocks;

import com.Polarice3.Goety.init.ModBlocks;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.server.ServerWorld;

import java.util.Random;

public class DarkCloudBlock extends Block {
    public static final BooleanProperty PERSISTENT = BlockStateProperties.PERSISTENT;

    public DarkCloudBlock() {
        super(Properties.of(Material.WEB)
                .sound(SoundType.WOOL)
                .randomTicks()
                .instabreak()
                .noCollission()
                .isValidSpawn(ModBlocks::never)
        );
        this.registerDefaultState(this.stateDefinition.any().setValue(PERSISTENT, Boolean.FALSE));
    }

    public boolean skipRendering(BlockState pState, BlockState pAdjacentBlockState, Direction pSide) {
        return pAdjacentBlockState.is(this) || super.skipRendering(pState, pAdjacentBlockState, pSide);
    }

    @Override
    public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos) {
        return false;
    }

    @Override
    public int getLightBlock (BlockState state, IBlockReader world, BlockPos pos) {
        return world.getMaxLightLevel();
    }

    public boolean isRandomlyTicking(BlockState pState) {
        return !pState.getValue(PERSISTENT);
    }

    public void randomTick(BlockState pState, ServerWorld pLevel, BlockPos pPos, Random pRandom) {
        if (!pState.getValue(PERSISTENT)) {
            this.checkDeadBlock(pLevel, pPos);
        }
    }

    public void checkDeadBlock(ServerWorld pLevel, BlockPos pPos){
        BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable(pPos.getX(), pPos.getY(), pPos.getZ());

        while(blockpos$mutable.getY() > 0 && !(pLevel.getBlockState(blockpos$mutable).getBlock() instanceof IDeadBlock)) {
            blockpos$mutable.move(Direction.DOWN);
        }

        BlockState blockState = pLevel.getBlockState(blockpos$mutable);
        if (!(blockState.getBlock() instanceof IDeadBlock)){
            pLevel.removeBlock(pPos, false);
        }
    }

    protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> pBuilder) {
        pBuilder.add(PERSISTENT);
    }

    public BlockRenderType getRenderShape(BlockState state) {
        return BlockRenderType.MODEL;
    }

}

As you can see, it's purpose is to block out the sun from the surface that will allow mobs to spawn and prevents undead from burning.

Link to comment
Share on other sites

5 hours ago, diesieben07 said:

This would be a case for the debugger.

I just tested my mod on a different instance and it looks like everythings working as it should! Looks like the main problem only happens when I use the debugger and used the same World to test my Block.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.