Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RubyBarrelBlock extends ContainerBlock {
- public RubyBarrelBlock() {
- super(AbstractBlock.Properties
- .create(Material.IRON, MaterialColor.IRON)
- .hardnessAndResistance(3.5f)
- .sound(SoundType.METAL));
- }
- @Override
- public boolean hasTileEntity(BlockState state) {
- return true;
- }
- @Nullable
- @Override
- public TileEntity createNewTileEntity(@NotNull IBlockReader worldIn) {
- return TileEntitiesRegistry.RUBY_BARREL.get().create();
- }
- @Override
- public @NotNull ActionResultType onBlockActivated(@NotNull BlockState state,
- @NotNull World worldIn,
- @NotNull BlockPos pos,
- @NotNull PlayerEntity player,
- @NotNull Hand handIn,
- @NotNull BlockRayTraceResult hit) {
- if (!worldIn.isRemote) {
- TileEntity tileentity = worldIn.getTileEntity(pos);
- if (tileentity instanceof RubyBarrelTileEntity) {
- NetworkHooks.openGui(
- ((ServerPlayerEntity) player), (RubyBarrelTileEntity) tileentity, pos);
- player.addStat(Stats.OPEN_BARREL);
- }
- return ActionResultType.SUCCESS;
- }
- return ActionResultType.SUCCESS;
- }
- @Override
- public void onReplaced(@NotNull BlockState state, @NotNull World worldIn, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving) {
- if (state.getBlock() != newState.getBlock()) {
- TileEntity tileEntity = worldIn.getTileEntity(pos);
- if (tileEntity instanceof RubyBarrelTileEntity) {
- InventoryHelper.dropItems(worldIn,
- pos,
- ((RubyBarrelTileEntity) tileEntity).getItems()
- );
- worldIn.updateComparatorOutputLevel(pos, this);
- }
- }
- }
- @Override
- public @NotNull BlockRenderType getRenderType(@NotNull BlockState state) {
- return BlockRenderType.MODEL;
- }
- @Override
- public boolean hasComparatorInputOverride(@NotNull BlockState state) {
- return true;
- }
- @Override
- public int getComparatorInputOverride(@NotNull BlockState blockState, World worldIn, @NotNull BlockPos pos) {
- return Container.calcRedstone(worldIn.getTileEntity(pos));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment