Advertisement
Guest User

TutLeaf

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