-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Orientable Blocks wiki page #111
base: main
Are you sure you want to change the base?
Changes from all commits
9f2a675
971e9e1
cb39f1a
7ecd6e5
b463da6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Creating an Oriented Block | ||
index: 0 | ||
--- | ||
|
||
# Creating an Oriented Block | ||
Orientable blocks are blocks that are placed in different directions based on where you click to place said block and which direction you're facing when placing said block. | ||
|
||
Blocks such as Oak, Spruce and Birch logs are an example of an oriented block. The following example will show you how to make your own oriented block | ||
with the "Glowing Blackwood Log" as an example block. | ||
|
||
|
||
First off, you will want to make two block model json like the following: | ||
The X, Y, and Z are your blockstate's axis. | ||
|
||
`src/main/resources/assets/example_mod/blockstates/glowing_blackwood.json`: | ||
```json | ||
{ | ||
"variants": { | ||
"axis=x": { | ||
"model": "example_mod:block/glowing_blackwood", | ||
"x": 90, | ||
"y": 90 | ||
}, | ||
"axis=y": { | ||
"model": "example_mod:block/glowing_blackwood" | ||
}, | ||
"axis=z": { | ||
"model": "example_mod:block/glowing_blackwood", | ||
"x": 90 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Then you will need to create a class file for the block you're adding. In this example, the file will be called "GlowingBlackwood.java". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd add an explanation for why we need to create a dedicated class for the block -- explain that it needs custom code in order to work |
||
|
||
`src/main/com/example/example_mod/blocks/GlowingBlackwood.java`: | ||
```java | ||
public class BeamBlock extends PillarBlock { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain this code!! why is it called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (by explain the code, i mean break it into smaller chunks and explain in the article instead of comments. I'd first present the rotate method, explain it, then explain the getPlacementState method) |
||
// The following deals with block rotation | ||
@Override | ||
public BlockState rotate(BlockState state, BlockRotation rotation) { | ||
return changeRotation(state, rotation); | ||
} | ||
|
||
public static BlockState changeRotation(BlockState state, BlockRotation rotation) { | ||
return switch (rotation) { | ||
case COUNTERCLOCKWISE_90, CLOCKWISE_90 -> switch (state.get(AXIS)) { | ||
case X -> state.with(AXIS, Direction.Axis.Z); | ||
case Z -> state.with(AXIS, Direction.Axis.X); | ||
default -> state; | ||
}; | ||
default -> state; | ||
}; | ||
} | ||
|
||
// Deals with placing the block properly in accordance to direction. | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext context) { | ||
return this.getDefaultState().with(AXIS, context.getSide().getAxis()); | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be moved, so that the code is directly after you say 'like the following'