public void readData(NBTTagCompound nbt, SyncType type) {
   super.readData(nbt, type);
   if (type == SyncType.SAVE || type == SyncType.SYNC) {
     this.cookTime = nbt.getShort("cookTime");
     this.active = nbt.getShort("active");
   }
 }
  @Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    World world = player.worldObj;
    int bID = player.worldObj.getBlockId(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);
    Block block = Block.blocksList[bID];
    if (block == null || bID < 1) return false;
    int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
    int shlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getSecondHarvestType());

    if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2")) {
      boolean cancelHarvest = false;
      for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
        if (mod.beforeBlockBreak(this, stack, x, y, z, player)) cancelHarvest = true;
      }

      return cancelHarvest;
    } else {
      if (!player.capabilities.isCreativeMode) onBlockDestroyed(stack, world, bID, x, y, z, player);
      world.setBlockToAir(x, y, z);
      if (!world.isRemote) world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
      return true;
    }
  }
 public static String getTitle(ItemStack aStack) {
   NBTTagCompound tNBT = aStack.getTagCompound();
   if (tNBT == null) {
     return "";
   }
   return tNBT.getString("title");
 }
  // インベントリの保存
  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]);
    }
  }
 protected final NBTTagCompound writeFacingNBT() {
   NBTTagCompound nbt = new NBTTagCompound();
   for (int i = 0; i < colors.length; i++) {
     nbt.setByte("color" + i, (byte) colors[i].ordinal());
   }
   return nbt;
 }
  public void readUpdatePacketData(NBTTagCompound tag) {

    int amt = tag.getInteger("partAmount");
    List<BPPart> found = new ArrayList<BPPart>();
    for (int i = 0; i < amt; i++) {
      String type = tag.getString("partType" + i);
      UUID id = UUID.fromString(tag.getString("partId" + i));
      NBTTagCompound t = tag.getCompoundTag("part" + i);
      BPPart p = getPartForId(id);
      if (p == null) addPart(p = PartRegistry.getInstance().createPart(type), id);
      p.load(t);
      found.add(p);
    }
    List<BPPart> removed = new ArrayList<BPPart>();
    for (BPPart p : getParts()) {
      if (!found.contains(p)) {
        removed.add(p);
      }
    }
    for (BPPart p : removed) removePart(p);

    found.clear();
    removed.clear();

    shouldReRender = true;
  }
 @Override
 public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket) {
   energyStorage.writeToNBT(nbt);
   nbt.setInteger("facing", facing.ordinal());
   //		nbt.setIntArray("sockets", sockets);
   nbt.setBoolean("active", active);
 }
  /// Initializes the entity's stats.
  @Override
  public void init(MobStatsInfo mobStats) {
    NBTTagCompound tag = new NBTTagCompound();
    mobStats.theEntity.writeToNBT(tag);

    NBTTagList tagList = tag.getTagList("Pos", Constants.NBT.TAG_DOUBLE);
    double x = tagList.func_150309_d(0);
    double y = tagList.func_150309_d(1);
    double z = tagList.func_150309_d(2);
    tagList.func_150304_a(0, new NBTTagDouble(0.0));
    tagList.func_150304_a(1, new NBTTagDouble(0.0));
    tagList.func_150304_a(2, new NBTTagDouble(0.0));

    tagList = tag.getTagList("Rotation", Constants.NBT.TAG_FLOAT);
    float yaw = tagList.func_150308_e(0);
    tagList.func_150304_a(0, new NBTTagFloat(0.0F));

    this.nbtStats.generate(mobStats.theEntity, tag, mobStats);

    tagList = tag.getTagList("Pos", Constants.NBT.TAG_DOUBLE);
    tagList.func_150304_a(0, new NBTTagDouble(tagList.func_150309_d(0) + x));
    tagList.func_150304_a(1, new NBTTagDouble(tagList.func_150309_d(1) + y));
    tagList.func_150304_a(2, new NBTTagDouble(tagList.func_150309_d(2) + z));

    tagList = tag.getTagList("Rotation", Constants.NBT.TAG_FLOAT);
    tagList.func_150304_a(0, new NBTTagFloat(tagList.func_150308_e(0) + yaw));

    mobStats.theEntity.readFromNBT(tag);
  }
 @Override
 protected void writeSyncTag(NBTTagCompound NBT) {
   super.writeSyncTag(NBT);
   NBT.setIntArray("CookTime", extractorCookTime);
   NBT.setInteger("drill", drillTime);
   NBT.setBoolean("bedrock", bedrock);
 }
  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;
  }
  private void loadTweaks(ItemStack stack, IPowerModule module) {
    NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
    NBTTagCompound moduleTag = itemTag.getCompoundTag(module.getName());

    propertyStrings = new HashMap();
    Set<String> tweaks = new HashSet<String>();

    Map<String, List<IPropertyModifier>> propertyModifiers = module.getPropertyModifiers();
    for (Map.Entry<String, List<IPropertyModifier>> property : propertyModifiers.entrySet()) {
      double currValue = 0;
      for (IPropertyModifier modifier : property.getValue()) {
        currValue = modifier.applyModifier(moduleTag, currValue);
        if (modifier instanceof PropertyModifierLinearAdditive) {
          tweaks.add(((PropertyModifierLinearAdditive) modifier).getTradeoffName());
        }
      }
      propertyStrings.put(property.getKey(), currValue);
    }

    sliders = new LinkedList();
    int y = 0;
    for (String tweak : tweaks) {
      y += 24;
      ClickableSlider slider =
          new ClickableSlider(
              new MusePoint2D((border.left() + border.right()) / 2, border.top() + y),
              border.right() - border.left() - 8,
              moduleTag,
              tweak);
      sliders.add(slider);
    }
  }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 @SideOnly(Side.CLIENT)
 public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean par4) {
   NBTTagCompound c = stack.getTagCompound();
   if (getBlockID() == Machine.DeepStorageUnit.getBlockId()
       && stack.getItemDamage() == Machine.DeepStorageUnit.getMeta()
       && c != null) {
     if (c.hasKey("storedStack")) {
       ItemStack storedItem = ItemStack.loadItemStackFromNBT(c.getCompoundTag("storedStack"));
       int storedQuantity = c.getInteger("storedQuantity");
       if (storedItem != null & storedQuantity > 0) {
         info.add(
             "Contains "
                 + storedQuantity
                 + " "
                 + storedItem.getDisplayName()
                 + " ("
                 + storedItem.itemID
                 + ":"
                 + storedItem.getItemDamageForDisplay()
                 + ")");
       } else {
         // info.add("Empty");
       }
     }
   } else if (getBlockID() == Machine.BioFuelGenerator.getBlockId()
       && stack.getItemDamage() == Machine.BioFuelGenerator.getMeta()) {
     info.add("Produces MJ only.");
   }
 }
 protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
   // super.readFromNBT(nbttagcompound);
   EnumDinoType[] DinoChart = EnumDinoType.values();
   this.BirthTick = nbttagcompound.getInteger("BirthTick");
   this.DinoInside = DinoChart[nbttagcompound.getInteger("DinoType")];
   this.ParentOwner = nbttagcompound.getString("ParentOwner");
 }
 public void writeData(NBTTagCompound nbt, SyncType type) {
   super.writeData(nbt, type);
   if (type == SyncType.SAVE || type == SyncType.SYNC) {
     nbt.setShort("cookTime", (short) this.cookTime);
     nbt.setShort("active", (short) this.active);
   }
 }
 @Override
 public void readFromNbt(NBTTagCompound compound) {
   super.readFromNbt(compound);
   if (compound.hasKey("effect")) {
     this.effect = compound.getBoolean("effect");
   }
 }
Exemple #16
0
  /** (abstract) Protected helper method to read subclass entity data from NBT. */
  public void readEntityFromNBT(NBTTagCompound p_70037_1_) {
    super.readEntityFromNBT(p_70037_1_);

    if (p_70037_1_.func_150297_b("ExplosionPower", 99)) {
      this.explosionStrength = p_70037_1_.getInteger("ExplosionPower");
    }
  }
Exemple #17
0
  public void writeToFile(boolean unloadInstances) {
    try {

      NBTTagCompound data = new NBTTagCompound();

      Collection playerDataCl = grid.values();
      Iterator it = playerDataCl.iterator();

      while (it.hasNext()) {
        BlockDataPoint bdp = (BlockDataPoint) it.next();
        data.setTag("" + bdp.hash, bdp.writeToNBT());
      }

      String saveFolder =
          CoroUtilFile.getWorldSaveFolderPath()
              + CoroUtilFile.getWorldFolderName()
              + "epoch"
              + File.separator;

      // Write out to file
      if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
      FileOutputStream fos =
          new FileOutputStream(
              saveFolder + "EpochBlockDataDim_" + world.provider.dimensionId + ".dat");
      CompressedStreamTools.writeCompressed(data, fos);
      fos.close();

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 public NBTTagCompound toNbt() {
   NBTTagCompound tag = new NBTTagCompound();
   tag.setTag("key", _key.toNbt());
   tag.setInteger("count", _count);
   tag.setBoolean("whitelisted", _whitelisted);
   return tag;
 }
Exemple #19
0
  /** 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);
    }
  }
  @Override
  public void modify(ItemStack[] input, ItemStack tool) {
    NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
    int[] keyPair;
    if (tags.hasKey(key)) {
      keyPair = tags.getIntArray(key);
      if (keyPair[0] % max == 0) {
        keyPair[0] += increase;
        keyPair[1] += max;
        tags.setIntArray(key, keyPair);

        int modifiers = tags.getInteger("Modifiers");
        modifiers -= 1;
        tags.setInteger("Modifiers", modifiers);
      } else {
        keyPair[0] += increase;
        tags.setIntArray(key, keyPair);
      }
      updateModTag(tool, keyPair);
    } else {
      int modifiers = tags.getInteger("Modifiers");
      modifiers -= 1;
      tags.setInteger("Modifiers", modifiers);
      String modName = TextHelper.AQUA + "Void Mod (" + increase + "/" + max + ")";
      int tooltipIndex = addToolTip(tool, tooltipName, modName);
      keyPair = new int[] {increase, max, tooltipIndex};
      tags.setIntArray(key, keyPair);
    }
  }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int idk,
      float what,
      float these,
      float are) {
    ItemStack playerItem = player.getCurrentEquippedItem();

    if (playerItem != null) {
      if (playerItem.getItem() instanceof TelepositionFocus) {
        SoulNetworkHandler.checkAndSetItemPlayer(playerItem, player);

        if (playerItem.getTagCompound() == null) {
          playerItem.setTagCompound(new NBTTagCompound());
        }

        NBTTagCompound itemTag = playerItem.getTagCompound();
        itemTag.setInteger("xCoord", x);
        itemTag.setInteger("yCoord", y);
        itemTag.setInteger("zCoord", z);
        itemTag.setInteger("dimensionId", world.provider.dimensionId);
        return true;
      }
    }
    player.openGui(AlchemicalWizardry.instance, 1, world, x, y, z);
    return true;
  }
  @Override
  public void writeToNBT(NBTTagCompound nbtTags) {
    super.writeToNBT(nbtTags);

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

    NBTTagList recurringList = new NBTTagList();

    for (Object3D wrapper : recurringNodes) {
      NBTTagCompound tagCompound = new NBTTagCompound();
      wrapper.write(tagCompound);
      recurringList.appendTag(tagCompound);
    }

    if (recurringList.tagCount() != 0) {
      nbtTags.setTag("recurringNodes", recurringList);
    }

    NBTTagList cleaningList = new NBTTagList();

    for (Object3D obj : cleaningNodes) {
      cleaningList.appendTag(obj.write(new NBTTagCompound()));
    }

    if (cleaningList.tagCount() != 0) {
      nbtTags.setTag("cleaningNodes", cleaningList);
    }
  }
  // インベントリの読み込み
  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]);
    }
  }
  public WorldInfo func_75803_c(String p_75803_1_) {
    File var2 = new File(this.field_75808_a, p_75803_1_);
    if (!var2.exists()) {
      return null;
    } else {
      File var3 = new File(var2, "level.dat");
      NBTTagCompound var4;
      NBTTagCompound var5;
      if (var3.exists()) {
        try {
          var4 = CompressedStreamTools.func_74796_a(new FileInputStream(var3));
          var5 = var4.func_74775_l("Data");
          return new WorldInfo(var5);
        } catch (Exception var7) {
          var7.printStackTrace();
        }
      }

      var3 = new File(var2, "level.dat_old");
      if (var3.exists()) {
        try {
          var4 = CompressedStreamTools.func_74796_a(new FileInputStream(var3));
          var5 = var4.func_74775_l("Data");
          return new WorldInfo(var5);
        } catch (Exception var6) {
          var6.printStackTrace();
        }
      }

      return null;
    }
  }
Exemple #25
0
  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");
    }
  }
 @Override
 public void writeToNBT(NBTTagCompound nbtTagCompound) {
   super.writeToNBT(nbtTagCompound);
   nbtTagCompound.setBoolean("fill", fill);
   inventory.writeToNBT(nbtTagCompound);
   nbtTagCompound.setTag("tank", tank.writeToNBT(new NBTTagCompound()));
 }
Exemple #27
0
 @Override
 public void readFromNBT(NBTTagCompound nbt) {
   super.readFromNBT(nbt);
   if (nbt.hasKey("s")) {
     signalLevel = nbt.getShort("s");
   }
 }
  float calculateStrength(NBTTagCompound tags, Block block, int meta) {
    float mineSpeed = tags.getInteger("MiningSpeed");
    int heads = 1;
    if (tags.hasKey("MiningSpeed2")) {
      mineSpeed += tags.getInteger("MiningSpeed2");
      heads++;
    }

    if (tags.hasKey("MiningSpeedHandle")) {
      mineSpeed += tags.getInteger("MiningSpeedHandle");
      heads++;
    }

    if (tags.hasKey("MiningSpeedExtra")) {
      mineSpeed += tags.getInteger("MiningSpeedExtra");
      heads++;
    }
    float trueSpeed = mineSpeed / (heads * 100f);
    int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
    int durability = tags.getInteger("Damage");

    float stonebound = tags.getFloat("Shoddy");
    float bonusLog = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
    trueSpeed += bonusLog;

    if (hlvl <= tags.getInteger("HarvestLevel")) return trueSpeed;
    return 0.1f;
  }
 public static String getAuthor(ItemStack aStack) {
   NBTTagCompound tNBT = aStack.getTagCompound();
   if (tNBT == null) {
     return "";
   }
   return tNBT.getString("author");
 }
  @Override
  public void readFromNBT(NBTTagCompound tag) {
    super.readFromNBT(tag);

    facing = ForgeDirection.getOrientation(tag.getInteger("facing"));
    linkedDir = ForgeDirection.getOrientation(tag.getInteger("linked"));
  }