mirror of
https://github.com/Theta-Dev/ConstructionWand.git
synced 2025-09-07 18:30:54 +02:00
76 lines
2.7 KiB
Java
76 lines
2.7 KiB
Java
package thetadev.constructionwand.crafting;
|
|
|
|
import net.minecraft.core.RegistryAccess;
|
|
import net.minecraft.world.inventory.CraftingContainer;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.crafting.CraftingBookCategory;
|
|
import net.minecraft.world.item.crafting.CustomRecipe;
|
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
|
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
|
|
import net.minecraft.world.level.Level;
|
|
import thetadev.constructionwand.api.IWandUpgrade;
|
|
import thetadev.constructionwand.basics.ConfigServer;
|
|
import thetadev.constructionwand.basics.option.WandOptions;
|
|
import thetadev.constructionwand.items.wand.ItemWand;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
public class RecipeWandUpgrade extends CustomRecipe
|
|
{
|
|
public static final SimpleCraftingRecipeSerializer<RecipeWandUpgrade> SERIALIZER = new SimpleCraftingRecipeSerializer<>(RecipeWandUpgrade::new);
|
|
|
|
public RecipeWandUpgrade(CraftingBookCategory category) {
|
|
super(category);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(@Nonnull CraftingContainer inv, @Nonnull Level worldIn) {
|
|
ItemStack wand = null;
|
|
IWandUpgrade upgrade = null;
|
|
|
|
for(int i = 0; i < inv.getContainerSize(); i++) {
|
|
ItemStack stack = inv.getItem(i);
|
|
if(!stack.isEmpty()) {
|
|
if(wand == null && stack.getItem() instanceof ItemWand) wand = stack;
|
|
else if(upgrade == null && stack.getItem() instanceof IWandUpgrade)
|
|
upgrade = (IWandUpgrade) stack.getItem();
|
|
else return false;
|
|
}
|
|
}
|
|
|
|
if(wand == null || upgrade == null) return false;
|
|
return !new WandOptions(wand).hasUpgrade(upgrade) && ConfigServer.getWandProperties(wand.getItem()).isUpgradeable();
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public ItemStack assemble(@Nonnull CraftingContainer inv, @Nonnull RegistryAccess registryAccess) {
|
|
ItemStack wand = null;
|
|
IWandUpgrade upgrade = null;
|
|
|
|
for(int i = 0; i < inv.getContainerSize(); i++) {
|
|
ItemStack stack = inv.getItem(i);
|
|
if(!stack.isEmpty()) {
|
|
if(stack.getItem() instanceof ItemWand) wand = stack;
|
|
else if(stack.getItem() instanceof IWandUpgrade) upgrade = (IWandUpgrade) stack.getItem();
|
|
}
|
|
}
|
|
|
|
if(wand == null || upgrade == null) return ItemStack.EMPTY;
|
|
|
|
ItemStack newWand = wand.copy();
|
|
new WandOptions(newWand).addUpgrade(upgrade);
|
|
return newWand;
|
|
}
|
|
|
|
@Override
|
|
public boolean canCraftInDimensions(int width, int height) {
|
|
return width * height >= 2;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public RecipeSerializer<?> getSerializer() {
|
|
return SERIALIZER;
|
|
}
|
|
}
|