generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/io/github/reoseah/magisterium/recipe/ColdSnapRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/resources/assets/magisterium/magisterium/spells/cold_snap.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/magisterium/models/item/cold_snap_page.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Binary file added
BIN
+388 Bytes
src/main/resources/assets/magisterium/textures/item/cold_snap_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "magisterium:cold_snap", | ||
"utterance": "magisterium:cold_snap", | ||
"duration": 10 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.