use of net.minecraft.nbt.NbtList in project FZMM-Mod by Zailer43.
the class DisplayUtils method addLore.
public DisplayUtils addLore(Text lore) {
NbtList oldLore = this.getLore();
oldLore.add(FzmmUtils.textToNbtString(lore, true));
this.setLore(oldLore);
return this;
}
use of net.minecraft.nbt.NbtList in project KiwiClient by TangyKiwi.
the class Tooltips method appendTooltip.
@Subscribe
@AllowConcurrentEvents
public void appendTooltip(ItemStackTooltipEvent event) {
// Stew
if (getSetting(0).asToggle().state) {
if (event.itemStack.getItem() == Items.SUSPICIOUS_STEW) {
NbtCompound tag = event.itemStack.getNbt();
if (tag != null) {
NbtList effects = tag.getList("Effects", 10);
if (effects != null) {
for (int i = 0; i < effects.size(); i++) {
NbtCompound effectTag = effects.getCompound(i);
byte effectId = effectTag.getByte("EffectId");
int effectDuration = effectTag.contains("EffectDuration") ? effectTag.getInt("EffectDuration") : 160;
StatusEffectInstance effect = new StatusEffectInstance(StatusEffect.byRawId(effectId), effectDuration, 0);
event.list.add(1, getStatusText(effect));
}
}
}
} else if (event.itemStack.getItem().isFood()) {
FoodComponent food = event.itemStack.getItem().getFoodComponent();
if (food != null) {
food.getStatusEffects().forEach((e) -> {
StatusEffectInstance effect = e.getFirst();
event.list.add(1, getStatusText(effect));
});
}
}
}
// Bees
if (getSetting(1).asToggle().state) {
if (event.itemStack.getItem() == Items.BEEHIVE || event.itemStack.getItem() == Items.BEE_NEST) {
NbtCompound tag = event.itemStack.getNbt();
if (tag != null) {
NbtCompound blockStateTag = tag.getCompound("BlockStateTag");
if (blockStateTag != null) {
int level = blockStateTag.getInt("honey_level");
event.list.add(1, new LiteralText(String.format("%sHoney Level: %s%d%s", Formatting.GRAY, Formatting.YELLOW, level, Formatting.GRAY)));
}
NbtCompound blockEntityTag = tag.getCompound("BlockEntityTag");
if (blockEntityTag != null) {
NbtList beesTag = blockEntityTag.getList("Bees", 10);
event.list.add(1, new LiteralText(String.format("%sBees: %s%d%s", Formatting.GRAY, Formatting.YELLOW, beesTag.size(), Formatting.GRAY)));
}
}
}
}
// Fish handled in EntityBucketItemMixin
}
use of net.minecraft.nbt.NbtList in project KiwiClient by TangyKiwi.
the class Utils method addEnchantment.
public static void addEnchantment(ItemStack itemStack, Enchantment enchantment, int level) {
NbtCompound tag = itemStack.getOrCreateNbt();
NbtList listTag;
if (!tag.contains("Enchantments", 9)) {
listTag = new NbtList();
tag.put("Enchantments", listTag);
} else {
listTag = tag.getList("Enchantments", 10);
}
String enchId = Registry.ENCHANTMENT.getId(enchantment).toString();
for (NbtElement _t : listTag) {
NbtCompound t = (NbtCompound) _t;
if (t.getString("id").equals(enchId)) {
t.putShort("lvl", (short) level);
return;
}
}
NbtCompound enchTag = new NbtCompound();
enchTag.putString("id", enchId);
enchTag.putShort("lvl", (short) level);
listTag.add(enchTag);
}
use of net.minecraft.nbt.NbtList in project Capybara-Fabricated by ZestyBlaze.
the class CapybaraEntity method writeCustomDataToNbt.
@Override
public void writeCustomDataToNbt(NbtCompound nbt) {
super.writeCustomDataToNbt(nbt);
if (inventory != null) {
final NbtList inv = new NbtList();
for (int i = 0; i < this.inventory.size(); i++) {
inv.add(inventory.getStack(i).writeNbt(new NbtCompound()));
}
nbt.put("Inventory", inv);
}
}
use of net.minecraft.nbt.NbtList in project Capybara-Fabricated by ZestyBlaze.
the class CapybaraEntity method readCustomDataFromNbt.
@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
if (nbt.contains("Inventory")) {
final NbtList inv = nbt.getList("Inventory", 10);
inventory = new SimpleInventory(inv.size());
for (int i = 0; i < inv.size(); i++) {
inventory.setStack(i, ItemStack.fromNbt(inv.getCompound(i)));
}
dataTracker.set(CHESTS, inv.size() > 27 ? 2 : 1);
}
}
Aggregations