com.magistuarmory.item.crafting.HeraldryRecipe Maven / Gradle / Ivy
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.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class HeraldryRecipe extends CustomRecipe
{
public static RecipeSerializer SERIALIZER = new RecipeSerializer<>()
{
@Override
public HeraldryRecipe m_6729_(ResourceLocation location, JsonObject json)
{
return new HeraldryRecipe(location);
}
@Override
public HeraldryRecipe m_8005_(ResourceLocation location, FriendlyByteBuf buf)
{
return new HeraldryRecipe(location);
}
@Override
public void toNetwork(FriendlyByteBuf buf, HeraldryRecipe recipe)
{
}
};
public HeraldryRecipe(ResourceLocation location)
{
super(location);
}
@Override
public boolean matches(CraftingContainer container, Level level)
{
ItemStack stack = ItemStack.f_41583_;
ItemStack stack2 = ItemStack.f_41583_;
for(int i = 0; i < container.m_6643_(); ++i)
{
ItemStack stack3 = container.m_8020_(i);
if (!stack3.m_41619_())
{
if (stack3.m_41720_() instanceof BannerItem)
{
if (!stack2.m_41619_())
return false;
stack2 = stack3;
}
else
{
if (!isApplicableForBanner(stack3.m_41720_()))
return false;
if (!stack.m_41619_())
return false;
if (BlockItem.m_186336_(stack3) != null)
return false;
stack = stack3;
}
}
}
return !stack.m_41619_() && !stack2.m_41619_();
}
@Override
public ItemStack assemble(CraftingContainer container)
{
ItemStack stack = ItemStack.f_41583_;
ItemStack stack1 = ItemStack.f_41583_;
for(int i = 0; i < container.m_6643_(); ++i)
{
ItemStack stack2 = container.m_8020_(i);
if (!stack2.m_41619_())
{
if (stack2.m_41720_() instanceof BannerItem)
{
stack = stack2;
}
else if (isApplicableForBanner(stack2.m_41720_()))
{
stack1 = stack2.m_41777_();
}
}
}
if (!stack1.m_41619_())
{
CompoundTag compoundtag = BlockItem.m_186336_(stack);
CompoundTag compoundtag1 = compoundtag == null ? new CompoundTag() : compoundtag.m_6426_();
DyeColor basecolor = ((BannerItem) stack.m_41720_()).m_40545_();
compoundtag1.m_128405_("Base", ((BannerItem) stack.m_41720_()).m_40545_().m_41060_());
if (wornWithSurcoat(stack1.m_41720_()))
stack1.m_41714_(Component.m_237110_("magistuarmory.withsurcoat." + basecolor.m_41065_(), stack1.m_41786_().getString()));
else if (wornWithCaparison(stack1.m_41720_()))
stack1.m_41714_(Component.m_237110_("magistuarmory.withcaparison." + basecolor.m_41065_(), stack1.m_41786_().getString()));
stack1.m_41700_("BlockEntityTag", compoundtag1);
}
return stack1;
}
@Override
public boolean m_8004_(int p_44298_, int p_44299_)
{
return p_44298_ * p_44299_ >= 2;
}
@Override
public @NotNull RecipeSerializer> m_7707_()
{
return getSerializerInstance();
}
@ExpectPlatform
public static RecipeSerializer getSerializerInstance()
{
throw new AssertionError();
}
static boolean isPaintableShield(Item item)
{
return item instanceof MedievalShieldItem && ((MedievalShieldItem)item).isPaintable();
}
static boolean wornWithCaparison(Item item)
{
return item instanceof HorseArmorItem;
}
static boolean wornWithSurcoat(Item item)
{
return item instanceof ArmorItem && (EpicKnights.GENERAL_CONFIG.enableSurcoatRecipeForAllArmor || item instanceof ISurcoat) && ((ArmorItem) item).m_40402_().equals(EquipmentSlot.CHEST);
}
static boolean isApplicableForBanner(Item item)
{
return isPaintableShield(item) || wornWithCaparison(item) || wornWithSurcoat(item);
}
}