Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mart.solar.common.blocks;
- import com.mart.solar.Solar;
- import com.mart.solar.common.blocks.base.BlockBase;
- import com.mart.solar.common.blocks.base.BlockEnum;
- import com.mart.solar.common.blocks.enums.EnumMenhir;
- import com.mart.solar.common.blocks.enums.EnumSunBurnt;
- import com.mart.solar.common.tileentities.TileMenhir;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.state.BlockFaceShape;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.Mirror;
- import net.minecraft.util.Rotation;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import javax.annotation.Nullable;
- public class BlockMenhir extends BlockEnum<EnumMenhir> {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- public BlockMenhir() {
- super(Material.ROCK, EnumMenhir.class);
- setUnlocalizedName(Solar.MODID + ".menhir_");
- setCreativeTab(Solar.solarTab);
- setHardness(3.0F);
- setResistance(5.0F);
- setSoundType(SoundType.STONE);
- setHarvestLevel("pickaxe", 0);
- setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
- }
- @Override
- public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- TileMenhir tileEntity = (TileMenhir) world.getTileEntity(pos);
- ItemStack heldItem = player.getHeldItem(hand);
- if (world.isRemote || tileEntity == null) {
- return true;
- }
- if (player.isSneaking()){
- player.swingArm(hand);
- tileEntity.extractItem(player);
- return true;
- }
- if (!heldItem.isEmpty()) {
- tileEntity.addRune(heldItem, player, hand);
- return true;
- }
- return true;
- }
- @Override
- public void breakBlock(World world, BlockPos pos, IBlockState state) {
- TileMenhir tileEntity = (TileMenhir) world.getTileEntity(pos);
- if (world.isRemote || tileEntity == null) {
- return;
- }
- if (tileEntity.getItemStackHandler().getStackInSlot(0).isEmpty()) {
- return;
- }
- double d0 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
- double d1 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
- double d2 = (double) (world.rand.nextFloat() * 0.5F) + 0.25D;
- EntityItem dropItem = new EntityItem(world, (double) pos.getX() + d0, (double) pos.getY() + d1, (double) pos.getZ() + d2, tileEntity.getItemStackHandler().getStackInSlot(0));
- dropItem.setDefaultPickupDelay();
- world.spawnEntity(dropItem);
- }
- @Override
- public boolean hasTileEntity(IBlockState state) {
- return true;
- }
- @Nullable
- @Override
- public TileEntity createTileEntity(World world, IBlockState state) {
- return new TileMenhir();
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- @Deprecated
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
- return BlockFaceShape.UNDEFINED;
- }
- /**
- * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
- * IBlockstate
- */
- @Override
- public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
- {
- return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
- }
- /**
- * Called by ItemBlocks after a block is set in the world, to allow post-place logic
- */
- @Override
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
- {
- worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
- }
- /**
- * Convert the given metadata into a BlockState for this Block
- */
- @Override
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
- }
- /**
- * Convert the BlockState into the correct metadata value
- */
- @Override
- public int getMetaFromState(IBlockState state)
- {
- return state.getValue(FACING).getHorizontalIndex();
- }
- /**
- * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
- * blockstate.
- */
- @Override
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
- }
- /**
- * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
- * blockstate.
- */
- @Override
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
- }
- @Override
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, FACING);
- }
- }
Add Comment
Please, Sign In to add comment