Skip to content

Instantly share code, notes, and snippets.

@dangeredwolf
Last active January 2, 2016 05:29
Show Gist options
  • Save dangeredwolf/8257804 to your computer and use it in GitHub Desktop.
Save dangeredwolf/8257804 to your computer and use it in GitHub Desktop.
//OptiLeaves v1.4 Progress
//THIS IS NOT A FULLY WORKING OPTILEAVES YET
//NOT EVERYTHING IS IN PLACE
//NOT EVERYTHING WORKS
//On the side note, if you have any info on any of the unknown fields/funcs, please let me know on my twitter or on a reply to the OptiLeaves Minecraft thread! @RyanDolan123
package net.minecraft.block;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.profiler.Profiler;
import net.minecraft.stats.StatList;
import net.minecraft.util.IIcon;
import net.minecraft.world.ColorizerFoliage;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockLeaves extends BlockLeavesBase
{
int[] adjacentTreeBlocks;
protected int field_150127_b; //Unknown, probably new
protected IIcon[][] field_150129_M = new IIcon[2][]; //iconArray
private static final String __OBFID = "CL_00000263"; //something to do with obfuscation
public boolean isOptiLeaves = true;
public String OptiLeavesName = "OptiLeaves";
public String OptiLeavesVersion = "1.4 [WORK IN PROGRESS]";
public String OptiLeavesDesignedMCVersion = "1.7.2";
private int[] FoliageColorCache = {ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorPine(), ColorizerFoliage.getFoliageColorBirch(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic(), ColorizerFoliage.getFoliageColorBasic()};
private int basicColor = ColorizerFoliage.getFoliageColor(0.5D, 1D);
private final Profiler profiler = new Profiler();
public BlockLeaves()
{
super(Material.field_151584_j, false); //Material.leaves
func_149675_a(true); //setTickRandomly
func_149647_a(CreativeTabs.tabDecorations); //setCreativeTab
func_149711_c(0.2F); //setHardness
func_149713_g(1); //setLightOpacity
func_149672_a(field_149779_h); //setFootstepSound
profiler.startSection(OptiLeavesName + " " + OptiLeavesVersion + " for Minecraft " + OptiLeavesDesignedMCVersion); //Does this even work at all?
}
public boolean func_149646_a(World par1World, int par2, int par3, int par4, int par5) //shouldSideBeRendered
{
if (par1World.func_147437_c(par2,par3,par4))
return true;
//return true;
return !par1World.func_147437_c(par2,par3,par4) && par1World.func_147439_a(par2,par3,par4) != this;
// isBlockOpaqueCube?
}
public int func_149635_D() //getBlockColor
{
return 0;
}
public int func_149741_i(int par1) throws IllegalArgumentException //getRenderColor
{
return FoliageColorCache[par1];
}
public int func_149720_d(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) //colorMultiplier
{
int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
switch(l & 3) {
case 1:
return ColorizerFoliage.getFoliageColorPine();
case 2:
return ColorizerFoliage.getFoliageColorBirch();
default:
int i1 = 0;
int j1 = 0;
int k1 = 0;
for (int l1 = -1; l1 <= 1; l1++)
{
for (int i2 = -1; i2 <= 1; i2++)
{
int j2 = par1IBlockAccess.getBiomeGenForCoords(par2 + i2, par4 + l1).func_150571_c(par2 + i2, par3, par4 + i2);
i1 += (j2 & 16711680) >> 16;
j1 += (j2 & 65280) >> 8;
k1 += j2 & 255;
}
}
return (i1 / 9 & 255) << 16 | (j1 / 9 & 255) << 8 | k1 / 9 & 255;
}
}
public void func_149749_a(World par1World, int par2, int par3, int par4, Block par5, int par6) //breakBlock
{
byte var7 = 1;
int var8 = var7 + 1;
if (par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
{
for (int var9 = -var7; var9 <= var7; ++var9)
{
for (int var10 = -var7; var10 <= var7; ++var10)
{
for (int var11 = -var7; var11 <= var7; ++var11)
{
if (par1World.func_147439_a(par2 + var9, par3 + var10, par4 + var11).func_149688_o() == Material.field_151584_j)
{
int var12 = par1World.getBlockMetadata(par2 + var9, par3 + var10, par4 + var11);
par1World.setBlockMetadataWithNotify(par2 + var9, par3 + var10, par4 + var11, var12 | 8, 4);
}
}
}
}
}
}
public void func_149674_a(World par1World, int par2, int par3, int par4, Random par5Random) //updateTick
{
if (!par1World.isRemote)
{
int var6 = par1World.getBlockMetadata(par2, par3, par4);
if ((var6 & 8) != 0 && (var6 & 4) == 0)
{
byte var7 = 4;
int var8 = var7 + 1;
byte var9 = 32;
int var10 = var9 * var9;
int var11 = var9 / 2;
if (adjacentTreeBlocks == null)
{
adjacentTreeBlocks = new int[var9 * var9 * var9];
}
int var12;
if (par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
{
int var13;
int var14;
for (var12 = -var7; var12 <= var7; ++var12)
{
for (var13 = -var7; var13 <= var7; ++var13)
{
for (var14 = -var7; var14 <= var7; ++var14)
{
Block var15 = par1World.func_147439_a(par2 + var12, par3 + var13, par4 + var14);
if (var15 != Blocks.field_150364_r && var15 != Blocks.field_150363_s)
{
if (var15.func_149688_o() == Material.field_151584_j)
{
adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = -2;
}
else
{
adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = -1;
}
}
else
{
adjacentTreeBlocks[(var12 + var11) * var10 + (var13 + var11) * var9 + var14 + var11] = 0;
}
}
}
}
for (var12 = 1; var12 <= 4; ++var12)
{
for (var13 = -var7; var13 <= var7; ++var13)
{
for (var14 = -var7; var14 <= var7; ++var14)
{
for (int var16 = -var7; var16 <= var7; ++var16)
{
if (adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var16 + var11] == var12 - 1)
{
if (adjacentTreeBlocks[(var13 + var11 - 1) * var10 + (var14 + var11) * var9 + var16 + var11] == -2)
{
adjacentTreeBlocks[(var13 + var11 - 1) * var10 + (var14 + var11) * var9 + var16 + var11] = var12;
}
if (adjacentTreeBlocks[(var13 + var11 + 1) * var10 + (var14 + var11) * var9 + var16 + var11] == -2)
{
adjacentTreeBlocks[(var13 + var11 + 1) * var10 + (var14 + var11) * var9 + var16 + var11] = var12;
}
if (adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 - 1) * var9 + var16 + var11] == -2)
{
adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 - 1) * var9 + var16 + var11] = var12;
}
if (adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 + 1) * var9 + var16 + var11] == -2)
{
adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11 + 1) * var9 + var16 + var11] = var12;
}
if (adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + (var16 + var11 - 1)] == -2)
{
adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + (var16 + var11 - 1)] = var12;
}
if (adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var16 + var11 + 1] == -2)
{
adjacentTreeBlocks[(var13 + var11) * var10 + (var14 + var11) * var9 + var16 + var11 + 1] = var12;
}
}
}
}
}
}
}
var12 = adjacentTreeBlocks[var11 * var10 + var11 * var9 + var11];
if (var12 >= 0)
{
par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 & -9, 4);
}
else
{
func_150126_e(par1World, par2, par3, par4);
}
}
}
}
public void func_149734_b(World par1World, int par2, int par3, int par4, Random par5) //randomDisplayTick
{
if (par1World.canLightningStrikeAt(par2, par3 + 1, par4) && !World.func_147466_a(par1World, par2, par3 - 1, par4) && par5.nextInt(15) == 1)
{
double var6 = (double)((float)par2 + par5.nextFloat());
double var8 = (double)par3 - 0.05D;
double var10 = (double)((float)par4 + par5.nextFloat());
par1World.spawnParticle("dripWater", var6, var8, var10, 0.0D, 0.0D, 0.0D);
}
}
private void func_150126_e(World par1World, int par2, int par3, int par4) //removeLeaves
{
func_149697_b(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
par1World.func_147468_f(par2, par3, par4);
}
public int func_149745_a(Random p_149745_1_) //quantityDropped
{
return p_149745_1_.nextInt(20) == 0 ? 1 : 0;
}
public Item func_149650_a(int par1, Random par2Random, int par3) //idDropped
{
return Item.func_150898_a(Blocks.field_150345_g);
}
public void func_149690_a(World par1World, int par2, int par3, int par4, int par5, float p_149690_6_, int p_149690_7_) //dropBlockAsItemWithChance
{
if (!par1World.isRemote)
{
int var8 = func_150123_b(par5);
if (p_149690_7_ > 0)
{
var8 -= 2 << p_149690_7_;
if (var8 < 10)
{
var8 = 10;
}
}
if (par1World.rand.nextInt(var8) == 0)
{
Item var9 = func_149650_a(par5, par1World.rand, p_149690_7_);
func_149642_a(par1World, par2, par3, par4, new ItemStack(var9, 1, func_149692_a(par5)));
}
var8 = 200;
if (p_149690_7_ > 0)
{
var8 -= 10 << p_149690_7_;
if (var8 < 40)
{
var8 = 40;
}
}
func_150124_c(par1World, par2, par3, par4, par5, var8);
}
}
protected void func_150124_c(World par1World, int par2, int par3, int par4, int par5, int par6) {}
protected int func_150123_b(int par1) //Unknown, probably new
{
return 20;
}
public void func_149636_a(World par1World, EntityPlayer par1EntityPlayer, int par3, int par4, int par5, int par6) //harvestBlock
{
if (!par1World.isRemote && par1EntityPlayer.getCurrentEquippedItem() != null && par1EntityPlayer.getCurrentEquippedItem().getItem() == Items.field_151097_aZ)
{
par1EntityPlayer.addStat(StatList.mineBlockStatArray[Block.func_149682_b(this)], 1);
func_149642_a(par1World, par3, par4, par5, new ItemStack(Item.func_150898_a(this), 1, par6 & 3));
}
else
{
super.func_149636_a(par1World, par1EntityPlayer, par3, par4, par5, par6);
}
}
public int func_149692_a(int par1) //damageDropped
{
return par1 & 3;
}
//public boolean func_149662_c()
//{
//return !field_150121_P;
//}
public abstract IIcon func_149691_a(int var1, int var2); //Unknown, probably new
public void func_150122_b(boolean par1) //setGraphicsLevel
{
field_150121_P = true;
field_150127_b = 0;
}
public boolean func_149662_c() //isOpaqueCube
{
return false;
}
protected ItemStack func_149644_j(int par1) //createStackedBlock
{
return new ItemStack(Item.func_150898_a(this), 1, par1 & 3);
}
//public int func_149745_a(Random p_149745_1_)
// {
//return 0;
//}
public int func_149701_w() //getRenderBlockPass
{
return 1;
}
public boolean func_149686_d() //renderAsNormalBlock
{
return true;
}
protected boolean func_149700_E() //Unknown, probably new
{
return false;
}
public abstract String[] func_150125_e(); //Unknown, probably new
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment