use of net.minecraft.server.v1_16_R2.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_R2.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_R2.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_R2.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));
}
use of net.minecraft.server.v1_16_R2.NBTTagList in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createEntityFromNBT.
@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
try {
NBTTagCompound nbt = (NBTTagCompound) serialized.get();
NBTTagList positionTagList = nbt.getList("Pos", 6);
if (positionTagList == null)
positionTagList = new NBTTagList();
this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
nbt.set("Pos", positionTagList);
NBTTagList rotationTagList = nbt.getList("Rotation", 5);
if (rotationTagList == null)
rotationTagList = new NBTTagList();
this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
nbt.set("Rotation", rotationTagList);
// Reset the UUID to resolve possible duplicates
nbt.a("UUID", UUID.randomUUID());
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
if (optionalEntity.isPresent()) {
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
if (entity == null)
throw new NullPointerException("Unable to create entity from NBT");
// Load NBT
entity.load(nbt);
if (addToWorld) {
IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
if (!(ichunkaccess instanceof Chunk))
throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
ichunkaccess.a(entity);
method_WorldServer_registerEntity.invoke(world, entity);
entity.noDamageTicks = 0;
}
return (LivingEntity) entity.getBukkitEntity();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations