コード例 #1
0
  // This is where you load the data that you saved in writeToNBT
  @Override
  public void readFromNBT(NBTTagCompound nbtTagCompound) {
    super.readFromNBT(
        nbtTagCompound); // The super call is required to save and load the tiles location
    final byte NBT_TYPE_COMPOUND = 10; // See NBTBase.createNewByType() for a listing
    NBTTagList dataForAllSlots = nbtTagCompound.getTagList("Items", NBT_TYPE_COMPOUND);

    Arrays.fill(itemStacks, null); // set all slots to empty
    for (int i = 0; i < dataForAllSlots.tagCount(); ++i) {
      NBTTagCompound dataForOneSlot = dataForAllSlots.getCompoundTagAt(i);
      byte slotNumber = dataForOneSlot.getByte("Slot");
      if (slotNumber >= 0 && slotNumber < this.itemStacks.length) {
        this.itemStacks[slotNumber] = ItemStack.loadItemStackFromNBT(dataForOneSlot);
      }
    }

    // Load everything else.  Trim the arrays (or pad with 0) to make sure they have the correct
    // number of elements
    cookTime = nbtTagCompound.getShort("CookTime");
    burnTimeRemaining =
        Arrays.copyOf(nbtTagCompound.getIntArray("burnTimeRemaining"), FUEL_SLOTS_COUNT);
    burnTimeInitialValue =
        Arrays.copyOf(nbtTagCompound.getIntArray("burnTimeInitial"), FUEL_SLOTS_COUNT);
    cachedNumberOfBurningSlots = -1;
  }
コード例 #2
0
  // インベントリの読み込み
  public void load() {
    // ItemStackのNBTを取得、空の中身を作成しておく
    NBTTagCompound nbttagcompound = this.baseChest.getEntityData();
    this.containerItems = new ItemStack[this.getSizeInventory()];

    // NBTが無ければ中身は空のままで
    if (nbttagcompound == null) {
      return;
    }

    NBTTagList nbttaglist = nbttagcompound.getTagList("EquipmentItems", 10);

    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
      int j = nbttagcompound1.getByte("EquipmentSlot") & 0xff;

      if (j >= 0 && j < this.containerItems.length) {
        this.containerItems[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }

    // EntityLivingのequipmentと同期
    for (int slot = 0; slot < this.containerItems.length; slot++) {
      this.baseChest.setCurrentItemOrArmor(slot, this.containerItems[slot]);
    }
  }
コード例 #3
0
  /** Reads a tile entity from NBT. */
  public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
    super.readFromNBT(par1NBTTagCompound);
    NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
    this.chestContents = new ItemStack[this.getSizeInventory()];

    if (par1NBTTagCompound.hasKey("chestID")) {
      this.id = par1NBTTagCompound.getInteger("chestID");
    }

    if (par1NBTTagCompound.hasKey("myAccessTick")) {
      this.accessTicks = par1NBTTagCompound.getInteger("myAccessTick");
    }

    if (par1NBTTagCompound.hasKey("CustomName")) {
      this.customName = par1NBTTagCompound.getString("CustomName");
    }

    for (int i = 0; i < nbttaglist.tagCount(); ++i) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.getCompoundTagAt(i);
      int j = nbttagcompound1.getByte("Slot") & 255;

      if (j >= 0 && j < this.chestContents.length) {
        this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }
  }
コード例 #4
0
  @Override
  public void onBlockPlacedBy(
      World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
    if (world.isRemote) return;
    if (stack.hasTagCompound()) {
      TileEntity te = world.getTileEntity(x, y, z);
      if (te instanceof TileVendorBlock) {
        TileVendorBlock tentity = (TileVendorBlock) te;
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
          return;
        }
        NBTTagList tagList = tagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < tagList.tagCount(); i++) {
          NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
          byte slot = tag.getByte("Slot");
          if (slot >= 0 && slot < tentity.getSizeInventory()) {
            tentity.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tag));
          }
        }
        tentity.coinSum = tagCompound.getInteger("CoinSum");
        tentity.userCoinSum = tagCompound.getInteger("UserCoinSum");
        tentity.itemPrice = tagCompound.getInteger("ItemPrice");
        tentity.blockOwner = tagCompound.getString("BlockOwner");
        tentity.infiniteMode = tagCompound.getBoolean("Infinite");
      }
      world.markBlockForUpdate(x, y, z);

    } else {
      // item has no owner so we'll set one and get out of here
      ((TileVendorBlock) world.getTileEntity(x, y, z)).blockOwner = entity.getCommandSenderName();
    }
    int meta = stack.getItemDamage();
    world.setBlockMetadataWithNotify(x, y, z, meta, 2);
  }
コード例 #5
0
  /** (abstract) Protected helper method to read subclass entity data from NBT. */
  public void readEntityFromNBT(NBTTagCompound tagCompund) {
    super.readEntityFromNBT(tagCompund);
    this.setEatingHaystack(tagCompund.getBoolean("EatingHaystack"));
    this.func_110242_l(tagCompund.getBoolean("Bred"));
    this.setChested(tagCompund.getBoolean("ChestedHorse"));
    this.setHasReproduced(tagCompund.getBoolean("HasReproduced"));
    this.setHorseType(tagCompund.getInteger("Type"));
    this.setHorseVariant(tagCompund.getInteger("Variant"));
    this.setTemper(tagCompund.getInteger("Temper"));
    this.setHorseTamed(tagCompund.getBoolean("Tame"));

    if (tagCompund.hasKey("OwnerUUID", 8)) {
      this.func_152120_b(tagCompund.getString("OwnerUUID"));
    }

    IAttributeInstance iattributeinstance =
        this.getAttributeMap().getAttributeInstanceByName("Speed");

    if (iattributeinstance != null) {
      this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
          .setBaseValue(iattributeinstance.getBaseValue() * 0.25D);
    }

    if (this.isChested()) {
      NBTTagList nbttaglist = tagCompund.getTagList("Items", 10);
      this.func_110226_cD();

      for (int i = 0; i < nbttaglist.tagCount(); ++i) {
        NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound1.getByte("Slot") & 255;

        if (j >= 2 && j < this.horseChest.getSizeInventory()) {
          this.horseChest.setInventorySlotContents(
              j, ItemStack.loadItemStackFromNBT(nbttagcompound1));
        }
      }
    }

    ItemStack itemstack;

    if (tagCompund.hasKey("ArmorItem", 10)) {
      itemstack = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("ArmorItem"));

      if (itemstack != null && func_146085_a(itemstack.getItem())) {
        this.horseChest.setInventorySlotContents(1, itemstack);
      }
    }

    if (tagCompund.hasKey("SaddleItem", 10)) {
      itemstack = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("SaddleItem"));

      if (itemstack != null && itemstack.getItem() == Items.saddle) {
        this.horseChest.setInventorySlotContents(0, itemstack);
      }
    } else if (tagCompund.getBoolean("Saddle")) {
      this.horseChest.setInventorySlotContents(0, new ItemStack(Items.saddle));
    }

    this.func_110232_cE();
  }
コード例 #6
0
ファイル: NbtDataUtil.java プロジェクト: Kiskae/SpongeCommon
 public static List<Text> getPagesFromNBT(NBTTagCompound compound) {
   final NBTTagList list = compound.getTagList(ITEM_BOOK_PAGES, TAG_STRING);
   if (list.hasNoTags()) {
     return new ArrayList<>();
   }
   return SpongeTexts.fromLegacy(list);
 }
コード例 #7
0
  public static ItemStack getSmelt(ItemStack smelt, ItemStack itemStack) {
    if (!itemStack.hasTagCompound() || !itemStack.getTagCompound().getBoolean("Smelt"))
      return smelt;
    NBTTagList items =
        itemStack.getTagCompound().getTagList("ItemsSmelt", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < items.tagCount(); ++i) {
      NBTTagCompound item = /*(NBTTagCompound)*/ items.getCompoundTagAt(i);
      byte slot = item.getByte("Slot");

      // Just double-checking that the saved slot index is within our inventory array bounds
      if (slot >= 0 && slot < 9) {
        if (!itemStack.getTagCompound().getBoolean("Invert")
            && ItemStack.loadItemStackFromNBT(item).isItemEqual(smelt))
          return FurnaceRecipes.smelting().getSmeltingResult(smelt) != null
              ? getOneSmelt(smelt)
              : smelt;
        else if (itemStack.getTagCompound().getBoolean("Invert")
            && !ItemStack.loadItemStackFromNBT(item).isItemEqual(smelt))
          return FurnaceRecipes.smelting().getSmeltingResult(smelt) != null
              ? getOneSmelt(smelt)
              : smelt;
      }
    }
    return smelt;
  }
コード例 #8
0
  @Override
  public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);

    // nbt.setInteger("MyMoveState", MoveState);
    // nbt.setFloat("MyMovement", MovementTimer);
    // nbt.setInteger("MyButterState", ButterState);
    nbt.setInteger("MyDirection", EntityDirection);
    nbt.setBoolean("CB", canBoil);
    nbt.setInteger("LA", LiquidAmount);
    nbt.setInteger("BA", BoilAmount);

    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < inv.length; ++i) {
      if (inv[i] != null) {
        NBTTagCompound nbtTagCompound = new NBTTagCompound();
        nbtTagCompound.setByte("Slot", (byte) i);
        inv[i].writeToNBT(nbtTagCompound);
        nbttaglist.appendTag(nbtTagCompound);
      }
    }

    nbt.setTag("Items", nbttaglist);
  }
コード例 #9
0
 public static void setLore(ItemStack stack, String... lore) {
   NBTTagCompound displayTag = getTagCompound(stack, "display");
   NBTTagList list = new NBTTagList();
   for (String s : lore) list.appendTag(new NBTTagString(s));
   displayTag.setTag("Lore", list);
   setTagCompound(stack, "display", displayTag);
 }
コード例 #10
0
  public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);

    NBTTagCompound energyTag = new NBTTagCompound();
    this.storage.writeToNBT(energyTag);
    nbt.setTag("storage", energyTag);
    nbt.setBoolean("flag", this.flag);
    nbt.setBoolean("flag1", this.flag1);
    NBTTagList list = new NBTTagList();

    for (int i = 0; i < this.slots.length; ++i) {
      if (this.slots[i] != null) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setByte("Slot", (byte) i);
        this.slots[i].writeToNBT(compound);
        list.appendTag(compound);
      }
    }

    nbt.setTag("Items", list);

    if (this.isInventoryNameLocalized()) {
      nbt.setString("CustomName", this.localizedName);
    }
  }
コード例 #11
0
  public void writeToNBT(NBTTagCompound p_98280_1_) {
    p_98280_1_.setString("EntityId", this.getEntityNameToSpawn());
    p_98280_1_.setShort("Delay", (short) this.spawnDelay);
    p_98280_1_.setShort("MinSpawnDelay", (short) this.minSpawnDelay);
    p_98280_1_.setShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
    p_98280_1_.setShort("SpawnCount", (short) this.spawnCount);
    p_98280_1_.setShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
    p_98280_1_.setShort("RequiredPlayerRange", (short) this.activatingRangeFromPlayer);
    p_98280_1_.setShort("SpawnRange", (short) this.spawnRange);

    if (this.getRandomMinecart() != null) {
      p_98280_1_.setTag("SpawnData", this.getRandomMinecart().field_98222_b.copy());
    }

    if (this.getRandomMinecart() != null
        || this.minecartToSpawn != null && this.minecartToSpawn.size() > 0) {
      NBTTagList var2 = new NBTTagList();

      if (this.minecartToSpawn != null && this.minecartToSpawn.size() > 0) {
        Iterator var3 = this.minecartToSpawn.iterator();

        while (var3.hasNext()) {
          MobSpawnerBaseLogic.WeightedRandomMinecart var4 =
              (MobSpawnerBaseLogic.WeightedRandomMinecart) var3.next();
          var2.appendTag(var4.func_98220_a());
        }
      } else {
        var2.appendTag(this.getRandomMinecart().func_98220_a());
      }

      p_98280_1_.setTag("SpawnPotentials", var2);
    }
  }
コード例 #12
0
 public NBTTagList func_179414_a() {
   NBTTagList var1 = new NBTTagList();
   var1.appendTag(new NBTTagFloat(this.field_179419_a));
   var1.appendTag(new NBTTagFloat(this.field_179417_b));
   var1.appendTag(new NBTTagFloat(this.field_179418_c));
   return var1;
 }
コード例 #13
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);

    Utils.readStacksFromNBT(nbttagcompound, "items", items);

    energyStored = nbttagcompound.getFloat("energyStored");

    NBTTagList list = nbttagcompound.getTagList("planned");

    for (int i = 0; i < list.tagCount(); ++i) {
      NBTTagCompound cpt = (NBTTagCompound) list.tagAt(i);

      ItemStack stack = ItemStack.loadItemStackFromNBT(cpt);

      for (AssemblyRecipe r : AssemblyRecipe.assemblyRecipes) {
        if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) {
          plannedOutput.add(r);
        }
      }
    }

    if (nbttagcompound.hasKey("recipe")) {
      ItemStack stack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("recipe"));

      for (AssemblyRecipe r : plannedOutput) {
        if (r.output.itemID == stack.itemID && r.output.getItemDamage() == stack.getItemDamage()) {
          setCurrentRecipe(r);
          break;
        }
      }
    }
  }
コード例 #14
0
  @Override
  public void readFromNBT(NBTTagCompound tagCompound) {
    super.readFromNBT(tagCompound);

    facing = ForgeDirection.getOrientation(tagCompound.getInteger("direction"));

    isValidMultiblock = tagCompound.getBoolean("isValidMultiblock");

    NBTTagList itemsTag = (NBTTagList) tagCompound.getTag("Items");
    furnaceItems = new ItemStack[getSizeInventory()];

    for (int i = 0; i < itemsTag.tagCount(); i++) {
      NBTTagCompound slotTag = (NBTTagCompound) itemsTag.getCompoundTagAt(i);
      byte slot = slotTag.getByte("Slot");

      if (slot >= 0 && slot < furnaceItems.length)
        furnaceItems[slot] = ItemStack.loadItemStackFromNBT(slotTag);
    }

    furnaceBurnTime = tagCompound.getShort("BurnTime");
    furnaceCookTime = tagCompound.getShort("CookTime");
    currentItemBurnTime = TileEntityFurnace.getItemBurnTime(furnaceItems[1]);
    cooking = tagCompound.getBoolean("active");
    type = tagCompound.getInteger("type");
    if (type == 1) partBlocks = stonebrick;
    hole = hole.readFromNBT(tagCompound, "hole");
  }
コード例 #15
0
ファイル: TileEntityAltar.java プロジェクト: Giliod/Roots
 @Override
 public NBTTagCompound writeToNBT(NBTTagCompound tag) {
   super.writeToNBT(tag);
   if (inventory.size() > 0) {
     NBTTagList list = new NBTTagList();
     for (int i = 0; i < inventory.size(); i++) {;
       if (inventory.get(i) != null) {
         list.appendTag(inventory.get(i).writeToNBT(new NBTTagCompound()));
       }
     }
     tag.setTag("inventory", list);
   }
   if (incenses.size() > 0) {
     NBTTagList list = new NBTTagList();
     for (int i = 0; i < incenses.size(); i++) {;
       if (incenses.get(i) != null) {
         list.appendTag(incenses.get(i).writeToNBT(new NBTTagCompound()));
       }
     }
     tag.setTag("incenses", list);
   }
   if (ritualName != null) {
     tag.setString("ritualName", ritualName);
   }
   tag.setInteger("progress", progress);
   return tag;
 }
コード例 #16
0
  /** Set the enchantments for the specified stack. */
  public static void setEnchantments(Map p_82782_0_, ItemStack p_82782_1_) {
    NBTTagList nbttaglist = new NBTTagList();
    Iterator iterator = p_82782_0_.keySet().iterator();

    while (iterator.hasNext()) {
      int i = ((Integer) iterator.next()).intValue();
      NBTTagCompound nbttagcompound = new NBTTagCompound();
      nbttagcompound.setShort("id", (short) i);
      nbttagcompound.setShort(
          "lvl", (short) ((Integer) p_82782_0_.get(Integer.valueOf(i))).intValue());
      nbttaglist.appendTag(nbttagcompound);

      if (p_82782_1_.getItem() == Items.enchanted_book) {
        Items.enchanted_book.addEnchantment(
            p_82782_1_,
            new EnchantmentData(i, ((Integer) p_82782_0_.get(Integer.valueOf(i))).intValue()));
      }
    }

    if (nbttaglist.tagCount() > 0) {
      if (p_82782_1_.getItem() != Items.enchanted_book) {
        p_82782_1_.setTagInfo("ench", nbttaglist);
      }
    } else if (p_82782_1_.hasTagCompound()) {
      p_82782_1_.getTagCompound().removeTag("ench");
    }
  }
コード例 #17
0
  @Override
  protected void getBody(ItemStack stack, List<String> currenttip, IWailaDataAccessor accessor) {
    TileEntity te = accessor.getTileEntity();

    if (te instanceof TileAugmentable) {
      if (WailaPlugins.proxy.isShiftKeyDown()) {
        currenttip.add(EnumChatFormatting.AQUA.toString() + "> " + lang.localize("augments.shown"));
        NBTTagList augments =
            accessor.getNBTData().getTagList("augments", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < augments.tagCount(); i++) {
          ItemStack augmentStack = ItemStack.loadItemStackFromNBT(augments.getCompoundTagAt(i));
          if (augmentStack != null) {
            IAugmentItem augment = (IAugmentItem) augmentStack.getItem();
            Set<String> descs = augment.getAugmentTypes(augmentStack);
            for (String s : descs) {
              currenttip.add(
                  EnumChatFormatting.WHITE
                      + "-"
                      + SpecialChars.TAB
                      + EnumChatFormatting.WHITE
                      + teLang.localize("augment." + s));
            }
          }
        }
      } else {
        currenttip.add(
            EnumChatFormatting.AQUA.toString()
                + "<"
                + EnumChatFormatting.ITALIC
                + lang.localize("augments.hidden")
                + EnumChatFormatting.AQUA
                + ">");
      }
    }
  }
コード例 #18
0
  public static boolean hasUpgrade(
      Class<? extends TurretUpgrades> tUpg, Map<Integer, ItemStack> upgMap) {
    if (upgMap == null || tUpg == null) return false;

    TurretUpgrades chkUpg = upgradeListCLT.get(tUpg);

    if (!upgMap.containsKey(chkUpg.getUpgradeID())
        || (upgMap.containsKey(chkUpg.getUpgradeID()) && upgMap.get(chkUpg.getUpgradeID()) == null))
      return false;

    if (upgMap.containsKey(chkUpg.getUpgradeID()) && upgMap.get(chkUpg.getUpgradeID()) != null) {
      ItemStack is = upgMap.get(chkUpg.getUpgradeID());
      if (CUS.areStacksEqualWithWCV(chkUpg.getItem(), is)) {
        if (is.isItemEnchanted() && chkUpg.getEnchantment() != null) {
          NBTTagList ench = is.getEnchantmentTagList();
          for (int j = 0; j < ench.tagCount(); ++j) {
            NBTTagCompound var4 = (NBTTagCompound) ench.tagAt(j);
            if (var4.getShort("id") == chkUpg.getEnchantment().effectId) {
              return true;
            }
          }
        } else if (chkUpg.getEnchantment() == null) {
          return true;
        }
      }
    }

    return false;
  }
コード例 #19
0
ファイル: BlockCrucible.java プロジェクト: Jee-Host/TFCraft
  public NBTTagCompound writeCrucibleToNBT(TECrucible te) {
    NBTTagCompound nbt = new NBTTagCompound();

    nbt.setInteger("temp", te.temperature);

    NBTTagList nbttaglist = new NBTTagList();
    Iterator iter = te.metals.values().iterator();
    while (iter.hasNext()) {
      MetalPair m = (MetalPair) iter.next();
      if (m != null) {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        nbttagcompound1.setInteger("ID", m.type.IngotID);
        nbttagcompound1.setFloat("AmountF", m.amount);
        nbttaglist.appendTag(nbttagcompound1);
      }
    }
    nbt.setTag("Metals", nbttaglist);

    nbttaglist = new NBTTagList();
    for (int i = 0; i < te.storage.length; i++) {
      if (te.storage[i] != null) {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        nbttagcompound1.setByte("Slot", (byte) i);
        te.storage[i].writeToNBT(nbttagcompound1);
        nbttaglist.appendTag(nbttagcompound1);
      }
    }

    nbt.setTag("Items", nbttaglist);

    return nbt;
  }
コード例 #20
0
  @Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    try {
      this.IC_Outputpacketamount = nbttagcompound.getShort("ICOutputpacketamount");
    } catch (Exception e) {
      this.IC_Outputpacketamount = nbttagcompound.getInteger("ICOutputpacketamount");
    }
    this.IC_Output = nbttagcompound.getInteger("ICOutput");
    this.IC_Outputpacketsize = nbttagcompound.getInteger("ICOutputpacketsize");
    this.UE_Output = nbttagcompound.getInteger("UEOutput");
    this.UE_Outputvoltage = nbttagcompound.getInteger("UEOutputvoltage");
    this.UE_Outputamp = nbttagcompound.getInteger("UEOutputamp");

    NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
    this.inventory = new ItemStack[getSizeInventory()];
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);

      byte byte0 = nbttagcompound1.getByte("Slot");
      if ((byte0 >= 0) && (byte0 < this.inventory.length)) {
        this.inventory[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }
  }
