Jump to content

[1.15.2] Rotating block to face while placing


Harry12OK

Recommended Posts

I created a custom model in blockbench and followed a tutorial on rotating the block to my face while placing but still it is not rotating to my face . My code is

public class Half extends Block {
	private static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;

	private static final SoundType RS = SoundType.STONE;

	public Half() {
         super(Block.Properties.create(Material.IRON).harvestTool(ToolType.PICKAXE).harvestLevel(2).lightValue(15).hardnessAndResistance(2.0f, 2.0f).sound(RS));
        
	}
	@Override
	public BlockState getStateForPlacement(BlockItemUseContext context) {
		
		return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
	}
	@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(Builder<Block, BlockState> builder) {
		
		builder.add(FACING);
	}

}

any help to why is it not working ?

Link to comment
Share on other sites

 

1 hour ago, poopoodice said:

does it change every time you place it with different direction

No, it doesnt change ,it is same no matter from wherever direction i place

 

1 hour ago, poopoodice said:

If yes, have you rotate its models according to its state in your blockstate file?

I have specified it in blockstate file .here see it

{
	"variants":{
		"facing=north": {"model": "hogwarts:block/half"},
		"facing=south": { "model":"hogwarts:block/half", "Y" : 180},
		"facing=west": { "model":"hogwarts:block/half", "Y" : 270},
		"facing=east": { "model":"hogwarts:block/half", "Y" : 90}
	}
}

Now i cant undertand what do you mean by debug screen ?

Link to comment
Share on other sites

Guys it was a small mistake in blockstate file i was extering 'Y' instead of 'y' that was causing problem ,now it's fixed. but there is one more thing i want to ask.

see this image:1948514703_bandicam2020-07-2516-21-09-747.jpg.6754b6dbe2bc1a070ca002c5b8e62d7f.jpg

You can see my block is rotating as i have created a semicircle but the problem now is if i want to rotate the block in such a way that a full circle can be made with it in above image.

is there any way to do it or is there any vanilla block with this behaviour so i can copy its block state file .

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.