Skip to content

Commit

Permalink
add simple cold snap spell
Browse files Browse the repository at this point in the history
  • Loading branch information
reoseah committed Oct 30, 2024
1 parent 87fb696 commit cfadc19
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/io/github/reoseah/magisterium/Magisterium.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void onInitialize() {
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:bookmark", BookmarkItem.INSTANCE);

Registry.register(Registries.DATA_COMPONENT_TYPE, "magisterium:current_page", SpellBookItem.CURRENT_PAGE);
Expand All @@ -82,7 +83,8 @@ 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.UNSTABLE_CHARGE);
entries.add(SpellPageItem.COLD_SNAP);
entries.add(BookmarkItem.INSTANCE);
}) //
.build();
Expand All @@ -100,6 +102,7 @@ public void onInitialize() {
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.SCREEN_HANDLER, "magisterium:spell_book", SpellBookScreenHandler.TYPE);
Registry.register(Registries.SCREEN_HANDLER, "magisterium:arcane_table", ArcaneTableScreenHandler.TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public static ItemStack createTestBook() {
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());
// list.set(6, SpellPageItem.UNSTABLE_CHARGE.getDefaultStack());
list.set(7, SpellPageItem.COLD_SNAP.getDefaultStack());
}));

return book;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SpellPageItem extends Item {
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 final Identifier spell;
protected final Text tooltip;
Expand Down
117 changes: 117 additions & 0 deletions src/main/java/io/github/reoseah/magisterium/recipe/ColdSnapRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package io.github.reoseah.magisterium.recipe;

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.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<ColdSnapRecipe> SERIALIZER = new SpellBookRecipe.SimpleSerializer<>(ColdSnapRecipe::new);

protected ColdSnapRecipe(Identifier utterance, int duration) {
super(utterance, duration);
}

@Override
public boolean matches(SpellBookRecipeInput input, World world) {
return true;
}

@Override
public ItemStack craft(SpellBookRecipeInput input, RegistryWrapper.WrapperLookup lookup) {
final int fullFreezeRadius = 11, maxRadius = 15;
final var map = new HashMap<BlockState, BlockState>();
map.put(Blocks.WATER.getDefaultState(), Blocks.ICE.getDefaultState());
map.put(Blocks.LAVA.getDefaultState(), Blocks.OBSIDIAN.getDefaultState());
for (var lava : Blocks.LAVA.getStateManager().getStates()) {
map.putIfAbsent(lava, Blocks.STONE.getDefaultState());
}
for (var fire : Blocks.FIRE.getStateManager().getStates()) {
map.put(fire, Blocks.AIR.getDefaultState());
}

boolean hasTargets = false;
boolean hasFrozen = false;
boolean hasFailed = false;

var world = input.player.getWorld();
var center = input.player.getBlockPos();
for (var pos : BlockPos.iterate(center.add(-maxRadius, -maxRadius, -maxRadius), center.add(maxRadius, maxRadius, maxRadius))) {
if (world.getBlockState(pos).isAir()) {
var below = world.getBlockState(pos.down());
var frozen = map.get(below);
if (frozen != null) {
hasTargets = true;

double distance = Math.sqrt(center.getSquaredDistance(pos));
double chance;
if (distance < fullFreezeRadius) {
chance = 1;
} else if (distance < maxRadius) {
chance = 1 - (distance - fullFreezeRadius) / (maxRadius - fullFreezeRadius);
} else {
chance = 0;
}
if (world.random.nextDouble() < chance) {
if (MagisteriumPlaygrounds.trySetBlockState(world, pos, frozen, input.player)) {
hasFrozen = true;
} else {
hasFailed = true;
}
}
} else if (below.isSideSolidFullSquare(world, pos.down(), Direction.UP)) {
hasTargets = true;

double distance = Math.sqrt(center.getSquaredDistance(pos));
double chance;
if (distance < fullFreezeRadius) {
chance = 1;
} else if (distance < maxRadius) {
chance = 1 - (distance - fullFreezeRadius) / (maxRadius - fullFreezeRadius);
} else {
chance = 0;
}
if (world.random.nextDouble() < chance) {
if (MagisteriumPlaygrounds.trySetBlockState(world, pos, Blocks.SNOW.getDefaultState(), input.player)) {
hasFrozen = true;
} else {
hasFailed = true;
}
}
}
}
}

if (!hasTargets) {
input.player.sendMessage(Text.translatable("magisterium.gui.no_targets"), true);
((ServerPlayerEntity) input.player).closeHandledScreen();
} else if (hasFailed && hasFrozen) {
input.player.sendMessage(Text.translatable("magisterium.gui.partial_success"), true);
} else if (hasFailed) {
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;
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/magisterium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"magisterium.spell.magisterium.conflagrate.description.0": "Unleash a burst of scorching fire, setting the entire area around the caster ablaze.",
"magisterium.spell.magisterium.conflagrate.description.1": "Additional items drastically increase the range of spell.",
"magisterium.spell.magisterium.conflagrate.utterance": "Iɢɴɪs ᴅᴏᴍɪɴᴀᴛᴜʀ, ɴɪʜɪʟ ʀᴇʟɪɴǫᴜᴇ ɪɴ ᴄɪɴᴇʀɪʙᴜs!\n\nMᴀᴛᴇʀɪᴀ ᴀʀᴅᴇᴀᴛ, sɪᴛ ꜰʟᴀᴍᴍɪs ᴄᴏɴsᴜᴍᴘᴛᴀ!\n\nOᴍɴɪᴀ ᴇᴛ sɪɴɢᴜʟᴀ ɪɴꜰʟᴀᴍᴍᴀʀᴇ!",
"magisterium.spell.magisterium.cold_snap": "Cold Snap",
"magisterium.spell.magisterium.cold_snap.heading": "ᴄᴏʟᴅ sɴᴀᴘ",
"magisterium.spell.magisterium.cold_snap.components": "ᴄᴏᴍᴘᴏɴᴇɴᴛs: up to three objects infused with cold element",
"magisterium.spell.magisterium.cold_snap.description.0": "Unleash a surge of biting frost, freezing the entire area around the caster.",
"magisterium.spell.magisterium.cold_snap.description.1": "Additional items drastically increase the range of spell.",
"magisterium.spell.magisterium.cold_snap.utterance": "Gᴇʟᴜᴍ ʀᴀᴘɪᴅᴜᴍ, ᴇx ᴄᴏʀᴅᴇ ᴍᴇᴏ ᴅɪꜰꜰᴜɴᴅᴇ!\n\nGʟᴀᴄɪᴇs ʀᴇɢɴᴇᴛ, ᴄᴀʟᴏʀ ᴀʙsᴄᴇᴅᴀᴛ!\n\nOᴍɴɪᴀ ᴛᴀɴɢᴀs ꜰʀɪɢᴏʀᴇ ᴀᴄᴜᴛᴏ!",
"magisterium.spell.magisterium.illusory_wall": "Illusory Wall",
"magisterium.spell.magisterium.illusory_wall.heading": "ɪʟʟᴜsᴏʀʏ ᴡᴀʟʟ",
"magisterium.spell.magisterium.illusory_wall.components": "ᴄᴏᴍᴘᴏɴᴇɴᴛs: material that the wall is to be made of, a line of arcane glyphs on the ground",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"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"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "magisterium:item/cold_snap_page"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/main/resources/data/magisterium/recipe/cold_snap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "magisterium:cold_snap",
"utterance": "magisterium:cold_snap",
"duration": 10
}
Binary file modified 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 cfadc19

Please sign in to comment.