コード例 #21
0
ファイル: MapData.java プロジェクト: sidben/CartoCraft
  /** write data to NBTTagCompound from this MapDataBase, similar to Entities and TileEntities */
  public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
    // DEBUG
    System.out.println("MapData.writeToNBT()");

    par1NBTTagCompound.setInteger("dimension", this.dimension);
    par1NBTTagCompound.setInteger("xCenter", this.xCenter);
    par1NBTTagCompound.setInteger("zCenter", this.zCenter);
    par1NBTTagCompound.setByte("scale", this.scale);
    par1NBTTagCompound.setShort("width", (short) 128);
    par1NBTTagCompound.setShort("height", (short) 128);
    par1NBTTagCompound.setByteArray("colors", this.colors);

    // CartoCraft - Save custom icons
    if (this.customIcons.size() > 0) {
      NBTTagList iconTagList = new NBTTagList();
      NBTTagCompound iconTagCompound;
      MapCoord mapcoord;

      for (Iterator iterator = this.customIcons.values().iterator(); iterator.hasNext(); ) {
        mapcoord = (MapCoord) iterator.next();

        iconTagCompound = new NBTTagCompound();
        iconTagCompound.setByte("icon", mapcoord.iconSize);
        iconTagCompound.setByte("xPos", mapcoord.centerX);
        iconTagCompound.setByte("zPos", mapcoord.centerZ);

        iconTagList.appendTag(iconTagCompound);
      }
      par1NBTTagCompound.setTag("customIcons", iconTagList);
    }
  }
コード例 #22
0
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

    nbtTags.setBoolean("finishedCalc", finishedCalc);

    if (fluidTank.getFluid() != null) {
      nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound()));
    }

    NBTTagList activeList = new NBTTagList();

    for (Coord4D wrapper : activeNodes) {
      NBTTagCompound tagCompound = new NBTTagCompound();
      wrapper.write(tagCompound);
      activeList.appendTag(tagCompound);
    }

    if (activeList.tagCount() != 0) {
      nbtTags.setTag("activeNodes", activeList);
    }

    NBTTagList usedList = new NBTTagList();

    for (Coord4D obj : usedNodes) {
      activeList.appendTag(obj.write(new NBTTagCompound()));
    }

    if (activeList.tagCount() != 0) {
      nbtTags.setTag("usedNodes", usedList);
    }
  }
コード例 #23
0
 public ItemStack getItemStackWithData(World world, int x, int y, int z) {
   ItemStack stack = new ItemStack(world.getBlock(x, y, z), 1, 0);
   TileEntity tentity = world.getTileEntity(x, y, z);
   if (tentity instanceof TileVendorBlock) {
     TileVendorBlock te = (TileVendorBlock) tentity;
     NBTTagList itemList = new NBTTagList();
     NBTTagCompound tagCompound = new NBTTagCompound();
     for (int i = 0; i < te.getSizeInventory(); i++) {
       ItemStack invStack = te.getStackInSlot(i);
       if (invStack != null) {
         NBTTagCompound tag = new NBTTagCompound();
         tag.setByte("Slot", (byte) i);
         invStack.writeToNBT(tag);
         itemList.appendTag(tag);
       }
     }
     tagCompound.setTag("Inventory", itemList);
     tagCompound.setInteger("CoinSum", te.coinSum);
     tagCompound.setInteger("UserCoinSum", te.userCoinSum);
     tagCompound.setInteger("ItemPrice", te.itemPrice);
     tagCompound.setString("BlockOwner", te.blockOwner);
     tagCompound.setBoolean("Infinite", te.infiniteMode);
     stack.setTagCompound(tagCompound);
     return stack;
   } else return stack;
 }
コード例 #24
0
 @Override
 public void onEnable() {
   if (mc.thePlayer.inventory.getStackInSlot(0) != null) {
     wurst.chat.error("Please clear the first slot in your hotbar.");
     setEnabled(false);
     return;
   } else if (!mc.thePlayer.capabilities.isCreativeMode) {
     wurst.chat.error("Creative mode only.");
     setEnabled(false);
     return;
   }
   ItemStack stack = new ItemStack(Items.potionitem);
   stack.setItemDamage(16384);
   NBTTagList effects = new NBTTagList();
   for (int i = 1; i <= 23; i++) {
     NBTTagCompound effect = new NBTTagCompound();
     effect.setInteger("Amplifier", Integer.MAX_VALUE);
     effect.setInteger("Duration", Integer.MAX_VALUE);
     effect.setInteger("Id", i);
     effects.appendTag(effect);
   }
   stack.setTagInfo("CustomPotionEffects", effects);
   stack.setStackDisplayName("§c§lTroll§6§lPotion");
   mc.thePlayer.sendQueue.addToSendQueue(new C10PacketCreativeInventoryAction(36, stack));
   wurst.chat.message("Potion created. Trololo!");
   setEnabled(false);
 }
