Jump to content

[1.16.1] Overriding Block#getCollisionShape gives invisible block


Recommended Posts

Posted

I want to make the bed has no collision when player wears a set of armor, so I extended `BedBlock` in my new `Block` class and overrided the method `Block#getCollisionShape` as below:

 

public class VanishingBedBlock extends BedBlock {
    public VanishingBedBlock(BedBlock block) {
        super(block.getColor(), Properties.from(block));
    }

    @Override
    public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        Entity entity = context.getEntity();
        if(entity instanceof LivingEntity) {
            if(/*check item somehow*/) {
                return VoxelShapes.empty();
            }
        }
        return super.getCollisionShape(state, worldIn, pos, context);
    }
}

 

However, when I place the bed in Minecraft, there is only the outline of the bed when I'm not wearing the armor. The bed just goes invisible.

I'm quite sure it is the problem of this class since cancelling the overriding doesn't give any problem at all.

 

What should I do?

Posted (edited)
5 minutes ago, NorthWestWind said:

The bed just goes invisible.

That's because beds are usually renderered through a TER. You need to create a TER by default for it tor render, or just change the render type to block to support it. Nothing to do with what you said.

Edited by ChampionAsh5357
Posted (edited)

Ok so I have no idea about what a TER is and does "change the render type" means overriding Block#getRenderType or something?

 

Edit: I just figured out what is TER. Sorry for that. So what do I do to create a TER?

Edited by NorthWestWind
Posted

Are you trying to make this work for vanilla bed or just for your custom bed? If you are trying to cancel the collision with vanilla bed thats not what Override is for. Look here for TER reference: https://mcforge.readthedocs.io/en/latest/tileentities/tesr/

Or just look at the vanilla bed block and BedTileEntityRenderer class to get and idea

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

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.