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/06/16 14:40] – redgrapefruit | tutorial:screenhandler [2022/02/03 18:14] – change generic ScreenHandler argument in the BoxScreen to be the actual BoxScreenHandler glisco | ||
---|---|---|---|
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 240: | Line 243: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class BoxScreen extends HandledScreen< | + | public class BoxScreen extends HandledScreen< |
//A path to the gui texture. In this example we use the texture from the dispenser | //A path to the gui texture. In this example we use the texture from the dispenser | ||
private static final Identifier TEXTURE = new Identifier(" | private static final Identifier TEXTURE = new Identifier(" | ||
- | public BoxScreen(ScreenHandler | + | public BoxScreen(BoxScreenHandler |
super(handler, | super(handler, | ||
} | } |
tutorial/screenhandler.txt · Last modified: 2024/02/19 02:51 by netuserget