Search in sources :

Example 1 with FrameBannerPattern

use of net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern in project frame-fabric by moddingplayground.

the class FrameBannerPatternConversions method makeData.

/**
 * Parses the given NBT data into a list of {@link FrameBannerPatternData} objects.
 *
 * @param nbt a nullable {@link NbtList} with Frame banner pattern data
 */
public static List<FrameBannerPatternData> makeData(NbtList nbt) {
    List<FrameBannerPatternData> res = new ArrayList<>();
    if (nbt != null) {
        for (NbtElement t : nbt) {
            NbtCompound patternNbt = (NbtCompound) t;
            FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(new Identifier(patternNbt.getString("Pattern")));
            if (pattern != null) {
                DyeColor color = DyeColor.byId(patternNbt.getInt("Color"));
                int index = patternNbt.getInt("Index");
                res.add(new FrameBannerPatternData(pattern, color, index));
            }
        }
    }
    return res;
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) ArrayList(java.util.ArrayList) NbtElement(net.minecraft.nbt.NbtElement) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor)

Example 2 with FrameBannerPattern

use of net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern in project frame-fabric by moddingplayground.

the class BannerItemMixin method frame_addBannerPatternLine.

@Unique
private static void frame_addBannerPatternLine(NbtCompound nbt, List<Text> lines) {
    Identifier id = Identifier.tryParse(nbt.getString("Pattern"));
    DyeColor color = DyeColor.byId(nbt.getInt("Color"));
    if (id != null) {
        FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(id);
        if (pattern != null)
            pattern.addPatternLine(lines, color);
    }
}
Also used : Identifier(net.minecraft.util.Identifier) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor) Unique(org.spongepowered.asm.mixin.Unique)

Example 3 with FrameBannerPattern

use of net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern 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);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) FrameBannerPatternData(net.moddingplayground.frame.impl.bannerpatterns.FrameBannerPatternData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with FrameBannerPattern

use of net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern in project frame-fabric by moddingplayground.

the class BannerBlockEntityRendererMixin method frame_renderBannerPattern.

@Unique
private static void frame_renderBannerPattern(FrameBannerPatternData data, MatrixStack stack, VertexConsumerProvider vertices, ModelPart part, int light, int overlay, boolean banner) {
    BannerContext context = BannerContext.from(banner);
    FrameBannerPattern pattern = data.pattern();
    Identifier id = pattern.getSpriteId(context);
    SpriteIdentifier spriteId = FRAME_SPRITE_IDS.apply(context.getAtlas(), id);
    DyeColor color = data.color();
    float[] colors = color.getColorComponents();
    part.render(stack, spriteId.getVertexConsumer(vertices, RenderLayer::getEntityNoOutline), light, overlay, colors[0], colors[1], colors[2], 1.0f);
}
Also used : SpriteIdentifier(net.minecraft.client.util.SpriteIdentifier) BannerContext(net.moddingplayground.frame.api.bannerpatterns.v0.BannerContext) SpriteIdentifier(net.minecraft.client.util.SpriteIdentifier) Identifier(net.minecraft.util.Identifier) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor) Unique(org.spongepowered.asm.mixin.Unique)

Aggregations

FrameBannerPattern (net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern)4 DyeColor (net.minecraft.util.DyeColor)3 Identifier (net.minecraft.util.Identifier)3 NbtCompound (net.minecraft.nbt.NbtCompound)2 Unique (org.spongepowered.asm.mixin.Unique)2 ArrayList (java.util.ArrayList)1 SpriteIdentifier (net.minecraft.client.util.SpriteIdentifier)1 NbtElement (net.minecraft.nbt.NbtElement)1 NbtList (net.minecraft.nbt.NbtList)1 BannerContext (net.moddingplayground.frame.api.bannerpatterns.v0.BannerContext)1 FrameBannerPatternData (net.moddingplayground.frame.impl.bannerpatterns.FrameBannerPatternData)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1