package micdoodle8.mods.galacticraft.core.blocks; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.energy.tile.TileBaseUniversalElectrical; import micdoodle8.mods.galacticraft.core.items.IShiftDescription; import micdoodle8.mods.galacticraft.core.tile.TileEntityRefinery; 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.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.EnumParticleTypes; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Random; public class BlockRefinery extends BlockAdvancedTile implements IShiftDescription, ISortableBlock { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockRefinery(String assetName) { super(Material.rock); this.setHardness(1.0F); this.setStepSound(Block.soundTypeMetal); this.setUnlocalizedName(assetName); } @Override public CreativeTabs getCreativeTabToDisplayOn() { return GalacticraftCore.galacticraftBlocksTab; } @Override @SideOnly(Side.CLIENT) public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { final TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityRefinery) { final TileEntityRefinery refinery = (TileEntityRefinery) te; if (refinery.processTicks > 0) { final float var7 = pos.getX() + 0.5F; final float var8 = pos.getY() + 1.1F; final float var9 = pos.getZ() + 0.5F; final float var10 = 0.0F; final float var11 = 0.0F; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, var7 + var11 + i * 0.2, var8, var9 + var10 + j * 0.2, 0.0D, 0.01D, 0.0D); worldIn.spawnParticle(EnumParticleTypes.FLAME, var7 + var11 + i * 0.1, var8 - 0.2, var9 + var10 + j * 0.1, 0.0D, 0.0001D, 0.0D); } } } } } @Override public boolean onMachineActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) { entityPlayer.openGui(GalacticraftCore.instance, -1, world, pos.getX(), pos.getY(), pos.getZ()); return true; } @Override public boolean onUseWrench(World world, BlockPos pos, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) { int metadata = getMetaFromState(world.getBlockState(pos)); int change = world.getBlockState(pos).getValue(FACING).rotateY().getHorizontalIndex(); world.setBlockState(pos, this.getStateFromMeta(metadata - (metadata % 4) + change), 3); TileEntity te = world.getTileEntity(pos); if (te instanceof TileBaseUniversalElectrical) { ((TileBaseUniversalElectrical) te).updateFacing(); } return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityRefinery(); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { final int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; worldIn.setBlockState(pos, getStateFromMeta(EnumFacing.getHorizontal(angle).getOpposite().getHorizontalIndex()), 3); } @Override public String getShiftDescription(int meta) { return GCCoreUtil.translate(this.getUnlocalizedName() + ".description"); } @Override public boolean showDescription(int meta) { return true; } @Override public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getHorizontal(meta); return this.getDefaultState().withProperty(FACING, enumfacing); } @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex(); } @Override protected BlockState createBlockState() { return new BlockState(this, FACING); } @Override public EnumSortCategoryBlock getCategory(int meta) { return EnumSortCategoryBlock.MACHINE; } }