use of net.minecraft.server.v1_16_R3.NBTTagList in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_16_R3 method deserialize.
private static InventoryHolder deserialize(NBTTagCompound tagCompound) {
InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
NBTTagList itemsList = tagCompound.getList("Items", 10);
for (int i = 0; i < itemsList.size(); i++) {
NBTTagCompound nbtTagCompound = itemsList.getCompound(i);
inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(ItemStack.a(nbtTagCompound)));
}
return inventory;
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_8_R3 method deserialize.
private InventoryHolder deserialize(NBTTagCompound tagCompound) {
InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
NBTTagList itemsList = tagCompound.getList("Items", 10);
for (int i = 0; i < itemsList.size(); i++) {
NBTTagCompound nbtTagCompound = itemsList.get(i);
inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(ItemStack.createStack(nbtTagCompound)));
}
return inventory;
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_12_R1 method serialize.
private void serialize(Inventory inventory, NBTTagCompound tagCompound) {
NBTTagList itemsList = new NBTTagList();
org.bukkit.inventory.ItemStack[] items = inventory.getContents();
for (int i = 0; i < items.length; ++i) {
if (items[i] != null) {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
nbtTagCompound.setByte("Slot", (byte) i);
CraftItemStack.asNMSCopy(items[i]).save(nbtTagCompound);
itemsList.add(nbtTagCompound);
}
}
tagCompound.setInt("Size", inventory.getSize());
tagCompound.set("Items", itemsList);
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project MechanicsMain by WeaponMechanics.
the class NBT_1_10_R1 method setAttribute.
@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
net.minecraft.server.v1_10_R1.ItemStack nmsItem = getNMSStack(bukkitItem);
if (nmsItem.getTag() == null) {
nmsItem.setTag(new NBTTagCompound());
}
NBTTagCompound compound = nmsItem.getTag();
if (compound.hasKey("AttributeModifiers")) {
NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
// NBT lists don't have an indexOf method, so we need to loop
// through each attribute, and determine if it is one we want to
// modify. We want to modify an attribute if the attribute was
// set using MechanicsCore, and it's attribute type matches the
// parameter attribute type.
boolean isModifiedAttribute = false;
for (int i = 0; i < list.size(); i++) {
// 10 is the id for nbt lists
if (list.get(i).getTypeId() != 10) {
continue;
}
NBTTagCompound nbt = list.get(i);
String name = nbt.getString("Name");
String attributeName = nbt.getString("AttributeName");
// There is no offhand, or slot argument in 1_8_8.
if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
continue;
}
// Since this attribute already exists, we only need to modify
// the existing value. No need to set the name/uuid
nbt.setDouble("Amount", value);
isModifiedAttribute = true;
break;
}
if (!isModifiedAttribute) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("AttributeName", attribute.getMinecraftName());
nbt.setString("Name", "MechanicsCoreAttribute");
nbt.setDouble("Amount", value);
// 0 == add
nbt.setInt("Operation", 0);
nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
if (slot != null) {
nbt.setString("Slot", slot.getSlotName());
}
}
}
bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project MechanicsMain by WeaponMechanics.
the class NBT_1_12_R1 method setAttribute.
@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
net.minecraft.server.v1_12_R1.ItemStack nmsItem = getNMSStack(bukkitItem);
if (nmsItem.getTag() == null) {
nmsItem.setTag(new NBTTagCompound());
}
NBTTagCompound compound = nmsItem.getTag();
if (compound.hasKey("AttributeModifiers")) {
NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
// NBT lists don't have an indexOf method, so we need to loop
// through each attribute, and determine if it is one we want to
// modify. We want to modify an attribute if the attribute was
// set using MechanicsCore, and it's attribute type matches the
// parameter attribute type.
boolean isModifiedAttribute = false;
for (int i = 0; i < list.size(); i++) {
// 10 is the id for nbt lists
if (list.get(i).getTypeId() != 10) {
continue;
}
NBTTagCompound nbt = list.get(i);
String name = nbt.getString("Name");
String attributeName = nbt.getString("AttributeName");
// There is no offhand, or slot argument in 1_8_8.
if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
continue;
}
// Since this attribute already exists, we only need to modify
// the existing value. No need to set the name/uuid
nbt.setDouble("Amount", value);
isModifiedAttribute = true;
break;
}
if (!isModifiedAttribute) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("AttributeName", attribute.getMinecraftName());
nbt.setString("Name", "MechanicsCoreAttribute");
nbt.setDouble("Amount", value);
// 0 == add
nbt.setInt("Operation", 0);
nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
if (slot != null) {
nbt.setString("Slot", slot.getSlotName());
}
}
}
bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
Aggregations