2015-12-27 19:38:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.IGrowable;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.IPlantable;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class ItemSigilGreenGrove extends ItemSigilToggleable
|
|
|
|
{
|
|
|
|
public ItemSigilGreenGrove()
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
super("greenGrove", 150);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-09 17:30:10 -08:00
|
|
|
public boolean onSigilUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
if (applyBonemeal(stack, world, blockPos))
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
world.playAuxSFX(2005, blockPos, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void onSigilUpdate(ItemStack stack, World worldIn, EntityPlayer player, int itemSlot, boolean isSelected)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
int range = 3;
|
|
|
|
int verticalRange = 2;
|
|
|
|
int posX = (int) Math.round(player.posX - 0.5f);
|
|
|
|
int posY = (int) player.posY;
|
|
|
|
int posZ = (int) Math.round(player.posZ - 0.5f);
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
for (int ix = posX - range; ix <= posX + range; ix++)
|
|
|
|
{
|
|
|
|
for (int iz = posZ - range; iz <= posZ + range; iz++)
|
|
|
|
{
|
|
|
|
for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
BlockPos blockPos = new BlockPos(ix, iy, iz);
|
|
|
|
Block block = worldIn.getBlockState(blockPos).getBlock();
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (block instanceof IPlantable || block instanceof IGrowable)
|
|
|
|
{
|
|
|
|
if (worldIn.rand.nextInt(50) == 0)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
IBlockState preBlockState = worldIn.getBlockState(blockPos);
|
|
|
|
block.updateTick(worldIn, blockPos, worldIn.getBlockState(blockPos), worldIn.rand);
|
|
|
|
|
|
|
|
if (!worldIn.getBlockState(blockPos).equals(preBlockState))
|
|
|
|
worldIn.playAuxSFX(2005, blockPos, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
private boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
return worldIn instanceof net.minecraft.world.WorldServer && applyBonemeal(stack, worldIn, target, net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer) worldIn));
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
private boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
IBlockState iblockstate = worldIn.getBlockState(target);
|
|
|
|
|
|
|
|
int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, target, iblockstate, stack);
|
2015-12-30 15:34:40 -05:00
|
|
|
if (hook != 0)
|
|
|
|
return hook > 0;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (iblockstate.getBlock() instanceof IGrowable)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
IGrowable igrowable = (IGrowable) iblockstate.getBlock();
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote))
|
|
|
|
{
|
|
|
|
if (!worldIn.isRemote)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))
|
|
|
|
igrowable.grow(worldIn, worldIn.rand, target, iblockstate);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|