コード例 #25
0
  // インベントリの保存
  public void save() {
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.containerItems.length; i++) {
      if (this.containerItems[i] != null) {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        nbttagcompound1.setByte("EquipmentSlot", (byte) i);
        this.containerItems[i].writeToNBT(nbttagcompound1);
        nbttaglist.appendTag(nbttagcompound1);
      }
    }

    // ItemStackのNBTに中身を保存
    NBTTagCompound nbttagcompound = this.baseChest.getEntityData();

    if (nbttagcompound == null) {
      nbttagcompound = new NBTTagCompound();
    }

    nbttagcompound.setTag("EquipmentItems", nbttaglist);

    // EntityLivingのequipmentと同期
    for (int slot = 0; slot < this.containerItems.length; slot++) {
      this.baseChest.setCurrentItemOrArmor(slot, this.containerItems[slot]);
    }
  }
コード例 #26
0
  private void mixPotions() {
    ItemStack resultPotion = new ItemStack(ModItems.mixedPotion, 1);
    int emulsifierLevel = calculateEmulsifierLevel();
    ArrayList<PotionEffect> resultList = new ArrayList<PotionEffect>();
    NBTTagCompound potionEffects = new NBTTagCompound();
    NBTTagList taglist = new NBTTagList();

    for (int i = POTION_START; i < getSizeInventory(); i++) {
      ItemStack potion = getStackInSlot(i);
      ArrayList<PotionEffect> effectList = getPotionEffects(potion);
      if (resultList.size() == emulsifierLevel) {
        break;
      } else if (resultList.size() + effectList.size() > emulsifierLevel) {
        continue;
      } else {
        for (PotionEffect effect : effectList) {
          if (!resultList.contains(effect)) {
            resultList.add(effect);
            NBTTagCompound effectCompound = new NBTTagCompound();
            taglist.appendTag(effect.writeCustomPotionEffectToNBT(effectCompound));
          }
        }
        // since this potion was used, remove it from the inventory
        setInventorySlotContents(i, null);
      }
    }

    potionEffects.setTag("CustomPotionEffects", taglist);
    resultPotion.setTagCompound(potionEffects);
    setInventorySlotContents(EMULSIFIER_INDEX, decrStackSize(EMULSIFIER_INDEX, 1));
    setInventorySlotContents(RESULT_INDEX, resultPotion);
  }
コード例 #27
0
  public ItemStack getCraftingResult() {
    this.cost = 0;
    ItemStack output = this.tool.getStack().copy();

    NBTTagList toolList = getEnchantmentTagList(output);
    NBTTagList bookList = getEnchantmentTagList(this.enchantedBook.copy());

    boolean changed = false;

    for (int iBook = 0; iBook < bookList.tagCount(); iBook++) {
      boolean found = false;
      NBTTagCompound bookEnchant = bookList.getCompoundTagAt(iBook);

      // Check the tool for allowed enchants
      if (!this.tool
          .getItem()
          .getAllowedEnchantments()
          .contains(Enchantment.enchantmentsList[bookEnchant.getShort("id")].type)) continue;

      // Check if the enchant already exists
      for (int iTool = 0; iTool < toolList.tagCount(); iTool++) {
        NBTTagCompound toolEnchant = toolList.getCompoundTagAt(iTool);
        if (toolEnchant.getShort("id") == bookEnchant.getShort("id")) {
          found = true;
          if (toolEnchant.getShort("lvl") < bookEnchant.getShort("lvl")) {
            changed = true;
            toolEnchant.setShort("lvl", bookEnchant.getShort("lvl"));
          }
          continue;
        }
      }

      // It doesn't exist yet, just add it
      if (!found) {
        boolean allowed = true;
        for (int iTool = 0; iTool < toolList.tagCount(); iTool++) {
          int toolEnchant = toolList.getCompoundTagAt(iTool).getShort("id");
          if (!Enchantment.enchantmentsList[toolEnchant].canApplyTogether(
              Enchantment.enchantmentsList[bookEnchant.getShort("id")])) {
            allowed = false;
          }
        }

        if (allowed) {
          changed = true;
          toolList.appendTag(bookEnchant);
          int lvl = bookEnchant.getShort("lvl") + 1;
          int cost = lvl * lvl * 2 / (this.tool.getHeadMaterial().arcaneLevel + 1);
          this.cost += cost;
        }
      }
    }

    if ((output.getEnchantmentTagList() == null || output.getEnchantmentTagList().tagCount() == 0)
        && toolList.tagCount() > 0) {
      output.getTagCompound().setTag("ench", toolList);
    }

    return changed ? output : null;
  }
