Exemplo n.º 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));
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 /**
  * Used to assign aspects to the given item/block. Attempts to automatically generate aspect tags
  * by checking registered recipes. Here is an example of the declaration for pistons:
  *
  * <p><i>ThaumcraftApi.registerComplexObjectTag(new ItemStack(Blocks.cobblestone), (new
  * AspectList()).add(Aspect.MECHANISM, 2).add(Aspect.MOTION, 4));</i>
  *
  * @param item, pass OreDictionary.WILDCARD_VALUE to meta if all damage values of this item/block
  *     should have the same aspects
  * @param aspects A ObjectTags object of the associated aspects
  */
 public static void registerComplexObjectTag(ItemStack item, AspectList aspects) {
   if (!exists(item.getItem(), item.getItemDamage())) {
     AspectList tmp = ThaumcraftApiHelper.generateTags(item.getItem(), item.getItemDamage());
     if (tmp != null && tmp.size() > 0) {
       for (Aspect tag : tmp.getAspects()) {
         aspects.add(tag, tmp.getAmount(tag));
       }
     }
     registerObjectTag(item, aspects);
   } else {
     AspectList tmp = ThaumcraftApiHelper.getObjectAspects(item);
     for (Aspect tag : aspects.getAspects()) {
       tmp.merge(tag, tmp.getAmount(tag));
     }
     registerObjectTag(item, tmp);
   }
 }
Exemplo n.º 3
0
 /**
  * @return the aspect aspects ordinal with the highest value. Used to determine scroll color and
  *     similar things
  */
 public Aspect getResearchPrimaryTag() {
   Aspect aspect = null;
   int highest = 0;
   if (tags != null) {
     for (Aspect tag : tags.getAspects()) {
       if (tags.getAmount(tag) > highest) {
         aspect = tag;
         highest = tags.getAmount(tag);
       }
       ;
     }
   }
   return aspect;
 }
Exemplo n.º 4
0
 private static void addAspect(
     EntityPlayer player, ScanResult scan, double chanceToIncrease, double increaseMult) {
   Thaumcraft.proxy
       .getResearchManager()
       .completeScannedObject(
           player, "@" + ScanManager.generateItemHash(Item.getItemById(scan.id), scan.meta));
   AspectList aspects =
       ThaumcraftCraftingManager.getObjectTags(
           new ItemStack(Item.getItemById(scan.id), 1, scan.meta));
   if (aspects != null) {
     PlayerKnowledge pk = Thaumcraft.proxy.getPlayerKnowledge();
     for (Aspect aspect : aspects.getAspects()) {
       if (pk.hasDiscoveredParentAspects(player.getCommandSenderName(), aspect)) {
         int amt = aspects.getAmount(aspect);
         if (chanceToIncrease > 0d && player.getEntityWorld().rand.nextDouble() < chanceToIncrease)
           amt = MathHelper.ceiling_double_int((double) amt * increaseMult);
         ScanManager.checkAndSyncAspectKnowledge(player, aspect, amt);
       }
     }
   }
 }
