Package vazkii.botania.common.item.equipment.bauble

Source Code of vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet

/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Apr 20, 2014, 10:58:00 PM (GMT)]
*/
package vazkii.botania.common.item.equipment.bauble;

import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.mana.ITinyPlanetExcempt;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.lib.LibItemNames;
import baubles.api.BaubleType;

public class ItemTinyPlanet extends ItemBauble {

  public static final String TAG_ORBIT = "orbit";

  public ItemTinyPlanet() {
    super(LibItemNames.TINY_PLANET);
  }

  @Override
  public BaubleType getBaubleType(ItemStack itemstack) {
    return BaubleType.AMULET;
  }

  @Override
  public void onWornTick(ItemStack stack, EntityLivingBase player) {
    super.onWornTick(stack, player);

    double x = player.posX;
    double y = player.posY + 1.2F;
    double z = player.posZ;
    if(player.worldObj.isRemote)
      y -= 1.62F;

    applyEffect(player.worldObj, x, y, z);
  }

  public static void applyEffect(World world, double x, double y, double z) {
    int range = 8;
    List<Entity> entities = world.getEntitiesWithinAABB(IManaBurst.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range, y + range, z + range));
    for(Entity entity : entities) {
      IManaBurst burst = (IManaBurst) entity;
      ItemStack lens = burst.getSourceLens();
      if(lens != null && lens.getItem() instanceof ITinyPlanetExcempt && !((ITinyPlanetExcempt) lens.getItem()).shouldPull(lens))
        continue;

      int orbitTime = getEntityOrbitTime(entity);
      if(orbitTime == 0)
        burst.setMinManaLoss(burst.getMinManaLoss() * 3);

      float radius = Math.min(7.5F, (Math.max(40, orbitTime) - 40) / 40F + 1.5F);
      int angle = orbitTime % 360;

      float xTarget = (float) (x + Math.cos(angle * 10 * Math.PI / 180F) * radius);
      float yTarget = (float) y;
      float zTarget = (float) (z + Math.sin(angle * 10 * Math.PI / 180F) * radius);

      Vector3 targetVec = new Vector3(xTarget, yTarget, zTarget);
      Vector3 currentVec = new Vector3(entity.posX, entity.posY, entity.posZ);
      Vector3 moveVector = targetVec.copy().sub(currentVec);

      burst.setMotion(moveVector.x, moveVector.y, moveVector.z);

      incrementOrbitTime(entity);
    }
  }

  public static int getEntityOrbitTime(Entity entity) {
    NBTTagCompound cmp = entity.getEntityData();
    if(cmp.hasKey(TAG_ORBIT))
      return cmp.getInteger(TAG_ORBIT);
    else return 0;
  }

  public static void incrementOrbitTime(Entity entity) {
    NBTTagCompound cmp = entity.getEntityData();
    int time = getEntityOrbitTime(entity);
    cmp.setInteger(TAG_ORBIT, time + 1);
  }

}
TOP

Related Classes of vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.