Posted August 15, 20205 yr 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?
August 15, 20205 yr 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.
August 15, 20205 yr Author But this method doesn't allow it to have collision under certain conditions?
August 15, 20205 yr 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
August 15, 20205 yr Author 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.
August 15, 20205 yr Oh ok, you are overriding the vanilla block with your custom one in the registry, i missed that, my bad! What Draco18 suggested you should be fine Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr Author 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()?
August 15, 20205 yr 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 August 15, 20205 yr by Beethoven92 Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr What about overriding the onEntityCollision method? Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr Author GlassBlock doesn't even override onEntityCollision and the original onEntityCollision does nothing. I was thinking about that may be some problem with the Entity itself, but I have no clue
August 15, 20205 yr GlassBlock doesn't override onEntityCollision, but it is inheriting it from the Block class, so you can specify your own version of this method in your custom block, even if the original method is doing nothing. Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr Well, since you are trying to make the block uncollidable under your conditions, you should check for that condition inside this method (eg check if the player is holding a special item when colliding with your block) and take the appropriate measure. Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr Author 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.
August 15, 20205 yr 😆 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
August 15, 20205 yr Author 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 August 15, 20205 yr by NorthWestWind
August 15, 20205 yr 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 August 15, 20205 yr by Beethoven92 Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr 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 August 15, 20205 yr by Crazzy4999
August 15, 20205 yr Yes, they will, because i return the selected voxel shape (null or "full" block) from the getShape method Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr 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.
August 15, 20205 yr 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
August 15, 20205 yr Author I think that's because you overrided one block and all kind of that block returns null VoxelShape when the condition is matched.
August 15, 20205 yr I just stick something together trying to solve the problem you had, so my block just extends Block and overrides onEntityCollision and getShape, nothing more Edited August 15, 20205 yr by Beethoven92 Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
August 15, 20205 yr Author 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.