package micdoodle8.mods.galacticraft.planets.venus.blocks; import micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.blocks.BlockTileGC; import micdoodle8.mods.galacticraft.core.blocks.ISortableBlock; import micdoodle8.mods.galacticraft.core.items.IShiftDescription; import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import micdoodle8.mods.galacticraft.planets.GalacticraftPlanets; import micdoodle8.mods.galacticraft.planets.GuiIdsPlanets; import micdoodle8.mods.galacticraft.planets.venus.tile.TileEntityGeothermalGenerator; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockGeothermalGenerator extends BlockTileGC implements ITileEntityProvider, IShiftDescription, IPartialSealableBlock, ISortableBlock { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final PropertyBool ACTIVE = PropertyBool.create("active"); public BlockGeothermalGenerator(String assetName) { super(Material.iron); this.setHardness(2.5F); this.setStepSound(Block.soundTypeMetal); this.setUnlocalizedName(assetName); } @Override public CreativeTabs getCreativeTabToDisplayOn() { return GalacticraftCore.galacticraftBlocksTab; } @Override public int getRenderType() { return 3; } @Override public boolean onMachineActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { playerIn.openGui(GalacticraftPlanets.instance, GuiIdsPlanets.MACHINE_VENUS, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; int change = EnumFacing.getHorizontal(angle).getOpposite().getHorizontalIndex(); worldIn.setBlockState(pos, getStateFromMeta(change), 3); } @Override public boolean onUseWrench(World world, BlockPos pos, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) { int change = world.getBlockState(pos).getValue(FACING).rotateY().getHorizontalIndex(); world.setBlockState(pos, this.getStateFromMeta(change), 3); return true; } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityGeothermalGenerator(); } @Override public String getShiftDescription(int meta) { return GCCoreUtil.translate(this.getUnlocalizedName() + ".description"); } @Override public boolean showDescription(int meta) { return true; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isSealed(World worldIn, BlockPos pos, EnumFacing direction) { return true; } @Override public EnumSortCategoryBlock getCategory(int meta) { return EnumSortCategoryBlock.MACHINE; } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getHorizontal(meta % 4); return this.getDefaultState().withProperty(FACING, enumfacing); } @Override public int getMetaFromState(IBlockState state) { return state.getValue(FACING).getHorizontalIndex(); } @Override protected BlockState createBlockState() { return new BlockState(this, FACING, ACTIVE); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { TileEntity tile = worldIn.getTileEntity(pos); if (!(tile instanceof TileEntityGeothermalGenerator)) { return state; } TileEntityGeothermalGenerator generator = (TileEntityGeothermalGenerator) tile; return state.withProperty(ACTIVE, generator.hasValidSpout() && !generator.getDisabled(0)); } }