2014-06-27 19:43:09 -04:00
|
|
|
package WayofTime.alchemicalWizardry.common.items.sigil;
|
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
|
2015-05-18 18:33:23 -04:00
|
|
|
import WayofTime.alchemicalWizardry.api.items.interfaces.ISigil;
|
2015-07-30 17:24:20 -04:00
|
|
|
import WayofTime.alchemicalWizardry.common.items.BindableItems;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.block.IGrowable;
|
2015-07-31 11:35:05 -04:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-07-31 11:35:05 -04:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-01-22 20:13:57 +03:00
|
|
|
import net.minecraft.util.StatCollector;
|
2014-06-27 19:43:09 -04:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.IPlantable;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.BonemealEvent;
|
2015-07-31 11:35:05 -04:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
2015-01-25 04:51:56 -05:00
|
|
|
|
2014-10-13 22:33:20 +02:00
|
|
|
import java.util.List;
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
public class SigilOfGrowth extends SigilToggleable implements ArmourUpgrade, ISigil
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
private int tickDelay = 100;
|
|
|
|
|
|
|
|
public SigilOfGrowth()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
setEnergyUsed(150);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
|
|
|
{
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.sigilofgrowth.desc1"));
|
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.sigilofgrowth.desc2"));
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-01-16 10:00:50 -05:00
|
|
|
if (!(par1ItemStack.getTagCompound() == null))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (this.getActivated(par1ItemStack))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.activated"));
|
2014-06-27 19:43:09 -04:00
|
|
|
} else
|
|
|
|
{
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.deactivated"));
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
|
2015-01-22 20:13:57 +03:00
|
|
|
par3List.add(StatCollector.translateToLocal("tooltip.owner.currentowner") + " " + par1ItemStack.getTagCompound().getString("ownerName"));
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-31 11:35:05 -04:00
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (BindableItems.checkAndSetItemOwner(stack, playerIn))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (applyBonemeal(stack, worldIn, pos, playerIn))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
BindableItems.syphonBatteries(stack, playerIn, getEnergyUsed());
|
2015-01-31 23:37:17 +00:00
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (worldIn.isRemote)
|
2015-01-31 23:37:17 +00:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
worldIn.playAuxSFX(2005, pos, 0);
|
2015-01-31 23:37:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
|
|
{
|
2015-07-30 17:24:20 -04:00
|
|
|
if (!BindableItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
|
2014-07-31 19:45:40 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
return par1ItemStack;
|
2014-07-31 19:45:40 -04:00
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-01-31 23:37:17 +00:00
|
|
|
if (par2World.isRemote)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
2015-01-16 10:00:50 -05:00
|
|
|
if (par1ItemStack.getTagCompound() == null)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
|
2015-01-16 10:00:50 -05:00
|
|
|
NBTTagCompound tag = par1ItemStack.getTagCompound();
|
2014-06-27 19:43:09 -04:00
|
|
|
tag.setBoolean("isActive", !(tag.getBoolean("isActive")));
|
|
|
|
|
2015-07-30 17:24:20 -04:00
|
|
|
if (tag.getBoolean("isActive") && BindableItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
par1ItemStack.setItemDamage(1);
|
|
|
|
tag.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % tickDelay);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
par1ItemStack.setItemDamage(par1ItemStack.getMaxDamage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return par1ItemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
|
|
|
|
{
|
2014-11-18 15:29:31 -05:00
|
|
|
if (!(par3Entity instanceof EntityPlayer) || par2World.isRemote)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-16 10:00:50 -05:00
|
|
|
if (par1ItemStack.getTagCompound() == null)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
par1ItemStack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (this.getActivated(par1ItemStack))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-02 11:05:07 -04:00
|
|
|
if (par2World.getWorldTime() % tickDelay == par1ItemStack.getTagCompound().getInteger("worldTimeDelay"))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-30 17:24:20 -04:00
|
|
|
if(!BindableItems.syphonBatteries(par1ItemStack, (EntityPlayer) par3Entity, getEnergyUsed()))
|
2014-11-07 15:55:00 -05:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
this.setActivated(par1ItemStack, false);
|
2014-11-07 15:55:00 -05:00
|
|
|
}
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
2014-11-18 15:29:31 -05:00
|
|
|
int range = 3;
|
2014-06-27 19:43:09 -04:00
|
|
|
int verticalRange = 2;
|
|
|
|
int posX = (int) Math.round(par3Entity.posX - 0.5f);
|
|
|
|
int posY = (int) par3Entity.posY;
|
|
|
|
int posZ = (int) Math.round(par3Entity.posZ - 0.5f);
|
|
|
|
|
|
|
|
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-07-31 11:35:05 -04:00
|
|
|
IBlockState block = par2World.getBlockState(new BlockPos(ix, iy, iz));
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-01-25 04:51:56 -05:00
|
|
|
if (block instanceof IPlantable || block instanceof IGrowable)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2014-11-19 18:48:26 -05:00
|
|
|
if (par2World.rand.nextInt(50) == 0)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
block.getBlock().updateTick(par2World, new BlockPos(ix, iy, iz), block, par2World.rand);
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
public static boolean applyBonemeal(ItemStack p_179234_0_, World world, BlockPos blockPos, EntityPlayer player)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
IBlockState block = world.getBlockState(blockPos);
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
BonemealEvent event = new BonemealEvent(player, world, blockPos, block);
|
2014-06-27 19:43:09 -04:00
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (event.getResult() == Event.Result.ALLOW)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block instanceof IGrowable)
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
IGrowable igrowable = (IGrowable) block;
|
2014-06-27 19:43:09 -04:00
|
|
|
|
2015-07-31 11:35:05 -04:00
|
|
|
if (igrowable.isStillGrowing(world, blockPos, block, world.isRemote))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (!world.isRemote)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
if (igrowable.canUseBonemeal(world, world.rand, blockPos, block))
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
igrowable.grow(world, world.rand, blockPos, block);
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack)
|
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
if (world.isRemote)
|
2014-07-31 19:45:40 -04:00
|
|
|
{
|
2014-10-13 22:33:20 +02:00
|
|
|
return;
|
2014-07-31 19:45:40 -04:00
|
|
|
}
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
int range = 5;
|
|
|
|
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);
|
|
|
|
|
|
|
|
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-07-31 11:35:05 -04:00
|
|
|
IBlockState block = world.getBlockState(new BlockPos(ix, iy, iz));
|
2014-10-13 22:33:20 +02:00
|
|
|
|
2014-06-27 19:43:09 -04:00
|
|
|
if (block instanceof IPlantable)
|
|
|
|
{
|
2014-11-19 18:48:26 -05:00
|
|
|
if (world.rand.nextInt(100) == 0)
|
2014-06-27 19:43:09 -04:00
|
|
|
{
|
2015-07-31 11:35:05 -04:00
|
|
|
block.getBlock().updateTick(world, new BlockPos(ix, iy, iz), block, world.rand);
|
2014-06-27 19:43:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUpgrade()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyForTenSeconds()
|
|
|
|
{
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
}
|