Jump to content

[1.16]How to hide the block's CollisionBoundingBox in 1.16?


middangeardim

Recommended Posts

In 12.2, there was a method can be Override to high the block's CollisionBoundingBox

@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
    return Block.NULL_AABB;
}

 

But I can't find this method in Blocks anymore in 1.16,so how can I hide the block's CollisionBoundingBox in 1.16?

Link to comment
Share on other sites

On 5/10/2021 at 12:31 AM, diesieben07 said:

You can either return an empty VoxelShape in getShape or cancel DrawHighlightEvent.HighlightBlock if you want the block to keep its collision.

sorry about that I a noob modder, I don't know how to cancel an event, I try to write it like this but it doesn't work

    @SubscribeEvent
    public static void lookToBlock(DrawHighlightEvent.HighlightBlock event){
        event.setCanceled(true);
    }

What should I do to cancel it?

Link to comment
Share on other sites

10 minutes ago, Luis_ST said:

looks good. is the event called?
how do you register the event listener

Well....here is code...

    @Mod.EventBusSubscriber()
    public static class MyStaticClientOnlyEventHandler {
     @SubscribeEvent
         public static void lookToBlock(DrawHighlightEvent.HighlightBlock event){
             event.setCanceled(true);
         }
    }

The problem is seems I canceled all highlightevent in the world. Is it possible to only cancel my mod's block's highlight?

Link to comment
Share on other sites

16 minutes ago, middangeardim said:

@Mod.EventBusSubscriber()

I'm not sure, but I think you need to include your Mod ID here

 

16 minutes ago, middangeardim said:

The problem is seems I canceled all highlightevent in the world. Is it possible to only cancel my mod's block's highlight?

would be useful but shouldn't be the problem
And I have no idea where you can get the world for it, because you only get a BlockRayTraceResult from the event and this does not contain a world
Edit: you can get a ClientWorld from the WorldRenderer so you can use World#getBlockState to check whether the block at that point is your block

Edited by Luis_ST
Link to comment
Share on other sites

16 minutes ago, Luis_ST said:

I'm not sure, but I think you need to include your Mod ID here

If only there was some documentation...

https://mcforge.readthedocs.io/en/1.16.x/events/intro/

 

That said, middangeardim, I'm not sure why you're going about doing this with events when the "method to override" path is available to you and all you need to do is return an empty VoxelShape instead of a null one.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

15 minutes ago, Luis_ST said:

And I have no idea where you can get the world for it, because you only get a BlockRayTraceResult from the event and this does not contain a world
Edit: you can get a ClientWorld from the WorldRenderer so you can use World#getBlockState to check whether the block at that point is your block

solution for the world is you can get it from Minecraft (Minecraft#getInstance().level)
your event should work, I cannot reproduce your error after trying something

1 minute ago, Draco18s said:

If only there was some documentation...

😅

 

 

Link to comment
Share on other sites

12 minutes ago, Draco18s said:

If only there was some documentation...

https://mcforge.readthedocs.io/en/1.16.x/events/intro/

 

That said, middangeardim, I'm not sure why you're going about doing this with events when the "method to override" path is available to you and all you need to do is return an empty VoxelShape instead of a null one.

Unfortunatly, I'm designing a cropblock. If I return an empty VoxelShape, then how can I break it?(I can't even touch it?😂)

Link to comment
Share on other sites

4 minutes ago, middangeardim said:

I can't even touch it?

There are different methods in the block class that return a VoxelShape (getInteractionShape, getCollisionShape, getRenderShape, getShape, ...).
you should use getRenderShape but I'm not sure (test)

Edited by Luis_ST
Link to comment
Share on other sites

10 minutes ago, Luis_ST said:

There are different methods in the block class that return a VoxelShape (getInteractionShape, getCollisionShape, getRenderShape, getShape, ...).
you should use getRenderShape but I'm not sure (test)

actually there is only one method about shape in #Block

"makeCuboidShape" and I think it doesn't help🤔

the getRenderShape means I have to change the block into a TileEntity Block

Edited by middangeardim
Link to comment
Share on other sites

9 minutes ago, Luis_ST said:

no, you have to overwrite the method in your Block class

But I already Override the getShape method in the class because the cropsblock need it

    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPES[state.get(this.getAgeProperty())];
    }

Is it possible to override another method to get the shape again? All I want is cancel the highlight, not to change the shape of the cropsblock(My brain totally mess up😱)

 

here is the whole code in the class

public class original_pumpkin_cropblock extends CropsBlock {
    private static final VoxelShape[] SHAPES = new VoxelShape[]{Block.makeCuboidShape(5.0D, 0.0D, 5.0D, 10.0D, 4.0D, 10.0D),
                                                                Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 11.0D, 7.0D, 11.0D),
                                                                Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 11.0D, 9.0D, 11.0D),
                                                                Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 9.0D, 13.0D),
                                                                Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 9.0D, 13.0D),
                                                                Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 9.0D, 13.0D),
                                                                Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D),
                                                                Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D)};

    public original_pumpkin_cropblock() {
        super(AbstractBlock.Properties.create(Material.PLANTS).doesNotBlockMovement().tickRandomly().zeroHardnessAndResistance().sound(SoundType.CROP));
    }

    @Override
    protected IItemProvider getSeedsItem() {
        return ItemRegistry.originalPumpkinSeed.get();
    }

    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return SHAPES[state.get(this.getAgeProperty())];
    }

    @Override
    protected int getBonemealAgeIncrease(World worldIn) {
        return MathHelper.nextInt(worldIn.rand, 1, 2);
    }
}

 

Link to comment
Share on other sites

14 minutes ago, middangeardim said:

Is it possible to override another method to get the shape again? All I want is cancel the highlight, not to change the shape of the cropsblock(My brain totally mess up😱)

here is the whole code in the clas

So I think you should use the event because if you overwrite getShape in the block class you can no longer interact with it

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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