package micdoodle8.mods.galacticraft.core.blocks; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.items.IShiftDescription; import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Random; public class BlockGlowstoneTorch extends BlockTorchBase implements IShiftDescription, ISortableBlock { public BlockGlowstoneTorch(String assetName) { super(Material.circuits); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP)); this.setTickRandomly(true); this.setUnlocalizedName(assetName); this.setLightLevel(0.85F); this.setStepSound(Block.soundTypeWood); } @Override public CreativeTabs getCreativeTabToDisplayOn() { return GalacticraftCore.galacticraftBlocksTab; } @Override public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) { return null; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } @Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { for (EnumFacing enumfacing : FACING.getAllowedValues()) { if (this.canPlaceAt(worldIn, pos, enumfacing)) { return true; } } return false; } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.checkForDrop(worldIn, pos, state); } @Override public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { this.onNeighborChangeInternal(worldIn, pos, state); } protected boolean onNeighborChangeInternal(World worldIn, BlockPos pos, IBlockState state) { if (!this.checkForDrop(worldIn, pos, state)) { return true; } else { EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); EnumFacing.Axis enumfacing$axis = enumfacing.getAxis(); EnumFacing enumfacing1 = enumfacing.getOpposite(); boolean flag = false; if (enumfacing$axis.isHorizontal() && !worldIn.isSideSolid(pos.offset(enumfacing1), enumfacing, true)) { flag = true; } else if (enumfacing$axis.isVertical() && !this.canPlaceOn(worldIn, pos.offset(enumfacing1))) { flag = true; } if (flag) { this.dropBlockAsItem(worldIn, pos, state, 0); worldIn.setBlockToAir(pos); return true; } else { return false; } } } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (getMetaFromState(state) == 0) { this.onBlockAdded(worldIn, pos, state); } } @Override public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end) { int l = getMetaFromState(worldIn.getBlockState(pos)) & 7; float f = 0.15F; if (l == 1) { this.setBlockBounds(0.0F, 0.2F, 0.5F - f, f * 2.0F, 0.8F, 0.5F + f); } else if (l == 2) { this.setBlockBounds(1.0F - f * 2.0F, 0.2F, 0.5F - f, 1.0F, 0.8F, 0.5F + f); } else if (l == 3) { this.setBlockBounds(0.5F - f, 0.2F, 0.0F, 0.5F + f, 0.8F, f * 2.0F); } else if (l == 4) { this.setBlockBounds(0.5F - f, 0.2F, 1.0F - f * 2.0F, 0.5F + f, 0.8F, 1.0F); } else { f = 0.1F; this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.6F, 0.5F + f); } return super.collisionRayTrace(worldIn, pos, start, end); } @Override @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { return EnumWorldBlockLayer.CUTOUT; } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { FACING }); } @Override public String getShiftDescription(int meta) { return GCCoreUtil.translate(this.getUnlocalizedName() + ".description"); } @Override public boolean showDescription(int meta) { return true; } @Override public EnumSortCategoryBlock getCategory(int meta) { return EnumSortCategoryBlock.GENERAL; } }