Jump to content

[1.16.1] Voxel Shapes Broken


IDuckz_

Recommended Posts

Hello, I setup a custom model like this: https://gyazo.com/51fabdfc1ebaee01e766dc20aea486c2 but in game it doesn't show it correctly. It shows the block bound or voxelshape like this: https://gyazo.com/594430fbe27b6941a81afa85319f73b7 The problem is that it has diagonal shape and it doesn't seem to like diagonal shapes and it decides to break.

 

My voxelshape code (It's a lot of code that I can't show it all since it's too big but I think you get the idea): https://gyazo.com/6e7d09f1b467f404b6fa73b5326eb62c

 

If anyone could help, that would be greatly appreciated. Thank you

 

Edited by IDuckz_
Link to comment
Share on other sites

You cannot have a diagonal voxel shape. The closest you can get is approximation. Also, you should use the least amount of voxel shapes as possible. Large amounts of voxel shapes tend to impact the game in a negative way. Finally, I can tell you generated the voxel shape via block bench. This is more of an opinion, but just use VoxelShapes#or instead of constructing the stream. Makes little to no sense to do so in my opinion as the approach is exactly what the method does anyways.

 

If you're talking about the misalignment, that's probably because you need to create a voxel shape for every possible rotation and then change it via it's block state.

  • Thanks 1
Link to comment
Share on other sites

Your cauldron handle does not need a voxel boundary. Its basically irrelevant.

  • Like 1

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

Okay, I will try using less voxelshapes in the future and I did remove the stream#of and replaced it with VoxelShapes#or I also removed the return and reduce type at the end so the code wasn't necessary provided by BlockBench when I exported it as VoxelShapes, and it is maybe irrelevant but if I want make more custom blocks in the future it might include diagonal shapes too. Also, one question, how would I create a voxelshape for every possible rotation and change it via it's block state? Also thanks for all the help by the way, greatly appreciated. :)

Edited by IDuckz_
Link to comment
Share on other sites

Um ok here:

package com.iduckz.usefulemeralds.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraftforge.common.ToolType;

import javax.annotation.Nullable;
import java.util.stream.Stream;

public class WitchCauldron extends Block {

    public WitchCauldron() {
        super(Block.Properties.create(Material.IRON)
            .hardnessAndResistance(2.5f, 3.5f)
            .sound(SoundType.METAL)
            .harvestLevel(2)
            .harvestTool(ToolType.PICKAXE)
            .setRequiresTool());
    }

    private static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
    
    public static final VoxelShape SHAPE_N = VoxelShapes.or(
            Block.makeCuboidShape(14, 6, -2, 15, 7, 7),
            Block.makeCuboidShape(1, 6, -2, 2, 7, 7),
            Block.makeCuboidShape(2, 2.6999999999999993D, -1.4600000000000009D, 14, 3.6999999999999993D, -0.46000000000000085D),
            Block.makeCuboidShape(9, 0, 9, 11, 2, 11),
            Block.makeCuboidShape(10, 0, 11, 11, 2, 12),
            Block.makeCuboidShape(11, 0, 10, 12, 2, 11),
            Block.makeCuboidShape(11, 0, 11, 13, 2, 13),
            Block.makeCuboidShape(12, 0, 13, 13, 2, 14),
            Block.makeCuboidShape(13, 0, 12, 14, 2, 13),
            Block.makeCuboidShape(13, 0, 13, 15, 2, 15),
            Block.makeCuboidShape(3, 0, 13, 4, 2, 14),
            Block.makeCuboidShape(1, 0, 13, 3, 2, 15),
            Block.makeCuboidShape(2, 0, 12, 3, 2, 13),
            Block.makeCuboidShape(3, 0, 11, 5, 2, 13),
            Block.makeCuboidShape(4, 0, 10, 5, 2, 11),
            Block.makeCuboidShape(5, 0, 11, 6, 2, 12),
            Block.makeCuboidShape(5, 0, 9, 7, 2, 11),
            Block.makeCuboidShape(3, 0, 2, 4, 2, 3),
            Block.makeCuboidShape(5, 0, 5, 7, 2, 7),
            Block.makeCuboidShape(3, 0, 3, 5, 2, 5),
            Block.makeCuboidShape(1, 0, 1, 3, 2, 3),
            Block.makeCuboidShape(4, 0, 5, 5, 2, 6),
            Block.makeCuboidShape(5, 0, 4, 6, 2, 5),
            Block.makeCuboidShape(2, 0, 3, 3, 2, 4),
            Block.makeCuboidShape(13, 0, 1, 15, 2, 3),
            Block.makeCuboidShape(9, 0, 5, 11, 2, 7),
            Block.makeCuboidShape(11, 0, 3, 13, 2, 5),
            Block.makeCuboidShape(10, 0, 4, 11, 2, 5),
            Block.makeCuboidShape(11, 0, 5, 12, 2, 6),
            Block.makeCuboidShape(12, 0, 2, 13, 2, 3),
            Block.makeCuboidShape(13, 0, 3, 14, 2, 4),
            Block.makeCuboidShape(7, 0, 9, 9, 2, 16),
            Block.makeCuboidShape(0, 0, 7, 16, 2, 9),
            Block.makeCuboidShape(7, 0, 0, 9, 2, 7),
            Block.makeCuboidShape(2, 2, 2, 14, 3, 14),
            Block.makeCuboidShape(3, 3, 2, 13, 13, 3),
            Block.makeCuboidShape(3, 3, 13, 13, 13, 14),
            Block.makeCuboidShape(13, 3, 2, 14, 13, 14),
            Block.makeCuboidShape(2, 3, 2, 3, 13, 14)
    );

    public static final VoxelShape SHAPE_E = VoxelShapes.or(
            Block.makeCuboidShape(9, 6, 14, 18, 7, 15),
            Block.makeCuboidShape(9, 6, 1, 18, 7, 2),
            Block.makeCuboidShape(16.46f, 2.7f, 2, 17.46f, 3.7f, 14),
            Block.makeCuboidShape(5, 0, 9, 7, 2, 11),
            Block.makeCuboidShape(4, 0, 10, 5, 2, 11),
            Block.makeCuboidShape(5, 0, 11, 6, 2, 12),
            Block.makeCuboidShape(3, 0, 11, 5, 2, 13),
            Block.makeCuboidShape(2, 0, 12, 3, 2, 13),
            Block.makeCuboidShape(3, 0, 13, 4, 2, 14),
            Block.makeCuboidShape(1, 0, 13, 3, 2, 15),
            Block.makeCuboidShape(2, 0, 3, 3, 2, 4),
            Block.makeCuboidShape(1, 0, 1, 3, 2, 3),
            Block.makeCuboidShape(3, 0, 2, 4, 2, 3),
            Block.makeCuboidShape(3, 0, 3, 5, 2, 5),
            Block.makeCuboidShape(5, 0, 4, 6, 2, 5),
            Block.makeCuboidShape(4, 0, 5, 5, 2, 6),
            Block.makeCuboidShape(5, 0, 5, 7, 2, 7),
            Block.makeCuboidShape(13, 0, 3, 14, 2, 4),
            Block.makeCuboidShape(9, 0, 5, 11, 2, 7),
            Block.makeCuboidShape(11, 0, 3, 13, 2, 5),
            Block.makeCuboidShape(13, 0, 1, 15, 2, 3),
            Block.makeCuboidShape(10, 0, 4, 11, 2, 5),
            Block.makeCuboidShape(11, 0, 5, 12, 2, 6),
            Block.makeCuboidShape(12, 0, 2, 13, 2, 3),
            Block.makeCuboidShape(13, 0, 13, 15, 2, 15),
            Block.makeCuboidShape(9, 0, 9, 11, 2, 11),
            Block.makeCuboidShape(11, 0, 11, 13, 2, 13),
            Block.makeCuboidShape(11, 0, 10, 12, 2, 11),
            Block.makeCuboidShape(10, 0, 11, 11, 2, 12),
            Block.makeCuboidShape(13, 0, 12, 14, 2, 13),
            Block.makeCuboidShape(12, 0, 13, 13, 2, 14),
            Block.makeCuboidShape(0, 0, 7, 7, 2, 9),
            Block.makeCuboidShape(7, 0, 0, 9, 2, 16),
            Block.makeCuboidShape(9, 0, 7, 16, 2, 9),
            Block.makeCuboidShape(2, 2, 2, 14, 3, 14),
            Block.makeCuboidShape(13, 3, 3, 14, 13, 13),
            Block.makeCuboidShape(2, 3, 3, 3, 13, 13),
            Block.makeCuboidShape(2, 3, 13, 14, 13, 14),
            Block.makeCuboidShape(2, 3, 2, 14, 13, 3)
    );

    public static final VoxelShape SHAPE_S = VoxelShapes.or(
            Block.makeCuboidShape(1, 6, 9, 2, 7, 18),
            Block.makeCuboidShape(14, 6, 9, 15, 7, 18),
            Block.makeCuboidShape(2, 2.6999999999999993D, 16.46f, 14, 3.6999999999999993D, 17.46f),
            Block.makeCuboidShape(5, 0, 5, 7, 2, 7),
            Block.makeCuboidShape(5, 0, 4, 6, 2, 5),
            Block.makeCuboidShape(4, 0, 5, 5, 2, 6),
            Block.makeCuboidShape(3, 0, 3, 5, 2, 5),
            Block.makeCuboidShape(3, 0, 2, 4, 2, 3),
            Block.makeCuboidShape(2, 0, 3, 3, 2, 4),
            Block.makeCuboidShape(1, 0, 1, 3, 2, 3),
            Block.makeCuboidShape(12, 0, 2, 13, 2, 3),
            Block.makeCuboidShape(13, 0, 1, 15, 2, 3),
            Block.makeCuboidShape(13, 0, 3, 14, 2, 4),
            Block.makeCuboidShape(11, 0, 3, 13, 2, 5),
            Block.makeCuboidShape(11, 0, 5, 12, 2, 6),
            Block.makeCuboidShape(10, 0, 4, 11, 2, 5),
            Block.makeCuboidShape(9, 0, 5, 11, 2, 7),
            Block.makeCuboidShape(12, 0, 13, 13, 2, 14),
            Block.makeCuboidShape(9, 0, 9, 11, 2, 11),
            Block.makeCuboidShape(11, 0, 11, 13, 2, 13),
            Block.makeCuboidShape(13, 0, 13, 15, 2, 15),
            Block.makeCuboidShape(11, 0, 10, 12, 2, 11),
            Block.makeCuboidShape(10, 0, 11, 11, 2, 12),
            Block.makeCuboidShape(13, 0, 12, 14, 2, 13),
            Block.makeCuboidShape(1, 0, 13, 3, 2, 15),
            Block.makeCuboidShape(5, 0, 9, 7, 2, 11),
            Block.makeCuboidShape(3, 0, 11, 5, 2, 13),
            Block.makeCuboidShape(5, 0, 11, 6, 2, 12),
            Block.makeCuboidShape(4, 0, 10, 5, 2, 11),
            Block.makeCuboidShape(3, 0, 13, 4, 2, 14),
            Block.makeCuboidShape(2, 0, 12, 3, 2, 13),
            Block.makeCuboidShape(7, 0, 0, 9, 2, 7),
            Block.makeCuboidShape(0, 0, 7, 16, 2, 9),
            Block.makeCuboidShape(7, 0, 9, 9, 2, 16),
            Block.makeCuboidShape(2, 2, 2, 14, 3, 14),
            Block.makeCuboidShape(3, 3, 13, 13, 13, 14),
            Block.makeCuboidShape(3, 3, 2, 13, 13, 3),
            Block.makeCuboidShape(2, 3, 2, 3, 13, 14),
            Block.makeCuboidShape(13, 3, 2, 14, 13, 14)
    );

    public static final VoxelShape SHAPE_W = VoxelShapes.or(
            Block.makeCuboidShape(-2, 6, 1, 7, 7, 2),
            Block.makeCuboidShape(-2, 6, 14, 7, 7, 15),
            Block.makeCuboidShape(-1.4600000000000009D, 2.6999999999999993D, 2, -0.46000000000000085D, 3.6999999999999993D, 14),
            Block.makeCuboidShape(9, 0, 5, 11, 2, 7),
            Block.makeCuboidShape(11, 0, 5, 12, 2, 6),
            Block.makeCuboidShape(10, 0, 4, 11, 2, 5),
            Block.makeCuboidShape(11, 0, 3, 13, 2, 5),
            Block.makeCuboidShape(13, 0, 3, 14, 2, 4),
            Block.makeCuboidShape(12, 0, 2, 13, 2, 3),
            Block.makeCuboidShape(13, 0, 1, 15, 2, 3),
            Block.makeCuboidShape(13, 0, 12, 14, 2, 13),
            Block.makeCuboidShape(13, 0, 13, 15, 2, 15),
            Block.makeCuboidShape(12, 0, 13, 13, 2, 14),
            Block.makeCuboidShape(11, 0, 11, 13, 2, 13),
            Block.makeCuboidShape(10, 0, 11, 11, 2, 12),
            Block.makeCuboidShape(11, 0, 10, 12, 2, 11),
            Block.makeCuboidShape(9, 0, 9, 11, 2, 11),
            Block.makeCuboidShape(2, 0, 12, 3, 2, 13),
            Block.makeCuboidShape(5, 0, 9, 7, 2, 11),
            Block.makeCuboidShape(3, 0, 11, 5, 2, 13),
            Block.makeCuboidShape(1, 0, 13, 3, 2, 15),
            Block.makeCuboidShape(5, 0, 11, 6, 2, 12),
            Block.makeCuboidShape(4, 0, 10, 5, 2, 11),
            Block.makeCuboidShape(3, 0, 13, 4, 2, 14),
            Block.makeCuboidShape(1, 0, 1, 3, 2, 3),
            Block.makeCuboidShape(5, 0, 5, 7, 2, 7),
            Block.makeCuboidShape(3, 0, 3, 5, 2, 5),
            Block.makeCuboidShape(4, 0, 5, 5, 2, 6),
            Block.makeCuboidShape(5, 0, 4, 6, 2, 5),
            Block.makeCuboidShape(2, 0, 3, 3, 2, 4),
            Block.makeCuboidShape(3, 0, 2, 4, 2, 3),
            Block.makeCuboidShape(9, 0, 7, 16, 2, 9),
            Block.makeCuboidShape(7, 0, 0, 9, 2, 16),
            Block.makeCuboidShape(0, 0, 7, 7, 2, 9),
            Block.makeCuboidShape(2, 2, 2, 14, 3, 14),
            Block.makeCuboidShape(2, 3, 3, 3, 13, 13),
            Block.makeCuboidShape(13, 3, 3, 14, 13, 13),
            Block.makeCuboidShape(2, 3, 2, 14, 13, 3),
            Block.makeCuboidShape(2, 3, 13, 14, 13, 14)
    );

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); }

    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        switch(state.get(FACING)) {
            case NORTH:
                return SHAPE_N;
            case SOUTH:
                return SHAPE_S;
            case WEST:
                return SHAPE_W;
            default:
                return SHAPE_E;
        }
    }

    @Override
    public BlockState rotate(BlockState state, Rotation rot) {
        return state.with(FACING, rot.rotate(state.get(FACING)));
    }

    @Override
    public BlockState mirror(BlockState state, Mirror mirrorIn) {
        return state.rotate(mirrorIn.toRotation(state.get(FACING)));
    }

    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING); }

    @Override
    public float getAmbientOcclusionLightValue(BlockState state, IBlockReader worldIn, BlockPos pos) {
        return 0.3f;
    }
}

 

Link to comment
Share on other sites

You've created a shape for every single rotation and it will change dependent on it. There is nothing wrong here, you've already done what you asked. However, once again, that's a bit too many defined and combined VoxelShapes for one block.

 

As for non-related critiques, do not hardcode the property parameter within the constructor, and the property should be public in case you would like to access or set the state in a location from outside the block itself.

Link to comment
Share on other sites

I will try changing the block to use less VoxelShapes but for now I want to see how I could fix this issue. If I have already done what I asked for how come is it misaligned? Unless I misunderstood.

19 hours ago, ChampionAsh5357 said:

As for non-related critiques, do not hardcode the property parameter within the constructor, and the property should be public in case you would like to access or set the state in a location from outside the block itself.

Ok I will fix that. Thanks

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.



×
×
  • Create New...

Important Information

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