2015-12-27 19:38:12 -05:00
|
|
|
package WayofTime.bloodmagic.item.sigil;
|
|
|
|
|
2016-11-11 16:57:50 -08:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
2017-08-15 18:14:28 -07:00
|
|
|
import WayofTime.bloodmagic.api_impl.BloodMagicAPI;
|
2015-12-27 19:38:12 -05:00
|
|
|
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.EnumFacing;
|
2017-08-15 18:14:28 -07:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-03-18 15:38:26 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.world.World;
|
2016-10-01 13:35:34 -04:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.BonemealEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class ItemSigilGreenGrove extends ItemSigilToggleableBase {
|
|
|
|
public ItemSigilGreenGrove() {
|
2015-12-27 19:38:12 -05:00
|
|
|
super("greenGrove", 150);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean onSigilUse(ItemStack stack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
2016-11-11 16:57:50 -08:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return false;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (applyBonemeal(world, blockPos, player, stack)) {
|
|
|
|
if (!world.isRemote) {
|
2016-10-01 16:18:48 -04:00
|
|
|
world.playEvent(2005, blockPos, 0);
|
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onSigilUpdate(ItemStack stack, World worldIn, EntityPlayer player, int itemSlot, boolean isSelected) {
|
2016-11-11 16:57:50 -08:00
|
|
|
if (PlayerHelper.isFakePlayer(player))
|
|
|
|
return;
|
|
|
|
|
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);
|
|
|
|
|
2017-08-15 21:30:48 -07: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);
|
2017-08-15 18:14:28 -07:00
|
|
|
IBlockState state = worldIn.getBlockState(blockPos);
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!BloodMagicAPI.INSTANCE.getBlacklist().getGreenGrove().contains(state)) {
|
|
|
|
if (state.getBlock() instanceof IGrowable) {
|
|
|
|
if (worldIn.rand.nextInt(50) == 0) {
|
2016-01-23 00:32:10 -08:00
|
|
|
IBlockState preBlockState = worldIn.getBlockState(blockPos);
|
2017-08-15 18:14:28 -07:00
|
|
|
state.getBlock().updateTick(worldIn, blockPos, state, worldIn.rand);
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2016-05-29 16:39:31 -07:00
|
|
|
IBlockState newState = worldIn.getBlockState(blockPos);
|
2016-10-01 16:18:48 -04:00
|
|
|
if (!newState.equals(preBlockState) && !worldIn.isRemote)
|
|
|
|
worldIn.playEvent(2005, blockPos, 0);
|
2016-01-23 00:32:10 -08:00
|
|
|
}
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
private boolean applyBonemeal(World worldIn, BlockPos target, EntityPlayer player, ItemStack sigilStack) {
|
2015-12-27 19:38:12 -05:00
|
|
|
IBlockState iblockstate = worldIn.getBlockState(target);
|
|
|
|
|
2017-08-15 18:14:28 -07:00
|
|
|
BonemealEvent event = new BonemealEvent(player, worldIn, target, iblockstate, EnumHand.MAIN_HAND, sigilStack);
|
2016-10-01 13:35:34 -04:00
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
return false;
|
|
|
|
else if (event.getResult() == Result.ALLOW)
|
|
|
|
return true;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (iblockstate.getBlock() instanceof IGrowable) {
|
2015-12-27 19:38:12 -05:00
|
|
|
IGrowable igrowable = (IGrowable) iblockstate.getBlock();
|
|
|
|
|
2017-08-15 21:30:48 -07: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;
|
|
|
|
}
|
|
|
|
}
|