Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.theonlytails.ruby.blocks;
- import com.theonlytails.ruby.init.TileEntitiesRegistry;
- import com.theonlytails.ruby.tileentity.RubyBarrelTileEntity;
- import net.minecraft.block.AbstractBlock;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockState;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.material.MaterialColor;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.entity.player.ServerPlayerEntity;
- import net.minecraft.inventory.InventoryHelper;
- import net.minecraft.state.BooleanProperty;
- import net.minecraft.state.StateContainer;
- import net.minecraft.state.properties.BlockStateProperties;
- import net.minecraft.stats.Stats;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.ActionResultType;
- import net.minecraft.util.Hand;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.BlockRayTraceResult;
- import net.minecraft.world.IBlockReader;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.network.NetworkHooks;
- import org.jetbrains.annotations.NotNull;
- import org.jetbrains.annotations.Nullable;
- @SuppressWarnings("deprecation")
- public class RubyBarrelBlock extends Block {
- public static final BooleanProperty OPEN_PROPERTY = BlockStateProperties.OPEN;
- public RubyBarrelBlock() {
- super(AbstractBlock.Properties
- .create(Material.IRON, MaterialColor.IRON)
- .hardnessAndResistance(3.5f)
- .sound(SoundType.METAL));
- this.setDefaultState(this.getStateContainer().getBaseState().with(OPEN_PROPERTY, false));
- }
- @Override
- public boolean hasTileEntity(BlockState state) {
- return true;
- }
- @Nullable
- @Override
- public TileEntity createTileEntity(BlockState state, IBlockReader world) {
- 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()
- );
- }
- }
- }
- @Override
- protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
- builder.add(OPEN_PROPERTY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment