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

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

There is a newer version: 8.10
Show newest version
package com.magistuarmory.item.crafting;

import com.magistuarmory.EpicKnights;
import com.magistuarmory.item.ArmorDecorationItem;
import com.magistuarmory.item.DyeableArmorDecorationItem;
import com.magistuarmory.item.MedievalBagItem;
import com.magistuarmory.item.ModItems;
import dev.architectury.injectables.annotations.ExpectPlatform;
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_1819;
import net.minecraft.class_1852;
import net.minecraft.class_1865;
import net.minecraft.class_1866;
import net.minecraft.class_1937;
import net.minecraft.class_2215;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2960;
import net.minecraft.class_4059;
import net.minecraft.class_5455;
import net.minecraft.class_7710;
import net.minecraft.class_7923;
import net.minecraft.class_8566;
import net.minecraft.world.item.*;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


public class DecorationRemoveRecipe extends class_1852
{
    public static class_1865 SERIALIZER = new class_1866<>(DecorationRemoveRecipe::new);

    public DecorationRemoveRecipe(class_7710 category)
    {
        super(category);
        //super(location, CraftingBookCategory.MISC);
    }

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

        for(int i = 0; i < container.method_5439(); ++i)
        {
            class_1799 stack2 = container.method_5438(i);
            if (stack2.method_7960())
                continue;
            
            if (isDecorated(stack2))
            {
                if (!stack.method_7960())
                    return false;
                
                stack = stack2;
                continue;
            }
            
            return false;
        }

        return !stack.method_7960();
    }

    @Override
    public class_1799 assemble(class_8566 container, @NotNull class_5455 access)
    {
        class_1799 stack = class_1799.field_8037;

        for(int i = 0; i < container.method_5439(); ++i)
        {
            class_1799 stack2 = container.method_5438(i);
            if (stack2.method_7960())
                continue;

            if (isDecorated(stack2))
            {
                stack = stack2;
                break;
            }
        }
        
        if (!stack.method_7960())
        {
            class_1799 bagstack = new class_1799(ModItems.MEDIEVAL_BAG.get());
            List stacks = takeApart(stack);
            if (stacks.isEmpty())
                return class_1799.field_8037;
            MedievalBagItem.setContents(bagstack, stacks);
            return bagstack;
        }
        
        return class_1799.field_8037;
    }

    @Override
    public boolean method_8113(int i, int j)
    {
        return i * j >= 1;
    }

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

    @ExpectPlatform
    public static class_1865 getSerializerInstance()
    {
        throw new AssertionError();
    }
    
    static boolean mightBeDecorated(class_1792 item)
    {
        return item instanceof class_1738 || item instanceof class_1819 || item instanceof class_4059;
    }

    static boolean isDecorated(class_1799 stack)
    {
        if (!mightBeDecorated(stack.method_7909()))
            return false;
        
        class_2487 blockcompound = class_1747.method_38072(stack);
        if (blockcompound != null && blockcompound.method_10545("Base"))
            return true;
        
        class_2487 decorationdata = stack.method_7941("ArmorDecoration");
        return decorationdata != null && !decorationdata.method_10554("Items", 10).isEmpty();
    }
    
    static List takeApart(class_1799 stack)
    {
        List stacks = new ArrayList<>();
        class_1799 newstack = stack.method_7972();
        class_2487 blockcompound = class_1747.method_38072(newstack);
        if (blockcompound != null)
        {
            if (blockcompound.method_10545("Base"))
            {
                class_1746 banner = (class_1746) class_2215.method_9398(class_1767.method_7791(blockcompound.method_10550("Base"))).method_8389();
                class_1799 bannerstack = new class_1799(banner);
                bannerstack.method_7959("BlockEntityTag", blockcompound.method_10553());

                newstack.method_7983("BlockEntityTag");
                
                stacks.add(bannerstack);
            }
        }
        class_2487 decorationdata = newstack.method_7941("ArmorDecoration");
        if (decorationdata != null)
        {
            class_2499 listtag = decorationdata.method_10554("Items", 10);
            while (!listtag.isEmpty())
            {
                class_2487 tag = listtag.method_10602(listtag.size() - 1);
                String name = tag.method_10558("name");
                int color = tag.method_10550("color");
                ArmorDecorationItem decoration = (ArmorDecorationItem) class_7923.field_41178.method_10223(new class_2960(EpicKnights.ID, name + "_decoration"));
                class_1799 decorationstack = new class_1799(decoration);
                if (decoration instanceof DyeableArmorDecorationItem dyeabedecoration)
                    dyeabedecoration.method_7799(decorationstack, color);

                listtag.method_10536(listtag.size() - 1);
                decorationdata.method_10566("Items", listtag);
                newstack.method_7959("ArmorDecoration", decorationdata);
                
                stacks.add(decorationstack);
            }
        }
        newstack.method_7925();
        stacks.add(newstack);
        return stacks;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy