Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. @Override
  2. public void onInitialize() {
  3. be_desk = Registry.register(Registry.BLOCK_ENTITY, "schoolmod:desk",
  4. BlockEntityType.Builder.create(BlockEntityDesk::new).build(null));
  5. BlockEntityRendererRegistry.INSTANCE.register(BlockEntityDesk.class, new BlockEntityDeskRender());
  6. }
  7.  
  8.  
  9.  
  10.  
  11.  
  12. public class BlockDesk extends BlockWithEntity {
  13.  
  14. public static DirectionProperty FACING;
  15.  
  16. public BlockDesk(Settings b) {
  17. super(b);
  18. this.setDefaultState((BlockState) ((BlockState) ((BlockState) this.stateFactory.getDefaultState()).with(FACING,
  19. Direction.NORTH)));
  20.  
  21. }
  22.  
  23. public boolean activate(BlockState bs, World world, BlockPos bp, PlayerEntity player, Hand hand,
  24. BlockHitResult bhr) {
  25. ItemStack i = player.getStackInHand(hand);
  26. BlockEntityDesk d = (BlockEntityDesk) world.getBlockEntity(bp);
  27. if (i.isEmpty()) {
  28. d.addItem();
  29. System.out.println(d.getNumberOfItems());
  30. return true;
  31.  
  32. }
  33. return false;
  34. }
  35.  
  36. protected void appendProperties(StateFactory.Builder<Block, BlockState> s) {
  37. s.add(FACING);
  38. }
  39.  
  40. public BlockState getPlacementState(ItemPlacementContext c) {
  41. return (BlockState) this.getDefaultState().with(FACING, c.getPlayerFacing().getOpposite());
  42. }
  43.  
  44. @Override
  45. public boolean isOpaque(BlockState blockState_1) {
  46. return false;
  47. }
  48.  
  49. @Override
  50. public boolean isSideInvisible(BlockState bs, BlockState bs2, Direction d1) {
  51. return true;
  52. }
  53.  
  54. @Override
  55. public BlockEntity createBlockEntity(BlockView var1) {
  56. return new BlockEntityDesk();
  57. }
  58.  
  59. @Override
  60. public boolean hasBlockEntity() {
  61. return true;
  62. }
  63.  
  64. static {
  65. FACING = HorizontalFacingBlock.FACING;
  66. }
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. public class BlockEntityDesk extends BlockEntity {
  74.  
  75. private int numberOfItems;
  76.  
  77. public BlockEntityDesk() {
  78. super(SchoolMod.be_desk);
  79. System.out.println("Initialized Block Entity");
  80. }
  81.  
  82.  
  83. @Override
  84. public CompoundTag toTag(CompoundTag t) {
  85. super.toTag(t);
  86. t.putInt("item", numberOfItems);
  87. return t;
  88. }
  89.  
  90. @Override
  91. public void fromTag(CompoundTag t) {
  92. super.fromTag(t);
  93. numberOfItems = t.getInt("item");
  94. }
  95.  
  96.  
  97. public void addItem() {
  98. numberOfItems++;
  99. markDirty();
  100. }
  101.  
  102. public int getNumberOfItems() {
  103. return numberOfItems;
  104. }
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111. @Environment(EnvType.CLIENT)
  112. public class BlockEntityDeskRender extends BlockEntityRenderer<BlockEntityDesk> {
  113.  
  114. public BlockEntityDeskRender() {
  115. System.out.println("called oninit");
  116. }
  117.  
  118. @Override
  119. public void render(BlockEntityDesk be, double x, double y, double z, float b, int t) {
  120. super.render(be, x, y, z, b, t);
  121.  
  122. System.out.println("Rendering"); // Never prints
  123.  
  124. ItemEntity item = new ItemEntity(MinecraftClient.getInstance().world, x, y, z, new ItemStack(Items.BOOK));
  125.  
  126. GlStateManager.pushMatrix();
  127. // GlStateManager.translated(x, y, z);
  128. MinecraftClient.getInstance().getEntityRenderManager().render(item, 0, 0, 0, 0F, 0F, false);
  129. GlStateManager.popMatrix();
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement