123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- package me.km.blocks;
- import java.util.Random;
- import me.km.KajetansMod;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockDirectional;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.state.BlockFaceShape;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.item.Item;
- import net.minecraft.util.BlockRenderLayer;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumParticleTypes;
- 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 net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class BlockLantern extends BlockDirectional implements IBlockBase
- {
- protected static final AxisAlignedBB HANGING_AABB = new AxisAlignedBB(0.1875d, 0.125d, 0.1875d, 0.8125d, 1, 0.875d);
- protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(0.1875d, 0, 0.1875d, 0.8125d, 0.75d, 0.875d);
-
- protected static final AxisAlignedBB TORCH_NORTH_AABB = new AxisAlignedBB(0.1875d, 0, 0.375d, 0.8125d, 1, 1);
- protected static final AxisAlignedBB TORCH_SOUTH_AABB = new AxisAlignedBB(0.1875d, 0, 0, 0.8125d, 1, 0.625d);
- protected static final AxisAlignedBB TORCH_WEST_AABB = new AxisAlignedBB(0.375d, 0, 0.1875d, 1, 1, 0.8125d);
- protected static final AxisAlignedBB TORCH_EAST_AABB = new AxisAlignedBB(0, 0, 0.1875d, 0.625d, 1, 0.8125d);
-
- protected String name;
-
- public BlockLantern(String name, String local)
- {
- super(Material.IRON);
- this.name = name;
- super.setHardness(0.0F);
- super.setLightLevel(0.9375F);
- super.setSoundType(SoundType.METAL);
- this.setRegistryName(name);
- super.setUnlocalizedName(local);
- super.setCreativeTab(CreativeTabs.DECORATIONS);
-
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
- super.setTickRandomly(true);
- }
- @Override
- public void registerItemModel(Item itemBlock)
- {
- KajetansMod.proxy.registerItemRenderer(itemBlock, 0, name);
- }
- @Override
- public BlockLantern setSoundType(SoundType sound)
- {
- super.setSoundType(sound);
- return this;
- }
- @Override
- public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess w, BlockPos pos)
- {
- return NULL_AABB;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state)
- {
- return false;
- }
- @Override
- public boolean isFullCube(IBlockState state)
- {
- return false;
- }
- @Override
- public boolean canPlaceBlockOnSide(World w, BlockPos pos, EnumFacing side)
- {
- return canPlaceBlock(w, pos, side);
- }
- @Override
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
- {
- for(EnumFacing enumfacing : EnumFacing.values())
- {
- if(canPlaceBlock(worldIn, pos, enumfacing))
- {
- return true;
- }
- }
- return false;
- }
- protected static boolean canPlaceBlock(World w, BlockPos pos, EnumFacing direction)
- {
- BlockPos blockpos = pos.offset(direction.getOpposite());
- IBlockState state = w.getBlockState(blockpos);
- Block block = state.getBlock();
- if(direction == EnumFacing.UP)
- {
- return block.canPlaceTorchOnTop(state, w, pos);
- }
- else
- {
- return !isExceptBlockForAttachWithPiston(block) && state.getBlockFaceShape(w, blockpos, direction) == BlockFaceShape.SOLID;
- }
- }
- @Override
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- return canPlaceBlock(worldIn, pos, facing) ? this.getDefaultState().withProperty(FACING, facing) : this.getDefaultState().withProperty(FACING, EnumFacing.DOWN);
- }
- @Override
- public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
- {
- if(this.checkForDrop(worldIn, pos, state) && !canPlaceBlock(worldIn, pos, state.getValue(FACING)))
- {
- this.dropBlockAsItem(worldIn, pos, state, 0);
- worldIn.setBlockToAir(pos);
- }
- }
- private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
- {
- if(this.canPlaceBlockAt(worldIn, pos))
- {
- return true;
- }
- else
- {
- this.dropBlockAsItem(worldIn, pos, state, 0);
- worldIn.setBlockToAir(pos);
- return false;
- }
- }
- @Override
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
- {
- EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
- switch(enumfacing)
- {
- case EAST:
- return TORCH_EAST_AABB;
- case WEST:
- return TORCH_WEST_AABB;
- case SOUTH:
- return TORCH_SOUTH_AABB;
- case NORTH:
- default:
- return TORCH_NORTH_AABB;
- case UP:
- return STANDING_AABB;
- case DOWN:
- return HANGING_AABB;
- }
- }
- @Override
- public IBlockState getStateFromMeta(int meta)
- {
- EnumFacing enumfacing;
- switch(meta & 7)
- {
- case 0:
- enumfacing = EnumFacing.DOWN;
- break;
- case 1:
- enumfacing = EnumFacing.EAST;
- break;
- case 2:
- enumfacing = EnumFacing.WEST;
- break;
- case 3:
- enumfacing = EnumFacing.SOUTH;
- break;
- case 4:
- enumfacing = EnumFacing.NORTH;
- break;
- case 5:
- default:
- enumfacing = EnumFacing.UP;
- }
- return this.getDefaultState().withProperty(FACING, enumfacing);
- }
- @Override
- public int getMetaFromState(IBlockState state)
- {
- switch(state.getValue(FACING))
- {
- case EAST: return 1;
- case WEST: return 2;
- case SOUTH: return 3;
- case NORTH: return 4;
- case UP:
- default: return 5;
- case DOWN: return 0;
- }
- }
- @Override
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
- }
- @Override
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
- }
- @Override
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {FACING});
- }
- @Override
- public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_)
- {
- return BlockFaceShape.UNDEFINED;
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void randomDisplayTick(IBlockState state, World w, BlockPos pos, Random rand)
- {
- EnumFacing face = state.getValue(FACING);
- double x = pos.getX() + 0.5D;
- double y = pos.getY() + 0.7D;
- double z = pos.getZ() + 0.5D;
- switch(face)
- {
- case EAST:
- case WEST:
- case SOUTH:
- case NORTH:
- EnumFacing oface = face.getOpposite();
- x += 0.1875d * oface.getFrontOffsetX();
- z += 0.1875d * oface.getFrontOffsetZ();
- break;
- case DOWN:
- break;
- case UP:
- y -= 0.125d;
- break;
- }
- w.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x, y , z, 0, 0, 0);
- w.spawnParticle(EnumParticleTypes.FLAME, x, y, z, 0, 0, 0);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public BlockRenderLayer getBlockLayer()
- {
- return BlockRenderLayer.TRANSLUCENT;
- }
- }
|