Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onInitialize() {
- be_desk = Registry.register(Registry.BLOCK_ENTITY, "schoolmod:desk",
- BlockEntityType.Builder.create(BlockEntityDesk::new).build(null));
- BlockEntityRendererRegistry.INSTANCE.register(BlockEntityDesk.class, new BlockEntityDeskRender());
- }
- public class BlockDesk extends BlockWithEntity {
- public static DirectionProperty FACING;
- public BlockDesk(Settings b) {
- super(b);
- this.setDefaultState((BlockState) ((BlockState) ((BlockState) this.stateFactory.getDefaultState()).with(FACING,
- Direction.NORTH)));
- }
- public boolean activate(BlockState bs, World world, BlockPos bp, PlayerEntity player, Hand hand,
- BlockHitResult bhr) {
- ItemStack i = player.getStackInHand(hand);
- BlockEntityDesk d = (BlockEntityDesk) world.getBlockEntity(bp);
- if (i.isEmpty()) {
- d.addItem();
- System.out.println(d.getNumberOfItems());
- return true;
- }
- return false;
- }
- protected void appendProperties(StateFactory.Builder<Block, BlockState> s) {
- s.add(FACING);
- }
- public BlockState getPlacementState(ItemPlacementContext c) {
- return (BlockState) this.getDefaultState().with(FACING, c.getPlayerFacing().getOpposite());
- }
- @Override
- public boolean isOpaque(BlockState blockState_1) {
- return false;
- }
- @Override
- public boolean isSideInvisible(BlockState bs, BlockState bs2, Direction d1) {
- return true;
- }
- @Override
- public BlockEntity createBlockEntity(BlockView var1) {
- return new BlockEntityDesk();
- }
- @Override
- public boolean hasBlockEntity() {
- return true;
- }
- static {
- FACING = HorizontalFacingBlock.FACING;
- }
- }
- public class BlockEntityDesk extends BlockEntity {
- private int numberOfItems;
- public BlockEntityDesk() {
- super(SchoolMod.be_desk);
- System.out.println("Initialized Block Entity");
- }
- @Override
- public CompoundTag toTag(CompoundTag t) {
- super.toTag(t);
- t.putInt("item", numberOfItems);
- return t;
- }
- @Override
- public void fromTag(CompoundTag t) {
- super.fromTag(t);
- numberOfItems = t.getInt("item");
- }
- public void addItem() {
- numberOfItems++;
- markDirty();
- }
- public int getNumberOfItems() {
- return numberOfItems;
- }
- }
- @Environment(EnvType.CLIENT)
- public class BlockEntityDeskRender extends BlockEntityRenderer<BlockEntityDesk> {
- public BlockEntityDeskRender() {
- System.out.println("called oninit");
- }
- @Override
- public void render(BlockEntityDesk be, double x, double y, double z, float b, int t) {
- super.render(be, x, y, z, b, t);
- System.out.println("Rendering"); // Never prints
- ItemEntity item = new ItemEntity(MinecraftClient.getInstance().world, x, y, z, new ItemStack(Items.BOOK));
- GlStateManager.pushMatrix();
- // GlStateManager.translated(x, y, z);
- MinecraftClient.getInstance().getEntityRenderManager().render(item, 0, 0, 0, 0F, 0F, false);
- GlStateManager.popMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement