package thaumcraft.common.blocks.world.ore; import java.util.*; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.*; import net.minecraft.block.state.*; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.*; 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.common.property.*; import thaumcraft.api.ThaumcraftApiHelper; import thaumcraft.api.aspects.Aspect; import thaumcraft.api.aura.AuraHelper; import thaumcraft.common.config.ConfigItems; import thaumcraft.common.lib.SoundsTC; import thaumcraft.common.lib.utils.BlockUtils; import thaumcraft.common.world.aura.AuraHandler; public class BlockCrystal extends Block { public static final PropertyInteger SIZE = PropertyInteger.func_177719_a("size", 0, 3); public static final PropertyInteger GENERATION = PropertyInteger.func_177719_a("gen", 1, 4); public static final IUnlistedProperty NORTH = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("north")); public static final IUnlistedProperty EAST = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("east")); public static final IUnlistedProperty SOUTH = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("south")); public static final IUnlistedProperty WEST = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("west")); public static final IUnlistedProperty UP = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("up")); public static final IUnlistedProperty DOWN = new net.minecraftforge.common.property.Properties.PropertyAdapter(PropertyBool.func_177716_a("down")); public Aspect aspect; public BlockCrystal(String name, Aspect aspect) { super(Material.field_151592_s); func_149663_c(name); setRegistryName("thaumcraft", name); this.aspect = aspect; func_149711_c(0.25F); func_149672_a(SoundsTC.CRYSTAL); func_149675_a(true); func_149647_a(ConfigItems.TABTC); func_180632_j(field_176227_L.func_177621_b().func_177226_a(SIZE, Integer.valueOf(0)).func_177226_a(GENERATION, Integer.valueOf(1))); } public SoundType func_185467_w() { return SoundsTC.CRYSTAL; } public BlockFaceShape func_193383_a(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) { return BlockFaceShape.UNDEFINED; } public EnumBlockRenderType func_149645_b(IBlockState state) { return EnumBlockRenderType.MODEL; } public Item func_180660_a(IBlockState state, Random rand, int fortune) { return Item.func_150899_d(0); } protected boolean func_149700_E() { return false; } public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { List ret = new ArrayList(); int count = getGrowth(state) + 1; for(int i = 0; i < count; i++) { ret.add(ThaumcraftApiHelper.makeCrystal(aspect)); } return ret; } public void func_180650_b(World worldIn, BlockPos pos, IBlockState state, Random rand) { if(!worldIn.field_72995_K && rand.nextInt(3 + getGeneration(state)) == 0) { int threshold = 10; int growth = getGrowth(state); int generation = getGeneration(state); if(aspect != Aspect.FLUX) { if(AuraHelper.getVis(worldIn, pos) <= (float)threshold) { if(growth > 0) { worldIn.func_175656_a(pos, state.func_177226_a(SIZE, Integer.valueOf(growth - 1))); AuraHelper.addVis(worldIn, pos, threshold); } else if(BlockUtils.isBlockTouching(worldIn, pos, this)) { worldIn.func_175698_g(pos); AuraHandler.addVis(worldIn, pos, threshold); } } else if(AuraHelper.getVis(worldIn, pos) > (float)(AuraHandler.getAuraBase(worldIn, pos) + threshold)) { if(growth < 3 && (long)growth < (long)(5 - generation) + pos.func_177986_g() % 3L) { if(AuraHelper.drainVis(worldIn, pos, threshold, false) > 0.0F) { worldIn.func_175656_a(pos, state.func_177226_a(SIZE, Integer.valueOf(growth + 1))); } } else if(generation < 4) { BlockPos p2 = spreadCrystal(worldIn, pos); if(p2 != null && AuraHelper.drainVis(worldIn, pos, threshold, false) > 0.0F) { if(rand.nextInt(6) == 0) { generation--; } worldIn.func_175656_a(p2, func_176223_P().func_177226_a(GENERATION, Integer.valueOf(generation + 1))); } } } } else if(AuraHelper.getFlux(worldIn, pos) <= (float)threshold) { if(growth > 0) { worldIn.func_175656_a(pos, state.func_177226_a(SIZE, Integer.valueOf(growth - 1))); AuraHelper.polluteAura(worldIn, pos, threshold, false); } else if(BlockUtils.isBlockTouching(worldIn, pos, this)) { worldIn.func_175698_g(pos); AuraHelper.polluteAura(worldIn, pos, threshold, false); } } else if(AuraHelper.getFlux(worldIn, pos) > (float)(AuraHandler.getAuraBase(worldIn, pos) + threshold)) { if(growth < 3 && (long)growth < (long)(5 - generation) + pos.func_177986_g() % 3L) { if(AuraHelper.drainFlux(worldIn, pos, threshold, false) > 0.0F) { worldIn.func_175656_a(pos, state.func_177226_a(SIZE, Integer.valueOf(growth + 1))); } } else if(generation < 4) { BlockPos p2 = spreadCrystal(worldIn, pos); if(p2 != null && AuraHelper.drainFlux(worldIn, pos, threshold, false) > 0.0F) { if(rand.nextInt(6) == 0) { generation--; } worldIn.func_175656_a(p2, func_176223_P().func_177226_a(GENERATION, Integer.valueOf(generation + 1))); } } } } } public static BlockPos spreadCrystal(World world, BlockPos pos) { int xx = (pos.func_177958_n() + world.field_73012_v.nextInt(3)) - 1; int yy = (pos.func_177956_o() + world.field_73012_v.nextInt(3)) - 1; int zz = (pos.func_177952_p() + world.field_73012_v.nextInt(3)) - 1; BlockPos t = new BlockPos(xx, yy, zz); if(t.equals(pos)) { return null; } IBlockState bs = world.func_180495_p(t); Material bm = bs.func_185904_a(); if(!bm.func_76224_d() && (world.func_175623_d(t) || bs.func_177230_c().func_176200_f(world, t)) && world.field_73012_v.nextInt(16) == 0 && BlockUtils.isBlockTouching(world, t, Material.field_151576_e, true)) { return t; } else { return null; } } public void func_189540_a(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if(!BlockUtils.isBlockTouching(worldIn, pos, Material.field_151576_e, true)) { func_176226_b(worldIn, pos, state, 0); worldIn.func_175698_g(pos); } } public boolean isSideSolid(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing enumfacing) { return false; } private boolean drawAt(IBlockAccess worldIn, BlockPos pos, EnumFacing side) { IBlockState fbs = worldIn.func_180495_p(pos); return fbs.func_185904_a() == Material.field_151576_e && fbs.func_177230_c().isSideSolid(fbs, worldIn, pos, side.func_176734_d()); } public AxisAlignedBB func_185496_a(IBlockState bs, IBlockAccess iblockaccess, BlockPos pos) { IBlockState state = getExtendedState(bs, iblockaccess, pos); if(state instanceof IExtendedBlockState) { IExtendedBlockState es = (IExtendedBlockState)state; int c = 0; if(((Boolean)es.getValue(UP)).booleanValue()) { c++; } if(((Boolean)es.getValue(DOWN)).booleanValue()) { c++; } if(((Boolean)es.getValue(EAST)).booleanValue()) { c++; } if(((Boolean)es.getValue(WEST)).booleanValue()) { c++; } if(((Boolean)es.getValue(SOUTH)).booleanValue()) { c++; } if(((Boolean)es.getValue(NORTH)).booleanValue()) { c++; } if(c > 1) { return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } if(((Boolean)es.getValue(UP)).booleanValue()) { return new AxisAlignedBB(0.0D, 0.5D, 0.0D, 1.0D, 1.0D, 1.0D); } if(((Boolean)es.getValue(DOWN)).booleanValue()) { return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D); } if(((Boolean)es.getValue(EAST)).booleanValue()) { return new AxisAlignedBB(0.5D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } if(((Boolean)es.getValue(WEST)).booleanValue()) { return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.5D, 1.0D, 1.0D); } if(((Boolean)es.getValue(SOUTH)).booleanValue()) { return new AxisAlignedBB(0.0D, 0.0D, 0.5D, 1.0D, 1.0D, 1.0D); } if(((Boolean)es.getValue(NORTH)).booleanValue()) { return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.5D); } } return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } public AxisAlignedBB func_180646_a(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return null; } public boolean func_149662_c(IBlockState state) { return false; } public boolean func_149686_d(IBlockState state) { return false; } public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { return 1; } public int func_185484_c(IBlockState state, IBlockAccess source, BlockPos pos) { int i = source.func_175626_b(pos, state.getLightValue(source, pos)); int j = 180; int k = i & 0xff; int l = j & 0xff; int i1 = i >> 16 & 0xff; int j1 = j >> 16 & 0xff; return (k <= l ? l : k) | (i1 <= j1 ? j1 : i1) << 16; } protected BlockStateContainer func_180661_e() { IProperty listedProperties[] = { SIZE, GENERATION }; IUnlistedProperty unlistedProperties[] = { UP, DOWN, NORTH, EAST, WEST, SOUTH }; return new ExtendedBlockState(this, listedProperties, unlistedProperties); } public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { if(state instanceof IExtendedBlockState) { IExtendedBlockState retval = (IExtendedBlockState)state; return retval.withProperty(UP, Boolean.valueOf(drawAt(world, pos.func_177984_a(), EnumFacing.UP))).withProperty(DOWN, Boolean.valueOf(drawAt(world, pos.func_177977_b(), EnumFacing.DOWN))).withProperty(NORTH, Boolean.valueOf(drawAt(world, pos.func_177978_c(), EnumFacing.NORTH))).withProperty(EAST, Boolean.valueOf(drawAt(world, pos.func_177974_f(), EnumFacing.EAST))).withProperty(SOUTH, Boolean.valueOf(drawAt(world, pos.func_177968_d(), EnumFacing.SOUTH))).withProperty(WEST, Boolean.valueOf(drawAt(world, pos.func_177976_e(), EnumFacing.WEST))); } else { return state; } } public IBlockState func_176221_a(IBlockState state, IBlockAccess worldIn, BlockPos pos) { return state; } public IBlockState func_176203_a(int meta) { return func_176223_P().func_177226_a(SIZE, Integer.valueOf(meta & 3)).func_177226_a(GENERATION, Integer.valueOf(1 + (meta >> 2 & 3))); } public int func_176201_c(IBlockState state) { int i = 0; i |= ((Integer)state.func_177229_b(SIZE)).intValue(); i |= ((Integer)state.func_177229_b(GENERATION)).intValue() - 1 << 2; return i; } public int getGrowth(IBlockState state) { return func_176201_c(state) & 3; } public int getGeneration(IBlockState state) { return 1 + (func_176201_c(state) >> 2); } public void func_149666_a(CreativeTabs tab, NonNullList list) { list.add(new ItemStack(this, 1, 0)); } public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer) { return true; } public boolean func_176196_c(World worldIn, BlockPos pos) { return BlockUtils.isBlockTouching(worldIn, pos, Material.field_151576_e, true) && super.func_176196_c(worldIn, pos); } }