tutorial:screenhandler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:screenhandler [2021/02/18 14:22] – [Block and BlockEntity classes] Add missing ; technici4n | tutorial:screenhandler [2021/09/01 00:28] – updated BlockEntityType.Builder to FabricBlockEntityTypeBuilder for 1.17 lvanderzande | ||
---|---|---|---|
Line 23: | Line 23: | ||
@Override | @Override | ||
- | public BlockEntity createBlockEntity(BlockView world) { | + | public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { |
- | return new BoxBlockEntity(); | + | return new BoxBlockEntity(pos, state); |
} | } | ||
Line 81: | Line 81: | ||
private final DefaultedList< | private final DefaultedList< | ||
- | public BoxBlockEntity() { | + | public BoxBlockEntity(BlockPos pos, BlockState state) { |
- | super(ExampleMod.BOX_BLOCK_ENTITY); | + | super(ExampleMod.BOX_BLOCK_ENTITY, pos, state); |
} | } | ||
Line 111: | Line 111: | ||
| | ||
@Override | @Override | ||
- | public void fromTag(BlockState state, CompoundTag tag) { | + | public void readNbt(NbtCompound nbt) { |
- | super.fromTag(state, tag); | + | super.readNbt(nbt); |
- | Inventories.fromTag(tag, this.inventory); | + | Inventories.readNbt(nbt, this.inventory); |
} | } | ||
@Override | @Override | ||
- | public | + | public |
- | super.toTag(tag); | + | super.writeNbt(nbt); |
- | Inventories.toTag(tag, this.inventory); | + | Inventories.writeNbt(nbt, this.inventory); |
- | return | + | return |
} | } | ||
} | } | ||
Line 146: | Line 146: | ||
//The parameter of build at the very end is always null, do not worry about it | //The parameter of build at the very end is always null, do not worry about it | ||
+ | // pre-1.17 | ||
BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, | BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, | ||
+ | // In 1.17 use FabricBlockEntityTypeBuilder instead of BlockEntityType.Builder | ||
+ | BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, | ||
} | } | ||
Line 250: | Line 253: | ||
@Override | @Override | ||
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { | protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { | ||
- | RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); | + | RenderSystem.setShader(GameRenderer:: |
- | | + | RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); |
+ | | ||
int x = (width - backgroundWidth) / 2; | int x = (width - backgroundWidth) / 2; | ||
int y = (height - backgroundHeight) / 2; | int y = (height - backgroundHeight) / 2; |
tutorial/screenhandler.txt · Last modified: 2024/02/19 02:51 by netuserget