-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'enjarai:master' into master
- Loading branch information
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/enjarai/trickster/item/recipe/ModRecipes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.enjarai.trickster.item.recipe; | ||
|
||
import dev.enjarai.trickster.Trickster; | ||
import net.minecraft.recipe.RecipeSerializer; | ||
import net.minecraft.recipe.SpecialRecipeSerializer; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public class ModRecipes { | ||
public static final RecipeSerializer<ScrollCloningRecipe> SCROLL_CLONING_RECIPE = | ||
Registry.register(Registries.RECIPE_SERIALIZER, Trickster.id("scroll_cloning"), new SpecialRecipeSerializer<>(ScrollCloningRecipe::new)); | ||
|
||
public static void register() { | ||
|
||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/dev/enjarai/trickster/item/recipe/ScrollCloningRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package dev.enjarai.trickster.item.recipe; | ||
|
||
import dev.enjarai.trickster.item.ModItems; | ||
import dev.enjarai.trickster.item.WrittenScrollItem; | ||
import dev.enjarai.trickster.item.component.ModComponents; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.recipe.RecipeSerializer; | ||
import net.minecraft.recipe.SpecialCraftingRecipe; | ||
import net.minecraft.recipe.book.CraftingRecipeCategory; | ||
import net.minecraft.recipe.input.CraftingRecipeInput; | ||
import net.minecraft.registry.RegistryWrapper; | ||
import net.minecraft.util.collection.DefaultedList; | ||
import net.minecraft.world.World; | ||
|
||
public class ScrollCloningRecipe extends SpecialCraftingRecipe { | ||
public ScrollCloningRecipe(CraftingRecipeCategory craftingRecipeCategory) { | ||
super(craftingRecipeCategory); | ||
} | ||
|
||
public boolean matches(CraftingRecipeInput craftingRecipeInput, World world) { | ||
int i = 0; | ||
ItemStack itemStack = ItemStack.EMPTY; | ||
|
||
for(int j = 0; j < craftingRecipeInput.getSize(); ++j) { | ||
ItemStack itemStack2 = craftingRecipeInput.getStackInSlot(j); | ||
if (!itemStack2.isEmpty()) { | ||
if (itemStack2.isOf(ModItems.WRITTEN_SCROLL)) { | ||
if (!itemStack.isEmpty()) { | ||
return false; | ||
} | ||
|
||
itemStack = itemStack2; | ||
} else { | ||
if (!itemStack2.isOf(ModItems.SCROLL_AND_QUILL)) { | ||
return false; | ||
} | ||
|
||
++i; | ||
} | ||
} | ||
} | ||
|
||
return !itemStack.isEmpty() && i > 0; | ||
} | ||
|
||
public ItemStack craft(CraftingRecipeInput craftingRecipeInput, RegistryWrapper.WrapperLookup wrapperLookup) { | ||
int i = 0; | ||
ItemStack itemStack = ItemStack.EMPTY; | ||
|
||
for(int j = 0; j < craftingRecipeInput.getSize(); ++j) { | ||
ItemStack itemStack2 = craftingRecipeInput.getStackInSlot(j); | ||
if (!itemStack2.isEmpty()) { | ||
if (itemStack2.isOf(ModItems.WRITTEN_SCROLL)) { | ||
if (!itemStack.isEmpty()) { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
itemStack = itemStack2; | ||
} else { | ||
if (!itemStack2.isOf(ModItems.SCROLL_AND_QUILL)) { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
++i; | ||
} | ||
} | ||
} | ||
|
||
var meta = itemStack.get(ModComponents.WRITTEN_SCROLL_META); | ||
var spell = itemStack.get(ModComponents.SPELL); | ||
if (!itemStack.isEmpty() && i >= 1 && meta != null && spell != null) { | ||
var newMeta = meta.copy(); | ||
if (newMeta == null) { | ||
return ItemStack.EMPTY; | ||
} else { | ||
ItemStack itemStack3 = itemStack.copyWithCount(i); | ||
itemStack3.set(ModComponents.WRITTEN_SCROLL_META, newMeta); | ||
itemStack3.set(ModComponents.SPELL, spell); | ||
return itemStack3; | ||
} | ||
} else { | ||
return ItemStack.EMPTY; | ||
} | ||
} | ||
|
||
public DefaultedList<ItemStack> getRemainder(CraftingRecipeInput craftingRecipeInput) { | ||
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(craftingRecipeInput.getSize(), ItemStack.EMPTY); | ||
|
||
for(int i = 0; i < defaultedList.size(); ++i) { | ||
ItemStack itemStack = craftingRecipeInput.getStackInSlot(i); | ||
if (itemStack.getItem().hasRecipeRemainder()) { | ||
defaultedList.set(i, new ItemStack(itemStack.getItem().getRecipeRemainder())); | ||
} else if (itemStack.getItem() instanceof WrittenScrollItem) { | ||
defaultedList.set(i, itemStack.copyWithCount(1)); | ||
break; | ||
} | ||
} | ||
|
||
return defaultedList; | ||
} | ||
|
||
@Override | ||
public RecipeSerializer<?> getSerializer() { | ||
return ModRecipes.SCROLL_CLONING_RECIPE; | ||
} | ||
|
||
@Override | ||
public boolean fits(int width, int height) { | ||
return width >= 2 && height >= 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "trickster:scroll_cloning" | ||
} |