Skip to content

Commit

Permalink
Added grimoires
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Mar 9, 2024
1 parent 3b7d199 commit 01a4b34
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package miyucomics.hexical.casting.patterns.spells

import at.petrak.hexcasting.api.misc.DiscoveryHandlers
import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import miyucomics.hexical.items.GrimoireItem
import miyucomics.hexical.registry.HexicalItems
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.math.Vec3d

class OpInscribeInGrimoire : SpellAction {
override val argc = 2

override fun execute(args: List<Iota>, ctx: CastingContext): Triple<RenderedSpell, Int, List<ParticleSpray>> {
val pattern = args.getPattern(0, argc);
val hex = args.getList(1, argc).toList();
val (stack, _) = ctx.getHeldItemToOperateOn { it.item is GrimoireItem }
val trueName = MishapOthersName.getTrueNameFromArgs(hex, ctx.caster)
if (trueName != null)
throw MishapOthersName(trueName)
return Triple(Spell(pattern, hex, stack), MediaConstants.SHARD_UNIT, listOf())
}

private data class Spell(val pattern: HexPattern, val hex: List<Iota>, val stack: ItemStack) : RenderedSpell {
override fun cast(ctx: CastingContext) {
GrimoireItem.writeToGrimoire(stack, pattern, hex)
}
}
}
32 changes: 32 additions & 0 deletions common/src/main/java/miyucomics/hexical/items/GrimoireItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package miyucomics.hexical.items

import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.utils.putList
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtList
import net.minecraft.server.world.ServerWorld


