From 3c7ec41fe1b857d5e8b0926e815eeffa7c1cdee9 Mon Sep 17 00:00:00 2001 From: reoseah Date: Sun, 3 Nov 2024 02:25:18 +0100 Subject: [PATCH] refactor the spell system :scream_cat: --- .../reoseah/magisterium/Magisterium.java | 53 ++++--- .../magisterium/MagisteriumClient.java | 9 -- .../reoseah/magisterium/data/SpellRecipe.java | 89 +++++++++++ .../effect/ArcaneLiftEffect.java} | 48 +++--- .../effect/AwakenFlameEffect.java} | 42 +++-- .../effect/ColdSnapEffect.java} | 37 ++--- .../effect/ConflagrateEffect.java} | 36 ++--- .../effect/DispelMagicEffect.java} | 40 ++--- .../effect/GlyphicIgnitionEffect.java} | 34 ++-- .../effect/IllusoryWallEffect.java} | 39 ++--- .../effect/QuenchFlameEffect.java} | 39 ++--- .../magisterium/data/effect/SpellEffect.java | 29 ++++ .../magisterium/data/element/BookElement.java | 23 +++ .../data/element/BookInventory.java | 94 +++++++++++ .../{spellbook => data}/element/Bookmark.java | 2 +- .../element/BookmarkElement.java | 14 +- .../element/DivisibleBlock.java | 2 +- .../{spellbook => data}/element/Fold.java | 21 ++- .../{spellbook => data}/element/Heading.java | 19 ++- .../element/PageBreak.java | 11 +- .../element/Paragraph.java | 29 ++-- .../element/SimpleBlock.java | 11 +- .../data/element/SlotProperties.java | 73 +++++++++ .../data/element/SlotPropertiesProvider.java | 7 + .../element/Utterance.java | 36 +++-- .../element/VerticallyCenteredElement.java} | 17 +- .../magisterium/item/SpellBookItem.java | 1 - .../magisterium/item/SpellPageItem.java | 1 - .../network/SlotLayoutPayload.java | 2 +- ...e.java => OldSpellBookCraftingRecipe.java} | 22 +-- ...ookRecipe.java => OldSpellBookRecipe.java} | 8 +- .../recipe/SpellBookRecipeInput.java | 6 +- .../recipe/UnstableChargeRecipe.java | 40 ----- .../magisterium/screen/SpellBookScreen.java | 16 +- .../screen/SpellBookScreenHandler.java | 36 +++-- .../magisterium/screen/SpellBookSlot.java | 4 +- .../magisterium/spellbook/BookLayout.java | 11 +- .../magisterium/spellbook/SpellData.java | 11 -- .../spellbook/SpellDataLoader.java | 148 ------------------ .../spellbook/element/BookElement.java | 9 -- .../spellbook/element/BookInventory.java | 75 --------- .../spellbook/element/SlotProperties.java | 56 ------- .../element/SlotPropertiesProvider.java | 5 - .../assets/magisterium/lang/en_us.json | 8 +- .../magisterium/spells/arcane_lift.json | 43 ----- .../magisterium/spells/awaken_the_flame.json | 21 --- .../magisterium/spells/cold_snap.json | 66 -------- .../magisterium/spells/conflagrate.json | 67 -------- .../magisterium/spells/dispel_magic.json | 21 --- .../magisterium/spells/glyphic_ignition.json | 25 --- .../magisterium/spells/illusory_wall.json | 43 ----- .../magisterium/spells/quench_the_flame.json | 21 --- .../magisterium/spells/unstable_charge.json | 47 ------ .../models/item/unstable_charge_page.json | 6 - .../data/magisterium/recipe/arcane_lift.json | 62 +++++++- .../magisterium/recipe/awaken_the_flame.json | 36 ++++- .../data/magisterium/recipe/cold_snap.json | 87 +++++++++- .../data/magisterium/recipe/conflagrate.json | 87 +++++++++- .../data/magisterium/recipe/dispel_magic.json | 36 ++++- .../magisterium/recipe/glyphic_ignition.json | 42 ++++- .../magisterium/recipe/illusory_wall.json | 62 +++++++- .../magisterium/recipe/quench_the_flame.json | 36 ++++- .../magisterium/recipe/unstable_charge.json | 5 - .../unstable_charge_page.png | Bin 64 files changed, 1076 insertions(+), 1050 deletions(-) create mode 100644 src/main/java/io/github/reoseah/magisterium/data/SpellRecipe.java rename src/main/java/io/github/reoseah/magisterium/{recipe/ArcaneLiftRecipe.java => data/effect/ArcaneLiftEffect.java} (62%) rename src/main/java/io/github/reoseah/magisterium/{recipe/AwakenFlameRecipe.java => data/effect/AwakenFlameEffect.java} (60%) rename src/main/java/io/github/reoseah/magisterium/{recipe/ColdSnapRecipe.java => data/effect/ColdSnapEffect.java} (82%) rename src/main/java/io/github/reoseah/magisterium/{recipe/ConflagrateRecipe.java => data/effect/ConflagrateEffect.java} (83%) rename src/main/java/io/github/reoseah/magisterium/{recipe/DispelMagicRecipe.java => data/effect/DispelMagicEffect.java} (57%) rename src/main/java/io/github/reoseah/magisterium/{recipe/GlyphicIgnitionRecipe.java => data/effect/GlyphicIgnitionEffect.java} (66%) rename src/main/java/io/github/reoseah/magisterium/{recipe/IllusoryWallRecipe.java => data/effect/IllusoryWallEffect.java} (80%) rename src/main/java/io/github/reoseah/magisterium/{recipe/QuenchFlameRecipe.java => data/effect/QuenchFlameEffect.java} (67%) create mode 100644 src/main/java/io/github/reoseah/magisterium/data/effect/SpellEffect.java create mode 100644 src/main/java/io/github/reoseah/magisterium/data/element/BookElement.java create mode 100644 src/main/java/io/github/reoseah/magisterium/data/element/BookInventory.java rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/Bookmark.java (59%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/BookmarkElement.java (67%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/DivisibleBlock.java (96%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/Fold.java (54%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/Heading.java (75%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/PageBreak.java (53%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/Paragraph.java (69%) rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/SimpleBlock.java (80%) create mode 100644 src/main/java/io/github/reoseah/magisterium/data/element/SlotProperties.java create mode 100644 src/main/java/io/github/reoseah/magisterium/data/element/SlotPropertiesProvider.java rename src/main/java/io/github/reoseah/magisterium/{spellbook => data}/element/Utterance.java (84%) rename src/main/java/io/github/reoseah/magisterium/{spellbook/element/VerticalCenterElement.java => data/element/VerticallyCenteredElement.java} (55%) rename src/main/java/io/github/reoseah/magisterium/recipe/{SpellBookCraftingRecipe.java => OldSpellBookCraftingRecipe.java} (79%) rename src/main/java/io/github/reoseah/magisterium/recipe/{SpellBookRecipe.java => OldSpellBookRecipe.java} (88%) delete mode 100644 src/main/java/io/github/reoseah/magisterium/recipe/UnstableChargeRecipe.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/SpellData.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/SpellDataLoader.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/element/BookElement.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/element/BookInventory.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotProperties.java delete mode 100644 src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotPropertiesProvider.java delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/arcane_lift.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/awaken_the_flame.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/cold_snap.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/conflagrate.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/dispel_magic.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/glyphic_ignition.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/illusory_wall.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/quench_the_flame.json delete mode 100644 src/main/resources/assets/magisterium/magisterium/spells/unstable_charge.json delete mode 100644 src/main/resources/assets/magisterium/models/item/unstable_charge_page.json delete mode 100644 src/main/resources/data/magisterium/recipe/unstable_charge.json rename {src/main/resources/assets/magisterium/textures/item => unused_assets}/unstable_charge_page.png (100%) diff --git a/src/main/java/io/github/reoseah/magisterium/Magisterium.java b/src/main/java/io/github/reoseah/magisterium/Magisterium.java index 5d6329d..41e1204 100644 --- a/src/main/java/io/github/reoseah/magisterium/Magisterium.java +++ b/src/main/java/io/github/reoseah/magisterium/Magisterium.java @@ -3,6 +3,10 @@ import com.google.common.collect.ImmutableSet; import io.github.reoseah.magisterium.block.*; import io.github.reoseah.magisterium.data.ItemValuesLoader; +import io.github.reoseah.magisterium.data.effect.*; +import io.github.reoseah.magisterium.data.element.BookElement; +import io.github.reoseah.magisterium.data.SpellRecipe; +import io.github.reoseah.magisterium.data.element.*; import io.github.reoseah.magisterium.item.BookmarkItem; import io.github.reoseah.magisterium.item.SpellBookItem; import io.github.reoseah.magisterium.item.SpellPageItem; @@ -11,10 +15,8 @@ import io.github.reoseah.magisterium.network.StopUtterancePayload; import io.github.reoseah.magisterium.network.UseBookmarkPayload; import io.github.reoseah.magisterium.particle.MagisteriumParticles; -import io.github.reoseah.magisterium.recipe.*; import io.github.reoseah.magisterium.screen.ArcaneTableScreenHandler; import io.github.reoseah.magisterium.screen.SpellBookScreenHandler; -import io.github.reoseah.magisterium.spellbook.SpellDataLoader; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.player.UseBlockCallback; @@ -24,7 +26,6 @@ import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl; import net.minecraft.block.LecternBlock; import net.minecraft.block.entity.LecternBlockEntity; import net.minecraft.entity.player.PlayerEntity; @@ -43,14 +44,12 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; -import net.minecraft.util.Util; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; import java.util.Set; public class Magisterium implements ModInitializer { @@ -74,7 +73,6 @@ public void onInitialize() { Registry.register(Registries.ITEM, "magisterium:glyphic_ignition_page", SpellPageItem.GLYPHIC_IGNITION); Registry.register(Registries.ITEM, "magisterium:conflagrate_page", SpellPageItem.CONFLAGRATE); Registry.register(Registries.ITEM, "magisterium:illusory_wall_page", SpellPageItem.ILLUSORY_WALL); - Registry.register(Registries.ITEM, "magisterium:unstable_charge_page", SpellPageItem.UNSTABLE_CHARGE); Registry.register(Registries.ITEM, "magisterium:cold_snap_page", SpellPageItem.COLD_SNAP); Registry.register(Registries.ITEM, "magisterium:arcane_lift_page", SpellPageItem.ARCANE_LIFT); Registry.register(Registries.ITEM, "magisterium:dispel_magic_page", SpellPageItem.DISPEL_MAGIC); @@ -96,7 +94,6 @@ public void onInitialize() { entries.add(SpellPageItem.GLYPHIC_IGNITION); entries.add(SpellPageItem.CONFLAGRATE); entries.add(SpellPageItem.ILLUSORY_WALL); -// entries.add(SpellPageItem.UNSTABLE_CHARGE); entries.add(SpellPageItem.COLD_SNAP); entries.add(SpellPageItem.ARCANE_LIFT); entries.add(SpellPageItem.DISPEL_MAGIC); @@ -105,21 +102,9 @@ public void onInitialize() { .build(); Registry.register(Registries.ITEM_GROUP, "magisterium", group); - // TODO if spell data is server loaded, won't need these recipes anymore - // currently, they load parts of the spell data that the server needs to know - // and they have to match the client data... - Registry.register(Registries.RECIPE_TYPE, "magisterium:spell_book", SpellBookRecipe.TYPE); - - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:spell_crafting", SpellBookCraftingRecipe.Serializer.INSTANCE); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:awaken_the_flame", AwakenFlameRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:quench_the_flame", QuenchFlameRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:glyphic_ignition", GlyphicIgnitionRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:conflagrate", ConflagrateRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:illusory_wall", IllusoryWallRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:unstable_charge", UnstableChargeRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:cold_snap", ColdSnapRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:arcane_lift", ArcaneLiftRecipe.SERIALIZER); - Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:dispel_magic", DispelMagicRecipe.SERIALIZER); + Registry.register(Registries.RECIPE_TYPE, "magisterium:spell", SpellRecipe.TYPE); + + Registry.register(Registries.RECIPE_SERIALIZER, "magisterium:spell", SpellRecipe.SERIALIZER); Registry.register(Registries.SCREEN_HANDLER, "magisterium:spell_book", SpellBookScreenHandler.TYPE); Registry.register(Registries.SCREEN_HANDLER, "magisterium:arcane_table", ArcaneTableScreenHandler.TYPE); @@ -134,6 +119,24 @@ public void onInitialize() { Registry.register(Registries.SOUND_EVENT, "magisterium:chant", MagisteriumSounds.CHANT); Registry.register(Registries.SOUND_EVENT, "magisterium:arcane_lift_loop", MagisteriumSounds.ARCANE_LIFT_LOOP); + Registry.register(BookElement.REGISTRY, "magisterium:heading", Heading.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:paragraph", Paragraph.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:page_break", PageBreak.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:inventory", BookInventory.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:utterance", Utterance.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:fold", Fold.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:bookmark", BookmarkElement.CODEC); + Registry.register(BookElement.REGISTRY, "magisterium:vertically_centered", VerticallyCenteredElement.CODEC); + + Registry.register(SpellEffect.REGISTRY, "magisterium:awaken_the_flame", AwakenFlameEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:quench_the_flame", QuenchFlameEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:glyphic_ignition", GlyphicIgnitionEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:conflagrate", ConflagrateEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:cold_snap", ColdSnapEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:illusory_wall", IllusoryWallEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:arcane_lift", ArcaneLiftEffect.CODEC); + Registry.register(SpellEffect.REGISTRY, "magisterium:dispel_magic", DispelMagicEffect.CODEC); + ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new ItemValuesLoader()); MagisteriumGameRules.initialize(); @@ -179,8 +182,7 @@ private static ActionResult interact(PlayerEntity player, World world, Hand hand var state = world.getBlockState(pos); var be = world.getBlockEntity(pos); - if (state.getBlock() instanceof LecternBlock - && be instanceof LecternBlockEntity lectern) { + if (state.getBlock() instanceof LecternBlock && be instanceof LecternBlockEntity lectern) { var book = lectern.getBook(); if (book.isEmpty() && stack.isOf(SpellBookItem.INSTANCE)) { if (MagisteriumPlaygrounds.canModifyWorld(world, pos, player)) { @@ -240,8 +242,7 @@ private static boolean tryPlaceGlyph(PlayerEntity player, World world, Hand hand } } var sounds = placementState.getSoundGroup(); - world.playSound(player, placementPos, sounds.getPlaceSound(), SoundCategory.BLOCKS, (sounds.getVolume() + 1.0F) / 2.0F, - sounds.getPitch()); + world.playSound(player, placementPos, sounds.getPlaceSound(), SoundCategory.BLOCKS, (sounds.getVolume() + 1.0F) / 2.0F, sounds.getPitch()); world.emitGameEvent(player, GameEvent.BLOCK_PLACE, placementPos); return true; diff --git a/src/main/java/io/github/reoseah/magisterium/MagisteriumClient.java b/src/main/java/io/github/reoseah/magisterium/MagisteriumClient.java index 2d993f5..ce48f53 100644 --- a/src/main/java/io/github/reoseah/magisterium/MagisteriumClient.java +++ b/src/main/java/io/github/reoseah/magisterium/MagisteriumClient.java @@ -12,28 +12,19 @@ import io.github.reoseah.magisterium.screen.ArcaneTableScreenHandler; import io.github.reoseah.magisterium.screen.SpellBookScreen; import io.github.reoseah.magisterium.screen.SpellBookScreenHandler; -import io.github.reoseah.magisterium.spellbook.SpellDataLoader; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; -import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.fabricmc.fabric.impl.resource.loader.ResourceManagerHelperImpl; import net.minecraft.client.gui.screen.ingame.HandledScreens; import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; -import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; public class MagisteriumClient implements ClientModInitializer { @Override public void onInitializeClient() { - // perhaps it could be loaded on the server and sent to client, - // like the recipes do? - // this will help with making items for each spell - ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SpellDataLoader()); - BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), ArcaneTableBlock.INSTANCE, GlyphBlock.INSTANCE); ModelLoadingPlugin.register(ctx -> ctx.addModels(Identifier.of("magisterium", "item/spell_book_in_hand"))); diff --git a/src/main/java/io/github/reoseah/magisterium/data/SpellRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/SpellRecipe.java new file mode 100644 index 0000000..a54bf19 --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/SpellRecipe.java @@ -0,0 +1,89 @@ +package io.github.reoseah.magisterium.data; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import io.github.reoseah.magisterium.data.element.BookElement; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; +import net.minecraft.item.ItemStack; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.world.World; +import io.github.reoseah.magisterium.data.effect.SpellEffect; + +import java.util.List; + +public class SpellRecipe implements Recipe { + public static final RecipeType TYPE = new RecipeType<>() { + }; + + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + BookElement.CODEC.listOf().fieldOf("elements").forGetter(SpellRecipe::getElements), // + SpellEffect.CODEC.listOf().fieldOf("effects").forGetter(SpellRecipe::getEffects) // + ).apply(instance, SpellRecipe::new)); + + public static final PacketCodec PACKET_CODEC = PacketCodecs.registryCodec(CODEC.codec()); + + public static final RecipeSerializer SERIALIZER = new RecipeSerializer<>() { + @Override + public MapCodec codec() { + return CODEC; + } + + @Override + public PacketCodec packetCodec() { + return PACKET_CODEC; + } + }; + + public final List elements; + public final List effects; + + public SpellRecipe(List elements, List effects) { + this.elements = elements; + this.effects = effects; + } + + public List getElements() { + return elements; + } + + public List getEffects() { + return effects; + } + + @Override + public boolean matches(SpellBookRecipeInput input, World world) { + // TODO implement + return true; + } + + @Override + public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + return ItemStack.EMPTY; + } + + @Override + public boolean fits(int width, int height) { + return true; + } + + @Override + public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { + return ItemStack.EMPTY; + } + + @Override + public RecipeSerializer getSerializer() { + return SERIALIZER; + } + + @Override + public RecipeType getType() { + return TYPE; + } +} diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/ArcaneLiftRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/ArcaneLiftEffect.java similarity index 62% rename from src/main/java/io/github/reoseah/magisterium/recipe/ArcaneLiftRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/ArcaneLiftEffect.java index 85dd60c..c1e5bd8 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/ArcaneLiftRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/ArcaneLiftEffect.java @@ -1,38 +1,42 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.ArcaneLiftBlock; import io.github.reoseah.magisterium.block.GlyphBlock; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraft.world.WorldAccess; -public class ArcaneLiftRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(ArcaneLiftRecipe::new); +public class ArcaneLiftEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), // + Codec.INT.fieldOf("duration").forGetter(effect -> effect.duration) // + ).apply(instance, ArcaneLiftEffect::new)); - protected ArcaneLiftRecipe(Identifier utterance, int duration) { + private static final int SEARCH_RADIUS = 8; + + public ArcaneLiftEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { var world = input.getPlayer().getWorld(); var pos = input.getPlayer().getBlockPos(); var circlePos = find3x3GlyphCircle(world, pos); if (circlePos == null) { - return ItemStack.EMPTY; + return; } if (world.isAir(circlePos)) { @@ -41,23 +45,21 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup MagisteriumPlaygrounds.trySetBlockState(world, circlePos, ArcaneLiftBlock.INSTANCE.getDefaultState(), input.getPlayer()); // TODO check result and send feedback } - - return ItemStack.EMPTY; } - private static final int SEARCH_RADIUS = 8; - private static BlockPos find3x3GlyphCircle(WorldAccess world, BlockPos start) { for (var pos : BlockPos.iterateOutwards(start, SEARCH_RADIUS, SEARCH_RADIUS, SEARCH_RADIUS)) { boolean isCircle = true; for (int dx = -1; dx <= 1; dx++) { for (int dz = -1; dz <= 1; dz++) { if (dx == 0 && dz == 0) { + if (!world.isAir(pos.add(dx, 0, dz))) { + isCircle = false; + } continue; } if (!world.getBlockState(pos.add(dx, 0, dz)).isOf(GlyphBlock.INSTANCE)) { isCircle = false; - continue; } } } @@ -68,14 +70,4 @@ private static BlockPos find3x3GlyphCircle(WorldAccess world, BlockPos start) { return null; } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; - } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/AwakenFlameRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/AwakenFlameEffect.java similarity index 60% rename from src/main/java/io/github/reoseah/magisterium/recipe/AwakenFlameRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/AwakenFlameEffect.java index fa703b4..90fdfd1 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/AwakenFlameRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/AwakenFlameEffect.java @@ -1,11 +1,15 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.MagisteriumBlockTags; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.tag.TagKey; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.state.property.Properties; import net.minecraft.text.Text; @@ -13,22 +17,27 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class AwakenFlameRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(AwakenFlameRecipe::new); +// TODO make a more general set block property effect +public class AwakenFlameEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), + Codec.INT.fieldOf("duration").forGetter(effect -> effect.duration) + ).apply(instance, AwakenFlameEffect::new)); public static final int RADIUS = 16; + public static final TagKey TAG = MagisteriumBlockTags.AWAKEN_THE_FIRE_TARGETS; - protected AwakenFlameRecipe(Identifier utterance, int duration) { + public AwakenFlameEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { boolean hasTargets = false; boolean hasLit = false; boolean hasFailed = false; @@ -37,8 +46,7 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup BlockPos center = input.player.getBlockPos(); for (BlockPos pos : BlockPos.iterate(center.add(-RADIUS, -RADIUS, -RADIUS), center.add(RADIUS, RADIUS, RADIUS))) { BlockState state = world.getBlockState(pos); - if (state.getProperties().contains(Properties.LIT) // - && state.isIn(MagisteriumBlockTags.AWAKEN_THE_FIRE_TARGETS)) { + if (state.isIn(TAG) && state.getProperties().contains(Properties.LIT)) { hasTargets = true; if (MagisteriumPlaygrounds.trySetBlockState(world, pos, state.with(Properties.LIT, true), input.player)) { hasLit = true; @@ -57,17 +65,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup input.player.sendMessage(Text.translatable("magisterium.gui.no_success"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/ColdSnapRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/ColdSnapEffect.java similarity index 82% rename from src/main/java/io/github/reoseah/magisterium/recipe/ColdSnapRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/ColdSnapEffect.java index d486f5b..5dd6dc4 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/ColdSnapRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/ColdSnapEffect.java @@ -1,35 +1,40 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.data.ItemValuesLoader; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.World; import java.util.HashMap; -public class ColdSnapRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(ColdSnapRecipe::new); +public class ColdSnapEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), // + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) // + ).apply(instance, ColdSnapEffect::new)); - protected ColdSnapRecipe(Identifier utterance, int duration) { + public ColdSnapEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { int totalValue = 0; for (int i = 0; i < input.getSize(); i++) { var stack = input.getStackInSlot(i); @@ -116,17 +121,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup input.player.sendMessage(Text.translatable("magisterium.gui.no_success"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/ConflagrateRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/ConflagrateEffect.java similarity index 83% rename from src/main/java/io/github/reoseah/magisterium/recipe/ConflagrateRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/ConflagrateEffect.java index e5a04ce..6e33c0c 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/ConflagrateRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/ConflagrateEffect.java @@ -1,35 +1,41 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.data.ItemValuesLoader; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.ConnectingBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; -public class ConflagrateRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(ConflagrateRecipe::new); +public class ConflagrateEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), // + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) // + ).apply(instance, ConflagrateEffect::new)); - protected ConflagrateRecipe(Identifier utterance, int duration) { + public ConflagrateEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { // TODO: extract this to a helper method, reuse in other recipes int totalValue = 0; for (int i = 0; i < input.getSize(); i++) { @@ -102,8 +108,6 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup input.player.sendMessage(Text.translatable("magisterium.gui.no_success"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); } - - return ItemStack.EMPTY; } private static BlockState getFireStateForPosition(World world, BlockPos pos) { @@ -128,14 +132,4 @@ private static BlockState getFireStateForPosition(World world, BlockPos pos) { return fireState; } } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; - } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/DispelMagicRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/DispelMagicEffect.java similarity index 57% rename from src/main/java/io/github/reoseah/magisterium/recipe/DispelMagicRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/DispelMagicEffect.java index 0b4fca5..22e6f34 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/DispelMagicRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/DispelMagicEffect.java @@ -1,32 +1,37 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.Dispelable; import io.github.reoseah.magisterium.block.MagisteriumBlockTags; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -public class DispelMagicRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(DispelMagicRecipe::new); +public class DispelMagicEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), // + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) // + ).apply(instance, DispelMagicEffect::new)); - protected DispelMagicRecipe(Identifier utterance, int duration) { + private static final int RANGE = 16; + + public DispelMagicEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } - private static final int RANGE = 16; - @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { var world = input.getPlayer().getWorld(); var center = input.getPlayer().getBlockPos(); @@ -43,16 +48,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup break; } } - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/GlyphicIgnitionRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/GlyphicIgnitionEffect.java similarity index 66% rename from src/main/java/io/github/reoseah/magisterium/recipe/GlyphicIgnitionRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/GlyphicIgnitionEffect.java index 2f9694e..bd18904 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/GlyphicIgnitionRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/GlyphicIgnitionEffect.java @@ -1,34 +1,39 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.GlyphBlock; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class GlyphicIgnitionRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(GlyphicIgnitionRecipe::new); +public class GlyphicIgnitionEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), // + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) // + ).apply(instance, GlyphicIgnitionEffect::new)); public static final int RADIUS = 16; - protected GlyphicIgnitionRecipe(Identifier utterance, int duration) { + public GlyphicIgnitionEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { boolean hasTargets = false; boolean hasLit = false; boolean hasFailed = false; @@ -57,16 +62,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup ((ServerPlayerEntity) input.player).closeHandledScreen(); } - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/IllusoryWallRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/IllusoryWallEffect.java similarity index 80% rename from src/main/java/io/github/reoseah/magisterium/recipe/IllusoryWallRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/IllusoryWallEffect.java index 7234ebf..afd3bd7 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/IllusoryWallRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/IllusoryWallEffect.java @@ -1,47 +1,46 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.GlyphBlock; import io.github.reoseah.magisterium.block.IllusoryWallBlock; -import io.github.reoseah.magisterium.block.IllusoryWallBlockEntity; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import net.minecraft.block.BlockRenderType; import net.minecraft.block.Blocks; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import org.apache.commons.lang3.stream.Streams; import java.util.ArrayDeque; import java.util.HashSet; -public class IllusoryWallRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(IllusoryWallRecipe::new); +public class IllusoryWallEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) + ).apply(instance, IllusoryWallEffect::new)); private static final int GLYPH_SEARCH_RADIUS = 5; private static final int MAX_GLYPHS_CONVERTED = 8; private static final int MAX_HEIGHT = 3; - protected IllusoryWallRecipe(Identifier utterance, int duration) { + public IllusoryWallEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { var world = input.player.getWorld(); var playerPos = input.player.getBlockPos(); @@ -55,7 +54,7 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup if (illusionState.isAir() || illusionState.getRenderType() != BlockRenderType.MODEL) { input.player.sendMessage(Text.translatable("magisterium.gui.invalid_illusion_block"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); - return ItemStack.EMPTY; + return; } var startPos = Streams.of(BlockPos.iterateOutwards(playerPos, GLYPH_SEARCH_RADIUS, GLYPH_SEARCH_RADIUS, GLYPH_SEARCH_RADIUS)) @@ -66,7 +65,7 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup if (startPos == null) { input.player.sendMessage(Text.translatable("magisterium.gui.no_glyphs_found"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); - return ItemStack.EMPTY; + return; } boolean hasSuccess = false, hasFailure = false; @@ -118,11 +117,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup ((ServerPlayerEntity) input.player).closeHandledScreen(); } - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/QuenchFlameRecipe.java b/src/main/java/io/github/reoseah/magisterium/data/effect/QuenchFlameEffect.java similarity index 67% rename from src/main/java/io/github/reoseah/magisterium/recipe/QuenchFlameRecipe.java rename to src/main/java/io/github/reoseah/magisterium/data/effect/QuenchFlameEffect.java index b6b990c..85195d5 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/QuenchFlameRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/QuenchFlameEffect.java @@ -1,34 +1,39 @@ -package io.github.reoseah.magisterium.recipe; +package io.github.reoseah.magisterium.data.effect; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.block.MagisteriumBlockTags; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; import io.github.reoseah.magisterium.world.MagisteriumPlaygrounds; import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.state.property.Properties; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class QuenchFlameRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(QuenchFlameRecipe::new); +public class QuenchFlameEffect extends SpellEffect { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("utterance").forGetter(effect -> effect.utterance), + Codecs.POSITIVE_INT.fieldOf("duration").forGetter(effect -> effect.duration) + ).apply(instance, QuenchFlameEffect::new)); - public static final int RADIUS = AwakenFlameRecipe.RADIUS; + public static final int RADIUS = AwakenFlameEffect.RADIUS; - protected QuenchFlameRecipe(Identifier utterance, int duration) { + public QuenchFlameEffect(Identifier utterance, int duration) { super(utterance, duration); } @Override - public boolean matches(SpellBookRecipeInput input, World world) { - return true; + public MapCodec getCodec() { + return CODEC; } @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { + public void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { boolean hasTargets = false; boolean hasQuenched = false; boolean hasFailed = false; @@ -58,17 +63,5 @@ public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup input.player.sendMessage(Text.translatable("magisterium.gui.no_success"), true); ((ServerPlayerEntity) input.player).closeHandledScreen(); } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/reoseah/magisterium/data/effect/SpellEffect.java b/src/main/java/io/github/reoseah/magisterium/data/effect/SpellEffect.java new file mode 100644 index 0000000..8aae7be --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/effect/SpellEffect.java @@ -0,0 +1,29 @@ +package io.github.reoseah.magisterium.data.effect; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.Lifecycle; +import com.mojang.serialization.MapCodec; +import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.SimpleRegistry; +import net.minecraft.util.Identifier; + +public abstract class SpellEffect { + public static final RegistryKey>> REGISTRY_KEY = RegistryKey.ofRegistry(Identifier.of("magisterium", "spell_effects")); + public static final Registry> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.experimental()); + public static final Codec CODEC = REGISTRY.getCodec().dispatch("type", SpellEffect::getCodec, codec -> codec); + + public final Identifier utterance; + public final int duration; + + public SpellEffect(Identifier utterance, int duration) { + this.utterance = utterance; + this.duration = duration; + } + + public abstract MapCodec getCodec(); + + public abstract void finish(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup); +} diff --git a/src/main/java/io/github/reoseah/magisterium/data/element/BookElement.java b/src/main/java/io/github/reoseah/magisterium/data/element/BookElement.java new file mode 100644 index 0000000..4a97aae --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/element/BookElement.java @@ -0,0 +1,23 @@ +package io.github.reoseah.magisterium.data.element; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.Lifecycle; +import com.mojang.serialization.MapCodec; +import io.github.reoseah.magisterium.spellbook.BookLayout; +import io.github.reoseah.magisterium.spellbook.BookProperties; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.SimpleRegistry; +import net.minecraft.util.Identifier; + +public interface BookElement { + RegistryKey>> REGISTRY_KEY = RegistryKey.ofRegistry(Identifier.of("magisterium", "book_elements")); + Registry> REGISTRY = new SimpleRegistry<>(REGISTRY_KEY, Lifecycle.experimental()); + Codec CODEC = REGISTRY.getCodec().dispatch("type", BookElement::getCodec, codec -> codec); + + MapCodec getCodec(); + + void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer); +} + diff --git a/src/main/java/io/github/reoseah/magisterium/data/element/BookInventory.java b/src/main/java/io/github/reoseah/magisterium/data/element/BookInventory.java new file mode 100644 index 0000000..1b35743 --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/element/BookInventory.java @@ -0,0 +1,94 @@ +package io.github.reoseah.magisterium.data.element; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import io.github.reoseah.magisterium.spellbook.BookProperties; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; + +import java.util.List; +import java.util.Optional; + +public class BookInventory extends SimpleBlock { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Codecs.POSITIVE_INT.optionalFieldOf("height", 0).forGetter(inventory -> inventory.height), // + SlotProperties.CODEC.codec().listOf().fieldOf("slots").forGetter(inventory -> inventory.slots), // + Background.CODEC.codec().optionalFieldOf("background").forGetter(inventory -> inventory.background) // + ).apply(instance, BookInventory::new)); + + public final int height; + public final List slots; + public final Optional background; + + public BookInventory(int height, List slots, Optional background) { + this.height = height != 0 ? height : slots.stream().mapToInt(slot -> slot.output ? slot.y + 18 + 4 : slot.y + 18).max().orElse(0) + 1; + this.background = background; + this.slots = slots; + } + + @Override + public MapCodec getCodec() { + return CODEC; + } + + @Override + protected int getHeight(int width, TextRenderer textRenderer) { + return this.height; + } + + @Override + protected Drawable createWidget(int x, int y, BookProperties properties, int maxHeight, TextRenderer textRenderer) { + return new Widget(properties, x, y, background, slots); + } + + private static class Widget implements Drawable, SlotPropertiesProvider { + private final BookProperties properties; + private final int x; + private final int y; + private final Optional background; + private final List slots; + + public Widget(BookProperties properties, int x, int y, Optional background, List slots) { + this.properties = properties; + this.x = x; + this.y = y; + this.background = background; + this.slots = slots; + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + if (this.background.isPresent()) { + var background = this.background.get(); + context.drawTexture(background.texture, x + background.x, y + background.y, background.u, background.v, background.width, background.height); + } + for (SlotProperties slot : this.slots) { + if (slot.output) { + context.drawTexture(properties.texture, x + slot.x - 5, y + slot.y - 5, properties.resultSlotU, properties.resultSlotV, 26, 26); + } else { + context.drawTexture(properties.texture, x + slot.x - 1, y + slot.y - 1, properties.slotU, properties.slotV, 18, 18); + } + } + } + + @Override + public List getSlotProperties() { + return this.slots.stream().map(slot -> slot.offset(this.x, this.y)).toList(); + } + } + + public record Background(Identifier texture, int x, int y, int u, int v, int width, int height) { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Identifier.CODEC.fieldOf("texture").forGetter(Background::texture), // + Codecs.POSITIVE_INT.fieldOf("x").forGetter(Background::x), // + Codecs.POSITIVE_INT.fieldOf("y").forGetter(Background::y), // + Codecs.POSITIVE_INT.fieldOf("u").forGetter(Background::u), // + Codecs.POSITIVE_INT.fieldOf("v").forGetter(Background::v), // + Codecs.POSITIVE_INT.fieldOf("width").forGetter(Background::width), // + Codecs.POSITIVE_INT.fieldOf("height").forGetter(Background::height) // + ).apply(instance, Background::new)); + } +} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Bookmark.java b/src/main/java/io/github/reoseah/magisterium/data/element/Bookmark.java similarity index 59% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/Bookmark.java rename to src/main/java/io/github/reoseah/magisterium/data/element/Bookmark.java index 9969d06..28692aa 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Bookmark.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/Bookmark.java @@ -1,4 +1,4 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; import net.minecraft.text.Text; diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookmarkElement.java b/src/main/java/io/github/reoseah/magisterium/data/element/BookmarkElement.java similarity index 67% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/BookmarkElement.java rename to src/main/java/io/github/reoseah/magisterium/data/element/BookmarkElement.java index 8696106..d60d708 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookmarkElement.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/BookmarkElement.java @@ -1,11 +1,18 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; public class BookmarkElement implements BookElement, Bookmark { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + TextCodecs.STRINGIFIED_CODEC.fieldOf("text").forGetter(bookmark -> bookmark.text) // + ).apply(instance, BookmarkElement::new)); + public final Text text; public BookmarkElement(String translationKey) { @@ -16,6 +23,11 @@ public BookmarkElement(Text text) { this.text = text; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override public void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer) { builder.startNewFold(); diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/DivisibleBlock.java b/src/main/java/io/github/reoseah/magisterium/data/element/DivisibleBlock.java similarity index 96% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/DivisibleBlock.java rename to src/main/java/io/github/reoseah/magisterium/data/element/DivisibleBlock.java index 0db9ab4..51be40a 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/DivisibleBlock.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/DivisibleBlock.java @@ -1,4 +1,4 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Fold.java b/src/main/java/io/github/reoseah/magisterium/data/element/Fold.java similarity index 54% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/Fold.java rename to src/main/java/io/github/reoseah/magisterium/data/element/Fold.java index 64a460f..ccefc89 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Fold.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/Fold.java @@ -1,18 +1,31 @@ -package io.github.reoseah.magisterium.spellbook.element; - +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; +import java.util.List; + public class Fold implements BookElement { - private final SimpleBlock[] left, right; + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + SimpleBlock.CODEC.listOf().fieldOf("left").forGetter(fold -> fold.left), // + SimpleBlock.CODEC.listOf().fieldOf("right").forGetter(fold -> fold.right) // + ).apply(instance, Fold::new)); + + private final List left, right; - public Fold(SimpleBlock[] left, SimpleBlock[] right) { + public Fold(List left, List right) { this.left = left; this.right = right; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override public void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer) { builder.startNewFold(); diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Heading.java b/src/main/java/io/github/reoseah/magisterium/data/element/Heading.java similarity index 75% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/Heading.java rename to src/main/java/io/github/reoseah/magisterium/data/element/Heading.java index a2b6f37..8de8960 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Heading.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/Heading.java @@ -1,6 +1,7 @@ -package io.github.reoseah.magisterium.spellbook.element; - +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.spellbook.BookProperties; import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.client.font.TextRenderer; @@ -8,21 +9,27 @@ import net.minecraft.client.gui.Drawable; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; import java.util.ArrayList; import java.util.List; public class Heading extends SimpleBlock { - protected final Text text; + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + TextCodecs.CODEC.fieldOf("text").forGetter(heading -> heading.text) // + ).apply(instance, Heading::new)); - public Heading(String translationKey) { - this(Text.translatable(translationKey)); - } + protected final Text text; public Heading(Text text) { this.text = text; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override protected int getHeight(int width, TextRenderer textRenderer) { return textRenderer.getWrappedLinesHeight(this.text, width); diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/PageBreak.java b/src/main/java/io/github/reoseah/magisterium/data/element/PageBreak.java similarity index 53% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/PageBreak.java rename to src/main/java/io/github/reoseah/magisterium/data/element/PageBreak.java index 3b99e95..48098c6 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/PageBreak.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/PageBreak.java @@ -1,10 +1,19 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; public class PageBreak implements BookElement { + public static final PageBreak INSTANCE = new PageBreak(); + public static final MapCodec CODEC = MapCodec.unit(INSTANCE); + + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override public void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer) { builder.advancePage(); diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Paragraph.java b/src/main/java/io/github/reoseah/magisterium/data/element/Paragraph.java similarity index 69% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/Paragraph.java rename to src/main/java/io/github/reoseah/magisterium/data/element/Paragraph.java index 6f423c4..90c87e4 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Paragraph.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/Paragraph.java @@ -1,24 +1,29 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.Drawable; -import net.minecraft.text.OrderedText; import net.minecraft.text.Text; - -import java.util.List; +import net.minecraft.text.TextCodecs; public class Paragraph extends DivisibleBlock { - protected final Text text; + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + TextCodecs.CODEC.fieldOf("text").forGetter(paragraph -> paragraph.text) // + ).apply(instance, Paragraph::new)); - public Paragraph(String translationKey) { - this(Text.translatable(translationKey)); - } + protected final Text text; public Paragraph(Text text) { this.text = text; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override protected int getHeight(int width, TextRenderer textRenderer) { return textRenderer.getWrappedLinesHeight(this.text, width); @@ -26,7 +31,7 @@ protected int getHeight(int width, TextRenderer textRenderer) { @Override protected Drawable createWidget(int x, int y, BookProperties properties, int maxHeight, TextRenderer textRenderer) { - List lines = textRenderer.wrapLines(this.text, properties.pageWidth); + var lines = textRenderer.wrapLines(this.text, properties.pageWidth); return (matrices, mouseX, mouseY, delta) -> { for (int i = 0; i < lines.size(); i++) { matrices.drawText(textRenderer, lines.get(i), x, y + i * textRenderer.fontHeight, 0x000000, false); @@ -41,11 +46,11 @@ protected boolean canDivide(int height, int maxHeight, TextRenderer textRenderer @Override protected WidgetPair createWidgetPair(int x, int y, int width, int maxHeight, int nextX, int nextY, int nextHeight, TextRenderer textRenderer) { - List lines = textRenderer.wrapLines(this.text, width); + var lines = textRenderer.wrapLines(this.text, width); int lineCountOnCurrentPage = maxHeight / textRenderer.fontHeight; - List linesOnCurrentPage = lines.subList(0, lineCountOnCurrentPage); - List linesOnNextPage = lines.subList(lineCountOnCurrentPage, lines.size()); + var linesOnCurrentPage = lines.subList(0, lineCountOnCurrentPage); + var linesOnNextPage = lines.subList(lineCountOnCurrentPage, lines.size()); return new WidgetPair((ctx, mouseX, mouseY, delta) -> { for (int i = 0; i < linesOnCurrentPage.size(); i++) { diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SimpleBlock.java b/src/main/java/io/github/reoseah/magisterium/data/element/SimpleBlock.java similarity index 80% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/SimpleBlock.java rename to src/main/java/io/github/reoseah/magisterium/data/element/SimpleBlock.java index 90fb1d6..f9d8e1c 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SimpleBlock.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/SimpleBlock.java @@ -1,11 +1,20 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.Drawable; public abstract class SimpleBlock implements BookElement { + public static final Codec CODEC = BookElement.CODEC.flatXmap(element -> { + if (element instanceof SimpleBlock simpleBlock) { + return DataResult.success(simpleBlock); + } + return DataResult.error(() -> "Not a SimpleBlock: " + element); + }, DataResult::success); + @Override public void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer) { int elementHeight = this.getHeight(properties.pageWidth, textRenderer); diff --git a/src/main/java/io/github/reoseah/magisterium/data/element/SlotProperties.java b/src/main/java/io/github/reoseah/magisterium/data/element/SlotProperties.java new file mode 100644 index 0000000..5fbee60 --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/element/SlotProperties.java @@ -0,0 +1,73 @@ +package io.github.reoseah.magisterium.data.element; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.recipe.Ingredient; +import net.minecraft.screen.PlayerScreenHandler; +import net.minecraft.util.Identifier; +import net.minecraft.util.dynamic.Codecs; + +import java.util.Optional; + +public class SlotProperties { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + Codecs.NONNEGATIVE_INT.fieldOf("x").forGetter(slot -> slot.x), // + Codecs.NONNEGATIVE_INT.fieldOf("y").forGetter(slot -> slot.y), // + Codec.BOOL.optionalFieldOf("output", false).forGetter(slot -> slot.output), // + Ingredient.ALLOW_EMPTY_CODEC.optionalFieldOf("ingredient").forGetter(slot -> slot.ingredient), // + Identifier.CODEC.optionalFieldOf("background").forGetter(slot -> slot.background) // + ).apply(instance, SlotProperties::new)); + + public final int x; + public final int y; + public final boolean output; + public final Optional ingredient; + public final Optional background; + + public SlotProperties(int x, int y, boolean output, Optional ingredient, Optional background) { + this.x = x; + this.y = y; + this.background = background; + this.ingredient = ingredient; + this.output = output; + } + + public SlotProperties offset(int x, int y) { + return new SlotProperties(this.x + x, this.y + y, this.output, this.ingredient, this.background); + } + + public Pair getBackgroundSprite() { + return this.background.isPresent() ? Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, this.background.get()) : null; + } + + public void write(RegistryByteBuf buf) { + buf.writeVarInt(this.x); + buf.writeVarInt(this.y); + buf.writeBoolean(this.output); + if (this.ingredient.isPresent()) { + buf.writeBoolean(true); + Ingredient.PACKET_CODEC.encode(buf, this.ingredient.get()); + } else { + buf.writeBoolean(false); + } + if (this.background.isPresent()) { + buf.writeBoolean(true); + buf.writeIdentifier(this.background.get()); + } else { + buf.writeBoolean(false); + } + } + + public static SlotProperties read(RegistryByteBuf buf) { + int x = buf.readVarInt(); + int y = buf.readVarInt(); + boolean output = buf.readBoolean(); + Optional ingredient = buf.readBoolean() ? Optional.of(Ingredient.PACKET_CODEC.decode(buf)) : Optional.empty(); + Optional background = buf.readBoolean() ? Optional.of(buf.readIdentifier()) : Optional.empty(); + + return new SlotProperties(x, y, output, ingredient, background); + } +} diff --git a/src/main/java/io/github/reoseah/magisterium/data/element/SlotPropertiesProvider.java b/src/main/java/io/github/reoseah/magisterium/data/element/SlotPropertiesProvider.java new file mode 100644 index 0000000..949c7fc --- /dev/null +++ b/src/main/java/io/github/reoseah/magisterium/data/element/SlotPropertiesProvider.java @@ -0,0 +1,7 @@ +package io.github.reoseah.magisterium.data.element; + +import java.util.List; + +public interface SlotPropertiesProvider { + List getSlotProperties(); +} \ No newline at end of file diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Utterance.java b/src/main/java/io/github/reoseah/magisterium/data/element/Utterance.java similarity index 84% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/Utterance.java rename to src/main/java/io/github/reoseah/magisterium/data/element/Utterance.java index 1f2421a..76281ed 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/Utterance.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/Utterance.java @@ -1,6 +1,8 @@ -package io.github.reoseah.magisterium.spellbook.element; - +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.network.StartUtterancePayload; import io.github.reoseah.magisterium.network.StopUtterancePayload; import io.github.reoseah.magisterium.screen.SpellBookScreenHandler; @@ -13,32 +15,41 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.Element; -import net.minecraft.text.MutableText; import net.minecraft.text.OrderedText; import net.minecraft.text.Text; +import net.minecraft.text.TextCodecs; import net.minecraft.util.Identifier; -import java.time.Instant; import java.util.List; // TODO: have the utterance text shortly highlight to indicate finishing // TODO: consider renaming this and other Utterance* classes to Spell or SpellElement public class Utterance extends SimpleBlock { - protected final String translationKey; + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + TextCodecs.CODEC.fieldOf("text").forGetter(utterance -> utterance.text), // + Identifier.CODEC.fieldOf("id").forGetter(utterance -> utterance.id), // + Codec.FLOAT.fieldOf("duration").forGetter(utterance -> utterance.duration) // + ).apply(instance, Utterance::new)); + + protected final Text text; protected final Identifier id; protected final float duration; - public Utterance(String translationKey, Identifier id, float duration) { - this.translationKey = translationKey; + public Utterance(Text text, Identifier id, float duration) { + this.text = text; this.id = id; this.duration = duration; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override protected int getHeight(int width, TextRenderer textRenderer) { - MutableText text = Text.translatable(this.translationKey); - List lines = textRenderer.wrapLines(text, width - 12); - List linesAsString = lines.stream().map(t -> { + var lines = textRenderer.wrapLines(this.text, width - 12); + var linesAsString = lines.stream().map(t -> { StringBuilder builder = new StringBuilder(); t.accept((index, style, codePoint) -> { builder.appendCodePoint(codePoint); @@ -65,7 +76,7 @@ protected int getTopMargin() { @Override protected Drawable createWidget(int x, int y, BookProperties properties, int maxHeight, TextRenderer textRenderer) { - return new UtteranceWidget(this.translationKey, x, y, properties, properties.pageWidth, textRenderer); + return new UtteranceWidget(this.text, x, y, properties, properties.pageWidth, textRenderer); } private class UtteranceWidget implements Drawable, Element { @@ -85,11 +96,10 @@ private class UtteranceWidget implements Drawable, Element { private boolean mouseDown = false; private long mouseDownTime = 0L; - public UtteranceWidget(String translationKey, int x, int y, BookProperties properties, int width, TextRenderer textRenderer) { + public UtteranceWidget(Text text, int x, int y, BookProperties properties, int width, TextRenderer textRenderer) { this.properties = properties; this.textRenderer = textRenderer; - MutableText text = Text.translatable(translationKey); this.lines = textRenderer.wrapLines(text, width - properties.spellButtonWidth); this.linesAsString = lines.stream().map(t -> { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/VerticalCenterElement.java b/src/main/java/io/github/reoseah/magisterium/data/element/VerticallyCenteredElement.java similarity index 55% rename from src/main/java/io/github/reoseah/magisterium/spellbook/element/VerticalCenterElement.java rename to src/main/java/io/github/reoseah/magisterium/data/element/VerticallyCenteredElement.java index 1624f6d..c211248 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/VerticalCenterElement.java +++ b/src/main/java/io/github/reoseah/magisterium/data/element/VerticallyCenteredElement.java @@ -1,16 +1,27 @@ -package io.github.reoseah.magisterium.spellbook.element; +package io.github.reoseah.magisterium.data.element; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.reoseah.magisterium.spellbook.BookProperties; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.Drawable; -public class VerticalCenterElement extends SimpleBlock { +public class VerticallyCenteredElement extends SimpleBlock { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( // + SimpleBlock.CODEC.fieldOf("element").forGetter(element -> element.element) // + ).apply(instance, VerticallyCenteredElement::new)); + private final SimpleBlock element; - public VerticalCenterElement(SimpleBlock element) { + public VerticallyCenteredElement(SimpleBlock element) { this.element = element; } + @Override + public MapCodec getCodec() { + return CODEC; + } + @Override protected int getHeight(int width, TextRenderer textRenderer) { // forces new page diff --git a/src/main/java/io/github/reoseah/magisterium/item/SpellBookItem.java b/src/main/java/io/github/reoseah/magisterium/item/SpellBookItem.java index b25a04a..fbe6f5e 100644 --- a/src/main/java/io/github/reoseah/magisterium/item/SpellBookItem.java +++ b/src/main/java/io/github/reoseah/magisterium/item/SpellBookItem.java @@ -57,7 +57,6 @@ public static ItemStack createTestBook() { list.set(6, SpellPageItem.ILLUSORY_WALL.getDefaultStack()); list.set(7, SpellPageItem.ARCANE_LIFT.getDefaultStack()); list.set(8, SpellPageItem.DISPEL_MAGIC.getDefaultStack()); -// list.set(17, SpellPageItem.UNSTABLE_CHARGE.getDefaultStack()); })); return book; diff --git a/src/main/java/io/github/reoseah/magisterium/item/SpellPageItem.java b/src/main/java/io/github/reoseah/magisterium/item/SpellPageItem.java index e0b5408..d7acb3b 100644 --- a/src/main/java/io/github/reoseah/magisterium/item/SpellPageItem.java +++ b/src/main/java/io/github/reoseah/magisterium/item/SpellPageItem.java @@ -15,7 +15,6 @@ public class SpellPageItem extends Item { public static final Item GLYPHIC_IGNITION = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:glyphic_ignition")); public static final Item CONFLAGRATE = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:conflagrate")); public static final Item ILLUSORY_WALL = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:illusory_wall")); - public static final Item UNSTABLE_CHARGE = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:unstable_charge")); public static final Item COLD_SNAP = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:cold_snap")); public static final Item ARCANE_LIFT = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:arcane_lift")); public static final Item DISPEL_MAGIC = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:dispel_magic")); diff --git a/src/main/java/io/github/reoseah/magisterium/network/SlotLayoutPayload.java b/src/main/java/io/github/reoseah/magisterium/network/SlotLayoutPayload.java index 373c331..6a9654e 100644 --- a/src/main/java/io/github/reoseah/magisterium/network/SlotLayoutPayload.java +++ b/src/main/java/io/github/reoseah/magisterium/network/SlotLayoutPayload.java @@ -1,7 +1,7 @@ package io.github.reoseah.magisterium.network; -import io.github.reoseah.magisterium.spellbook.element.SlotProperties; +import io.github.reoseah.magisterium.data.element.SlotProperties; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.packet.CustomPayload; diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookCraftingRecipe.java b/src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookCraftingRecipe.java similarity index 79% rename from src/main/java/io/github/reoseah/magisterium/recipe/SpellBookCraftingRecipe.java rename to src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookCraftingRecipe.java index a101646..ff5fbbe 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookCraftingRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookCraftingRecipe.java @@ -16,11 +16,11 @@ import java.util.List; -public class SpellBookCraftingRecipe extends SpellBookRecipe { +public class OldSpellBookCraftingRecipe extends OldSpellBookRecipe { public final List ingredients; public final ItemStack result; - protected SpellBookCraftingRecipe(Identifier utterance, int duration, List ingredients, ItemStack result) { + protected OldSpellBookCraftingRecipe(Identifier utterance, int duration, List ingredients, ItemStack result) { super(utterance, duration); this.ingredients = ingredients; this.result = result; @@ -70,18 +70,18 @@ public DefaultedList getIngredients() { return DefaultedList.copyOf(Ingredient.EMPTY, this.ingredients.toArray(new Ingredient[0])); } - public static class Serializer implements RecipeSerializer { - public static final MapCodec CODEC = RecordCodecBuilder // + public static class Serializer implements RecipeSerializer { + public static final MapCodec CODEC = RecordCodecBuilder // .mapCodec(instance -> instance.group( // Identifier.CODEC.fieldOf("utterance").forGetter(recipe -> recipe.utterance), // Codecs.POSITIVE_INT.fieldOf("duration").forGetter(recipe -> recipe.duration), // Codec.list(Ingredient.DISALLOW_EMPTY_CODEC).fieldOf("ingredients").forGetter(recipe -> recipe.ingredients), // ItemStack.VALIDATED_CODEC.fieldOf("result").forGetter(recipe -> recipe.result)) // - .apply(instance, SpellBookCraftingRecipe::new)); + .apply(instance, OldSpellBookCraftingRecipe::new)); - public static final PacketCodec PACKET_CODEC = new PacketCodec<>() { + public static final PacketCodec PACKET_CODEC = new PacketCodec<>() { @Override - public void encode(RegistryByteBuf buf, SpellBookCraftingRecipe value) { + public void encode(RegistryByteBuf buf, OldSpellBookCraftingRecipe value) { buf.writeIdentifier(value.utterance); buf.writeVarInt(value.duration); buf.writeVarInt(value.ingredients.size()); @@ -92,7 +92,7 @@ public void encode(RegistryByteBuf buf, SpellBookCraftingRecipe value) { } @Override - public SpellBookCraftingRecipe decode(RegistryByteBuf buf) { + public OldSpellBookCraftingRecipe decode(RegistryByteBuf buf) { Identifier utterance = buf.readIdentifier(); int duration = buf.readVarInt(); int size = buf.readVarInt(); @@ -101,19 +101,19 @@ public SpellBookCraftingRecipe decode(RegistryByteBuf buf) { ingredients.set(i, Ingredient.PACKET_CODEC.decode(buf)); } ItemStack result = ItemStack.PACKET_CODEC.decode(buf); - return new SpellBookCraftingRecipe(utterance, duration, ingredients, result); + return new OldSpellBookCraftingRecipe(utterance, duration, ingredients, result); } }; public static final Serializer INSTANCE = new Serializer(); @Override - public MapCodec codec() { + public MapCodec codec() { return CODEC; } @Override - public PacketCodec packetCodec() { + public PacketCodec packetCodec() { return PACKET_CODEC; } } diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipe.java b/src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookRecipe.java similarity index 88% rename from src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipe.java rename to src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookRecipe.java index c6a4b54..929325a 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipe.java +++ b/src/main/java/io/github/reoseah/magisterium/recipe/OldSpellBookRecipe.java @@ -12,8 +12,8 @@ import java.util.function.BiFunction; -public abstract class SpellBookRecipe implements Recipe { - public static final RecipeType TYPE = new RecipeType<>() { +public abstract class OldSpellBookRecipe implements Recipe { + public static final RecipeType TYPE = new RecipeType<>() { @Override public String toString() { return "magisterium:spell_book"; @@ -25,7 +25,7 @@ public String toString() { public final Identifier utterance; public final int duration; - protected SpellBookRecipe(Identifier utterance, int duration) { + protected OldSpellBookRecipe(Identifier utterance, int duration) { this.utterance = utterance; this.duration = duration; } @@ -40,7 +40,7 @@ public boolean fits(int width, int height) { return true; } - public static class SimpleSerializer implements RecipeSerializer { + public static class SimpleSerializer implements RecipeSerializer { private final BiFunction constructor; private final MapCodec codec; private final PacketCodec packetCodec; diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipeInput.java b/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipeInput.java index 8ae1a7b..22f7793 100644 --- a/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipeInput.java +++ b/src/main/java/io/github/reoseah/magisterium/recipe/SpellBookRecipeInput.java @@ -7,9 +7,9 @@ import net.minecraft.recipe.input.RecipeInput; public class SpellBookRecipeInput implements RecipeInput { - protected final Inventory inventory; - protected final PlayerEntity player; - protected final SpellBookScreenHandler.Context context; + public final Inventory inventory; + public final PlayerEntity player; + public final SpellBookScreenHandler.Context context; public SpellBookRecipeInput(Inventory inventory, PlayerEntity player, SpellBookScreenHandler.Context context) { this.inventory = inventory; diff --git a/src/main/java/io/github/reoseah/magisterium/recipe/UnstableChargeRecipe.java b/src/main/java/io/github/reoseah/magisterium/recipe/UnstableChargeRecipe.java deleted file mode 100644 index a4e8051..0000000 --- a/src/main/java/io/github/reoseah/magisterium/recipe/UnstableChargeRecipe.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.reoseah.magisterium.recipe; - -import io.github.reoseah.magisterium.item.SpellBookItem; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.registry.RegistryWrapper; -import net.minecraft.util.Identifier; -import net.minecraft.util.Unit; -import net.minecraft.world.World; - -public class UnstableChargeRecipe extends SpellBookRecipe { - public static final RecipeSerializer SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(UnstableChargeRecipe::new); - - protected UnstableChargeRecipe(Identifier utterance, int duration) { - super(utterance, duration); - } - - @Override - public boolean matches(SpellBookRecipeInput input, World world) { - // TODO: require ingredients, like a Nether Wart and a Bottle o' Enchanting - return true; - } - - @Override - public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) { - input.getContext().setStackComponent(SpellBookItem.UNSTABLE_CHARGE, Unit.INSTANCE); - - return ItemStack.EMPTY; - } - - @Override - public ItemStack getResult(RegistryWrapper.WrapperLookup registriesLookup) { - return ItemStack.EMPTY; - } - - @Override - public RecipeSerializer getSerializer() { - return SERIALIZER; - } -} diff --git a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreen.java b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreen.java index 2705d18..799cd89 100644 --- a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreen.java +++ b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreen.java @@ -1,5 +1,7 @@ package io.github.reoseah.magisterium.screen; +import io.github.reoseah.magisterium.data.SpellRecipe; +import io.github.reoseah.magisterium.data.element.*; import io.github.reoseah.magisterium.item.BookmarkItem; import io.github.reoseah.magisterium.item.SpellBookItem; import io.github.reoseah.magisterium.item.SpellPageItem; @@ -7,8 +9,6 @@ import io.github.reoseah.magisterium.network.UseBookmarkPayload; import io.github.reoseah.magisterium.spellbook.BookLayout; import io.github.reoseah.magisterium.spellbook.BookProperties; -import io.github.reoseah.magisterium.spellbook.SpellDataLoader; -import io.github.reoseah.magisterium.spellbook.element.*; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.gui.DrawContext; @@ -20,6 +20,7 @@ import net.minecraft.component.DataComponentTypes; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -28,6 +29,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Map; +import java.util.stream.Collectors; + public class SpellBookScreen extends HandledScreen { private static final Logger LOGGER = LogManager.getLogger(); @@ -106,6 +110,12 @@ protected void init() { .formatted(Formatting.ITALIC).styled(style -> style.withColor(0xc4b090)); private void buildPages() { + var clientWorld = this.client.world; + var recipeManager = clientWorld.getRecipeManager(); + Map spellRecipes = recipeManager.listAllOfType(SpellRecipe.TYPE) // + .stream() // + .collect(Collectors.toMap(RecipeEntry::id, RecipeEntry::value)); + var pages = this.handler.getSpellBook().getOrDefault(SpellBookItem.CONTENTS, DefaultedList.ofSize(18, ItemStack.EMPTY)); var builder = new BookLayout.Builder(this.properties); @@ -116,7 +126,7 @@ private void buildPages() { LOGGER.warn("Spell id not found in stack {}", stack); continue; } - var spell = SpellDataLoader.SPELLS.get(id); + var spell = spellRecipes.get(id); if (spell == null) { LOGGER.warn("Spell data for id {} not found", id); continue; diff --git a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreenHandler.java b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreenHandler.java index e8d0508..6c7d3ab 100644 --- a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreenHandler.java +++ b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookScreenHandler.java @@ -1,10 +1,10 @@ package io.github.reoseah.magisterium.screen; import io.github.reoseah.magisterium.MagisteriumSounds; +import io.github.reoseah.magisterium.data.SpellRecipe; import io.github.reoseah.magisterium.item.SpellBookItem; -import io.github.reoseah.magisterium.recipe.SpellBookRecipe; import io.github.reoseah.magisterium.recipe.SpellBookRecipeInput; -import io.github.reoseah.magisterium.spellbook.element.SlotProperties; +import io.github.reoseah.magisterium.data.element.SlotProperties; import it.unimi.dsi.fastutil.ints.IntArraySet; import net.minecraft.block.LecternBlock; import net.minecraft.block.entity.BlockEntity; @@ -28,6 +28,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import io.github.reoseah.magisterium.data.effect.SpellEffect; public class SpellBookScreenHandler extends ScreenHandler { public static final ScreenHandlerType TYPE = new ScreenHandlerType<>(SpellBookScreenHandler::new, FeatureFlags.DEFAULT_ENABLED_FEATURES); @@ -42,7 +43,8 @@ public class SpellBookScreenHandler extends ScreenHandler { private long utteranceStart; - private @Nullable SpellBookRecipe utteranceRecipe; + // TODO change this to a list of effects + private @Nullable SpellEffect spellEffect; public SpellBookScreenHandler(int syncId, PlayerInventory playerInv) { this(syncId, playerInv, new ClientContext()); @@ -77,13 +79,14 @@ public boolean canInsert(ItemStack stack) { public void startUtterance(Identifier id, ServerPlayerEntity player) { player.getWorld().getRecipeManager() // - .getAllMatches(SpellBookRecipe.TYPE, new SpellBookRecipeInput(this.inventory, player, this.context), player.getWorld()) // + .getAllMatches(SpellRecipe.TYPE, new SpellBookRecipeInput(this.inventory, player, this.context), player.getWorld()) // .stream() // .map(RecipeEntry::value) // - .filter(recipe -> recipe.utterance.equals(id)) // + .flatMap(recipe -> recipe.effects.stream()) // + .filter(effect -> effect.utterance.equals(id)) // .findFirst() // - .ifPresent(recipe -> this.utteranceRecipe = recipe); - if (this.utteranceRecipe != null) { + .ifPresent(effect -> this.spellEffect = effect); + if (this.spellEffect != null) { this.isUttering.set(1); this.utteranceStart = player.getWorld().getTime(); } @@ -92,7 +95,7 @@ public void startUtterance(Identifier id, ServerPlayerEntity player) { public void stopUtterance() { this.isUttering.set(0); this.utteranceStart = 0; - this.utteranceRecipe = null; + this.spellEffect = null; this.sendContentUpdates(); } @@ -115,7 +118,7 @@ public ItemStack quickMove(PlayerEntity player, int index) { int total = 0; for (int i = 0; i < 16; i++) { SlotProperties definition = ((SpellBookSlot) this.getSlot(i)).config; - if (definition != null && !definition.output && (definition.ingredient == null || definition.ingredient.test(stack))) { + if (definition != null && !definition.output && (definition.ingredient.isEmpty() || definition.ingredient.get().test(stack))) { ItemStack slotStack = this.getSlot(i).getStack(); if (slotStack.isEmpty() || ItemStack.areItemsAndComponentsEqual(slotStack, stack)) { slotsToSpreadStackTo.add(i); @@ -168,17 +171,16 @@ public void onClosed(PlayerEntity player) { @Override public boolean canUse(PlayerEntity player) { // this gets called every tick, so it's a tick method effectively - - // TODO allow for spells that are active as long as the player holds the casting button down? - if (this.utteranceRecipe != null) { - var recipeDuration = this.utteranceRecipe.duration; + if (this.spellEffect != null) { + var recipeDuration = this.spellEffect.duration; long time = player.getWorld().getTime(); if (time - this.utteranceStart >= recipeDuration * player.getWorld().getTickManager().getTickRate()) { - ItemStack result = this.utteranceRecipe.craft(new SpellBookRecipeInput(this.inventory, player, this.context), player.getWorld().getRegistryManager()); +// ItemStack result = + this.spellEffect.finish(new SpellBookRecipeInput(this.inventory, player, this.context), player.getWorld().getRegistryManager()); - if (!result.isEmpty()) { - this.insertResult(result, player); - } +// if (!result.isEmpty()) { +// this.insertResult(result, player); +// } this.stopUtterance(); } else if (this.lastSoundTime == null || time - this.lastSoundTime >= 50) { if (this.lastSoundTime == null || time - this.utteranceStart <= recipeDuration * player.getWorld().getTickManager().getTickRate() - 50) { diff --git a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookSlot.java b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookSlot.java index 1fcab78..f3cbe9e 100644 --- a/src/main/java/io/github/reoseah/magisterium/screen/SpellBookSlot.java +++ b/src/main/java/io/github/reoseah/magisterium/screen/SpellBookSlot.java @@ -1,7 +1,7 @@ package io.github.reoseah.magisterium.screen; import com.mojang.datafixers.util.Pair; -import io.github.reoseah.magisterium.spellbook.element.SlotProperties; +import io.github.reoseah.magisterium.data.element.SlotProperties; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -30,7 +30,7 @@ public SlotProperties getConfiguration() { @Override public boolean canInsert(ItemStack stack) { - return this.config != null && !this.config.output && (this.config.ingredient == null || this.config.ingredient.test(stack)); + return this.config != null && !this.config.output && (this.config.ingredient.isEmpty() || this.config.ingredient.get().test(stack)); } @Nullable diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/BookLayout.java b/src/main/java/io/github/reoseah/magisterium/spellbook/BookLayout.java index e184ed8..9d0a5e3 100644 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/BookLayout.java +++ b/src/main/java/io/github/reoseah/magisterium/spellbook/BookLayout.java @@ -1,15 +1,14 @@ package io.github.reoseah.magisterium.spellbook; -import io.github.reoseah.magisterium.spellbook.element.Bookmark; -import io.github.reoseah.magisterium.spellbook.element.SlotProperties; -import io.github.reoseah.magisterium.spellbook.element.SlotPropertiesProvider; +import io.github.reoseah.magisterium.data.element.Bookmark; +import io.github.reoseah.magisterium.data.element.SlotProperties; +import io.github.reoseah.magisterium.data.element.SlotPropertiesProvider; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import net.minecraft.client.gui.Drawable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Stream; @@ -37,10 +36,10 @@ public SlotProperties[] getFoldSlots(int leftPage) { // TODO build and keep a separate map of slots per page Stream leftSlots = this.getPage(leftPage).stream() .filter(drawable -> drawable instanceof SlotPropertiesProvider) - .flatMap(drawable -> Arrays.stream(((SlotPropertiesProvider) drawable).getSlotProperties())); + .flatMap(drawable -> ((SlotPropertiesProvider) drawable).getSlotProperties().stream()); Stream rightSlots = this.getPage(leftPage + 1).stream() .filter(drawable -> drawable instanceof SlotPropertiesProvider) - .flatMap(drawable -> Arrays.stream(((SlotPropertiesProvider) drawable).getSlotProperties())); + .flatMap(drawable -> ((SlotPropertiesProvider) drawable).getSlotProperties().stream()); return Stream.concat(leftSlots, rightSlots).limit(16).toArray(SlotProperties[]::new); } diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/SpellData.java b/src/main/java/io/github/reoseah/magisterium/spellbook/SpellData.java deleted file mode 100644 index 4cbe400..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/SpellData.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.reoseah.magisterium.spellbook; - -import io.github.reoseah.magisterium.spellbook.element.BookElement; - -public final class SpellData { - public final BookElement[] elements; - - public SpellData(BookElement[] elements) { - this.elements = elements; - } -} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/SpellDataLoader.java b/src/main/java/io/github/reoseah/magisterium/spellbook/SpellDataLoader.java deleted file mode 100644 index 41376f8..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/SpellDataLoader.java +++ /dev/null @@ -1,148 +0,0 @@ -package io.github.reoseah.magisterium.spellbook; - -import com.google.common.collect.ImmutableMap; -import com.google.gson.*; -import com.mojang.serialization.JsonOps; -import io.github.reoseah.magisterium.spellbook.element.*; -import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; -import net.minecraft.recipe.Ingredient; -import net.minecraft.resource.JsonDataLoader; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.profiler.Profiler; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.ArrayList; -import java.util.Map; - -public class SpellDataLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { - private static final Gson GSON = new Gson(); - private static final Logger LOGGER = LogManager.getLogger(); - - public static ImmutableMap SPELLS = ImmutableMap.of(); - - public SpellDataLoader() { - super(GSON, "magisterium/spells"); - } - - @Override - public Identifier getFabricId() { - return Identifier.of("magisterium", "spells"); - } - - @Override - protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { - boolean errors = false; - var builder = ImmutableMap.builder(); - - for (Map.Entry entry : prepared.entrySet()) { - try { - var json = JsonHelper.asObject(entry.getValue(), "spell_data"); - var elements = new ArrayList(); - try { - var elementsJson = JsonHelper.getArray(json, "elements"); - - for (int i = 0; i < elementsJson.size(); i++) { - var element = readElement(JsonHelper.asObject(elementsJson.get(i), "element")); - elements.add(element); - } - } catch (Exception e) { - LOGGER.error("Error loading spell elements from {}", entry.getKey(), e); - errors = true; - } - - var spell = new SpellData(elements.toArray(new BookElement[0])); - builder.put(entry.getKey(), spell); - } catch (Exception e) { - LOGGER.error("Error loading spell data from {}", entry.getKey(), e); - errors = true; - } - } - if (errors) { - throw new IllegalStateException("Failed to load spell data"); - } - - SPELLS = builder.build(); - LOGGER.debug("Loaded {} spell data", SPELLS.size()); - } - - private static BookElement readElement(JsonObject json) { - var type = JsonHelper.getString(json, "type"); - return switch (type) { - case "heading" -> new Heading(JsonHelper.getString(json, "translation_key")); - case "paragraph" -> new Paragraph(JsonHelper.getString(json, "translation_key")); - case "page_break" -> new PageBreak(); - case "chapter" -> new BookmarkElement(JsonHelper.getString(json, "translation_key")); - case "fold" -> { - var left = readSimpleElements(JsonHelper.getArray(json, "left", new JsonArray())); - var right = readSimpleElements(JsonHelper.getArray(json, "right", new JsonArray())); - yield new Fold(left, right); - } - case "vertically_centered" -> { - var element = readElement(JsonHelper.getObject(json, "element")); - if (element instanceof SimpleBlock simple) { - yield new VerticalCenterElement(simple); - } else { - throw new JsonParseException("Cannot use special element here: " + element); - } - } - case "utterance" -> { - var translationKey = JsonHelper.getString(json, "translation_key"); - var id = Identifier.of(JsonHelper.getString(json, "id")); - int duration = JsonHelper.getInt(json, "duration"); - yield new Utterance(translationKey, id, duration); - } - case "inventory" -> { - var slotsJson = JsonHelper.getArray(json, "slots"); - - if (slotsJson.size() >= 16) { - throw new JsonParseException("Too many slots for inventory element"); - } - - var slots = new SlotProperties[slotsJson.size()]; - for (int j = 0; j < slotsJson.size(); j++) { - var slot = JsonHelper.asObject(slotsJson.get(j), "slot"); - int x = JsonHelper.getInt(slot, "x"); - int y = JsonHelper.getInt(slot, "y"); - var background = slot.has("background") ? Identifier.of(JsonHelper.getString(slot, "background")) : null; - boolean output = slot.has("output") && JsonHelper.getBoolean(slot, "output"); - var ingredient = slot.has("ingredient") ? Ingredient.ALLOW_EMPTY_CODEC.parse(JsonOps.INSTANCE, slot.get("ingredient")).getOrThrow() : null; - - slots[j] = new SlotProperties(x, y, output, ingredient, background); - } - - BookInventory.Background background = null; - if (json.has("background")) { - var backgroundJson = JsonHelper.asObject(json.get("background"), "background"); - var texture = Identifier.of(JsonHelper.getString(backgroundJson, "texture")); - int x = JsonHelper.getInt(backgroundJson, "x"); - int y = JsonHelper.getInt(backgroundJson, "y"); - int u = JsonHelper.getInt(backgroundJson, "u"); - int v = JsonHelper.getInt(backgroundJson, "v"); - int width = JsonHelper.getInt(backgroundJson, "width"); - int height = JsonHelper.getInt(backgroundJson, "height"); - background = new BookInventory.Background(texture, x, y, u, v, width, height); - } - int height = JsonHelper.getInt(json, "height", 0); - - yield new BookInventory(height, background, slots); - } - default -> throw new JsonParseException("Unknown element type: " + type); - }; - } - - public static SimpleBlock[] readSimpleElements(JsonArray elementsJson) { - var elements = new SimpleBlock[elementsJson.size()]; - for (int i = 0; i < elementsJson.size(); i++) { - var element = readElement(JsonHelper.asObject(elementsJson.get(i), "element")); - if (element instanceof SimpleBlock simple) { - elements[i] = simple; - } else { - throw new JsonParseException("Cannot use special element here: " + element); - } - } - return elements; - } -} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookElement.java b/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookElement.java deleted file mode 100644 index 098e8b5..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookElement.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.github.reoseah.magisterium.spellbook.element; - -import io.github.reoseah.magisterium.spellbook.BookLayout; -import io.github.reoseah.magisterium.spellbook.BookProperties; -import net.minecraft.client.font.TextRenderer; - -public interface BookElement { - void visit(BookLayout.Builder builder, BookProperties properties, TextRenderer textRenderer); -} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookInventory.java b/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookInventory.java deleted file mode 100644 index 54f3b50..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/BookInventory.java +++ /dev/null @@ -1,75 +0,0 @@ -package io.github.reoseah.magisterium.spellbook.element; - - -import io.github.reoseah.magisterium.spellbook.BookProperties; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.Drawable; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; - -public class BookInventory extends SimpleBlock { - public final int height; - public final SlotProperties[] slots; - public final @Nullable BookInventory.Background background; - - public BookInventory(int height, @Nullable BookInventory.Background background, SlotProperties... slots) { - this.height = height != 0 ? height : Arrays.stream(slots).mapToInt(slot -> slot.output ? slot.y + 18 + 4 : slot.y + 18).max().orElse(0) + 1; - this.background = background; - this.slots = slots; - } - - @Override - protected int getHeight(int width, TextRenderer textRenderer) { - return this.height; - } - - @Override - protected Drawable createWidget(int x, int y, BookProperties properties, int maxHeight, TextRenderer textRenderer) { - return new Widget(properties, x, y); - } - - private class Widget implements Drawable, SlotPropertiesProvider { - private final BookProperties properties; - private final int x; - private final int y; - - public Widget(BookProperties properties, int x, int y) { - this.properties = properties; - this.x = x; - this.y = y; - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - if (BookInventory.this.background != null) { - context.drawTexture( - BookInventory.this.background.texture, - x + BookInventory.this.background.x, - y + BookInventory.this.background.y, - BookInventory.this.background.u, - BookInventory.this.background.v, - BookInventory.this.background.width, - BookInventory.this.background.height); - } - for (SlotProperties slot : BookInventory.this.slots) { - if (slot.output) { - context.drawTexture(properties.texture, x + slot.x - 5, y + slot.y - 5, properties.resultSlotU, properties.resultSlotV, 26, 26); - - } else { - context.drawTexture(properties.texture, x + slot.x - 1, y + slot.y - 1, properties.slotU, properties.slotV, 18, 18); - } - } - } - - @Override - public SlotProperties[] getSlotProperties() { - return Arrays.stream(BookInventory.this.slots).map(slot -> slot.withOffset(this.x, this.y)).toArray(SlotProperties[]::new); - } - } - - public record Background(Identifier texture, int x, int y, int u, int v, int width, int height) { - } -} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotProperties.java b/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotProperties.java deleted file mode 100644 index 4b57b99..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotProperties.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.reoseah.magisterium.spellbook.element; - -import com.mojang.datafixers.util.Pair; -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.recipe.Ingredient; -import net.minecraft.screen.PlayerScreenHandler; -import net.minecraft.util.Identifier; - -public class SlotProperties { - public final int x; - public final int y; - public final boolean output; - public final Ingredient ingredient; - public final Identifier background; - - public SlotProperties(int x, int y, boolean output, Ingredient ingredient) { - this(x, y, output, ingredient, null); - } - - public SlotProperties(int x, int y, boolean output, Ingredient ingredient, Identifier background) { - this.x = x; - this.y = y; - this.background = background; - this.ingredient = ingredient; - this.output = output; - } - - public Pair getBackgroundSprite() { - return this.background != null ? Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, this.background) : null; - } - - public SlotProperties withOffset(int x, int y) { - return new SlotProperties(this.x + x, this.y + y, this.output, this.ingredient, this.background); - } - - public void write(RegistryByteBuf buf) { - buf.writeVarInt(this.x); - buf.writeVarInt(this.y); - buf.writeBoolean(this.output); - if (this.ingredient != null) { - buf.writeBoolean(true); - Ingredient.PACKET_CODEC.encode(buf, this.ingredient); - } else { - buf.writeBoolean(false); - } - } - - public static SlotProperties read(RegistryByteBuf buf) { - int x = buf.readVarInt(); - int y = buf.readVarInt(); - boolean output = buf.readBoolean(); - Ingredient ingredient = buf.readBoolean() ? Ingredient.PACKET_CODEC.decode(buf) : null; - - return new SlotProperties(x, y, output, ingredient); - } -} diff --git a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotPropertiesProvider.java b/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotPropertiesProvider.java deleted file mode 100644 index 8b8acea..0000000 --- a/src/main/java/io/github/reoseah/magisterium/spellbook/element/SlotPropertiesProvider.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.github.reoseah.magisterium.spellbook.element; - -public interface SlotPropertiesProvider { - SlotProperties[] getSlotProperties(); -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/lang/en_us.json b/src/main/resources/assets/magisterium/lang/en_us.json index caabeb9..ae9a327 100644 --- a/src/main/resources/assets/magisterium/lang/en_us.json +++ b/src/main/resources/assets/magisterium/lang/en_us.json @@ -71,11 +71,5 @@ "magisterium.spell.magisterium.dispel_magic": "Dispel Magic", "magisterium.spell.magisterium.dispel_magic.heading": "ᴅɪsᴘᴇʟ ᴍᴀɢɪᴄ", "magisterium.spell.magisterium.dispel_magic.description": "End the effects of the closest spell or magical effect.", - "magisterium.spell.magisterium.dispel_magic.utterance": "Mᴀɢɪᴀ ᴅɪssᴏʟᴠᴀᴛᴜʀ, ᴠɪɴᴄᴜʟᴀ ᴀʀᴄᴀɴᴀ ʀᴜᴍᴘᴀɴᴛᴜʀ!\n\nNɪʜɪʟ ᴍᴀɴᴇᴀᴛ, ᴀʀs ɪʟʟᴀ ᴇxsᴛɪɴɢᴜᴀᴛᴜʀ!", - "magisterium.spell.magisterium.unstable_charge": "Unstable Charge", - "magisterium.spell.magisterium.unstable_charge.heading": "ᴜɴsᴛᴀʙʟᴇ ᴄʜᴀʀɢᴇ", - "magisterium.spell.magisterium.unstable_charge.components": "ᴄᴏᴍᴘᴏɴᴇɴᴛs: one measure of nether wart and a bottle of liquid magic", - "magisterium.spell.magisterium.unstable_charge.description.0": "Infuse the book with volatile energy that releases on impact.", - "magisterium.spell.magisterium.unstable_charge.description.1": "On next enemy hit, deal massive damage and knockback. Killing blow can behead the victim.", - "magisterium.spell.magisterium.unstable_charge.utterance": "Aʀᴄᴀɴᴜᴍ ɪɴsᴛᴀʙɪʟᴇ, ɪɴᴛʀᴀ ʜᴏᴄ ᴠᴀs ᴅᴏʀᴍɪ!\n\nPᴇʀᴄᴜᴛᴇ ᴀᴜᴛ ᴘᴇʀᴄᴜᴛᴇ, ᴇᴛ ᴠɪ ᴇxᴘʟᴏsɪᴠᴀ ʟɪʙᴇʀᴀ!" + "magisterium.spell.magisterium.dispel_magic.utterance": "Mᴀɢɪᴀ ᴅɪssᴏʟᴠᴀᴛᴜʀ, ᴠɪɴᴄᴜʟᴀ ᴀʀᴄᴀɴᴀ ʀᴜᴍᴘᴀɴᴛᴜʀ!\n\nNɪʜɪʟ ᴍᴀɴᴇᴀᴛ, ᴀʀs ɪʟʟᴀ ᴇxsᴛɪɴɢᴜᴀᴛᴜʀ!" } \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/arcane_lift.json b/src/main/resources/assets/magisterium/magisterium/spells/arcane_lift.json deleted file mode 100644 index b0b1384..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/arcane_lift.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "elements": [ - { - "type": "fold", - "left": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.arcane_lift.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.arcane_lift.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.arcane_lift.description" - } - ], - "right": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.arcane_lift.heading" - }, - { - "type": "inventory", - "slots": [ - { - "x": 42, - "y": 0, - "background": "magisterium:item/placeholder/question_mark" - } - ] - }, - { - "type": "utterance", - "id": "magisterium:arcane_lift", - "translation_key": "magisterium.spell.magisterium.arcane_lift.utterance", - "duration": 8 - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/awaken_the_flame.json b/src/main/resources/assets/magisterium/magisterium/spells/awaken_the_flame.json deleted file mode 100644 index cea1c4c..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/awaken_the_flame.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "elements": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.awaken_the_flame.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.awaken_the_flame.description" - }, - { - "type": "utterance", - "id": "magisterium:awaken_the_flame", - "translation_key": "magisterium.spell.magisterium.awaken_the_flame.utterance", - "duration": 4 - }, - { - "type": "page_break" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/cold_snap.json b/src/main/resources/assets/magisterium/magisterium/spells/cold_snap.json deleted file mode 100644 index 0835c30..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/cold_snap.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "elements": [ - { - "type": "fold", - "left": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.cold_snap.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.cold_snap.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.cold_snap.description.0" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.cold_snap.description.1" - } - ], - "right": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.cold_snap.heading" - }, - { - "type": "inventory", - "slots": [ - { - "x": 33, - "y": 0, - "ingredient": { - "tag": "magisterium:cold_snap_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - }, - { - "x": 51, - "y": 0, - "ingredient": { - "tag": "magisterium:cold_snap_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - }, - { - "x": 42, - "y": 18, - "ingredient": { - "tag": "magisterium:cold_snap_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - } - ] - }, - { - "type": "utterance", - "id": "magisterium:cold_snap", - "duration": 10, - "translation_key": "magisterium.spell.magisterium.cold_snap.utterance" - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/conflagrate.json b/src/main/resources/assets/magisterium/magisterium/spells/conflagrate.json deleted file mode 100644 index 8e09946..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/conflagrate.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "elements": [ - { - "type": "fold", - "left": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.conflagrate.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.conflagrate.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.conflagrate.description.0" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.conflagrate.description.1" - } - ], - "right": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.conflagrate.heading" - }, - { - "type": "inventory", - "--comment": "triangle shape is a reference to alchemical symbol for fire, similar frost spell would use a triangle pointing down", - "slots": [ - { - "x": 42, - "y": 0, - "ingredient": { - "tag": "magisterium:conflagrate_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - }, - { - "x": 33, - "y": 18, - "ingredient": { - "tag": "magisterium:conflagrate_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - }, - { - "x": 51, - "y": 18, - "ingredient": { - "tag": "magisterium:conflagrate_ingredients" - }, - "background": "magisterium:item/placeholder/question_mark" - } - ] - }, - { - "type": "utterance", - "id": "magisterium:conflagrate", - "duration": 10, - "translation_key": "magisterium.spell.magisterium.conflagrate.utterance" - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/dispel_magic.json b/src/main/resources/assets/magisterium/magisterium/spells/dispel_magic.json deleted file mode 100644 index b92c5a4..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/dispel_magic.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "elements": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.dispel_magic.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.dispel_magic.description" - }, - { - "type": "utterance", - "id": "magisterium:dispel_magic", - "translation_key": "magisterium.spell.magisterium.dispel_magic.utterance", - "duration": 4 - }, - { - "type": "page_break" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/glyphic_ignition.json b/src/main/resources/assets/magisterium/magisterium/spells/glyphic_ignition.json deleted file mode 100644 index b493941..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/glyphic_ignition.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "elements": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.glyphic_ignition.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.glyphic_ignition.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.glyphic_ignition.description" - }, - { - "type": "utterance", - "id": "magisterium:glyphic_ignition", - "translation_key": "magisterium.spell.magisterium.glyphic_ignition.utterance", - "duration": 3 - }, - { - "type": "page_break" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/illusory_wall.json b/src/main/resources/assets/magisterium/magisterium/spells/illusory_wall.json deleted file mode 100644 index 0408d0c..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/illusory_wall.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "elements": [ - { - "type": "fold", - "left": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.illusory_wall.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.illusory_wall.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.illusory_wall.description" - } - ], - "right": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.illusory_wall.heading" - }, - { - "type": "inventory", - "slots": [ - { - "x": 42, - "y": 0, - "background": "magisterium:item/placeholder/question_mark" - } - ] - }, - { - "type": "utterance", - "id": "magisterium:illusory_wall", - "translation_key": "magisterium.spell.magisterium.illusory_wall.utterance", - "duration": 8 - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/quench_the_flame.json b/src/main/resources/assets/magisterium/magisterium/spells/quench_the_flame.json deleted file mode 100644 index d364354..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/quench_the_flame.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "elements": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.quench_the_flame.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.quench_the_flame.description" - }, - { - "type": "utterance", - "id": "magisterium:quench_the_flame", - "translation_key": "magisterium.spell.magisterium.quench_the_flame.utterance", - "duration": 4 - }, - { - "type": "page_break" - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/magisterium/spells/unstable_charge.json b/src/main/resources/assets/magisterium/magisterium/spells/unstable_charge.json deleted file mode 100644 index b53c719..0000000 --- a/src/main/resources/assets/magisterium/magisterium/spells/unstable_charge.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "elements": [ - { - "type": "fold", - "left": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.unstable_charge.heading" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.unstable_charge.components" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.unstable_charge.description.0" - }, - { - "type": "paragraph", - "translation_key": "magisterium.spell.magisterium.unstable_charge.description.1" - } - ], - "right": [ - { - "type": "heading", - "translation_key": "magisterium.spell.magisterium.unstable_charge.heading" - }, - { - "type": "inventory", - "slots": [ - { - "x": 42, - "y": 0, - "background": "magisterium:item/placeholder/question_mark" - } - ] - }, - { - "type": "utterance", - "id": "magisterium:unstable_charge", - "translation_key": "magisterium.spell.magisterium.unstable_charge.utterance", - "duration": 8 - } - ] - } - ] -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/models/item/unstable_charge_page.json b/src/main/resources/assets/magisterium/models/item/unstable_charge_page.json deleted file mode 100644 index 8277f33..0000000 --- a/src/main/resources/assets/magisterium/models/item/unstable_charge_page.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "minecraft:item/generated", - "textures": { - "layer0": "magisterium:item/unstable_charge_page" - } -} \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/arcane_lift.json b/src/main/resources/data/magisterium/recipe/arcane_lift.json index 54cc568..86bdf3b 100644 --- a/src/main/resources/data/magisterium/recipe/arcane_lift.json +++ b/src/main/resources/data/magisterium/recipe/arcane_lift.json @@ -1,5 +1,61 @@ { - "type": "magisterium:arcane_lift", - "utterance": "magisterium:arcane_lift", - "duration": 8 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:fold", + "left": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.arcane_lift.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.arcane_lift.components" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.arcane_lift.description" + } + } + ], + "right": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.arcane_lift.heading" + } + }, + { + "type": "magisterium:inventory", + "slots": [ + { + "x": 42, + "y": 0, + "background": "magisterium:item/placeholder/question_mark" + } + ] + }, + { + "type": "magisterium:utterance", + "id": "magisterium:arcane_lift", + "text": { + "translate": "magisterium.spell.magisterium.arcane_lift.utterance" + }, + "duration": 8 + } + ] + } + ], + "effects": [ + { + "type": "magisterium:arcane_lift", + "utterance": "magisterium:arcane_lift", + "duration": 8 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/awaken_the_flame.json b/src/main/resources/data/magisterium/recipe/awaken_the_flame.json index b5d2634..f26bf19 100644 --- a/src/main/resources/data/magisterium/recipe/awaken_the_flame.json +++ b/src/main/resources/data/magisterium/recipe/awaken_the_flame.json @@ -1,5 +1,35 @@ { - "type": "magisterium:awaken_the_flame", - "utterance": "magisterium:awaken_the_flame", - "duration": 4 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.awaken_the_flame.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.awaken_the_flame.description" + } + }, + { + "type": "magisterium:utterance", + "id": "magisterium:awaken_the_flame", + "text": { + "translate": "magisterium.spell.magisterium.awaken_the_flame.utterance" + }, + "duration": 4 + }, + { + "type": "magisterium:page_break" + } + ], + "effects": [ + { + "type": "magisterium:awaken_the_flame", + "utterance": "magisterium:awaken_the_flame", + "duration": 4 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/cold_snap.json b/src/main/resources/data/magisterium/recipe/cold_snap.json index d02427d..6da6a7c 100644 --- a/src/main/resources/data/magisterium/recipe/cold_snap.json +++ b/src/main/resources/data/magisterium/recipe/cold_snap.json @@ -1,5 +1,86 @@ { - "type": "magisterium:cold_snap", - "utterance": "magisterium:cold_snap", - "duration": 10 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:fold", + "left": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.components" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.description.0" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.description.1" + } + } + ], + "right": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.heading" + } + }, + { + "type": "magisterium:inventory", + "slots": [ + { + "x": 33, + "y": 0, + "ingredient": { + "tag": "magisterium:cold_snap_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + }, + { + "x": 51, + "y": 0, + "ingredient": { + "tag": "magisterium:cold_snap_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + }, + { + "x": 42, + "y": 18, + "ingredient": { + "tag": "magisterium:cold_snap_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + } + ] + }, + { + "type": "magisterium:utterance", + "id": "magisterium:cold_snap", + "duration": 10, + "text": { + "translate": "magisterium.spell.magisterium.cold_snap.utterance" + } + } + ] + } + ], + "effects": [ + { + "type": "magisterium:cold_snap", + "utterance": "magisterium:cold_snap", + "duration": 10 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/conflagrate.json b/src/main/resources/data/magisterium/recipe/conflagrate.json index 2e8592e..91c577b 100644 --- a/src/main/resources/data/magisterium/recipe/conflagrate.json +++ b/src/main/resources/data/magisterium/recipe/conflagrate.json @@ -1,5 +1,86 @@ { - "type": "magisterium:conflagrate", - "utterance": "magisterium:conflagrate", - "duration": 10 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:fold", + "left": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.components" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.description.0" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.description.1" + } + } + ], + "right": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.heading" + } + }, + { + "type": "magisterium:inventory", + "slots": [ + { + "x": 42, + "y": 0, + "ingredient": { + "tag": "magisterium:conflagrate_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + }, + { + "x": 33, + "y": 18, + "ingredient": { + "tag": "magisterium:conflagrate_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + }, + { + "x": 51, + "y": 18, + "ingredient": { + "tag": "magisterium:conflagrate_ingredients" + }, + "background": "magisterium:item/placeholder/question_mark" + } + ] + }, + { + "type": "magisterium:utterance", + "id": "magisterium:conflagrate", + "duration": 10, + "text": { + "translate": "magisterium.spell.magisterium.conflagrate.utterance" + } + } + ] + } + ], + "effects": [ + { + "type": "magisterium:conflagrate", + "utterance": "magisterium:conflagrate", + "duration": 10 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/dispel_magic.json b/src/main/resources/data/magisterium/recipe/dispel_magic.json index 35f18b3..d415879 100644 --- a/src/main/resources/data/magisterium/recipe/dispel_magic.json +++ b/src/main/resources/data/magisterium/recipe/dispel_magic.json @@ -1,5 +1,35 @@ { - "type": "magisterium:dispel_magic", - "utterance": "magisterium:dispel_magic", - "duration": 4 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.dispel_magic.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.dispel_magic.description" + } + }, + { + "type": "magisterium:utterance", + "id": "magisterium:dispel_magic", + "text": { + "translate": "magisterium.spell.magisterium.dispel_magic.utterance" + }, + "duration": 4 + }, + { + "type": "magisterium:page_break" + } + ], + "effects": [ + { + "type": "magisterium:dispel_magic", + "utterance": "magisterium:dispel_magic", + "duration": 4 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/glyphic_ignition.json b/src/main/resources/data/magisterium/recipe/glyphic_ignition.json index d7cd2b5..aa3c713 100644 --- a/src/main/resources/data/magisterium/recipe/glyphic_ignition.json +++ b/src/main/resources/data/magisterium/recipe/glyphic_ignition.json @@ -1,5 +1,41 @@ { - "type": "magisterium:glyphic_ignition", - "utterance": "magisterium:glyphic_ignition", - "duration": 3 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.glyphic_ignition.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.glyphic_ignition.components" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.glyphic_ignition.description" + } + }, + { + "type": "magisterium:utterance", + "id": "magisterium:glyphic_ignition", + "text": { + "translate": "magisterium.spell.magisterium.glyphic_ignition.utterance" + }, + "duration": 3 + }, + { + "type": "magisterium:page_break" + } + ], + "effects": [ + { + "type": "magisterium:glyphic_ignition", + "utterance": "magisterium:glyphic_ignition", + "duration": 3 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/illusory_wall.json b/src/main/resources/data/magisterium/recipe/illusory_wall.json index f3d8cd0..08bd32a 100644 --- a/src/main/resources/data/magisterium/recipe/illusory_wall.json +++ b/src/main/resources/data/magisterium/recipe/illusory_wall.json @@ -1,5 +1,61 @@ { - "type": "magisterium:illusory_wall", - "utterance": "magisterium:illusory_wall", - "duration": 8 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:fold", + "left": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.illusory_wall.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.illusory_wall.components" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.illusory_wall.description" + } + } + ], + "right": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.illusory_wall.heading" + } + }, + { + "type": "magisterium:inventory", + "slots": [ + { + "x": 42, + "y": 0, + "background": "magisterium:item/placeholder/question_mark" + } + ] + }, + { + "type": "magisterium:utterance", + "id": "magisterium:illusory_wall", + "text": { + "translate": "magisterium.spell.magisterium.illusory_wall.utterance" + }, + "duration": 8 + } + ] + } + ], + "effects": [ + { + "type": "magisterium:illusory_wall", + "utterance": "magisterium:illusory_wall", + "duration": 8 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/quench_the_flame.json b/src/main/resources/data/magisterium/recipe/quench_the_flame.json index 7610885..0657a1f 100644 --- a/src/main/resources/data/magisterium/recipe/quench_the_flame.json +++ b/src/main/resources/data/magisterium/recipe/quench_the_flame.json @@ -1,5 +1,35 @@ { - "type": "magisterium:quench_the_flame", - "utterance": "magisterium:quench_the_flame", - "duration": 4 + "type": "magisterium:spell", + "elements": [ + { + "type": "magisterium:heading", + "text": { + "translate": "magisterium.spell.magisterium.quench_the_flame.heading" + } + }, + { + "type": "magisterium:paragraph", + "text": { + "translate": "magisterium.spell.magisterium.quench_the_flame.description" + } + }, + { + "type": "magisterium:utterance", + "id": "magisterium:quench_the_flame", + "text": { + "translate": "magisterium.spell.magisterium.quench_the_flame.utterance" + }, + "duration": 4 + }, + { + "type": "magisterium:page_break" + } + ], + "effects": [ + { + "type": "magisterium:quench_the_flame", + "utterance": "magisterium:quench_the_flame", + "duration": 4 + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/magisterium/recipe/unstable_charge.json b/src/main/resources/data/magisterium/recipe/unstable_charge.json deleted file mode 100644 index 0d44240..0000000 --- a/src/main/resources/data/magisterium/recipe/unstable_charge.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "type": "magisterium:unstable_charge", - "utterance": "magisterium:unstable_charge", - "duration": 8 -} \ No newline at end of file diff --git a/src/main/resources/assets/magisterium/textures/item/unstable_charge_page.png b/unused_assets/unstable_charge_page.png similarity index 100% rename from src/main/resources/assets/magisterium/textures/item/unstable_charge_page.png rename to unused_assets/unstable_charge_page.png