Package vazkii.botania.api.mana.spark

Examples of vazkii.botania.api.mana.spark.ISparkAttachable


  @Override
  public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xv, float yv, float zv) {
    TileEntity tile = world.getTileEntity(x, y, z);
    if(tile instanceof ISparkAttachable) {
      ISparkAttachable attach = (ISparkAttachable) tile;
      if(attach.canAttachSpark(stack) && attach.getAttachedSpark() == null) {
        stack.stackSize--;
        if(!world.isRemote) {
          EntitySpark spark = new EntitySpark(world);
          spark.setPosition(x + 0.5, y + 1.5, z + 0.5);
          world.spawnEntityInWorld(spark);
          attach.attachSpark(spark);
          world.markBlockForUpdate(x, y, z);
        }
        return true;
      }
    }
View Full Code Here


  @Override
  public void onUpdate() {
    super.onUpdate();

    ISparkAttachable tile = getAttachedTile();
    if(tile == null) {
      if(!worldObj.isRemote)
        setDead();
      return;
    }


    List<ISparkEntity> allSparks = SparkHelper.getSparksAround(worldObj, posX, posY, posZ);
    if(worldObj.isRemote && !didStartupParticles) {
      for(ISparkEntity spark : allSparks) {
        Entity e = (Entity) spark;
        Vector3 orig = new Vector3(e.posX , e.posY + 0.25, e.posZ);
        Vector3 end = new Vector3(posX, posY + 0.25, posZ);
        Vector3 diff = end.copy().sub(orig);
        Vector3 movement = diff.copy().normalize().multiply(0.05);
        int iters = (int) (diff.mag() / movement.mag());
        float huePer = 1F / iters;
        float hueSum = (float) Math.random();

        Vector3 currentPos = orig.copy();
        for(int i = 0; i < iters; i++) {
          float hue = i * huePer + hueSum;
          Color color = Color.getHSBColor(hue, 1F, 1F);
          float r = Math.min(1F, color.getRed() / 255F + 0.4F);
          float g = Math.min(1F, color.getGreen() / 255F + 0.4F);
          float b = Math.min(1F, color.getBlue() / 255F + 0.4F);

          Botania.proxy.setSparkleFXNoClip(true);
          Botania.proxy.sparkleFX(worldObj, currentPos.x, currentPos.y, currentPos.z, r, g, b, 0.6F, 12);
          Botania.proxy.setSparkleFXNoClip(false);
          currentPos.add(movement);
        }
      }

      didStartupParticles = true;
    }

    Collection<ISparkEntity> transfers = getTransfers();

    int upgrade = getUpgrade();
    if(upgrade != 0) {
      switch(upgrade) {
      case 1 : { // Dispersive
        List<EntityPlayer> players = SparkHelper.getEntitiesAround(EntityPlayer.class, worldObj, posX, posY, posZ);

        Map<EntityPlayer, Map<ItemStack, Integer>> receivingPlayers = new HashMap();

        ItemStack input = new ItemStack(ModItems.spark);
        for(EntityPlayer player : players) {
          List<ItemStack> stacks = new ArrayList();
          stacks.addAll(Arrays.asList(player.inventory.mainInventory));
          stacks.addAll(Arrays.asList(player.inventory.armorInventory));
          stacks.addAll(Arrays.asList(PlayerHandler.getPlayerBaubles(player).stackList));

          for(ItemStack stack : stacks) {
            if(stack == null || !(stack.getItem() instanceof IManaItem))
              continue;

            IManaItem manaItem = (IManaItem) stack.getItem();
            if(manaItem.canReceiveManaFromItem(stack, input)) {
              Map receivingStacks;
              boolean add = false;
              if(!receivingPlayers.containsKey(player)) {
                add = true;
                receivingStacks = new HashMap();
              } else receivingStacks = receivingPlayers.get(player);

              int recv = Math.min(getAttachedTile().getCurrentMana(), Math.min(TRANSFER_RATE, manaItem.getMaxMana(stack) - manaItem.getMana(stack)));
              if(recv > 0) {
                receivingStacks.put(stack, recv);
                if(add)
                  receivingPlayers.put(player, receivingStacks);
              }
            }
          }
        }

        if(!receivingPlayers.isEmpty()) {
          List<EntityPlayer> keys = new ArrayList(receivingPlayers.keySet());
          Collections.shuffle(keys);
          EntityPlayer player = keys.iterator().next();

          Map<ItemStack, Integer> items = receivingPlayers.get(player);
          ItemStack stack = items.keySet().iterator().next();
          int cost = items.get(stack);
          int manaToPut = Math.min(getAttachedTile().getCurrentMana(), cost);
          ((IManaItem) stack.getItem()).addMana(stack, manaToPut);
          getAttachedTile().recieveMana(-manaToPut);
          particlesTowards(player);
        }

        break;
      }
      case 2 : { // Dominant
        for(ISparkEntity spark : allSparks) {
          if(spark == this)
            continue;

          int upgrade_ = spark.getUpgrade();
          if(upgrade_ == 0)
            spark.registerTransfer(this);
        }
        break;
      }
      case 3 : { // Recessive
        for(ISparkEntity spark : allSparks) {
          if(spark == this)
            continue;

          int upgrade_ = spark.getUpgrade();
          if(upgrade_ != 2 && upgrade_ != 3 && upgrade_ != 4)
            transfers.add(spark);
        }
        break;
      }
      }
    }

    if(!transfers.isEmpty()) {
      int manaTotal = Math.min(TRANSFER_RATE * transfers.size(), tile.getCurrentMana());
      int manaForEach = manaTotal / transfers.size();
      if(manaForEach > transfers.size()) {
        for(ISparkEntity spark : transfers) {
          if(spark.getAttachedTile() == null || spark.getAttachedTile().isFull() || spark.areIncomingTransfersDone()) {
            manaTotal -= manaForEach;
            continue;
          }

          ISparkAttachable attached = spark.getAttachedTile();
          attached.recieveMana(manaForEach);

          particlesTowards((Entity) spark);
        }
        tile.recieveMana(-manaTotal);
      }
View Full Code Here

    dataWatcher.updateObject(28, upgrade);
  }

  @Override
  public boolean areIncomingTransfersDone() {
    ISparkAttachable tile = getAttachedTile();
    if(tile instanceof IManaPool)
      return removeTransferants > 0;

      return tile != null && tile.areIncomingTranfersDone();
  }
View Full Code Here

TOP

Related Classes of vazkii.botania.api.mana.spark.ISparkAttachable

Copyright © 2018 www.massapicom. 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.