Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.blocks;
- import java.awt.Color;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockLeaves;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.IIcon;
- import net.minecraft.world.ColorizerFoliage;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraft.world.biome.BiomeGenBase;
- import net.minecraft.world.biome.BiomeGenBase.TempCategory;
- import net.minecraft.world.biome.BiomeGenDesert;
- import net.minecraft.world.biome.BiomeGenJungle;
- import net.minecraft.world.biome.BiomeGenSavanna;
- import net.minecraft.world.biome.BiomeGenTaiga;
- import net.minecraftforge.common.util.ForgeDirection;
- import com.chef.mod.Debugger;
- import com.chef.mod.Reference;
- import com.chef.mod.init.MyBlocks;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class MangoLeaves extends BlockLeaves {
- int[] fieldA;
- @SideOnly(Side.CLIENT)
- private IIcon[] iconArray;
- private boolean recentlyGrownMango = false;
- private int recentlyGrownMangoTime = 0;
- @SideOnly(Side.CLIENT)
- public int getRenderColor(int i)
- {
- return (i & 3) == 1 ? ColorizerFoliage.getFoliageColorPine() : ((i & 3) == 2 ? ColorizerFoliage.getFoliageColorBirch() : super.getRenderColor(i));
- }
- @Override
- protected int func_150123_b(int metadata)
- {
- return 100;
- }
- @Override
- public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face)
- {
- return 30;
- }
- @Override
- public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face)
- {
- return 60;
- }
- /**
- * Called when fire is updating, checks if a block face can catch fire.
- *
- *
- * @param world The current world
- * @param x The blocks X position
- * @param y The blocks Y position
- * @param z The blocks Z position
- * @param face The face that the fire is coming from
- * @return True if the face can be on fire, false otherwise.
- */
- public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face)
- {
- return true;
- }
- /**
- * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
- * when first determining what to render.
- */
- @SideOnly(Side.CLIENT)
- public int colorMultiplier(IBlockAccess world, int x, int y, int z)
- {
- Color c = new Color(world.getBiomeGenForCoords(x, z).getBiomeFoliageColor(x, y, z));
- return c.brighter().getRGB();
- }
- public int getDamageValue(World world, int x, int y, int z) {
- return world.getBlockMetadata(x, y, z);
- }
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int meta) {
- this.setGraphicsLevel(Minecraft.getMinecraft().gameSettings.fancyGraphics);
- return this.iconArray[this.field_150127_b];
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconRegister) {
- this.iconArray = new IIcon[2];
- this.iconArray[0] = iconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(5));
- this.iconArray[1] = iconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(5) + "_opaque");
- }
- public void updateTick(World worldIn, int x, int y, int z, Random rand) {
- int metadata = worldIn.getBlockMetadata(x, y, z);
- super.updateTick(worldIn, x, y, z, rand);
- if (worldIn.getBlockLightValue(x, y, z) >= 5) {
- if (metadata == 1) {
- if (this.canGrowMango(worldIn, x, y, z, rand)) {
- if (rand.nextInt(calculateGrowthSpeed(worldIn, x, y, z, rand)) == 0) {
- this.growMango(worldIn, x, y - 1, z, rand);
- recentlyGrownMangoTime = 200;
- }
- }
- if (recentlyGrownMangoTime > 0) {
- recentlyGrownMango = true;
- recentlyGrownMangoTime--;
- } else {
- recentlyGrownMango = false;
- }
- }
- }
- }
- public int calculateGrowthSpeed(World worldIn, int x, int y, int z, Random rand) {
- BiomeGenBase biome = worldIn.getBiomeGenForCoords(x, z);
- TempCategory tempCategory = biome.getTempCategory();
- // The Growth speed the plant will have
- int growthSpeed = 20;
- // The extra growth speed
- int extraGrowthSpeed = 0;
- // The extraSpeed you get from the light value
- int extraSpeedLightValue = Math.round(worldIn.getBlockLightValue(x, y, z) / 3);
- // The extra Speed you get from the biome temperature and biome
- int biomeExtraSpeed = Math.round(biome.temperature);
- if (tempCategory == biome.getTempCategory().COLD) {
- biomeExtraSpeed -= 3;
- } else if (tempCategory == biome.getTempCategory().MEDIUM) {
- biomeExtraSpeed += 5;
- } else if (tempCategory == biome.getTempCategory().WARM) {
- biomeExtraSpeed -= 2;
- }
- if (biome instanceof BiomeGenJungle) {
- biomeExtraSpeed += 3;
- } else if (biome instanceof BiomeGenTaiga) {
- biomeExtraSpeed -= 2;
- } else if (biome instanceof BiomeGenDesert) {
- biomeExtraSpeed -= 2;
- } else if (biome instanceof BiomeGenSavanna) {
- biomeExtraSpeed -= 1;
- }
- if (worldIn.isRaining()) {
- extraGrowthSpeed += 3;
- }
- extraGrowthSpeed = extraSpeedLightValue + biomeExtraSpeed;
- growthSpeed -= extraGrowthSpeed;
- return growthSpeed;
- }
- public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase livingBase, ItemStack itemstack) {
- worldIn.setBlockMetadataWithNotify(x, y, z, 15, 2);
- }
- private void growMango(World worldIn, int x, int y, int z, Random rand) {
- worldIn.setBlock(x, y, z, MyBlocks.mangoes);
- }
- private boolean canGrowMango(World worldIn, int x, int y, int z, Random rand) {
- Block block = worldIn.getBlock(x, y - 1, z);
- if (this.isConnectedToTree(worldIn, x, y, z)) {
- if (block == Blocks.air) {
- if (worldIn.getBlock(x - 1, y - 1, z - 1) == Blocks.air && worldIn.getBlock(x - 1, y - 1, z) == Blocks.air
- && worldIn.getBlock(x - 1, y - 1, z + 1) == Blocks.air && worldIn.getBlock(x, y - 1, z - 1) == Blocks.air
- && worldIn.getBlock(x, y - 1, z) == Blocks.air && worldIn.getBlock(x, y - 1, z + 1) == Blocks.air
- && worldIn.getBlock(x + 1, y - 1, z - 1) == Blocks.air && worldIn.getBlock(x + 1, y - 1, z) == Blocks.air
- && worldIn.getBlock(x + 1, y - 1, z + 1) == Blocks.air) {
- if (recentlyGrownMango) {
- return false;
- } else {
- return true;
- }
- }
- }
- }
- return false;
- }
- private boolean isConnectedToTree(World worldIn, int x, int y, int z) {
- byte b0 = 4;
- int i1 = b0 + 1;
- byte b1 = 32;
- int j1 = b1 * b1;
- int k1 = b1 / 2;
- if (this.fieldA == null) {
- this.fieldA = new int[b1 * b1 * b1];
- }
- int l1;
- if (worldIn.checkChunksExist(x - i1, y - i1, z - i1, x + i1, y + i1, z + i1)) {
- int i2;
- int j2;
- for (l1 = -b0; l1 <= b0; ++l1) {
- for (i2 = -b0; i2 <= b0; ++i2) {
- for (j2 = -b0; j2 <= b0; ++j2) {
- Block block = worldIn.getBlock(x + l1, y + i2, z + j2);
- if (!block.canSustainLeaves(worldIn, x + l1, y + i2, z + j2)) {
- if (block.isLeaves(worldIn, x + l1, y + i2, z + j2)) {
- this.fieldA[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
- } else {
- this.fieldA[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
- }
- } else {
- this.fieldA[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
- }
- }
- }
- }
- for (l1 = 1; l1 <= 4; ++l1) {
- for (i2 = -b0; i2 <= b0; ++i2) {
- for (j2 = -b0; j2 <= b0; ++j2) {
- for (int k2 = -b0; k2 <= b0; ++k2) {
- if (this.fieldA[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1) {
- if (this.fieldA[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
- this.fieldA[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
- }
- if (this.fieldA[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2) {
- this.fieldA[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
- }
- if (this.fieldA[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2) {
- this.fieldA[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
- }
- if (this.fieldA[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2) {
- this.fieldA[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
- }
- if (this.fieldA[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2) {
- this.fieldA[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
- }
- if (this.fieldA[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2) {
- this.fieldA[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
- }
- }
- }
- }
- }
- }
- }
- l1 = this.fieldA[k1 * j1 + k1 * b1 + k1];
- if (l1 >= 0) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public String[] func_150125_e() {
- return null;
- }
- public boolean isOpaqueCube() {
- this.setGraphicsLevel(Minecraft.getMinecraft().isFancyGraphicsEnabled());
- return !this.field_150121_P;
- }
- public int damageDropped(int i) {
- return 0;
- }
- public Item getItemDropped(int i, Random rand, int fortune) {
- return Item.getItemFromBlock(MyBlocks.sapling);
- }
- }
Add Comment
Please, Sign In to add comment