Jump to content

Recommended Posts

Posted

I have a TV block that is 48 wide and 16 high.

As you can see on the video above, I have an issue where player can put any other block on extra space of TV and I can't figure out how to stop that from happening.

SHAPE is defined like this:

private static final VoxelShape SHAPE = Block.box(-16.0D, 0.0D, 0.0D, 32.0D, 16.0D, 16.0D);

I have overridden all possible methods to return this shape but issue is still there:

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

	@Override
	public VoxelShape getOcclusionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
		return SHAPE;
	}

	@Override
	public VoxelShape getBlockSupportShape(BlockState pState, BlockGetter pReader, BlockPos pPos) {
		return SHAPE;
	}

	@Override
	public VoxelShape getInteractionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
		return SHAPE;
	}

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

	@Override
	public VoxelShape getVisualShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
		return SHAPE;
	}

 

Any hints/ideas on how to fix this?

Thanks! :)

Posted

first of all a block takes up one block on the world. no discussion.
even if it appears larger (sure, the model can overflow outside of "one block size boundary"), it is still one block.

take for example crops (which is a reasonable scenario). you can make a model that is 16px across x and z axis (base) and 24 in height (y axis).
you can. no argument there, even though blocks are 16x16x16 pixels in size. (*kinda-pixels)
but you need to handle the block above the base, because it is a separate block as far as the game is concerned.

in a crop example, you would need to override method neighborChanged in the block class, and if somebody places a cobblestone block above the base of your crop block, you destroy your block.

shape functions that you override in the post above are something else. collision shape controls what happens when player tries to pass through your block or jump on top of it. in the case of my first example (crop), i would put an empty bounding box - meaning, allow player to pass through the block.

visual shape is a set of boxes that control where you need to aim to interact with the block; you should set this shape to match what the player sees in-game.

second example, you want to make a bush (like sweetberries), but wider than one block area. fine. make a model that goes from -8 to 16+8 on x and z axes. set shapes as you please. but the important part is - you need to set behavior manually. override neighborChanged because you can't have players putting something in block spaces that your block kind-of-occupies. override setPlacedBy and mayPlaceOn to react to player attempting to place your block down.

one more thing (again me and my long unreadable posts) - things above have maximums, separate maximums. while a (visually) 2-block-big "block" is not a big problem, you will find that a 3-block-big block is a serious challenge for your hair. know when to give up and rethink the plan.

Posted

@MFMods thank you for so many hints :)

I will dig into the methods that you have mentioned and experiment a bit. Hopefully I will not end up bald. :)

I am still new to a lot of concepts in Forge/Minecraft, but it's still fun and challenging to make stuff on your own.

After all, it is one fine working TV as you can see. :D

Posted (edited)

The best approach is to do what vanilla beds and doors do i.e. have multiple blocks placed when you place the item. Then when you break any of the blocks, break them all and drop a single item.

Edited by Alpvax
Fixed typo

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.