TristanvO

customleaf.java

Apr 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.79 KB | None | 0 0
  1. package com.tristanvo.mod;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.BlockLeavesBase;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.client.Minecraft;
  12. import net.minecraft.client.renderer.texture.IIconRegister;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.IIcon;
  17. import net.minecraft.world.ColorizerFoliage;
  18. import net.minecraft.world.IBlockAccess;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.common.IShearable;
  21.  
  22. public class mangoLeaf extends BlockLeavesBase implements IShearable
  23. {
  24.    
  25.     int[] field_150128_a;
  26.     @SideOnly(Side.CLIENT)
  27.     protected int field_150127_b;
  28.     protected IIcon icon1;
  29.     protected IIcon icon2;
  30.            
  31.     public mangoLeaf()
  32.     {
  33.         super(Material.leaves, false);
  34.         this.setTickRandomly(true);
  35.         this.setHardness(0.2F);
  36.         this.setLightOpacity(1);
  37.         this.setStepSound(soundTypeGrass);
  38.     }
  39.  
  40.     @SideOnly(Side.CLIENT)
  41.     public int getBlockColor()
  42.     {
  43.         double d0 = 0.5D;
  44.         double d1 = 1.0D;
  45.         return ColorizerFoliage.getFoliageColor(d0, d1);
  46.     }
  47.  
  48.     /**
  49.      * Returns the color this block should be rendered. Used by leaves.
  50.      */
  51.     @SideOnly(Side.CLIENT)
  52.     public int getRenderColor(int par1)
  53.     {
  54.         return ColorizerFoliage.getFoliageColorBasic();
  55.     }
  56.  
  57.     /**
  58.      * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
  59.      * when first determining what to render.
  60.      */
  61.     @SideOnly(Side.CLIENT)
  62.     public int colorMultiplier(IBlockAccess par1, int par2, int par3, int par4)
  63.     {
  64.         int l = 0;
  65.         int i1 = 0;
  66.         int j1 = 0;
  67.  
  68.         for (int k1 = -1; k1 <= 1; ++k1)
  69.         {
  70.             for (int l1 = -1; l1 <= 1; ++l1)
  71.             {
  72.                 int i2 = par1.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeFoliageColor(par2 + l1, par3, par4 + k1);
  73.                 l += (i2 & 16711680) >> 16;
  74.                 i1 += (i2 & 65280) >> 8;
  75.                 j1 += i2 & 255;
  76.             }
  77.         }
  78.  
  79.         return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
  80.     }
  81.  
  82.     public void breakBlock(World world, int x, int y, int z, Block blocks, int side)
  83.     {
  84.         byte b0 = 1;
  85.         int i1 = b0 + 1;
  86.  
  87.         if (world.checkChunksExist(x - i1, y - i1, z - i1, x + i1, y + i1, z + i1))
  88.         {
  89.             for (int j1 = -b0; j1 <= b0; ++j1)
  90.             {
  91.                 for (int k1 = -b0; k1 <= b0; ++k1)
  92.                 {
  93.                     for (int l1 = -b0; l1 <= b0; ++l1)
  94.                     {
  95.                         Block block = world.getBlock(x + j1, y + k1, z + l1);
  96.                         if (block.isLeaves(world, x + j1, y + k1, z + l1))
  97.                         {
  98.                             block.beginLeavesDecay(world, x + j1, y + k1, z + l1);
  99.                         }
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.     }
  105.  
  106.     /**
  107.      * Ticks the block if it's been scheduled
  108.      */
  109.     public void updateTick(World world, int par2, int par3, int par4, Random random)
  110.     {
  111.         if (!world.isRemote)
  112.         {
  113.             int l = world.getBlockMetadata(par2, par3, par4);
  114.  
  115.             if ((l & 8) != 0 && (l & 4) == 0)
  116.             {
  117.                 byte b0 = 4;
  118.                 int i1 = b0 + 1;
  119.                 byte b1 = 32;
  120.                 int j1 = b1 * b1;
  121.                 int k1 = b1 / 2;
  122.  
  123.                 if (this.field_150128_a == null)
  124.                 {
  125.                     this.field_150128_a = new int[b1 * b1 * b1];
  126.                 }
  127.  
  128.                 int l1;
  129.  
  130.                 if (world.checkChunksExist(par2 - i1, par3 - i1, par4 - i1, par2 + i1, par3 + i1, par4 + i1))
  131.                 {
  132.                     int i2;
  133.                     int j2;
  134.  
  135.                     for (l1 = -b0; l1 <= b0; ++l1)
  136.                     {
  137.                         for (i2 = -b0; i2 <= b0; ++i2)
  138.                         {
  139.                             for (j2 = -b0; j2 <= b0; ++j2)
  140.                             {
  141.                                 Block block = world.getBlock(par2 + l1, par3 + i2, par4 + j2);
  142.  
  143.                                 if (!block.canSustainLeaves(world, par2 + l1, par3 + i2, par4 + j2))
  144.                                 {
  145.                                     if (block.isLeaves(world, par2 + l1, par3 + i2, par4 + j2))
  146.                                     {
  147.                                         this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
  148.                                     }
  149.                                     else
  150.                                     {
  151.                                         this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -1;
  152.                                     }
  153.                                 }
  154.                                 else
  155.                                 {
  156.                                     this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = 0;
  157.                                 }
  158.                             }
  159.                         }
  160.                     }
  161.  
  162.                     for (l1 = 1; l1 <= 4; ++l1)
  163.                     {
  164.                         for (i2 = -b0; i2 <= b0; ++i2)
  165.                         {
  166.                             for (j2 = -b0; j2 <= b0; ++j2)
  167.                             {
  168.                                 for (int k2 = -b0; k2 <= b0; ++k2)
  169.                                 {
  170.                                     if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1] == l1 - 1)
  171.                                     {
  172.                                         if (this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
  173.                                         {
  174.                                             this.field_150128_a[(i2 + k1 - 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
  175.                                         }
  176.  
  177.                                         if (this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] == -2)
  178.                                         {
  179.                                             this.field_150128_a[(i2 + k1 + 1) * j1 + (j2 + k1) * b1 + k2 + k1] = l1;
  180.                                         }
  181.  
  182.                                         if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] == -2)
  183.                                         {
  184.                                             this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 - 1) * b1 + k2 + k1] = l1;
  185.                                         }
  186.  
  187.                                         if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] == -2)
  188.                                         {
  189.                                             this.field_150128_a[(i2 + k1) * j1 + (j2 + k1 + 1) * b1 + k2 + k1] = l1;
  190.                                         }
  191.  
  192.                                         if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] == -2)
  193.                                         {
  194.                                             this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + (k2 + k1 - 1)] = l1;
  195.                                         }
  196.  
  197.                                         if (this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] == -2)
  198.                                         {
  199.                                             this.field_150128_a[(i2 + k1) * j1 + (j2 + k1) * b1 + k2 + k1 + 1] = l1;
  200.                                         }
  201.                                     }
  202.                                 }
  203.                             }
  204.                         }
  205.                     }
  206.                 }
  207.  
  208.                 l1 = this.field_150128_a[k1 * j1 + k1 * b1 + k1];
  209.  
  210.                 if (l1 >= 0)
  211.                 {
  212.                     world.setBlockMetadataWithNotify(par2, par3, par4, l & -9, 4);
  213.                 }
  214.                 else
  215.                 {
  216.                     this.removeLeaves(world, par2, par3, par4);
  217.                 }
  218.             }
  219.         }
  220.     }
  221.  
  222.     /**
  223.      * A randomly called display update to be able to add particles or other items for display
  224.      */
  225.     @SideOnly(Side.CLIENT)
  226.     public void randomDisplayTick(World world, int par2, int par3, int par4, Random random)
  227.     {
  228.         if (world.canLightningStrikeAt(par2, par3 + 1, par4) && !World.doesBlockHaveSolidTopSurface(world, par2, par3 - 1, par4) && random.nextInt(15) == 1)
  229.         {
  230.             double d0 = (double)((float)par2 + random.nextFloat());
  231.             double d1 = (double)par3 - 0.05D;
  232.             double d2 = (double)((float)par4 + random.nextFloat());
  233.             world.spawnParticle("dripWater", d0, d1, d2, 0.0D, 0.0D, 0.0D);
  234.         }
  235.     }
  236.  
  237.     private void removeLeaves(World world, int par2, int par3, int par4)
  238.     {
  239.         this.dropBlockAsItem(world, par2, par3, par4, world.getBlockMetadata(par2, par3, par4), 0);
  240.         world.setBlockToAir(par2, par3, par4);
  241.     }
  242.  
  243.     /**
  244.      * Returns the quantity of items to drop on block destruction.
  245.      */
  246.     public int quantityDropped(Random random)
  247.     {
  248.         return random.nextInt(20) == 0 ? 1 : 0;
  249.     }
  250.  
  251.     public Item getItemDropped(int par1, Random random, int par3)
  252.     {
  253.         return Item.getItemFromBlock(mod.mangoSapling);
  254.     }
  255.  
  256.     /**
  257.      * Drops the block items with a specified chance of dropping the specified items
  258.      */
  259.     public void dropBlockAsItemWithChance(World world, int par2, int par3, int par4, int par5, float par6, int par7)
  260.     {
  261.         super.dropBlockAsItemWithChance(world, par2, par3, par4, par5, 1.0f, par7);
  262.     }
  263.  
  264.     protected void func_150124_c(World world, int par2, int par3, int par4, int par5, int par6) {}
  265.  
  266.     protected int func_150123_b(int par1)
  267.     {
  268.         return 20;
  269.     }
  270.  
  271.     /**
  272.      * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
  273.      * block and l is the block's subtype/damage.
  274.      */
  275.     public void harvestBlock(World world, EntityPlayer entityplayer, int par3, int par4, int par5, int par6)
  276.     {
  277.         {
  278.             super.harvestBlock(world, entityplayer, par3, par4, par5, par6);
  279.         }
  280.     }
  281.  
  282.     /**
  283.      * Determines the damage on the item the block drops. Used in cloth and wood.
  284.      */
  285.     public int damageDropped(int par1)
  286.     {
  287.         return par1 & 3;
  288.     }
  289.  
  290.     /**
  291.      * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
  292.      * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  293.      */
  294.     public boolean isOpaqueCube()
  295.     {
  296.         return false;
  297.     }
  298.    
  299.  
  300.     /**
  301.      * Gets the block's texture. Args: side, meta
  302.      */
  303.     @SideOnly(Side.CLIENT)
  304.     public IIcon getIcon(int side, int meta)
  305.     {
  306.         if(Minecraft.isFancyGraphicsEnabled())
  307.         {
  308.             return icon1;
  309.         }
  310.         else
  311.         {
  312.             return icon2;
  313.         }
  314.     }
  315.     @Override
  316.     public void registerBlockIcons(IIconRegister icon)
  317.     {
  318.             icon1 = icon.registerIcon("moem:mangoleaf_sidefancy");
  319.             icon2 = icon.registerIcon("moem:mangoleaf_sidefast");
  320.     }
  321.    
  322.     @SideOnly(Side.CLIENT)
  323.     public void setGraphicsLevel(boolean par1)
  324.     {
  325.         this.setGraphicsLevel(par1);
  326.         this.field_150127_b = par1 ? 0 : 1;
  327.     }
  328.  
  329.     /**
  330.      * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
  331.      * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
  332.      */
  333.     protected ItemStack createStackedBlock(int par1)
  334.     {
  335.         return new ItemStack(Item.getItemFromBlock(this), 1, par1 & 3);
  336.     }
  337.  
  338.     public String[] func_150125_e() {
  339.         return null;
  340.     }
  341.  
  342.  
  343.     @Override
  344.     public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)
  345.     {
  346.         return true;
  347.     }
  348.  
  349.     @Override
  350.     public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)
  351.     {
  352.         ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  353.         ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z) & 3));
  354.         return ret;
  355.     }
  356.  
  357.     @Override
  358.     public void beginLeavesDecay(World world, int x, int y, int z)
  359.     {
  360.  
  361.         int i2 = world.getBlockMetadata(x, y, z);
  362.  
  363.         if ((i2 & 8) == 0)
  364.         {
  365.             world.setBlockMetadataWithNotify(x, y, z, i2 | 8, 4);
  366.         }
  367.         world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) | 8, 4);
  368.     }
  369.  
  370.     @Override
  371.     public boolean isLeaves(IBlockAccess world, int x, int y, int z)
  372.     {
  373.         return true;
  374.     }
  375.  
  376.  
  377.     @Override
  378.     public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
  379.     {
  380.         ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
  381.         int chance = this.func_150123_b(metadata);
  382.  
  383.         if (fortune > 0)
  384.         {
  385.             chance -= 2 << fortune;
  386.             if (chance < 10) chance = 10;
  387.         }
  388.  
  389.         if (world.rand.nextInt(chance) == 0)
  390.             ret.add(new ItemStack(this.getItemDropped(metadata, world.rand, fortune), 1, this.damageDropped(metadata)));
  391.  
  392.         chance = 200;
  393.         if (fortune > 0)
  394.         {
  395.             chance -= 10 << fortune;
  396.             if (chance < 40) chance = 40;
  397.         }
  398.  
  399.         this.captureDrops(true);
  400.         this.func_150124_c(world, x, y, z, metadata, chance); // Dammet mojang
  401.         ret.addAll(this.captureDrops(false));
  402.         return ret;
  403.     }
  404. }
Add Comment
Please, Sign In to add comment