TristanvO

BlockLeaves.class

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