Jump to content

Recommended Posts

Posted

I want to make some vanilla blocks to have no collision under certain condition, so I override the block (in this example, glass block):

public class CustomGlassBlock extends GlassBlock {
    public CustomGlassBlock(Block block) {
        super(Properties.from(block));
    }

    @Override
    public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        if(/*some condition*/) {
          return VoxelShapes.empty();
        }
        return super.getCollisionShape(state, worldIn, pos, context);
    }
}

As far as I know, returning VoxelShapes.empty() in Block#getCollisionShape will actually make the block have no collision, at least I think that is true.

When testing, the block does have no collision, but it is still pushing me out. What am I missing?

Posted

Block.Properties#doesNotBlockMovement()

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.

Posted
5 hours ago, NorthWestWind said:

I want to make some vanilla blocks to have no collision under certain condition, so I override the block (in this example, glass block):

Do you want to make the Vanilla block have no collision or your custom block? You cannot modify a vanilla block behaviour by extending the block and overriding a method in your custom block

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

Posted
Quote

Do you want to make the Vanilla block have no collision or your custom block?

I want to make the Vanilla block have no collision.
 

Quote

You cannot modify a vanilla block behaviour by extending the block and overriding a method in your custom block

But I do that on other blocks and it works. I extend the block and register the block again.

Posted
25 minutes ago, Beethoven92 said:

What Draco18 suggested you should be fine

But I want it to have collision under some conditions. I don't think I can do that with Block.Properties#doesNotBlockMovement()?

Posted (edited)

Well, if you specify doesNotBlockMovement in the block properties, instead of returning a VoxelShapes#empty under your conditions,you could instead return the collision shape of the block when the condition is not verified. Basically invert what you were doing here:

    @Override
    public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        if(/*some condition*/) {
          return VoxelShapes.empty();
        }
        return super.getCollisionShape(state, worldIn, pos, context);
    }

 

Edited by Beethoven92

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

Posted

I tried to remove the bounding box of the player by Entity#setBoundingBox in onEntityCollision and it didn't go well.

As soon as I touch the block, my entire game runs at 1 fps and I found myself at the bottom of the world.

I have a feeling that I used the set bounding box method wrongly because I just get the bounding box of the entity and use AxisAlignedBB#shrink to get rid of the bounding box.

Posted

😆 i guess by removing the entity (your player in this case) bounding box, collision with the ground are not checked anymore, thats why you just sank out of the world. Don't touch the entity bounding box...i was thinking at something like...is there a collision between your block and the player? Is your condition satisfied? ----> get rid of the collision shape of the block , else the block is acting as normal with the collisions and all the rest

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

Posted (edited)

I did cancel the collision shape of the block (in the very first try) and I'm sure the condition is satisfied since when I have the item, I can clip into the block (and it covers my screen), but there is a force constantly pushing me out and doesn't allow me to walk through the block. Without that item, the block just acts like normal block.

Edited by NorthWestWind
Posted (edited)

So...i tried to code that myself and i made it work, but my solution may not be the best or the most elegant one. Turns out that onEntityCollision happens only if the shape of the block is set to be smaller than the full block. So i set two different voxel shapes, a null voxel shape and one that is slightly smaller than the cube, with dimensions:

Block.makeCuboidShape(0.1F, 0.1F, 0.1F, 15.9F, 15.9F, 15.9F)

which doesn't basically change anything visually but lets the collision event happen (For some reason i am still unable to understand). Inside the event i just check for the condition and select the appropriate voxel shape, which then needs to be returned by getShape (not getCollisionShape). It works but as i said before this seems to be a slightly "hacky" solution and also present some issues:

1) you will be able to walk on the border of your block when in its solid form

2) any other entity will be able to walk through your block while you are inside the block with your condition being verified

3) being the voxel shapes static and shared between all blocks of the same type, when you make one of them not solid, if other are present they will all become not solid

Edited by Beethoven92

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

Posted (edited)
52 minutes ago, Beethoven92 said:

being the voxel shapes static and shared between all blocks of the same type, when you make one of them not solid, if other are present they will all become not solid

It won't

edit: i meant "They won't"

Edited by Crazzy4999
Posted

But you're only doing it for the block at a given position.

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.

Posted
2 minutes ago, Draco18s said:

But you're only doing it for the block at a given position.

That's what i was thinking, but after testing with multiple blocks it appears that with my code if i am inside one block (and so its voxel shape its null), all the other blocks also have null voxel shapes 🤔

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

Posted

I think getShape is just used to render the block's outline. It cannot change the collision shape by itself, but since getCollisionShape just call getShape by default, overriding getShape also overrides getCollisionShape.

 

I took a look at what Properties#doesNotBlockMovement does before and turns out it only changes the collision shape, not the shape itself. A good example would be torches because they have no collision, but at the same time have an outline.

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

    • I recently built a mod pack ,RLMCC Insanity Unfolds, and Ive been playing it to make sure its stable and playable, these last few days the game has been running fine with the exception of a few player loading quirks here and there but nothing game breaking, fast forward to this morning attempting to load into my survival world results in the game crashing, I will reach 100% on world loading, the joining game prompt will appear, the loading terrain prompt will appear, I get a large lag spike, and then the game says Saving world and then crashes throwing an unknown error in the launcher when checking the logs I can see that right before the world gets shut down better combat throws a fatal error, I had assumed at first that maybe when the world got shutdown last that something got stuck in an invalid state so I removed the mod and played for a bit to hopefully un-stick whatever it was, no luck there. When I placed the mod back into the game the world continued to crash the game when loading in. I figured that maybe there was a bug introduced in the latest version so I downgraded a couple versions and worked my way back up. The original version of Better Combat the mod pack was using was better combat 1.8.6 - 1.20.1, I tried better combat 1.8.1 - 1.20.1 and worked my way up to version 1.8.5 - 1.20.1, still running into the problem. Removing Better combat solves the problem but removing the mod renders a major part of my mod pack broken as one of the major aspects of the pack was focused around better combat. As mentioned the mod pack was working and running stable prior to this morning with Better Combat 1.8.6 - 1.20.1, and there was no change in the mod list this morning I do not believe that this is a mod compatibility issue as I am still able to generate a new world perfectly fine and the mod pack was working fine these last few days. The loading issue seems to only occur with my original survival world that I made when I built the mod pack.   Here is the last section from my latest.log file https://pastebin.com/6Q9e9ZLf  
    • 4747474785868478474734
    • It's called serverconfig file. You can find it by opening curseforge selecting your modpack, click the 3 dots next to play, select open folder then from there go to saves > your world that isn't working > serverconfig. Then highlight all the files within the serverconfig folder and delete them
×
×
  • Create New...

Important Information

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