Skip to content

Commit

Permalink
Merge branch 'enjarai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 authored Jul 5, 2024
2 parents 1cac4b4 + f6eb698 commit 6ffb3a9
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/dev/enjarai/trickster/Trickster.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.enjarai.trickster.config.TricksterConfig;
import dev.enjarai.trickster.item.ModItems;
import dev.enjarai.trickster.item.component.ModComponents;
import dev.enjarai.trickster.item.recipe.ModRecipes;
import dev.enjarai.trickster.net.ModNetworking;
import dev.enjarai.trickster.particle.ModParticles;
import dev.enjarai.trickster.screen.ModScreenHandlers;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void onInitialize() {
ModParticles.register();
ModSounds.register();
ModAttachments.register();
ModRecipes.register();
Tricks.register();
SpellCircleEvent.register();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import org.jetbrains.annotations.Nullable;

public record WrittenScrollMetaComponent(String title, String author, int generation) {
public static final Codec<WrittenScrollMetaComponent> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Expand All @@ -18,4 +19,9 @@ public record WrittenScrollMetaComponent(String title, String author, int genera
PacketCodecs.INTEGER, WrittenScrollMetaComponent::generation,
WrittenScrollMetaComponent::new
);

@Nullable
public WrittenScrollMetaComponent copy() {
return this.generation >= 2 ? null : new WrittenScrollMetaComponent(title, author, generation + 1);
}
}
16 changes: 16 additions & 0 deletions src/main/java/dev/enjarai/trickster/item/recipe/ModRecipes.java
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() {

}
}
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;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/data/trickster/recipe/scroll_cloning.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "trickster:scroll_cloning"
}

0 comments on commit 6ffb3a9

Please sign in to comment.