Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • Author
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?

9 minutes ago, middangeardim said:

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

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

  • Author
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?

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

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.

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...

😅

 

 

  • Author
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?😂)

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

  • Author
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

4 minutes ago, middangeardim said:

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

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

  • Author
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);
    }
}

 

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.