Skip to content

Commit

Permalink
custom sprites for each spell page, make all pages be separate items
Browse files Browse the repository at this point in the history
  • Loading branch information
reoseah committed Oct 29, 2024
1 parent d3abe96 commit 87fb696
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 33 deletions.
21 changes: 13 additions & 8 deletions src/main/java/io/github/reoseah/magisterium/Magisterium.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,31 @@ public void onInitialize() {

Registry.register(Registries.ITEM, "magisterium:arcane_table", new BlockItem(ArcaneTableBlock.INSTANCE, new Item.Settings()));
Registry.register(Registries.ITEM, "magisterium:spell_book", SpellBookItem.INSTANCE);
Registry.register(Registries.ITEM, "magisterium:spell_page", SpellPageItem.INSTANCE);
Registry.register(Registries.ITEM, "magisterium:awaken_the_flame_page", SpellPageItem.AWAKEN_THE_FLAME);
Registry.register(Registries.ITEM, "magisterium:quench_the_flame_page", SpellPageItem.QUENCH_THE_FLAME);
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:bookmark", BookmarkItem.INSTANCE);

Registry.register(Registries.DATA_COMPONENT_TYPE, "magisterium:current_page", SpellBookItem.CURRENT_PAGE);
Registry.register(Registries.DATA_COMPONENT_TYPE, "magisterium:page_data", SpellBookItem.PAGES);
Registry.register(Registries.DATA_COMPONENT_TYPE, "magisterium:unstable_charge", SpellBookItem.UNSTABLE_CHARGE);
Registry.register(Registries.DATA_COMPONENT_TYPE, "magisterium:spell", SpellPageItem.SPELL);

var group = FabricItemGroup.builder() //
.icon(SpellBookItem.INSTANCE::getDefaultStack) //
.displayName(Text.translatable("itemGroup.magisterium")) //
.entries((displayContext, entries) -> {
entries.add(ArcaneTableBlock.INSTANCE);
entries.add(SpellBookItem.INSTANCE);
entries.add(SpellBookItem.createTestBook());
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:awaken_the_flame")));
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:quench_the_flame")));
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:glyphic_ignition")));
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:conflagrate")));
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:illusory_wall")));
entries.add(SpellPageItem.createSpellPage(Identifier.of("magisterium:unstable_charge")));
entries.add(SpellPageItem.AWAKEN_THE_FLAME);
entries.add(SpellPageItem.QUENCH_THE_FLAME);
entries.add(SpellPageItem.GLYPHIC_IGNITION);
entries.add(SpellPageItem.CONFLAGRATE);
entries.add(SpellPageItem.ILLUSORY_WALL);
entries.add(SpellPageItem.UNSTABLE_CHARGE);
entries.add(BookmarkItem.INSTANCE);
}) //
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public static ItemStack createTestBook() {

book.set(PAGES, Util.make(DefaultedList.ofSize(18, ItemStack.EMPTY), list -> {
list.set(0, BookmarkItem.INSTANCE.getDefaultStack());
list.set(1, SpellPageItem.createSpellPage(Identifier.of("magisterium:awaken_the_flame")));
list.set(2, SpellPageItem.createSpellPage(Identifier.of("magisterium:quench_the_flame")));
list.set(3, SpellPageItem.createSpellPage(Identifier.of("magisterium:glyphic_ignition")));
list.set(4, SpellPageItem.createSpellPage(Identifier.of("magisterium:conflagrate")));
list.set(5, SpellPageItem.createSpellPage(Identifier.of("magisterium:illusory_wall")));
list.set(6, SpellPageItem.createSpellPage(Identifier.of("magisterium:unstable_charge")));
list.set(1, SpellPageItem.AWAKEN_THE_FLAME.getDefaultStack());
list.set(2, SpellPageItem.QUENCH_THE_FLAME.getDefaultStack());
list.set(3, SpellPageItem.GLYPHIC_IGNITION.getDefaultStack());
list.set(4, SpellPageItem.CONFLAGRATE.getDefaultStack());
list.set(5, SpellPageItem.ILLUSORY_WALL.getDefaultStack());
list.set(6, SpellPageItem.UNSTABLE_CHARGE.getDefaultStack());
}));

return book;
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/io/github/reoseah/magisterium/item/SpellPageItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.reoseah.magisterium.item;

import net.minecraft.component.ComponentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType;
Expand All @@ -11,29 +10,31 @@
import java.util.List;

public class SpellPageItem extends Item {
public static final ComponentType<Identifier> SPELL = ComponentType.<Identifier>builder().codec(Identifier.CODEC).packetCodec(Identifier.PACKET_CODEC).build();
public static final Item AWAKEN_THE_FLAME = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:awaken_the_flame"));
public static final Item QUENCH_THE_FLAME = new SpellPageItem(new Item.Settings().maxCount(16), Identifier.of("magisterium:quench_the_flame"));
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 INSTANCE = new SpellPageItem(new Item.Settings().maxCount(16));
public final Identifier spell;
protected final Text tooltip;

protected SpellPageItem(Settings settings) {
protected SpellPageItem(Settings settings, Identifier spell) {
super(settings);
this.spell = spell;
this.tooltip = Text.translatable("magisterium.spell." + spell.getNamespace() + "." + spell.getPath()).formatted(Formatting.GRAY);
}

public static ItemStack createSpellPage(Identifier spell) {
ItemStack page = new ItemStack(INSTANCE);

page.set(SPELL, spell);

return page;
@Override
protected String getOrCreateTranslationKey() {
return "item.magisterium.spell_page";
}

@Override
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
super.appendTooltip(stack, context, tooltip, type);

Identifier spell = stack.get(SPELL);
if (spell != null) {
tooltip.add(Text.translatable("magisterium.spell." + spell.getNamespace() + "." + spell.getPath()).formatted(Formatting.GRAY));
}
tooltip.add(this.tooltip);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private void buildPages() {

var builder = new BookLayout.Builder(this.properties);
for (ItemStack stack : pages) {
if (stack.isOf(SpellPageItem.INSTANCE) && stack.contains(SpellPageItem.SPELL)) {
var id = stack.get(SpellPageItem.SPELL);
if (stack.getItem() instanceof SpellPageItem spellPage) {
var id = spellPage.spell;
if (id == null) {
LOGGER.warn("Spell id not found in stack {}", stack);
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/awaken_the_flame_page"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/spell_page_1"
"layer0": "magisterium:item/conflagrate_page"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/glyphic_ignition_page"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/illusory_wall_page"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/quench_the_flame_page"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/unstable_charge_page"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"values": [
"magisterium:spell_page",
"magisterium:bookmark"
"magisterium:bookmark",
"#magisterium:spell_pages"
]
}
10 changes: 10 additions & 0 deletions src/main/resources/data/magisterium/tags/item/spell_pages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"values": [
"magisterium:awaken_the_flame_page",
"magisterium:quench_the_flame_page",
"magisterium:glyphic_ignition_page",
"magisterium:conflagrate_page",
"magisterium:illusory_wall_page",
"magisterium:unstable_charge_page"
]
}
Binary file added unused_assets/spell pages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 87fb696

Please sign in to comment.