use of net.minecraft.server.v1_13_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.
the class NBT_1_11_R1 method visit.
private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
StringBuilder builder = new StringBuilder(braceColor).append('{');
List<String> keys = new ArrayList<>(nbt.c());
Collections.sort(keys);
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
if (i != 0)
builder.append('\n');
builder.append(StringUtil.repeat(" ", indents));
String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
builder.append(color).append(key).append("&f&l: ").append(color);
if (value instanceof NBTTagCompound)
builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
else
builder.append(value);
}
return builder.append(braceColor).append("}\n");
}
use of net.minecraft.server.v1_13_R2.NBTTagCompound 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_13_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.
the class NBT_1_12_R1 method getBukkitCompound.
private NBTTagCompound getBukkitCompound(ItemStack bukkitStack, String plugin) {
net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitStack);
if (nmsStack.getTag() == null) {
nmsStack.setTag(new NBTTagCompound());
}
NBTTagCompound nbt = nmsStack.getTag().getCompound("PublicBukkitValues");
// internal map.
if (nbt.isEmpty()) {
nmsStack.getTag().set("PublicBukkitValues", nbt);
}
if (plugin == null) {
return nbt;
} else {
NBTTagCompound pluginCompound = nbt.getCompound(plugin);
if (pluginCompound.isEmpty()) {
nbt.set(plugin, pluginCompound);
}
return pluginCompound;
}
}
use of net.minecraft.server.v1_13_R2.NBTTagCompound in project MechanicsMain by WeaponMechanics.
the class NBT_1_12_R1 method visit.
private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
StringBuilder builder = new StringBuilder(braceColor).append('{');
List<String> keys = new ArrayList<>(nbt.c());
Collections.sort(keys);
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
if (i != 0)
builder.append('\n');
builder.append(StringUtil.repeat(" ", indents));
String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
builder.append(color).append(key).append("&f&l: ").append(color);
if (value instanceof NBTTagCompound)
builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
else
builder.append(value);
}
return builder.append(braceColor).append("}\n");
}
use of net.minecraft.server.v1_13_R2.NBTTagCompound in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method getItemStackNBTString.
@Override
public String getItemStackNBTString(ItemStack itemStack, String key) {
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
return tagCompound.getString(key);
}
Aggregations