use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class LoomScreenMixin method saveFrameBannerPatterns.
@Inject(method = "onInventoryChanged", at = @At("RETURN"))
private void saveFrameBannerPatterns(CallbackInfo ci) {
if (this.bannerPatterns != null) {
ItemStack banner = (this.handler).getOutputSlot().getStack();
NbtList ls = FrameBannerPatternConversions.getNbt(banner);
frame_bannerPatterns = FrameBannerPatternConversions.makeData(ls);
} else
frame_bannerPatterns = Collections.emptyList();
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class LoomScreenMixin method proxyPutPatterns.
/**
* If the pattern index indicates a Frame pattern, put the Frame
* pattern in the item NBT instead of a vanilla pattern.
*/
@Redirect(method = "drawBanner", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;put(Ljava/lang/String;Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;", ordinal = 0))
private NbtElement proxyPutPatterns(NbtCompound nbt, String key, NbtElement patterns) {
frame_singlePattern.clear();
if (frame_bannerPatternIndex < 0) {
int frameBannerPatternIdx = -frame_bannerPatternIndex - (1 + BannerPattern.LOOM_APPLICABLE_COUNT);
FrameBannerPattern pattern = FrameBannerPatternsInternal.get(frameBannerPatternIdx);
NbtList framePatterns = new NbtList();
NbtCompound patternNbtElement = new NbtCompound();
patternNbtElement.putString("Pattern", pattern.getId().toString());
patternNbtElement.putInt("Color", 0);
patternNbtElement.putInt("Index", 1);
framePatterns.add(patternNbtElement);
// pop dummy vanilla banner pattern
NbtList vanillaPatterns = (NbtList) patterns;
assert vanillaPatterns.size() == 2 : vanillaPatterns.size();
vanillaPatterns.remove(1);
nbt.put(FrameBannerPatternAccess.NBT_KEY, framePatterns);
frame_singlePattern.add(new FrameBannerPatternData(pattern, DyeColor.WHITE, 1));
}
FrameBannerPatternRenderContext.setFrameBannerPatterns(frame_singlePattern);
return nbt.put(key, patterns);
}
use of net.minecraft.nbt.NbtList in project frame-fabric by moddingplayground.
the class ClientBannerBlockEntityMixin method frame_getBannerPatterns.
@Override
public List<FrameBannerPatternData> frame_getBannerPatterns() {
if (this.patterns == null) {
NbtList nbt = ((FrameBannerPatternAccess.Internal) this).frame_getBannerPatternNbt();
frame_bannerPatterns = FrameBannerPatternConversions.makeData(nbt);
}
return Collections.unmodifiableList(frame_bannerPatterns);
}
use of net.minecraft.nbt.NbtList in project KahzerxMod by otakucraft.
the class SolExtension method createFirework.
private static ItemStack createFirework(FireworkHelper... fireworksConfigs) {
ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET, 1);
ItemStack star = new ItemStack(Items.FIREWORK_STAR);
NbtList explosions = new NbtList();
for (FireworkHelper config : fireworksConfigs) {
NbtCompound explosion = star.getOrCreateSubNbt(FireworkRocketItem.EXPLOSION_KEY).copy();
explosion.putIntArray(FireworkRocketItem.COLORS_KEY, config.getColors());
explosion.putByte(FireworkRocketItem.TYPE_KEY, (byte) config.getType());
explosion.putByte(FireworkRocketItem.FLICKER_KEY, (byte) config.getFlicker());
explosion.putByte(FireworkRocketItem.TRAIL_KEY, (byte) config.getTrail());
if (config.getFadeColors().length != 0) {
explosion.putIntArray(FireworkRocketItem.FADE_COLORS_KEY, config.getFadeColors());
}
explosions.add(explosion);
}
NbtCompound fireworks = firework.getOrCreateSubNbt(FireworkRocketItem.FIREWORKS_KEY);
fireworks.putByte(FireworkRocketItem.FLIGHT_KEY, (byte) 1);
fireworks.put(FireworkRocketItem.EXPLOSIONS_KEY, explosions);
firework.getOrCreateNbt().putBoolean("Sol", true);
return firework;
}
use of net.minecraft.nbt.NbtList in project KiwiClient by TangyKiwi.
the class Utils method removeEnchantment.
public static void removeEnchantment(ItemStack itemStack, Enchantment enchantment) {
NbtCompound nbt = itemStack.getNbt();
if (nbt == null)
return;
if (!nbt.contains("Enchantments", 9))
return;
NbtList list = nbt.getList("Enchantments", 10);
String enchId = Registry.ENCHANTMENT.getId(enchantment).toString();
for (Iterator<NbtElement> it = list.iterator(); it.hasNext(); ) {
NbtCompound ench = (NbtCompound) it.next();
if (ench.getString("id").equals(enchId)) {
it.remove();
break;
}
}
}
Aggregations