TheOnlyTails

Block

Sep 29th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. public class RubyBarrelBlock extends ContainerBlock {
  2.  
  3.     public RubyBarrelBlock() {
  4.         super(AbstractBlock.Properties
  5.                 .create(Material.IRON, MaterialColor.IRON)
  6.                 .hardnessAndResistance(3.5f)
  7.                 .sound(SoundType.METAL));
  8.     }
  9.  
  10.     @Override
  11.     public boolean hasTileEntity(BlockState state) {
  12.         return true;
  13.     }
  14.  
  15.     @Nullable
  16.     @Override
  17.     public TileEntity createNewTileEntity(@NotNull IBlockReader worldIn) {
  18.         return TileEntitiesRegistry.RUBY_BARREL.get().create();
  19.     }
  20.  
  21.     @Override
  22.     public @NotNull ActionResultType onBlockActivated(@NotNull BlockState state,
  23.                                                       @NotNull World worldIn,
  24.                                                       @NotNull BlockPos pos,
  25.                                                       @NotNull PlayerEntity player,
  26.                                                       @NotNull Hand handIn,
  27.                                                       @NotNull BlockRayTraceResult hit) {
  28.         if (!worldIn.isRemote) {
  29.             TileEntity tileentity = worldIn.getTileEntity(pos);
  30.  
  31.             if (tileentity instanceof RubyBarrelTileEntity) {
  32.                 NetworkHooks.openGui(
  33.                         ((ServerPlayerEntity) player), (RubyBarrelTileEntity) tileentity, pos);
  34.                 player.addStat(Stats.OPEN_BARREL);
  35.             }
  36.  
  37.             return ActionResultType.SUCCESS;
  38.  
  39.         }
  40.  
  41.         return ActionResultType.SUCCESS;
  42.     }
  43.  
  44.     @Override
  45.     public void onReplaced(@NotNull BlockState state, @NotNull World worldIn, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) {
  46.         if (state.getBlock() != newState.getBlock()) {
  47.             TileEntity tileEntity = worldIn.getTileEntity(pos);
  48.  
  49.             if (tileEntity instanceof RubyBarrelTileEntity) {
  50.                 InventoryHelper.dropItems(worldIn,
  51.                         pos,
  52.                         ((RubyBarrelTileEntity) tileEntity).getItems()
  53.  
  54.                 );
  55.  
  56.                 worldIn.updateComparatorOutputLevel(pos, this);
  57.             }
  58.         }
  59.     }
  60.  
  61.     @Override
  62.     public @NotNull BlockRenderType getRenderType(@NotNull BlockState state) {
  63.         return BlockRenderType.MODEL;
  64.     }
  65.  
  66.     @Override
  67.     public boolean hasComparatorInputOverride(@NotNull BlockState state) {
  68.         return true;
  69.     }
  70.  
  71.     @Override
  72.     public int getComparatorInputOverride(@NotNull BlockState blockState, World worldIn, @NotNull BlockPos pos) {
  73.         return Container.calcRedstone(worldIn.getTileEntity(pos));
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment