Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello,

I am creating a multiblock structure when I use an item.

And I want it to face the player when placed.

But I cannot figure out how to rotate it.

This i how I place the blocks (for now I am just trying to rotate it 90 clockwise)

        BlockState blockState = posBlock.Block.defaultBlockState();
        blockState.setValue(HorizontalDirectionalBlock.FACING, Direction.SOUTH);
        blockState.rotate(level, posBlock.Pos, Rotation.CLOCKWISE_90);

        //blockState.setValue(HorizontalDirectionalBlock.FACING, Direction.SOUTH);
        //blockState.setValue(HorizontalDirectionalBlock.FACING, context.getHorizontalDirection().getOpposite());

        level.setBlock(posBlock.Pos, blockState, 3);

        level.sendBlockUpdated(posBlock.Pos, blockState, blockState, Block.UPDATE_ALL_IMMEDIATE);

This is one my multiblock class:
 


public class lock00 extends HorizontalDirectionalBlock {

    private static final Map<Direction, VoxelShape> SHAPES = new EnumMap<>(Direction.class);

    private static final Optional<VoxelShape> SHAPE = Stream.of(
      // Shape removed for smaller text
    ).reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR));

    public Block00(Properties properties) {
        super(properties);
        registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH));
        runCalculation(SHAPE.orElse(Shapes.block()));
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        super.createBlockStateDefinition(builder);
        builder.add(FACING);
    }

    @Override
    public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
        return SHAPES.get(state.getValue(FACING));
    }

    @Override
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    protected void runCalculation(VoxelShape shape) {
        for (Direction direction : Direction.values())
            SHAPES.put(direction, Laputa.calculateShapes(direction, shape));
    }
}

The blockstatte:
 

{
  "variants": {
    "": { "model": "test_mod:block/block_00" }
  }
}

The model:
 

{
	"credit": "Made with Blockbench",
	"texture_size": [32, 32],
	"textures": {
		"1": "laputa:blocks/a",
		"2": "laputa:blocks/b",
		"3": "laputa:blocks/c",
		"4": "laputa:blocks/d",
		"5": "laputa:blocks/e",
		"7": "laputa:blocks/f",
		"8": "laputa:blocks/g",
		"particle": "laputa:blocks/h"
	},
	"elements": [
		{
			"from": [10, 13, 7],
			"to": [15, 16, 9],
			"shade": false,
			"faces": {
				"north": {"uv": [0, 1, 5, 4], "texture": "#4"},
				"east": {"uv": [5, 5, 7, 8], "texture": "#4"},
				"south": {"uv": [0, 5, 5, 8], "texture": "#4"},
				"west": {"uv": [7, 5, 9, 8], "texture": "#4"},
				"up": {"uv": [5, 0, 10, 2], "texture": "#4"},
				"down": {"uv": [5, 2, 10, 4], "texture": "#4"}
			}
		}
	],
	"groups": [
		{
			"name": "VoxelShapes",
			"origin": [8, 8, 8],
			"color": 0,
			"shade": false,
			"children": [
				{
					"name": "Group",
					"origin": [8, 8, 8],
					"color": 0,
					"shade": false,
					"children": [0]
				}
			]
		}
	]
}

 

  • Author
11 minutes ago, diesieben07 said:

This does nothing. BlockState is immutable, you need to actually use the return value of these methods.

Oh ok.
I did not know that those functions are immutable.

So I tried it, and I see now that the shape has changed (the black outline).
But the texture remains in the same orientation as before.

How can I make the texture rotate too?

  • Author
1 hour ago, diesieben07 said:

You have to change it in your blockstate. Look at the vanilla examples, for example the furnace.

Works like a charm.
Thank you :)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.