Changed sapling growth handler

This commit is contained in:
Kino 2017-02-21 01:05:17 -05:00
parent 1e6122ba13
commit ba0c19498b
2 changed files with 38 additions and 28 deletions

View file

@ -2,9 +2,15 @@ package com.legacy.aether.server.blocks;
import java.util.Random;
import net.minecraft.block.IGrowable;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -12,12 +18,12 @@ import net.minecraft.world.gen.feature.WorldGenerator;
import com.legacy.aether.server.blocks.natural.BlockAetherFlower;
public class BlockAetherSapling extends BlockAetherFlower implements IGrowable
public class BlockAetherSapling extends BlockAetherFlower
{
private Object treeGenObject = null;
public WorldGenerator treeGenObject = null;
public BlockAetherSapling(Object treeGen)
public BlockAetherSapling(WorldGenerator treeGen)
{
super();
float f = 0.4F;
@ -28,42 +34,43 @@ public class BlockAetherSapling extends BlockAetherFlower implements IGrowable
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random)
{
if (world.isRemote)
{
return;
}
super.updateTick(world, pos, state, random);
if (world.getLight(pos.up()) >= 9 && random.nextInt(30) == 0)
if (!world.isRemote)
{
this.grow(world, random, pos, state);
if (world.getLight(pos.up()) >= 9 && random.nextInt(30) == 0)
{
this.growTree(world, pos, random);
}
}
}
@Override
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return true;
}
@Override
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return worldIn.rand.nextFloat() < 0.45D;
}
@Override
public void grow(World world, Random rand, BlockPos pos, IBlockState state)
{
if (world.isRemote)
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (heldItem != null && heldItem.getItem() == Items.DYE && heldItem.getMetadata() == 15)
{
return;
if (!worldIn.isRemote)
{
worldIn.playEvent(2005, pos, 0);
}
if (worldIn.rand.nextFloat() < 0.45D)
{
this.growTree(worldIn, pos, worldIn.rand);
}
return true;
}
return false;
}
public void growTree(World world, BlockPos pos, Random rand)
{
world.setBlockState(pos, Blocks.AIR.getDefaultState());
if (!((WorldGenerator) this.treeGenObject).generate(world, rand, pos))
if (!this.treeGenObject.generate(world, world.rand, pos))
{
world.setBlockState(pos, this.getDefaultState());
}

View file

@ -3,6 +3,7 @@ package com.legacy.aether.server.blocks.decorative;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityXPOrb;
@ -23,7 +24,9 @@ public class BlockPresent extends Block
public BlockPresent()
{
super(Material.GRASS);
this.setHardness(0.6F);
this.setSoundType(SoundType.PLANT);
}
@Override