/
NLeaves.java
221 lines (193 loc) · 6.57 KB
/
NLeaves.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package mods.natura.blocks.trees;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import mods.natura.common.NContent;
import mods.natura.common.NaturaTab;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
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 cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class NLeaves extends BlockLeaves
{
int[] adjacentTreeBlocks;
public NLeaves()
{
super();
this.setTickRandomly(true);
this.setHardness(0.2F);
this.setLightOpacity(1);
this.setStepSound(Block.soundTypeGrass);
this.setBlockName("floraLeaves");
setCreativeTab(CreativeTabs.tabDecorations);
this.setCreativeTab(NaturaTab.tab);
}
@Override
@SideOnly(Side.CLIENT)
public int getBlockColor()
{
double d0 = 0.5D;
double d1 = 1.0D;
return ColorizerFoliage.getFoliageColor(d0, d1);
}
@SideOnly(Side.CLIENT)
public int getRenderColor(int p_149741_1_)
{
return ColorizerFoliage.getFoliageColorBasic();
}
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
{
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 = p_149720_1_.getBiomeGenForCoords(p_149720_2_ + l1, p_149720_4_ + k1).getBiomeFoliageColor(p_149720_2_ + l1, p_149720_3_, p_149720_4_ + k1);
l += (i2 & 16711680) >> 16;
i1 += (i2 & 65280) >> 8;
j1 += i2 & 255;
}
}
return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
}
@Override
public void updateTick (World world, int x, int y, int z, Random random)
{
if (!world.isRemote)
{
int meta = world.getBlockMetadata(x, y, z);
if ((meta & 4) == 0)
{
boolean nearbyTree = false;
byte range = 4;
for (int posX = x - range; posX <= x + range; posX++)
{
for (int posY = y - range; posY <= y + range; posY++)
{
for (int posZ = z - range; posZ <= z + range; posZ++)
{
Block block = world.getBlock(posX, posY, posZ);
if (block != null && block.canSustainLeaves(world, posX, posY, posZ))
nearbyTree = true;
}
}
}
if (!nearbyTree)
this.removeLeaves(world, x, y, z);
}
}
}
public void removeLeaves (World world, int x, int y, int z)
{
this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
world.setBlock(x, y, z, Blocks.air, 0, 7);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped (Random var1)
{
return var1.nextInt(20) == 0 ? 1 : 0;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@Override
public Item getItemDropped (int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
return Item.getItemFromBlock(NContent.floraSapling);
}
@Override
public void dropBlockAsItemWithChance (World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
{
if (!par1World.isRemote)
{
ArrayList<ItemStack> items = getDrops(par1World, par2, par3, par4, par5, par7);
for (ItemStack item : items)
{
if (par1World.rand.nextFloat() <= par6)
{
this.dropBlockAsItem(par1World, par2, par3, par4, item);
}
}
}
}
public IIcon[] fastIcons;
public IIcon[] fancyIcons;
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int metadata)
{
int meta = metadata % 4;
if (metadata == 3)
meta = 0;
if (field_150121_P)
return fancyIcons[meta];
else
return fastIcons[meta];
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons (IIconRegister iconRegister)
{
String[] textureNames = new String[] { "redwood", "eucalyptus", "hopseed" };
this.fastIcons = new IIcon[textureNames.length];
this.fancyIcons = new IIcon[textureNames.length];
for (int i = 0; i < this.fastIcons.length; i++)
{
this.fastIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fast");
this.fancyIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fancy");
}
}
/**
* Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
* coordinates. Args: blockAccess, x, y, z, side
*/
@Override
public boolean shouldSideBeRendered (IBlockAccess var1, int var2, int var3, int var4, int var5)
{
return this.field_150121_P ? super.shouldSideBeRendered(var1, var2, var3, var4, var5) : true;
}
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks (Block par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
}
public int getDamageValue (World par1World, int par2, int par3, int par4)
{
return this.damageDropped(par1World.getBlockMetadata(par2, par3, par4)) % 3;
}
@Override
public int getLightOpacity (IBlockAccess world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z) % 4;
if (meta == 0)
{
return 255;
}
return super.getLightOpacity(world, x, y, z);//this.getLightOpacity(world, x, y, z);//lightOpacity[blockID];
}
@Override
public String[] func_150125_e ()
{
return null;
}
}