Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tristanvo.mod;
- import java.util.ArrayList;
- import java.util.Random;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockLeavesBase;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.entity.player.EntityPlayer;
- 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.minecraftforge.common.IShearable;
- public class mangoLeaf extends BlockLeavesBase implements IShearable
- {
- int[] field_150128_a;
- @SideOnly(Side.CLIENT)
- protected int field_150127_b;
- protected IIcon icon1;
- protected IIcon icon2;
- public mangoLeaf()
- {
- super(Material.leaves, false);
- this.setTickRandomly(true);
- this.setHardness(0.2F);
- this.setLightOpacity(1);
- this.setStepSound(soundTypeGrass);
- }
- @SideOnly(Side.CLIENT)
- public int getBlockColor()
- {
- double d0 = 0.5D;
- double d1 = 1.0D;
- return ColorizerFoliage.getFoliageColor(d0, d1);
- }
- /**
- * Returns the color this block should be rendered. Used by leaves.
- */
- @SideOnly(Side.CLIENT)
- public int getRenderColor(int par1)
- {
- return ColorizerFoliage.getFoliageColorBasic();
- }
- /**
- * 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 par1, int par2, int par3, int par4)
- {
- int l = 0;
- int i1 = 0;
- int j1 = 0;
- for (int k1 = -1; k1 <= 1; ++k1)
- {
- for (int l1 = -1; l1 <= 1; ++l1)
- {
- int i2 = par1.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeFoliageColor(par2 + l1, par3, par4 + k1);
- l += (i2 & 16711680) >> 16;
- i1 += (i2 & 65280) >> 8;
- j1 += i2 & 255;
- }
- }
- return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
- }
- public void breakBlock(World world, int x, int y, int z, Block blocks, int side)
- {
- byte b0 = 1;
- int i1 = b0 + 1;
- if (world.checkChunksExist(x - i1, y - i1, z - i1, x + i1, y + i1, z + i1))
- {
- for (int j1 = -b0; j1 <= b0; ++j1)
- {
- for (int k1 = -b0; k1 <= b0; ++k1)
- {
- for (int l1 = -b0; l1 <= b0; ++l1)
- {
- Block block = world.getBlock(x + j1, y + k1, z + l1);
- if (block.isLeaves(world, x + j1, y + k1, z + l1))
- {
- block.beginLeavesDecay(world, x + j1, y + k1, z + l1);
- }
- }
- }
- }
- }
- }
- /**
- * Ticks the block if it's been scheduled
- */
- public void updateTick(World world, int par2, int par3, int par4, Random random)
- {
- if (!world.isRemote)
- {
- int l = world.getBlockMetadata(par2, par3, par4);
- if ((l & 8) != 0 && (l & 4) == 0)
- {
- byte b0 = 4;
- int i1 = b0 + 1;
- byte b1 = 32;
- int j1 = b1 * b1;
- int k1 = b1 / 2;
- if (this.field_150128_a == null)
- {
- this.field_150128_a = new int[b1 * b1 * b1];
- }
- int l1;
- if (world.checkChunksExist(par2 - i1, par3 - i1, par4 - i1, par2 + i1, par3 + i1, par4 + 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 = world.getBlock(par2 + l1, par3 + i2, par4 + j2);
- if (!block.canSustainLeaves(world, par2 + l1, par3 + i2, par4 + j2))
- {
- if (block.isLeaves(world, par2 + l1, par3 + i2, par4 + j2))
- {
- this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
- }
- else
- {
- this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
- }
- }
- else
- {
- this.field_150128_a[(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.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1)
- {
- if (this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
- {
- this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
- }
- if (this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
- {
- this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
- }
- if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2)
- {
- this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
- }
- if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2)
- {
- this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
- }
- if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2)
- {
- this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
- }
- if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2)
- {
- this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
- }
- }
- }
- }
- }
- }
- }
- l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1];
- if (l1 >= 0)
- {
- world.setBlockMetadataWithNotify(par2, par3, par4, l & -9, 4);
- }
- else
- {
- this.removeLeaves(world, par2, par3, par4);
- }
- }
- }
- }
- /**
- * A randomly called display update to be able to add particles or other items for display
- */
- @SideOnly(Side.CLIENT)
- public void randomDisplayTick(World world, int par2, int par3, int par4, Random random)
- {
- if (world.canLightningStrikeAt(par2, par3 + 1, par4) && !World.doesBlockHaveSolidTopSurface(world, par2, par3 - 1, par4) && random.nextInt(15) == 1)
- {
- double d0 = (double)((float)par2 + random.nextFloat());
- double d1 = (double)par3 - 0.05D;
- double d2 = (double)((float)par4 + random.nextFloat());
- world.spawnParticle("dripWater", d0, d1, d2, 0.0D, 0.0D, 0.0D);
- }
- }
- private void removeLeaves(World world, int par2, int par3, int par4)
- {
- this.dropBlockAsItem(world, par2, par3, par4, world.getBlockMetadata(par2, par3, par4), 0);
- world.setBlockToAir(par2, par3, par4);
- }
- /**
- * Returns the quantity of items to drop on block destruction.
- */
- public int quantityDropped(Random random)
- {
- return random.nextInt(20) == 0 ? 1 : 0;
- }
- public Item getItemDropped(int par1, Random random, int par3)
- {
- return Item.getItemFromBlock(mod.mangoSapling);
- }
- /**
- * Drops the block items with a specified chance of dropping the specified items
- */
- public void dropBlockAsItemWithChance(World world, int par2, int par3, int par4, int par5, float par6, int par7)
- {
- super.dropBlockAsItemWithChance(world, par2, par3, par4, par5, 1.0f, par7);
- }
- protected void func_150124_c(World world, int par2, int par3, int par4, int par5, int par6) {}
- protected int func_150123_b(int par1)
- {
- return 20;
- }
- /**
- * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
- * block and l is the block's subtype/damage.
- */
- public void harvestBlock(World world, EntityPlayer entityplayer, int par3, int par4, int par5, int par6)
- {
- {
- super.harvestBlock(world, entityplayer, par3, par4, par5, par6);
- }
- }
- /**
- * Determines the damage on the item the block drops. Used in cloth and wood.
- */
- public int damageDropped(int par1)
- {
- return par1 & 3;
- }
- /**
- * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
- * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
- */
- public boolean isOpaqueCube()
- {
- return false;
- }
- /**
- * Gets the block's texture. Args: side, meta
- */
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int side, int meta)
- {
- if(Minecraft.isFancyGraphicsEnabled())
- {
- return icon1;
- }
- else
- {
- return icon2;
- }
- }
- @Override
- public void registerBlockIcons(IIconRegister icon)
- {
- icon1 = icon.registerIcon("moem:mangoleaf_sidefancy");
- icon2 = icon.registerIcon("moem:mangoleaf_sidefast");
- }
- @SideOnly(Side.CLIENT)
- public void setGraphicsLevel(boolean par1)
- {
- this.setGraphicsLevel(par1);
- this.field_150127_b = par1 ? 0 : 1;
- }
- /**
- * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
- * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
- */
- protected ItemStack createStackedBlock(int par1)
- {
- return new ItemStack(Item.getItemFromBlock(this), 1, par1 & 3);
- }
- public String[] func_150125_e() {
- return null;
- }
- @Override
- public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)
- {
- return true;
- }
- @Override
- public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)
- {
- ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
- ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z) & 3));
- return ret;
- }
- @Override
- public void beginLeavesDecay(World world, int x, int y, int z)
- {
- int i2 = world.getBlockMetadata(x, y, z);
- if ((i2 & 8) == 0)
- {
- world.setBlockMetadataWithNotify(x, y, z, i2 | 8, 4);
- }
- world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, 4);
- }
- @Override
- public boolean isLeaves(IBlockAccess world, int x, int y, int z)
- {
- return true;
- }
- @Override
- public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
- {
- ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
- int chance = this.func_150123_b(metadata);
- if (fortune > 0)
- {
- chance -= 2 << fortune;
- if (chance < 10) chance = 10;
- }
- if (world.rand.nextInt(chance) == 0)
- ret.add(new ItemStack(this.getItemDropped(metadata, world.rand, fortune), 1, this.damageDropped(metadata)));
- chance = 200;
- if (fortune > 0)
- {
- chance -= 10 << fortune;
- if (chance < 40) chance = 40;
- }
- this.captureDrops(true);
- this.func_150124_c(world, x, y, z, metadata, chance); // Dammet mojang
- ret.addAll(this.captureDrops(false));
- return ret;
- }
- }
Add Comment
Please, Sign In to add comment