package net.minecraft.src;
public class BlockBlueberryBush extends BlockBush
{
public BlockBlueberryBush(int i, int j, Item k)
{
super(i, j, k);
this.setBlockName("BlueberryBush");
}
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
if(j == 1)
return mod_ModName.blueberrybush1;
else
return blockIndexInTexture;
}
}
And it extends a bush.
package net.minecraft.src;
import java.util.Random;
public class BlockBush extends Block
{
public BlockBush(int i, int j, Item k)
{
super(i, Material.plants);
blockIndexInTexture = j;
berry = k;
setTickOnLoad(true);
this.setHardness(0.2F).setLightOpacity(1).setStepSound(soundGrassFootstep);
}
public boolean canPlaceBlockAt(World world, int i, int j, int k)
{
return canThisPlantGrowOnThisBlockID(world.getBlockId(i, j - 1, k));
}
protected boolean canThisPlantGrowOnThisBlockID(int i)
{
return i == Block.grass.blockID || i == Block.dirt.blockID || i == Block.tilledField.blockID;
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
super.onNeighborBlockChange(world, i, j, k, l);
func_268_h(world, i, j, k);
}
public void updateTick(World world, int i, int j, int k, Random random)
{
func_268_h(world, i, j, k);
if(world.getBlockMetadata(i, j, k) == 0)
{
if(random.nextInt(200) == 0)
world.setBlockMetadataWithNotify(i, j, k, 1);
}
}
protected final void func_268_h(World world, int i, int j, int k)
{
if(!canBlockStay(world, i, j, k))
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
world.setBlockWithNotify(i, j, k, 0);
}
}
public boolean canBlockStay(World world, int i, int j, int k)
{
return (world.getBlockLightValue(i, j, k) >= 8 || world.canBlockSeeTheSky(i, j, k)) && canThisPlantGrowOnThisBlockID(world.getBlockId(i, j - 1, k));
}
public int quantityDropped(Random random)
{
return 0;
}
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
dropBerries(world, i, j, k);
return true;
}
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
{
dropBerries(world, i, j, k);
}
public void dropBerries(World world, int i, int j, int k)
{
Random random = new Random();
if(world.getBlockMetadata(i, j, k) == 1)
{
if(!world.multiplayerWorld)
{
for(int i1 = 0; i1 < 3; i1++)
{
if(random.nextInt(3) <= i1)
{
float f = 0.7F;
float f1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float f2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float f3 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
EntityItem entityitem = new EntityItem(world, (float)i + f1, (float)j + f2, (float)k + f3, new ItemStack(berry));
entityitem.delayBeforeCanPickup = 10;
world.entityJoinedWorld(entityitem);
}
}
}
world.setBlockMetadataWithNotify(i, j, k, 0);
}
}
private Item berry;
}
However, at night time, without a torch (or other light) and in plain sight of the sky, the bushes disappear! These bushes are designed to stay if the bushes see the sky! If there is torchlight, they're fine. Yet another block which extends BlockCrops (thus having the same properties) still survives. o_O
Any explanation for this bizarre phenomenon??? Thanks!
Rollback Post to RevisionRollBack
Has nice day!
Please no PMing, and no, I'm not a moderator.
Thanks for replying! I tried to extend BlockFlower, but making the bush be a cube started to become a little more work than I would want. Also, doing that didn't help :/
Anyhow, what I do in the daytime is place a blueberrybush block on dirt in plain sight of the sky (from the code, it seems that there has to be nothing directly above the block). There are no torches nearby. As the sky darkens, the bushes disappear. Since they don't drop anything, nothing pops out. In the nighttime, I try placing the blocks again, then I place a torch to update the blocks in the general area, and the bush disappears.
Strange stuff be happening..
New code:
package net.minecraft.src;
import java.util.Random;
public class BlockBush extends BlockFlower
{
public BlockBush(int i, int j, Item k)
{
super(i, j);
blockIndexInTexture = j;
berry = k;
setTickOnLoad(true);
this.setHardness(0.2F).setLightOpacity(1).setStepSound(soundGrassFootstep);
}
public void updateTick(World world, int i, int j, int k, Random random)
{
func_268_h(world, i, j, k);
if(world.getBlockMetadata(i, j, k) == 0)
{
if(random.nextInt(200) == 0)
world.setBlockMetadataWithNotify(i, j, k, 1);
}
}
public int quantityDropped(Random random)
{
return 0;
}
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
dropBerries(world, i, j, k);
return true;
}
public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
{
dropBerries(world, i, j, k);
}
public void dropBerries(World world, int i, int j, int k)
{
Random random = new Random();
if(world.getBlockMetadata(i, j, k) == 1)
{
if(!world.multiplayerWorld)
{
for(int i1 = 0; i1 < 3; i1++)
{
if(random.nextInt(3) <= i1)
{
float f = 0.7F;
float f1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float f2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
float f3 = world.rand.nextFloat() * f + (1.0F - f) * 0.5F;
EntityItem entityitem = new EntityItem(world, (float)i + f1, (float)j + f2, (float)k + f3, new ItemStack(berry));
entityitem.delayBeforeCanPickup = 10;
world.entityJoinedWorld(entityitem);
}
}
}
world.setBlockMetadataWithNotify(i, j, k, 0);
}
}
public boolean renderAsNormalBlock()
{
return true;
}
public int getRenderType()
{
return 0;
}
public boolean isOpaqueCube()
{
return true;
}
private Item berry;
}
Here is a picture of a bush placed after placing a torch (it's extending blockflower [thus the strange block shape] and using a colored leaf texture for now). The wheat-looking crop is a bush sprout that survives the night and extends BlockCrops.
Rollback Post to RevisionRollBack
Has nice day!
Please no PMing, and no, I'm not a moderator.
Fixed it! I figured that flowers and crops have a height that's slightly smaller than the average block, so by asking for whether they can see the sky or not, they're really asking if the small space above them can see the sky or not. So I changed that part to "world.canBlockSeeTheSky(i, j+1, k)" so it's asking if the block above (mimicking the tiny space) can see the sky.
Either that, or it may have to do with light opacity. My bush is not at all transparent, but crops and flowers are. So if they got the sky's light whereas mine's couldn't, then it would make sense that my block can't see through itself to see the sky.
Thanks Tomalla for trying! I really appreciate your help :biggrin.gif: Don't be afraid to ask me for anything :smile.gif:
Rollback Post to RevisionRollBack
Has nice day!
Please no PMing, and no, I'm not a moderator.
And it extends a bush.
However, at night time, without a torch (or other light) and in plain sight of the sky, the bushes disappear! These bushes are designed to stay if the bushes see the sky! If there is torchlight, they're fine. Yet another block which extends BlockCrops (thus having the same properties) still survives. o_O
Any explanation for this bizarre phenomenon??? Thanks!
Please no PMing, and no, I'm not a moderator.
Anyhow, what I do in the daytime is place a blueberrybush block on dirt in plain sight of the sky (from the code, it seems that there has to be nothing directly above the block). There are no torches nearby. As the sky darkens, the bushes disappear. Since they don't drop anything, nothing pops out. In the nighttime, I try placing the blocks again, then I place a torch to update the blocks in the general area, and the bush disappears.
Strange stuff be happening..
New code:
Here is a picture of a bush placed after placing a torch (it's extending blockflower [thus the strange block shape] and using a colored leaf texture for now). The wheat-looking crop is a bush sprout that survives the night and extends BlockCrops.
Please no PMing, and no, I'm not a moderator.
Please no PMing, and no, I'm not a moderator.
Either that, or it may have to do with light opacity. My bush is not at all transparent, but crops and flowers are. So if they got the sky's light whereas mine's couldn't, then it would make sense that my block can't see through itself to see the sky.
Thanks Tomalla for trying! I really appreciate your help :biggrin.gif: Don't be afraid to ask me for anything :smile.gif:
Please no PMing, and no, I'm not a moderator.