class GrimoireItem : Item(Settings().maxCount(1)) {
companion object {
fun writeToGrimoire (stack: ItemStack, key: HexPattern, information: List<Iota>) {
val patterns = NbtList()
for (iota in information)
patterns.add(HexIotaTypes.serialize(iota));
stack.orCreateNbt.putList(key.anglesSignature(), patterns)
}

fun getPatternInGrimoire (stack: ItemStack, key: HexPattern, world: ServerWorld): List<Iota>? {
val patsTag = stack.orCreateNbt.getList(key.anglesSignature(), NbtElement.COMPOUND_TYPE.toInt()) ?: return null;
val out = ArrayList<Iota>()
for (patTag in patsTag)
out.add(HexIotaTypes.deserialize(patTag as NbtCompound, world));
return out;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.spell.casting.CastingContext;
import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.casting.ControllerInfo;
import at.petrak.hexcasting.api.spell.casting.sideeffects.OperatorSideEffect;
import at.petrak.hexcasting.api.spell.iota.Iota;
import at.petrak.hexcasting.api.spell.iota.PatternIota;
import at.petrak.hexcasting.api.spell.math.HexDir;
import at.petrak.hexcasting.api.spell.math.HexPattern;
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import miyucomics.hexical.interfaces.CastingContextMixinInterface;
import miyucomics.hexical.items.ArchLampItem;
import miyucomics.hexical.utils.CastingUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -18,7 +25,10 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Mixin(value = CastingHarness.class)
Expand Down Expand Up @@ -56,4 +66,19 @@ private void withdrawMediaWisp(int mediaCost, boolean allowOvercast, CallbackInf
}
}
}

@Inject(method = "executeIota", at = @At("HEAD"), cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION, remap = false)
private void executeIotaMacro (Iota iota, ServerWorld world, CallbackInfoReturnable<ControllerInfo> cir) {
CastingContext ctx = hexical$harness.getCtx();
List<Iota> toExecute = new ArrayList<>(Collections.singleton(iota));
if (ctx.getSpellCircle() != null)
return;
if (!hexical$harness.getEscapeNext() && iota.getType() == HexIotaTypes.PATTERN && !((PatternIota) iota).getPattern().sigsEqual(HexPattern.fromAngles("qqqaw", HexDir.EAST))) {
HexPattern pattern = ((PatternIota) iota).getPattern();
toExecute = CastingUtils.Companion.grimoireLookup(ctx.getCaster(), pattern);
if (toExecute == null)
toExecute = new ArrayList<>(Collections.singleton(iota));
}
cir.setReturnValue(hexical$harness.executeIotas(toExecute, world));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.architectury.registry.registries.DeferredRegister
import miyucomics.hexical.Hexical
import miyucomics.hexical.items.ArchLampItem
import miyucomics.hexical.items.ConjuredStaffItem
import miyucomics.hexical.items.GrimoireItem
import miyucomics.hexical.items.LampItem
import net.minecraft.item.BlockItem
import net.minecraft.item.Item
Expand All @@ -12,12 +13,14 @@ import net.minecraft.util.registry.Registry
object HexicalItems {
private val ITEMS: DeferredRegister<Item> = DeferredRegister.create(Hexical.MOD_ID, Registry.ITEM_KEY)
val LAMP_ITEM: LampItem = LampItem()
val GRIMOIRE_ITEM: GrimoireItem = GrimoireItem()
val ARCH_LAMP_ITEM: ArchLampItem = ArchLampItem()
val CONJURED_STAFF_ITEM: ConjuredStaffItem = ConjuredStaffItem()

@JvmStatic
fun init() {
ITEMS.register("lamp") { LAMP_ITEM }
ITEMS.register("grimoire") { GRIMOIRE_ITEM }
ITEMS.register("arch_lamp") { ARCH_LAMP_ITEM }
ITEMS.register("conjured_staff") { CONJURED_STAFF_ITEM }
ITEMS.register("mage_block") { BlockItem(HexicalBlocks.MAGE_BLOCK, Item.Settings()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ object HexicalPatterns {
var ENTITY_WET: HexPattern = register(HexPattern.fromAngles("qqqqwaadq", HexDir.SOUTH_WEST), "is_wet", OpGetEntityWet())
var PLAYER_SPRINTING: HexPattern = register(HexPattern.fromAngles("eaq", HexDir.WEST), "is_sprinting", OpGetPlayerSprinting())

var WRITE_TO_GRIMOIRE: HexPattern = register(HexPattern.fromAngles("waqwa", HexDir.SOUTH_WEST), "write_grimoire", OpInscribeInGrimoire())

var PROGRAM_LAMP: HexPattern = register(HexPattern.fromAngles("wwqqqqq", HexDir.EAST), "program_lamp", OpProgramLamp())
var LAMP_POSITION: HexPattern = register(HexPattern.fromAngles("qwddedqdd", HexDir.SOUTH_WEST), "get_lamp_position", OpGetLampData(0))
var LAMP_ROTATION: HexPattern = register(HexPattern.fromAngles("qwddedadw", HexDir.SOUTH_WEST), "get_lamp_rotation", OpGetLampData(1))
Expand Down
16 changes: 16 additions & 0 deletions common/src/main/java/miyucomics/hexical/utils/CastingUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package miyucomics.hexical.utils
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.casting.CastingHarness
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.math.HexPattern
import miyucomics.hexical.interfaces.CastingContextMixinInterface
import miyucomics.hexical.items.GrimoireItem
import miyucomics.hexical.registry.HexicalItems
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.server.world.ServerWorld
import net.minecraft.text.Text

class CastingUtils {
companion object {
Expand All @@ -25,5 +28,18 @@ class CastingUtils {
return true
return false
}

fun grimoireLookup(player: ServerPlayerEntity, pattern: HexPattern): List<Iota>? {
for (stack in player.inventory.main) {
if (stack.item != HexicalItems.GRIMOIRE_ITEM)
continue
val value = GrimoireItem.getPatternInGrimoire(stack, pattern, player.getWorld())
if (value != null) {
player.sendMessage(Text.literal("WOO, IT HAD A PATTERN LIST"))
return value
}
}
return null
}
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/hexical/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"item.hexical.lamp": "Genie Lamp",
"item.hexical.grimoire": "Grimoire",
"item.hexical.arch_lamp": "Archgenie Lamp",
"item.hexical.conjured_staff": "Conjured Staff",
"block.hexical.mage_block": "Mage Block",

"subtitles.hexical.lamp_activate": "Lamp activates",
"subtitles.hexical.lamp_deactivate": "Lamp deactivates",

"hexcasting.spell.hexical:write_grimoire": "Write Grimoire",
"hexcasting.spell.hexical:program_lamp": "Educate Genie",
"hexcasting.spell.hexical:get_lamp_position": "Genie Refl.: Spatial",
"hexcasting.spell.hexical:get_lamp_rotation": "Genie Refl.: Rotational",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "minecraft:item/knowledge_book"
}
}

0 comments on commit 01a4b34

Please sign in to comment.