@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer)
{
if (!entityPlayer.isSneaking())
{
Vector3 position = this.getLink(itemStack);
if (position != null)
{
int blockId = position.getBlockID(world);
if (Block.blocksList[blockId] != null)
{
Chunk chunk = world.getChunkFromBlockCoords(position.intX(), position.intZ());
if (chunk != null && chunk.isChunkLoaded && (MFFSHelper.hasPermission(world, position, Action.RIGHT_CLICK_BLOCK, entityPlayer) || MFFSHelper.hasPermission(world, position, Permission.REMOTE_CONTROL, entityPlayer)))
{
float requiredEnergy = (float) Vector3.distance(new Vector3(entityPlayer), position) * (FluidContainerRegistry.BUCKET_VOLUME / 100);
int receivedEnergy = 0;
Set<IFortronFrequency> fortronTiles = FrequencyGrid.instance().getFortronTiles(world, new Vector3(entityPlayer), 50, this.getFrequency(itemStack));
for (IFortronFrequency fortronTile : fortronTiles)
{
int consumedEnergy = fortronTile.requestFortron((int) Math.ceil(requiredEnergy / fortronTiles.size()), true);
if (consumedEnergy > 0)
{
if (world.isRemote)
{
ModularForceFieldSystem.proxy.renderBeam(world, new Vector3(entityPlayer).add(new Vector3(0, entityPlayer.getEyeHeight() - 0.2, 0)), new Vector3((TileEntity) fortronTile).add(0.5), 0.6f, 0.6f, 1, 20);
}
receivedEnergy += consumedEnergy;
}
if (receivedEnergy >= requiredEnergy)
{
try
{
Block.blocksList[blockId].onBlockActivated(world, position.intX(), position.intY(), position.intZ(), entityPlayer, 0, 0, 0, 0);
}
catch (Exception e)
{
e.printStackTrace();
}