use of net.minecraft.nbt.NBTTagList in project BetterStorage by copygirl.
the class StackUtils method getEnchantments.
// Enchantment functions
/** Returns the enchantments on the item stack. */
public static Map<Integer, StackEnchantment> getEnchantments(ItemStack stack) {
Map<Integer, StackEnchantment> enchantments = new HashMap<Integer, StackEnchantment>();
NBTTagList list = ((stack.getItem() == Items.enchanted_book) ? Items.enchanted_book.func_92110_g(stack) : stack.getEnchantmentTagList());
if (list != null)
for (int i = 0; i < list.tagCount(); i++) {
StackEnchantment ench = new StackEnchantment(stack, list.getCompoundTagAt(i));
enchantments.put(ench.ench.effectId, ench);
}
return enchantments;
}
use of net.minecraft.nbt.NBTTagList in project BetterStorage by copygirl.
the class CratePileData method fromCompound.
public static CratePileData fromCompound(CratePileCollection collection, int crateId, NBTTagCompound compound) {
int numCrates = compound.getShort("numCrates");
CratePileData pileData = new CratePileData(collection, crateId, numCrates);
NBTTagList stacks = compound.getTagList("stacks", NBT.TAG_COMPOUND);
for (int j = 0; j < stacks.tagCount(); j++) {
NBTTagCompound stackCompound = stacks.getCompoundTagAt(j);
Item item = Item.getItemById(stackCompound.getShort("id"));
int count = stackCompound.getInteger("Count");
int damage = stackCompound.getShort("Damage");
ItemStack stack = new ItemStack(item, count, damage);
if (stackCompound.hasKey("tag"))
stack.stackTagCompound = stackCompound.getCompoundTag("tag");
if (stack.getItem() != null)
pileData.getContents().set(new ItemIdentifier(stack), stack.stackSize);
}
if (compound.hasKey("map"))
pileData.map = CratePileMap.fromCompound(compound.getCompoundTag("map"));
return pileData;
}
use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.
the class InventoryItem method readFromNBT.
protected void readFromNBT() {
reading = true;
NBTTagList itemList = (NBTTagList) ((NBTTagCompound) item.stackTagCompound.getTag("Inventory")).getTag("Items");
for (int i = 0; i < itemList.tagCount(); i++) {
NBTTagCompound slotEntry = itemList.getCompoundTagAt(i);
int j = slotEntry.getByte("Slot") & 0xff;
if (j >= 0 && j < getSizeInventory()) {
setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(slotEntry));
}
}
reading = false;
}
use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.
the class WorldConverter method convertTile.
private boolean convertTile(NBTTagCompound tag) {
NBTTagList parts = tag.getTagList("parts", new NBTTagCompound().getId());
int count = parts.tagCount();
FMPPart fmppart = new FMPPart(true);
for (int i = 0; i < count; i++) {
NBTTagCompound part = parts.getCompoundTagAt(i);
String id = part.getString("id");
for (IPartConverter c : converters) {
if (c.matches(id)) {
IPart p = c.convert(part);
if (p == null)
continue;
fmppart.addPart(p);
parts.removeTag(i);
i--;
break;
}
}
count = parts.tagCount();
}
if (fmppart.getParts().size() > 0) {
NBTTagCompound part = new NBTTagCompound();
fmppart.save(part);
part.setString("id", fmppart.getType());
parts.appendTag(part);
return true;
}
return false;
}
use of net.minecraft.nbt.NBTTagList in project BluePower by Qmunity.
the class WorldConverter method convertRegion.
private void convertRegion(File file) {
RegionFile reg = new RegionFile(file);
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
NBTTagCompound chunk = getChunk(reg, x, z);
if (chunk == null)
continue;
NBTTagList tileEntities = chunk.getTagList("TileEntities", new NBTTagCompound().getId());
boolean changed = false;
for (int i = 0; i < tileEntities.tagCount(); i++) {
NBTTagCompound te = tileEntities.getCompoundTagAt(i);
if (te.getString("id").equals("savedMultipart"))
changed |= convertTile(te);
}
if (changed)
saveChunk(reg, x, z, chunk);
}
}
try {
reg.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations