Started by
Cdztw
on
Topic category: Advanced modding
Hello there, I'm trying to make a custom fence. It was almost done except for block hitbox.
This fence have some custom boolean properties I created: "NORTH", "EAST", "SOUTH", "WEST" and "UP".
I want to make this block's hitbox work like this:
- If north is true, add a box into hitbox (box: 7, 7, 0, 9, 9, 8)
- If east is true, add a box into hitbox (box: 8, 7, 7, 16, 9, 9)
- If south is true, add a box into hitbox (box: 7, 7, 8, 9, 9, 16)
- If west is true, add a box into hitbox (box: 0, 7, 7, 8, 9, 9)
- If up is true, add a box into hitbox (box: 6, 0, 0, 10, 16, 10)
- If none of above is true, add a box into hitbox (box: 6, 0, 0, 10, 16, 10)
But I don't know how to do that. I searched up some tutorials, but them seem to be not suitable for the version I use.
I only knows how to make a static hitbox that won't adapt the block's custom state.
I messed around the codes and of course, nothing works.
Can someone help me? That will be a huge appreciated.
The version of MCreator I currently running is 2023.2.
Minecraft version is 1.19.2.
Here is parts of my code:
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
/*
Shapes BLOCKSHAPE = new Shapes();
if (state.getValue(NORTH))
BLOCKSHAPE.or(box(7, 7, 0, 9, 9, 8));
if (state.getValue(EAST))
BLOCKSHAPE.or(BLOCKSHAPE.block(), box(8, 7, 7, 16, 9, 9));
if (state.getValue(SOUTH))
BLOCKSHAPE.or(BLOCKSHAPE.block(), box(7, 7, 8, 9, 9, 16));
if (state.getValue(WEST))
BLOCKSHAPE.or(BLOCKSHAPE.block(), box(0, 7, 7, 8, 9, 9));
if (state.getValue(UP))
BLOCKSHAPE.or(BLOCKSHAPE.block(), box(6, 0, 6, 10, 16, 10));
*/
return box(6, 0, 6, 10, 16, 10);
}
Edited by Cdztw on Sun, 06/18/2023 - 02:25
nvm
I got the solution, works as expected but it needs lot of if-else statements.
I got a better solution!
It doesn't need that ridiculous amount of if-else statement to get the job done.