|
| 1 | +package wayoftime.bloodmagic.recipe; |
| 2 | + |
| 3 | + |
| 4 | +import com.google.gson.JsonObject; |
| 5 | +import net.minecraft.core.RegistryAccess; |
| 6 | +import net.minecraft.network.FriendlyByteBuf; |
| 7 | +import net.minecraft.resources.ResourceLocation; |
| 8 | +import net.minecraft.util.GsonHelper; |
| 9 | +import net.minecraft.world.Container; |
| 10 | +import net.minecraft.world.item.ItemStack; |
| 11 | +import net.minecraft.world.item.crafting.*; |
| 12 | +import net.minecraft.world.level.Level; |
| 13 | +import wayoftime.bloodmagic.BloodMagic; |
| 14 | +import wayoftime.bloodmagic.anointment.AnointmentData; |
| 15 | +import wayoftime.bloodmagic.anointment.AnointmentHolder; |
| 16 | +import wayoftime.bloodmagic.common.item.ItemAnointmentProvider; |
| 17 | +import wayoftime.bloodmagic.common.item.ItemBowAnointmentProvider; |
| 18 | +import wayoftime.bloodmagic.core.AnointmentRegistrar; |
| 19 | + |
| 20 | +public class RecipeAnointmentApply implements SmithingRecipe { |
| 21 | + @Override |
| 22 | + public boolean isTemplateIngredient(ItemStack stack) { |
| 23 | + return stack.getItem() instanceof ItemAnointmentProvider; |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public boolean isBaseIngredient(ItemStack stack) { |
| 28 | + return ItemAnointmentProvider.isItemSword(stack) |
| 29 | + || ItemAnointmentProvider.isItemTool(stack) |
| 30 | + || ItemBowAnointmentProvider.isItemBow(stack) |
| 31 | + || ItemBowAnointmentProvider.isItemCrossbow(stack); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public boolean isAdditionIngredient(ItemStack stack) { |
| 36 | + return false; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public boolean matches(Container container, Level level) { |
| 41 | + // 0 Template, 1 Base, 2 Extra |
| 42 | + ItemStack anointmentStack = container.getItem(0); |
| 43 | + ItemStack toolStack = container.getItem(1); |
| 44 | + if (anointmentStack.getItem() instanceof ItemAnointmentProvider toolProvider) { |
| 45 | + return toolProvider.isItemValidForApplication(toolStack); |
| 46 | + } |
| 47 | + |
| 48 | + return false; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public ItemStack assemble(Container container, RegistryAccess registries) { |
| 53 | + // 0 Template, 1 Base, 2 Extra |
| 54 | + ItemAnointmentProvider anointmentStack = (ItemAnointmentProvider) container.getItem(0).getItem(); |
| 55 | + ItemStack weaponStack = container.getItem(1).copy(); |
| 56 | + |
| 57 | + AnointmentHolder holder = AnointmentHolder.fromItemStack(weaponStack); |
| 58 | + if (holder == null) |
| 59 | + { |
| 60 | + holder = new AnointmentHolder(); |
| 61 | + } |
| 62 | + |
| 63 | + if (holder.applyAnointment(weaponStack, AnointmentRegistrar.ANOINTMENT_MAP.get(anointmentStack.anointRL), new AnointmentData(anointmentStack.level, 0, anointmentStack.maxDamage))) |
| 64 | + { |
| 65 | + holder.toItemStack(weaponStack); |
| 66 | + return weaponStack; |
| 67 | + } |
| 68 | + |
| 69 | + return ItemStack.EMPTY; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public ItemStack getResultItem(RegistryAccess registries) { |
| 74 | + return ItemStack.EMPTY; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public ResourceLocation getId() { |
| 79 | + return BloodMagic.rl("anointment_apply"); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public RecipeSerializer<?> getSerializer() { |
| 84 | + return null; |
| 85 | + } |
| 86 | + |
| 87 | + public static class Serializer implements RecipeSerializer<RecipeAnointmentApply> { |
| 88 | + public RecipeAnointmentApply fromJson(ResourceLocation p_266953_, JsonObject p_266720_) { |
| 89 | + return new RecipeAnointmentApply(); |
| 90 | + } |
| 91 | + |
| 92 | + public RecipeAnointmentApply fromNetwork(ResourceLocation p_267117_, FriendlyByteBuf p_267316_) { |
| 93 | + return new RecipeAnointmentApply(); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void toNetwork(FriendlyByteBuf p_44101_, RecipeAnointmentApply p_44102_) { |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments