Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mrcyberdragon.lightthenight.blocks;
- import com.mrcyberdragon.lightthenight.Main;
- import com.mrcyberdragon.lightthenight.init.ModBlocks;
- import com.mrcyberdragon.lightthenight.init.ModItems;
- import com.mrcyberdragon.lightthenight.util.IHasModel;
- import net.minecraft.block.*;
- 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.entity.EntityLivingBase;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemBlock;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.BlockRenderLayer;
- import net.minecraft.util.EnumFacing;
- 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;
- import javax.annotation.Nullable;
- import java.util.Random;
- public class BlockTreeGlowshrooms extends BlockHorizontal implements IHasModel {
- public BlockTreeGlowshrooms(String name, Material material){
- super(material);
- this.setUnlocalizedName(name);
- this.setRegistryName(name);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
- this.setLightLevel(0.3F);
- this.setCreativeTab(Main.ltntab);
- this.setSoundType(SoundType.PLANT);
- ModBlocks.BLOCKS.add(this);
- ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
- }
- public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
- if (!this.canBlockStay(worldIn, pos, state)) {
- this.dropBlock(worldIn, pos, state);
- }
- }
- public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
- {
- for (EnumFacing enumfacing : FACING.getAllowedValues())
- {
- if (this.canPlaceAt(worldIn, pos, enumfacing))
- {
- return true;
- }
- }
- return false;
- }
- private boolean canPlaceAt(World worldIn, BlockPos pos, EnumFacing facing)
- {
- BlockPos blockpos = pos.offset(facing.getOpposite());
- IBlockState iblockstate = worldIn.getBlockState(blockpos);
- Block block = iblockstate.getBlock();
- BlockFaceShape blockfaceshape = iblockstate.getBlockFaceShape(worldIn, blockpos, facing);
- if (facing != EnumFacing.UP && facing != EnumFacing.DOWN)
- {
- return (block==Blocks.LOG||block==Blocks.LOG2||block==ModBlocks.INFECTED_WOOD)&& blockfaceshape == BlockFaceShape.SOLID;
- }
- else
- {
- return false;
- }
- }
- public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
- {
- pos = pos.offset((EnumFacing)state.getValue(FACING));
- IBlockState iblockstate = worldIn.getBlockState(pos);
- return iblockstate.getBlock() == Blocks.LOG || iblockstate.getBlock()==Blocks.LOG2 || iblockstate.getBlock()==ModBlocks.INFECTED_WOOD;
- }
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
- }
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
- {
- EnumFacing enumfacing = EnumFacing.fromAngle((double)placer.rotationYaw);
- worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
- }
- public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
- {
- if (this.canPlaceAt(worldIn, pos, facing))
- {
- return this.getDefaultState().withProperty(FACING, facing);
- }
- else
- {
- for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
- {
- if (this.canPlaceAt(worldIn, pos, enumfacing))
- {
- return this.getDefaultState().withProperty(FACING, enumfacing);
- }
- }
- return this.getDefaultState();
- }
- }
- public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
- {
- if (!this.canBlockStay(worldIn, pos, state))
- {
- this.dropBlock(worldIn, pos, state);
- }
- }
- private void dropBlock(World worldIn, BlockPos pos, IBlockState state)
- {
- worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
- this.dropBlockAsItem(worldIn, pos, state, 0);
- }
- public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
- {
- return BlockFaceShape.UNDEFINED;
- }
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
- }
- public int getMetaFromState(IBlockState state)
- {
- int i = 0;
- i = i | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();
- return i;
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {FACING});
- }
- /*@Override
- public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
- if(worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)){
- }
- }*/
- @Nullable
- public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
- {
- return NULL_AABB;
- }
- @SideOnly(Side.CLIENT)
- public BlockRenderLayer getBlockLayer()
- {
- return BlockRenderLayer.TRANSLUCENT;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public int getPackedLightmapCoords(IBlockState state, IBlockAccess source, BlockPos pos)
- {
- return 15728880;
- }
- public boolean isOpaqueCube(IBlockState state)
- {
- return false;
- }
- public boolean isFullCube(IBlockState state)
- {
- return false;
- }
- @Override
- public void registerModels() {
- Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement