All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.item.crafting.HeraldryRecipe Maven / Gradle / Ivy

The newest version!
package com.magistuarmory.item.crafting;

import com.google.gson.JsonObject;
import com.magistuarmory.EpicKnights;
import com.magistuarmory.item.MedievalShieldItem;
import com.magistuarmory.item.armor.ISurcoat;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.class_1304;
import net.minecraft.class_1715;
import net.minecraft.class_1738;
import net.minecraft.class_1746;
import net.minecraft.class_1747;
import net.minecraft.class_1767;
import net.minecraft.class_1792;
import net.minecraft.class_1799;
import net.minecraft.class_1852;
import net.minecraft.class_1865;
import net.minecraft.class_1937;
import net.minecraft.class_2487;
import net.minecraft.class_2540;
import net.minecraft.class_2561;
import net.minecraft.class_2960;
import net.minecraft.class_4059;
import net.minecraft.world.item.*;
import org.jetbrains.annotations.NotNull;

public class HeraldryRecipe extends class_1852
{
    public static class_1865 SERIALIZER = new class_1865<>()
    {
        @Override
        public HeraldryRecipe method_8121(class_2960 location, JsonObject json)
        {
            return new HeraldryRecipe(location);
        }

        @Override
        public HeraldryRecipe method_8122(class_2960 location, class_2540 buf)
        {
            return new HeraldryRecipe(location);
        }

        @Override
        public void toNetwork(class_2540 buf, HeraldryRecipe recipe)
        {

        }
    };
    
    public HeraldryRecipe(class_2960 location)
    {
        super(location);
    }

    @Override
    public boolean matches(class_1715 container, class_1937 level)
    {
        class_1799 stack = class_1799.field_8037;
        class_1799 stack2 = class_1799.field_8037;

        for(int i = 0; i < container.method_5439(); ++i)
        {
            class_1799 stack3 = container.method_5438(i);
            if (!stack3.method_7960())
            {
                if (stack3.method_7909() instanceof class_1746)
                {
                    if (!stack2.method_7960())
                        return false;

                    stack2 = stack3;
                }
                else
                {
                    if (!isApplicableForBanner(stack3.method_7909()))
                        return false;

                    if (!stack.method_7960())
                        return false;

                    if (class_1747.method_38072(stack3) != null)
                        return false;

                    stack = stack3;
                }
            }
        }

        return !stack.method_7960() && !stack2.method_7960();
    }

    @Override
    public class_1799 assemble(class_1715 container)
    {
        class_1799 stack = class_1799.field_8037;
        class_1799 stack1 = class_1799.field_8037;

        for(int i = 0; i < container.method_5439(); ++i)
        {
            class_1799 stack2 = container.method_5438(i);
            if (!stack2.method_7960())
            {
                if (stack2.method_7909() instanceof class_1746)
                {
                    stack = stack2;
                }
                else if (isApplicableForBanner(stack2.method_7909()))
                {
                    stack1 = stack2.method_7972();
                }
            }
        }

        if (!stack1.method_7960())
        {
            class_2487 compoundtag = class_1747.method_38072(stack);
            class_2487 compoundtag1 = compoundtag == null ? new class_2487() : compoundtag.method_10553();
            class_1767 basecolor = ((class_1746) stack.method_7909()).method_7706();
            compoundtag1.method_10569("Base", ((class_1746) stack.method_7909()).method_7706().method_7789());

            if (wornWithSurcoat(stack1.method_7909()))
                stack1.method_7977(class_2561.method_43469("magistuarmory.withsurcoat." + basecolor.method_7792(), stack1.method_7964().getString()));
            else if (wornWithCaparison(stack1.method_7909()))
                stack1.method_7977(class_2561.method_43469("magistuarmory.withcaparison." + basecolor.method_7792(), stack1.method_7964().getString()));

            stack1.method_7959("BlockEntityTag", compoundtag1);
        }
        return stack1;
    }

    @Override
    public boolean method_8113(int p_44298_, int p_44299_)
    {
        return p_44298_ * p_44299_ >= 2;
    }

    @Override
    public @NotNull class_1865 method_8119()
    {
        return getSerializerInstance();
    }

    @ExpectPlatform
    public static class_1865 getSerializerInstance()
    {
        throw new AssertionError();
    }

    static boolean isPaintableShield(class_1792 item)
    {
        return item instanceof MedievalShieldItem && ((MedievalShieldItem)item).isPaintable();
    }

    static boolean wornWithCaparison(class_1792 item)
    {
        return item instanceof class_4059;
    }

    static boolean wornWithSurcoat(class_1792 item)
    {
        return item instanceof class_1738 && (EpicKnights.GENERAL_CONFIG.enableSurcoatRecipeForAllArmor || item instanceof ISurcoat) && ((class_1738) item).method_7685().equals(class_1304.field_6174);
    }

    static boolean isApplicableForBanner(class_1792 item)
    {
        return isPaintableShield(item) || wornWithCaparison(item) || wornWithSurcoat(item);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy