Skip to content

Commit

Permalink
progress on enchanted candlestick pages
Browse files Browse the repository at this point in the history
  • Loading branch information
reoseah committed Dec 7, 2024
1 parent 0a66dc7 commit bf783e5
Show file tree
Hide file tree
Showing 68 changed files with 393 additions and 151 deletions.
8 changes: 6 additions & 2 deletions src/main/java/io/github/reoseah/magisterium/Magisterium.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import io.github.reoseah.magisterium.data.BookLoader;
import io.github.reoseah.magisterium.data.SpellEffectLoader;
import io.github.reoseah.magisterium.data.SpellPageLoader;
import io.github.reoseah.magisterium.data.effect.*;
import io.github.reoseah.magisterium.data.element.*;
import io.github.reoseah.magisterium.item.*;
import io.github.reoseah.magisterium.magisterium.effect.*;
import io.github.reoseah.magisterium.magisterium.page.element.*;
import io.github.reoseah.magisterium.network.c2s.SpellBookScreenStatePayload;
import io.github.reoseah.magisterium.network.c2s.StartSpellPayload;
import io.github.reoseah.magisterium.network.c2s.StopSpellPayload;
Expand All @@ -22,6 +22,7 @@
import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import io.github.reoseah.magisterium.screen.ArcaneTableScreenHandler;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.util.WorldUtil;
import io.github.reoseah.magisterium.world.state.ActiveSpellTracker;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
Expand Down Expand Up @@ -88,6 +89,7 @@ public void onInitialize() {
Registry.register(Registries.ITEM, "magisterium:spell_book", SpellBookItem.SPELL_BOOK);
Registry.register(Registries.ITEM, "magisterium:elements_of_pyromancy", SpellBookItem.ELEMENTS_OF_PYROMANCY);
Registry.register(Registries.ITEM, "magisterium:lesser_arcanum", SpellBookItem.LESSER_ARCANUM);
Registry.register(Registries.ITEM, "magisterium:enchanted_candlestick_page", PageItem.ENCHANTED_CANDLESTICK);
Registry.register(Registries.ITEM, "magisterium:awaken_the_flame_page", PageItem.AWAKEN_THE_FLAME);
Registry.register(Registries.ITEM, "magisterium:quench_the_flame_page", PageItem.QUENCH_THE_FLAME);
Registry.register(Registries.ITEM, "magisterium:glyphic_ignition_page", PageItem.GLYPHIC_IGNITION);
Expand Down Expand Up @@ -115,6 +117,7 @@ public void onInitialize() {
.entries((displayContext, entries) -> {
entries.add(ArcaneTableBlock.INSTANCE);
entries.add(ArcaneDetectorBlock.INSTANCE);
entries.add(EnchantedCandlestickBlock.INSTANCE);
entries.add(SpellBookItem.SPELL_BOOK);

var filledBook = new ItemStack(SpellBookItem.SPELL_BOOK);
Expand Down Expand Up @@ -201,6 +204,7 @@ public void onInitialize() {
Registry.register(SpellEffect.REGISTRY, "magisterium:dispel_magic", DispelMagicEffect.CODEC);
Registry.register(SpellEffect.REGISTRY, "magisterium:magic_barrier", MagicBarrierEffect.CODEC);
Registry.register(SpellEffect.REGISTRY, "magisterium:command", ExecuteCommandEffect.CODEC);
Registry.register(SpellEffect.REGISTRY, "magisterium:craft_item", CraftItemEffect.CODEC);

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(SpellPageLoader.ID, SpellPageLoader::new);
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(SpellEffectLoader.ID, SpellEffectLoader::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import io.github.reoseah.magisterium.block.ArcaneTableBlock;
import io.github.reoseah.magisterium.block.EnchantedCandlestickBlock;
import io.github.reoseah.magisterium.block.GlyphBlock;
import io.github.reoseah.magisterium.block.MagicBarrierBlock;
import io.github.reoseah.magisterium.block.entity.ArcaneDetectorBlockEntity;
import io.github.reoseah.magisterium.block.entity.IllusoryWallBlockEntity;
import io.github.reoseah.magisterium.client.render.ArcaneResonatorRenderer;
import io.github.reoseah.magisterium.client.render.IllusoryWallBlockEntityRenderer;
import io.github.reoseah.magisterium.data.BookLoader;
import io.github.reoseah.magisterium.data.SpellPage;
import io.github.reoseah.magisterium.magisterium.page.SpellPage;
import io.github.reoseah.magisterium.network.s2c.FinishSpellPayload;
import io.github.reoseah.magisterium.network.s2c.SpellParticlePayload;
import io.github.reoseah.magisterium.network.s2c.SyncronizeBookDataPayload;
Expand Down Expand Up @@ -63,10 +62,7 @@ public void onInitializeClient() {
ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.BARRIER_SPARK, GlyphParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(MagisteriumParticles.BARRIER_ENERGY, GlyphParticle.Factory::new);

ClientPlayNetworking.registerGlobalReceiver(SyncronizeBookDataPayload.ID, (payload, context) -> {
var books = payload.books();
BookLoader.setClientSide(books);
});
ClientPlayNetworking.registerGlobalReceiver(SyncronizeBookDataPayload.ID, (payload, context) -> BookLoader.setClientSide(payload.books()));
ClientPlayNetworking.registerGlobalReceiver(SyncronizePageDataPayload.ID, (payload, context) -> pages = payload.pages());
ClientPlayNetworking.registerGlobalReceiver(SpellParticlePayload.ID, MagisteriumClient::spawnSpellParticles);
ClientPlayNetworking.registerGlobalReceiver(FinishSpellPayload.ID, MagisteriumClient::finishSpell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.serialization.MapCodec;
import io.github.reoseah.magisterium.block.entity.ArcaneDetectorBlockEntity;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.world.state.ActiveSpellTracker;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
Expand All @@ -12,7 +11,6 @@
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
Expand All @@ -30,7 +28,7 @@

import java.util.UUID;

public class ArcaneDetectorBlock extends BlockWithEntity implements SpellActivityListener {
public class ArcaneDetectorBlock extends BlockWithEntity implements ActiveSpellTracker.ActiveSpellListener {
public static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 2, 16);
public static final BooleanProperty POWERED = Properties.POWERED;
public static final MapCodec<ArcaneDetectorBlock> CODEC = createCodec(ArcaneDetectorBlock::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.reoseah.magisterium.block;

import io.github.reoseah.magisterium.MagisteriumSounds;
import io.github.reoseah.magisterium.data.effect.SpellWorldChangeTracker;
import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.block.*;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.block;

import io.github.reoseah.magisterium.data.effect.SpellWorldChangeTracker;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.util.math.BlockPos;

public interface CustomDispelBehavior {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.block;

import io.github.reoseah.magisterium.data.effect.WorldUtil;
import io.github.reoseah.magisterium.util.WorldUtil;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
Expand All @@ -20,7 +20,6 @@
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
Expand All @@ -31,6 +30,7 @@
public class EnchantedCandlestickBlock extends Block {
public static final VoxelShape SHAPE = Block.createCuboidShape(6, 0, 6, 10, 16, 10);
public static final BooleanProperty LIT = Properties.LIT;

private static final TagKey<Block> AFFECTED_BLOCKS = TagKey.of(RegistryKeys.BLOCK, Identifier.of("magisterium:enchanted_candlestick_affectable"));

public static final Block INSTANCE = new EnchantedCandlestickBlock(Settings.create() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.mojang.serialization.MapCodec;
import io.github.reoseah.magisterium.MagisteriumSounds;
import io.github.reoseah.magisterium.block.entity.MagicBarrierBlockEntity;
import io.github.reoseah.magisterium.data.effect.SpellWorldChangeTracker;
import io.github.reoseah.magisterium.particle.MagisteriumParticles;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.reoseah.magisterium.block.entity;

import io.github.reoseah.magisterium.block.ArcaneDetectorBlock;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.world.state.ActiveSpellTracker;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/github/reoseah/magisterium/data/BookLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.data;

import io.github.reoseah.magisterium.data.book.BookData;
import io.github.reoseah.magisterium.magisterium.book.Book;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.resource.JsonDataLoader;
Expand All @@ -10,28 +10,28 @@

import java.util.Map;

public class BookLoader extends JsonDataLoader<BookData> implements IdentifiableResourceReloadListener {
public class BookLoader extends JsonDataLoader<Book> implements IdentifiableResourceReloadListener {
public static final Identifier ID = Identifier.of("magisterium", "book");

public static BookLoader instance;

public Map<Identifier, BookData> books;
public Map<Identifier, Book> books;

public BookLoader(RegistryWrapper.WrapperLookup registries) {
super(registries, BookData.CODEC.codec(), "magisterium/books");
super(registries, Book.CODEC.codec(), "magisterium/books");
instance = this;
}

public BookLoader() {
super(BookData.CODEC.codec(), "magisterium/books");
super(Book.CODEC.codec(), "magisterium/books");
instance = this;
}

public static BookLoader getInstance() {
return instance;
}

public static void setClientSide(Map<Identifier, BookData> books) {
public static void setClientSide(Map<Identifier, Book> books) {
instance = new BookLoader();
instance.books = books;
}
Expand All @@ -46,7 +46,7 @@ public Identifier getFabricId() {
}

@Override
protected void apply(Map<Identifier, BookData> prepared, ResourceManager manager, Profiler profiler) {
protected void apply(Map<Identifier, Book> prepared, ResourceManager manager, Profiler profiler) {
this.books = prepared;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.reoseah.magisterium.data;

import io.github.reoseah.magisterium.data.effect.SpellEffect;
import io.github.reoseah.magisterium.magisterium.effect.SpellEffect;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.resource.JsonDataLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.reoseah.magisterium.data;

import io.github.reoseah.magisterium.magisterium.page.SpellPage;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.resource.JsonDataLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PageItem extends Item {
.build();

// TODO: on 1.21.4, have just single item and change texture through the new item model overrides?
public static final Item ENCHANTED_CANDLESTICK = createSpellPage("enchant_candlestick");
public static final Item AWAKEN_THE_FLAME = createSpellPage("awaken_the_flame");
public static final Item QUENCH_THE_FLAME = createSpellPage("quench_the_flame");
public static final Item GLYPHIC_IGNITION = createSpellPage("glyphic_ignition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class SpellBookItem extends Item {
public static final Item ELEMENTS_OF_PYROMANCY = create("elements_of_pyromancy", settings -> {
var pages = DefaultedList.ofSize(18, ItemStack.EMPTY);
pages.set(0, PageItem.ELEMENTS_OF_PYROMANCY.getDefaultStack());
pages.set(1, PageItem.AWAKEN_THE_FLAME.getDefaultStack());
pages.set(2, PageItem.QUENCH_THE_FLAME.getDefaultStack());
pages.set(3, PageItem.GLYPHIC_IGNITION.getDefaultStack());
pages.set(4, PageItem.CONFLAGRATE.getDefaultStack());
pages.set(1, PageItem.ENCHANTED_CANDLESTICK.getDefaultStack());
// pages.set(2, PageItem.QUENCH_THE_FLAME.getDefaultStack());
pages.set(2, PageItem.GLYPHIC_IGNITION.getDefaultStack());
pages.set(3, PageItem.CONFLAGRATE.getDefaultStack());

return new SpellBookItem(settings.rarity(Rarity.UNCOMMON).component(CONTENTS, pages));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reoseah.magisterium.data.book;
package io.github.reoseah.magisterium.magisterium.book;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
Expand All @@ -7,18 +7,17 @@
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;

public class BookData {
public static final MapCodec<BookData> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( //
public class Book {
public static final MapCodec<Book> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( //
Codec.BOOL.fieldOf("support_insertion").forGetter(data -> data.supportInsertion), //
BookAppearance.CODEC.fieldOf("appearance").forGetter(data -> data.appearance) //
).apply(instance, BookData::new));

public static final PacketCodec<RegistryByteBuf, BookData> PACKET_CODEC = PacketCodecs.registryCodec(CODEC.codec());
).apply(instance, Book::new));
public static final PacketCodec<RegistryByteBuf, Book> PACKET_CODEC = PacketCodecs.registryCodec(CODEC.codec());

public final boolean supportInsertion;
public final BookAppearance appearance;

public BookData(boolean supportInsertion, BookAppearance appearance) {
public Book(boolean supportInsertion, BookAppearance appearance) {
this.supportInsertion = supportInsertion;
this.appearance = appearance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reoseah.magisterium.data.book;
package io.github.reoseah.magisterium.magisterium.book;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.github.reoseah.magisterium.data.effect;
package io.github.reoseah.magisterium.magisterium.effect;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.reoseah.magisterium.block.ArcaneLiftBlock;
import io.github.reoseah.magisterium.screen.SpellBookInventory;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import net.minecraft.inventory.Inventory;
import io.github.reoseah.magisterium.util.SpellEffectUtil;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.dynamic.Codecs;

Expand All @@ -27,7 +29,7 @@ public MapCodec<? extends SpellEffect> getCodec() {
}

@Override
public void finish(ServerPlayerEntity player, Inventory inventory, SpellBookScreenHandler.Context screenContext) {
public void finish(ServerPlayerEntity player, SpellBookInventory inventory, SpellBookScreenHandler.Context screenContext) {
var world = player.getWorld();
var pos = player.getBlockPos();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.reoseah.magisterium.data.effect;
package io.github.reoseah.magisterium.magisterium.effect;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.reoseah.magisterium.screen.SpellBookInventory;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.block.Block;
import net.minecraft.inventory.Inventory;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -35,7 +36,7 @@ public MapCodec<? extends SpellEffect> getCodec() {
}

@Override
public void finish(ServerPlayerEntity player, Inventory inventory, SpellBookScreenHandler.Context screenContext) {
public void finish(ServerPlayerEntity player, SpellBookInventory inventory, SpellBookScreenHandler.Context screenContext) {
var world = player.getWorld();
var center = player.getBlockPos();
var helper = new SpellWorldChangeTracker(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.reoseah.magisterium.data.effect;
package io.github.reoseah.magisterium.magisterium.effect;

import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.reoseah.magisterium.screen.SpellBookInventory;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.util.SpellEffectUtil;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.inventory.Inventory;
import net.minecraft.recipe.Ingredient;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -60,7 +62,7 @@ public MapCodec<? extends SpellEffect> getCodec() {
}

@Override
public void finish(ServerPlayerEntity player, Inventory inventory, SpellBookScreenHandler.Context screenContext) {
public void finish(ServerPlayerEntity player, SpellBookInventory inventory, SpellBookScreenHandler.Context screenContext) {
int bonusRange = 0;
for (int i = 0; i < inventory.size(); i++) {
var stack = inventory.getStack(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.reoseah.magisterium.data.effect;
package io.github.reoseah.magisterium.magisterium.effect;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.reoseah.magisterium.screen.SpellBookInventory;
import io.github.reoseah.magisterium.screen.SpellBookScreenHandler;
import io.github.reoseah.magisterium.util.SpellEffectUtil;
import io.github.reoseah.magisterium.util.SpellWorldChangeTracker;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.Blocks;
import net.minecraft.inventory.Inventory;
import net.minecraft.recipe.Ingredient;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Pair;
Expand Down Expand Up @@ -54,7 +56,7 @@ public MapCodec<? extends SpellEffect> getCodec() {
}

@Override
public void finish(ServerPlayerEntity player, Inventory inventory, SpellBookScreenHandler.Context screenContext) {
public void finish(ServerPlayerEntity player, SpellBookInventory inventory, SpellBookScreenHandler.Context screenContext) {
int bonusRange = 0;
for (int i = 0; i < inventory.size(); i++) {
var stack = inventory.getStack(i);
Expand Down
Loading

0 comments on commit bf783e5

Please sign in to comment.