Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Ignite spell compatible with entities #746

Merged
merged 5 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import at.petrak.hexcasting.api.casting.RenderedSpell
import at.petrak.hexcasting.api.casting.castables.SpellAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getBlockPos
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.EntityIota
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.Vec3Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapInvalidIota
import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.ktxt.UseOnContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.InteractionHand
import net.minecraft.world.entity.Entity
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
Expand All @@ -25,17 +30,30 @@ object OpIgnite : SpellAction {
args: List<Iota>,
env: CastingEnvironment
): SpellAction.Result {
val target = args.getBlockPos(0, argc)
env.assertPosInRangeForEditing(target)

return SpellAction.Result(
Spell(target),
MediaConstants.DUST_UNIT,
listOf(ParticleSpray.burst(Vec3.atCenterOf(BlockPos(target)), 1.0))
)
when (val target = args[0]) {
is EntityIota -> {
val entity = args.getEntity(0, argc)
env.assertEntityInRange(entity)
return SpellAction.Result(
EntitySpell(entity),
MediaConstants.DUST_UNIT,
listOf(ParticleSpray.burst(entity.position(), 1.0))
)
}
is Vec3Iota -> {
val block = args.getBlockPos(0, argc)
env.assertPosInRangeForEditing(block)
return SpellAction.Result(
BlockSpell(block),
MediaConstants.DUST_UNIT,
listOf(ParticleSpray.burst(Vec3.atCenterOf(BlockPos(block)), 1.0))
)
}
else -> throw MishapInvalidIota.ofType(target, 0, "entity_or_vector")
}
}

private data class Spell(val pos: BlockPos) : RenderedSpell {
private data class BlockSpell(val pos: BlockPos) : RenderedSpell {
override fun cast(env: CastingEnvironment) {
// help
if (!tryToClick(env, pos, Items.FIRE_CHARGE)) {
Expand All @@ -56,4 +74,10 @@ object OpIgnite : SpellAction {
).consumesAction()
}
}
}

private data class EntitySpell(val entity: Entity) : RenderedSpell {
override fun cast(env: CastingEnvironment) {
entity.setSecondsOnFire(8)
}
}
}
miyucomics marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@
living: "a living entity",
},

entity_or_vector: "an entity or a vector",

unknown: "(unknown, uh-oh, this is a bug)",
},

Expand Down Expand Up @@ -1834,7 +1836,7 @@
conjure_light: "Conjure a magical light that softly glows with my pigment at the given position. Costs about one $(l:items/amethyst)$(item)Amethyst Dust/$.",
bonemeal: "Encourage a plant or sapling at the target position to grow, as if $(item)Bonemeal/$ was applied. Costs a bit more than one $(l:items/amethyst)$(item)Amethyst Dust/$.",
edify: "Forcibly infuse _media into the sapling at the target position, causing it to grow into an $(l:items/edified)$(thing)Edified Tree/$. Costs about one $(l:items/amethyst)$(item)Charged Amethyst/$.",
ignite: "Start a fire on top of the given location, as if a $(item)Fire Charge/$ was applied. Costs about one $(l:items/amethyst)$(item)Amethyst Dust/$.",
ignite: "Start a fire on top of the given location, as if a $(item)Fire Charge/$ was applied, or sets fire to a creature. Costs about one $(l:items/amethyst)$(item)Amethyst Dust/$.",
extinguish: "Extinguish blocks in a large area. Costs about six $(l:items/amethyst)$(item)Amethyst Dust/$.",
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"type": "hexcasting:pattern",
"op_id": "hexcasting:ignite",
"anchor": "hexcasting:ignite",
"input": "vector",
"input": "entity | vector",
"output": "",
"text": "hexcasting.page.blockworks.ignite"
},
Expand All @@ -87,4 +87,4 @@
"text": "hexcasting.page.blockworks.extinguish"
}
]
}
}
Loading