Jump to content

1.19.2 Need Help with Custom Block with a size greater than 1x1x1


KalamityF

Recommended Posts

Hello Forge Forums,

 

I am currently trying to create essentially a "Giant Door", I have the model loading in correctly however the collision and interaction sizes/shapes do not reflect the shape of the model. Code:

public class BlockGiantDoor extends BlockBasicGui<GiantDoorBlockEntity> {
    public BlockGiantDoor() {
        super(GiantDoorBlockEntity.class, BlockEntityRegistry.GIANT_DOOR, IBaseBlock.solid());
    }

    @Override
    public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
        System.out.println("Clicked on giant door");
        return InteractionResult.PASS;
    }

    @Override
    public RenderShape getRenderShape(BlockState pState) {
        return RenderShape.ENTITYBLOCK_ANIMATED;
    }

    @Override
    public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
        //three blocks tall, two blocks wide, 1/8th of a block thick
        return Block.box(0, 0, 0, 32, 48, 2);
    }

    @Override
    public boolean hasDynamicShape() {
        return true;
    }

    @Override
    public VoxelShape getCollisionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
        return this.getShape(pState, pLevel, pPos, pContext);
    }

    @Override
    public VoxelShape getInteractionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
        return this.getShape(pState, pLevel, pPos, CollisionContext.empty());
    }
}
public class GiantDoorBlockEntity extends BlockEntity implements IInventoryProvider, IAnimatable {

    private final AnimationFactory factory = GeckoLibUtil.createFactory(this);

    public GiantDoorBlockEntity(BlockPos pPos, BlockState pBlockState) {
        super(BlockEntityRegistry.GIANT_DOOR.get(), pPos, pBlockState);
    }

    @Override
    public Component getDisplayName() {
        return Component.literal("Giant Door");
    }

    @Nullable
    @Override
    public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
        return null;
    }

    @Override
    public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pIsMoving) {

    }

    @Override
    public void registerControllers(AnimationData animationData) {

    }

    @Override
    public AnimationFactory getFactory() {
        return factory;
    }


}
public class GiantDoorRenderer extends GeoBlockRenderer<GiantDoorBlockEntity> {
    public GiantDoorRenderer(BlockEntityRendererProvider.Context rendererProvider) {
        super(rendererProvider, AnimatedModel.block("giant_door"));
    }
}

The issue essentially is that players do not collide with the extended hit box, also they can only interact within the actual block position that the Giant Door was placed on, which does not reflect the correct size of the model.

When looking at the original block position the model gets "outlined" just like a block would, and the hitbox appears to fit the model perfectly, however collision and using just seem to ignore this shape.

Example when looking at the actual block position this was placed on:

XlGiIoG.png

 

Example when looking at the extended model: H7F2P9R.png
 

Link to comment
Share on other sites

A block should never be larger than a block. If you want to do that, you will need to create a multipart block. You can see how this works with the regular door block. Since it seems like you are animating a geckolib model as well, you can make the model render over all the blocks using a master controller block entity with the rest being slaves/delegates, but each block individually needs to be separate.

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.

Announcements



×
×
  • Create New...

Important Information

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