Exemplo n.º 5
0
  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;
  }
  @SuppressWarnings("unchecked")
  public void updateEntity() {
    if (!this.worldObj.isRemote && tickTime == 0)
      MiscUtils.sendPacketToAllAround(
          worldObj,
          getDescriptionPacket(),
          xCoord,
          yCoord,
          zCoord,
          worldObj.provider.dimensionId,
          16);

    int additionalStability = 0;

    if (hasAir) ++additionalStability;
    if (hasWater) ++additionalStability;
    if (hasFire) ++additionalStability;
    if (hasEarth) ++additionalStability;
    if (hasOrdo) ++additionalStability;
    if (hasEntropy) ++additionalStability;

    if (placerName == null || placerName.isEmpty() || placerName.contains("no placer")) return;

    List<Entity> entities =
        this.worldObj.getEntitiesWithinAABB(
            Entity.class,
            AxisAlignedBB.getBoundingBox(
                xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1));
    if (!entities.isEmpty()) {
      Entity e = entities.get(0);
      if (e != null && !e.isDead) {
        if (e instanceof EntityItem) {
          if (additionalStability >= 6) {
            EntityItem itm = (EntityItem) e;
            ItemStack stk = itm.getEntityItem();
            if (stk != null) {
              AspectList aspectsCompound = ThaumcraftCraftingManager.getObjectTags(stk);
              aspectsCompound = ThaumcraftCraftingManager.getBonusTags(stk, aspectsCompound);
              if (aspectsCompound != null && aspectsCompound.size() > 0) {
                ++tickTime;
                if (tickTime == 40) {
                  tickTime = 0;

                  --stk.stackSize;
                  if (stk.stackSize <= 0) itm.setDead();

                  AspectList primals = ResearchManager.reduceToPrimals(aspectsCompound);
                  Aspect a = null;
                  if (this.worldObj.rand.nextInt(40) < primals.visSize())
                    a =
                        primals
                            .getAspects()[this.worldObj.rand.nextInt(primals.getAspects().length)];

                  if (!this.worldObj.isRemote && a != null) {
                    EntityPlayerMP player =
                        MinecraftServer.getServer()
                            .getConfigurationManager()
                            .func_152612_a(placerName);
                    if (player != null) {
                      double distance = player.getDistance(xCoord + 0.5D, yCoord, zCoord + 0.5D);
                      if (additionalStability < 6)
                        if (this.worldObj.rand.nextInt(
                                MathHelper.floor_double(
                                    Math.max(1, (128 + additionalStability * 10) - distance)))
                            == 0) TBUtils.addWarpToPlayer(EntityPlayerMP.class.cast(e), 1, 0);

                      TBUtils.addAspectToKnowledgePool(player, a, (short) 1);
                    }
                  }
                }
              }
              Thaumcraft.proxy.blockRunes(
                  worldObj,
                  xCoord,
                  yCoord + MathUtils.randomDouble(this.worldObj.rand) * 0.5D,
                  zCoord,
                  1,
                  0.5F,
                  0.5F,
                  8,
                  0);
              return;
            }
          }
        } else {
          AspectList aspectsCompound = ScanManager.generateEntityAspects(e);
          if (aspectsCompound != null && aspectsCompound.size() > 0) {
            ++tickTime;

            tickTime += MathHelper.floor_double(additionalStability / 2);

            if (tickTime == 40) {
              tickTime = 0;
              e.attackEntityFrom(DamageSource.outOfWorld, 1);

              if (e instanceof EntityPlayerMP) {
                TBUtils.addWarpToPlayer(EntityPlayerMP.class.cast(e), 1, 0);
              }

              Aspect a =
                  aspectsCompound.getAspects()[this.worldObj.rand.nextInt(aspectsCompound.size())];

              if (!this.worldObj.isRemote) {
                EntityPlayerMP player =
                    MinecraftServer.getServer().getConfigurationManager().func_152612_a(placerName);
                if (player != null) {
                  double distance = player.getDistance(xCoord + 0.5D, yCoord, zCoord + 0.5D);
                  if (additionalStability < 6)
                    if (this.worldObj.rand.nextInt(
                            MathHelper.floor_double(
                                Math.max(1, (128 + additionalStability * 10) - distance)))
                        == 0) TBUtils.addWarpToPlayer(EntityPlayerMP.class.cast(e), 1, 0);

                  TBUtils.addAspectToKnowledgePool(player, a, (short) 1);
                }
              }
            }
            Thaumcraft.proxy.blockRunes(
                worldObj,
                xCoord,
                yCoord + MathUtils.randomDouble(this.worldObj.rand) * 0.5D,
                zCoord,
                1,
                0.5F,
                0.5F,
                8,
                0);
            return;
          }
        }
      }
    }

    tickTime = 0;
  }