コード例 #28
0
  static {
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("author", "Guess Who? :3");
    nbt.setString("title", "NotOnlyMoreOres");

    NBTTagList pages = new NBTTagList();
    pages.appendTag(
        new NBTTagString(
            "1",
            "Hey there handsome! ;) How are you doing today? "
                + "I see that you chose to play with this \u00a7nawesome\u00a7r mod that you found, \u00a7oSkorpio's NotOnlyMoreOres Mod\u00a7r! Just wanted to tell you some wise stuff about it! "
                + "Flip to the next page please! :)"));
    pages.appendTag(
        new NBTTagString(
            "2",
            "First of all, if you're just a normal player, I want you to have fun. Understood? Alright. "
                + "Are you a youtuber who's going to review this mod? Alright listen up man. You \u00a7lNEED TO READ THE THREAD FULLY \u00a70alright? ;) Thanks! :3 Flip again! :)"));
    pages.appendTag(
        new NBTTagString(
            "3",
            "And if you have any suggestions, PLEASE visit the thread for the mod and give the author a little help! :) "
                + "Now go, have fun! :D I'll talk to you later! <3"
                + "                               P.S. you seem to like flipping, so why don't you do it one more time? :3"));
    pages.appendTag(
        new NBTTagString(
            "4",
            "\u00a7bT\u00a71R\u00a72O\u00a73L\u00a74O\u00a75L\u00a76O\u00a77L\u00a78O\u00a7aL \u00a70nothing here! GOTCHA! x) \u00a7kSkorpio"));

    nbt.setTag("pages", pages);
    reading = new ItemStack(Item.writtenBook);
    reading.setTagCompound(nbt);
  }
コード例 #29
0
ファイル: TECrucible.java プロジェクト: jack42/TFCraft
  public void readFromItemNBT(NBTTagCompound nbt) {
    temperature = nbt.getInteger("temp");

    NBTTagList nbttaglist = nbt.getTagList("Metals");

    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
      int id = nbttagcompound1.getInteger("ID");
      float amount = nbttagcompound1.getShort("Amount");
      // Added so that hopefully old worlds that stored metal as shorts wont break
      float amountF = amount + nbttagcompound1.getFloat("AmountF");
      Metal m = MetalRegistry.instance.getMetalFromItem(Item.itemsList[id]);
      addMetal(MetalRegistry.instance.getMetalFromItem(Item.itemsList[id]), amount);
    }

    nbttaglist = nbt.getTagList("Items");
    storage = new ItemStack[getSizeInventory()];
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
      byte byte0 = nbttagcompound1.getByte("Slot");
      if (byte0 >= 0 && byte0 < storage.length) {
        storage[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }

    if (currentAlloy != null) {
      currentAlloy.outputAmount = nbt.getInteger("outputAmount");
    }
  }
コード例 #30
0
  // This is where you save any data that you don't want to lose when the tile entity unloads
  // In this case, it saves the state of the furnace (burn time etc) and the itemstacks stored in
  // the fuel, input, and output slots
  @Override
  public void writeToNBT(NBTTagCompound parentNBTTagCompound) {
    super.writeToNBT(
        parentNBTTagCompound); // The super call is required to save and load the tiles location

    //		// Save the stored item stacks

    // to use an analogy with Java, this code generates an array of hashmaps
    // The itemStack in each slot is converted to an NBTTagCompound, which is effectively a hashmap
    // of key->value pairs such
    //   as slot=1, id=2353, count=1, etc
    // Each of these NBTTagCompound are then inserted into NBTTagList, which is similar to an array.
    NBTTagList dataForAllSlots = new NBTTagList();
    for (int i = 0; i < this.itemStacks.length; ++i) {
      if (this.itemStacks[i] != null) {
        NBTTagCompound dataForThisSlot = new NBTTagCompound();
        dataForThisSlot.setByte("Slot", (byte) i);
        this.itemStacks[i].writeToNBT(dataForThisSlot);
        dataForAllSlots.appendTag(dataForThisSlot);
      }
    }
    // the array of hashmaps is then inserted into the parent hashmap for the container
    parentNBTTagCompound.setTag("Items", dataForAllSlots);

    // Save everything else
    parentNBTTagCompound.setShort("CookTime", cookTime);
    parentNBTTagCompound.setTag("burnTimeRemaining", new NBTTagIntArray(burnTimeRemaining));
    parentNBTTagCompound.setTag("burnTimeInitial", new NBTTagIntArray(burnTimeInitialValue));
  }