Rotate block on X or Z axis

Started by Quicksand on

Topic category: Help with modding (Java Edition)

Last seen on 22:24, 17. Sep 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Rotate block on X or Z axis

I need to rotate a block the way that items in an item frame rotate, which is not the same as setting direction to north, east, west, up/down etc. I'm guessing inverting the axes for the UV map programmatically in-game is not possible or too obscure for me rn as I jumped into all this a few days ago. I did my research looking at default procedures, searching online and all that first, totally possible I missed something though. There was some info suggesting it's not supported, but there's gotta be workarounds. Thanks in advance.

Last seen on 22:24, 17. Sep 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For anyone else that finds…
Mon, 09/11/2023 - 19:33

For anyone else that finds this thread: there's a TileRenderer that allows this sort of thing on a 2D plane, or a MapRenderer (names are from memory and wrong) which allows writing an array of RGB pixels on a 2D plane. General Java drawing methods could probably give you that array, definitely overkill though. You can't rotate on all 3 axes, just horizontal/vertical which gives blocks NESW and up/down. In terms of roll, pitch and yaw the missing one is roll.

You can also use blockstates (all these files have a .json file for their blockstate) and some custom rules. This is good for switching textures or models, maybe if you swapped models and had the UV mapped at different 90 degree rotations that would work (so, four different models each identical except the UV is rotated 90 deg). Then you'll have to modify the java class. Something like

public static final BooleanProperty YOURPROPERTY = Properties.YOURPROPERTY;

And in the constructor,
setDefaultState(getDefaultState().with(YOURPROPERTY, false));

I don't know if appendProperties is needed, but it's probably necessary,
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
    builder.add(YOURPROPERTY);
}

Then you can read it like (Boolean)state.get(Properties.YOURPROPERTY), there are other types besides BooleanProperty if you have a number or something. You can change it on the block like:
if (!(Boolean)state.get(YOURPROPERTY))
    world.setBlockState(pos, (BlockState) state.with(YOURPROPERTY, true), 3);
}

That's just generally how blockstates seem to work. Well, cheers, hope that helps the next person.