Example #1
0
  @Override
  public void updateEntity() {
    ItemStack jar = getStackInSlot(0);
    if (!worldObj.isRemote && jar != null && jar.getItem() instanceof ItemJarFilled) {
      ItemJarFilled item = (ItemJarFilled) jar.getItem();
      AspectList aspectList = item.getAspects(jar);
      if (aspectList != null && aspectList.size() == 1) {
        Aspect aspect = aspectList.getAspects()[0];

        TileEntity tile = worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
        if (tile != null && tile instanceof TileEntityHopper) {
          TileEntity tile1 =
              getHopperFacing(tile.xCoord, tile.yCoord, tile.zCoord, tile.getBlockMetadata());
          if (tile1 instanceof TileJarFillable) {
            TileJarFillable jar1 = (TileJarFillable) tile1;

            AspectList aspectList1 = jar1.getAspects();
            if (aspectList1 != null && aspectList1.size() == 0
                || aspectList1.getAspects()[0] == aspect
                    && aspectList1.getAmount(aspectList1.getAspects()[0]) < 64) {
              jar1.addToContainer(aspect, 1);
              item.setAspects(jar, aspectList.remove(aspect, 1));
            }
          }
        }
      }
    }
  }
  public boolean updateBehavior(boolean needUpdate) {
    if (fixedNode != null && owningNode.ticksExisted % 3 == 0) {
      if (owningNode.getWorldObj().getBlock(fixedNode.xCoord, fixedNode.yCoord, fixedNode.zCoord)
              != RegisteredBlocks.blockNode
          || owningNode
                  .getWorldObj()
                  .getTileEntity(fixedNode.xCoord, fixedNode.yCoord, fixedNode.zCoord)
              == null
          || fixedNode.isInvalid()) {
        fixedNode = null;
        return needUpdate;
      }
      AspectList currentAspects = fixedNode.getAspects();
      AspectList baseAspects = fixedNode.getAspectsBase();
      if (baseAspects.getAspects().length == 0) {
        int x = fixedNode.xCoord;
        int y = fixedNode.yCoord;
        int z = fixedNode.zCoord;
        removeFixedNode(x, y, z);
        return needUpdate;
      }
      Aspect a =
          baseAspects
              .getAspects()[owningNode.getWorldObj().rand.nextInt(baseAspects.getAspects().length)];
      if (baseAspects.getAmount(a) > 0) {
        if (baseAspects.reduce(a, 1)) {
          World world = owningNode.getWorldObj();
          int fx = fixedNode.xCoord;
          int fy = fixedNode.yCoord;
          int fz = fixedNode.zCoord;
          int ox = owningNode.xCoord;
          int oy = owningNode.yCoord;
          int oz = owningNode.zCoord;
          currentAspects.reduce(a, 1);

          ResearchHelper.distributeResearch(
              Gadomancy.MODID.toUpperCase() + ".GROWING_ATTACK",
              owningNode.getWorldObj(),
              owningNode.xCoord,
              owningNode.yCoord,
              owningNode.zCoord,
              16);

          EntityAspectOrb aspectOrb =
              new EntityAspectOrb(world, fx + 0.5D, fy + 0.5D, fz + 0.5D, a, 1);
          Vec3 dir =
              Vec3.createVectorHelper(fx + 0.5D, fy + 0.5D, fz + 0.5D)
                  .subtract(Vec3.createVectorHelper(ox + 0.5D, oy + 0.5D, oz + 0.5D))
                  .normalize();
          dir.addVector(randOffset(), randOffset(), randOffset()).normalize();
          aspectOrb.setVelocity(dir.xCoord, dir.yCoord, dir.zCoord);
          fixedNode.getWorldObj().spawnEntityInWorld(aspectOrb);

          NetworkRegistry.TargetPoint point =
              new NetworkRegistry.TargetPoint(
                  world.provider.dimensionId, ox + 0.5F, oy + 0.5F, oz + 0.5F, 32);
          PacketTCNodeBolt bolt =
              new PacketTCNodeBolt(
                  ox + 0.5F, oy + 0.5F, oz + 0.5F, fx + 0.5F, fy + 0.5F, fz + 0.5F, 0, false);
          PacketHandler.INSTANCE.sendToAllAround(bolt, point);

          PacketAnimationAbsorb packet = new PacketAnimationAbsorb(ox, oy, oz, fx, fy, fz, 7);
          PacketHandler.INSTANCE.sendToAllAround(packet, point);

          world.markBlockForUpdate(fx, fy, fz);
          fixedNode.markDirty();
          needUpdate = true;
        } else {
          if (baseAspects.size() <= 1) {
            int x = fixedNode.xCoord;
            int y = fixedNode.yCoord;
            int z = fixedNode.zCoord;
            removeFixedNode(x, y, z);
            needUpdate = true;
          }
          baseAspects.remove(a);
          currentAspects.remove(a);
          return needUpdate;
        }
      } else {
        if (baseAspects.size() <= 1) {
          int x = fixedNode.xCoord;
          int y = fixedNode.yCoord;
          int z = fixedNode.zCoord;
          removeFixedNode(x, y, z);
          needUpdate = true;
        }
        baseAspects.remove(a);
        currentAspects.remove(a);
        return needUpdate;
      }
    }
    return needUpdate;
  }