fix lots of ops bypassing spawn protection

This commit is contained in:
yrsegal@gmail.com 2022-04-18 20:55:00 -04:00
parent 4a172b6fb8
commit 8fc3b080ad
13 changed files with 45 additions and 6 deletions

View file

@ -34,6 +34,9 @@ object OpBreakBlock : SpellOperator {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(v)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
val blockstate = ctx.world.getBlockState(pos)
val tier =
HexConfig.Server.getOpBreakHarvestLevelBecauseForgeThoughtItWasAGoodIdeaToImplementHarvestTiersUsingAnHonestToGodTopoSort()

View file

@ -34,6 +34,10 @@ class OpConjure(val light: Boolean) : SpellOperator {
private data class Spell(val target: Vec3, val light: Boolean) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(target)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
val placeContext = DirectionalPlaceContext(ctx.world, pos, Direction.DOWN, ItemStack.EMPTY, Direction.UP)
val worldState = ctx.world.getBlockState(pos)

View file

@ -30,11 +30,15 @@ object OpCreateWater : SpellOperator {
private data class Spell(val target: Vec3) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(target)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
// Just steal bucket code lmao
val charlie = Items.WATER_BUCKET
if (charlie is BucketItem) {
// make the player null so we don't give them a usage statistic for example
charlie.emptyContents(null, ctx.world, BlockPos(target), null)
charlie.emptyContents(null, ctx.world, pos, null)
} else {
HexMod.getLogger().warn("Items.WATER_BUCKET wasn't a BucketItem?")
}

View file

@ -51,7 +51,7 @@ object OpDestroyWater : SpellOperator {
val here = todo.removeFirst()
val distFromFocus =
ctx.caster.position().distanceToSqr(Vec3(here.x.toDouble(), here.y.toDouble(), here.z.toDouble()))
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here)) {
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && ctx.world.mayInteract(ctx.caster, here)) {
// never seen this pos in my life
val fluid = ctx.world.getFluidState(here)
if (fluid != Fluids.EMPTY.defaultFluidState()) {

View file

@ -36,6 +36,9 @@ object OpEdifySapling : SpellOperator {
private data class Spell(val pos: BlockPos) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (!ctx.world.mayInteract(ctx.caster, pos))
return
val bs = ctx.world.getBlockState(pos)
for (i in 0 until 8) {
val success = AkashicTreeGrower.INSTANCE.growTree(

View file

@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.util.Mth
import net.minecraft.world.level.Explosion
import net.minecraft.world.phys.Vec3
@ -30,6 +31,9 @@ class OpExplode(val fire: Boolean) : SpellOperator {
private data class Spell(val pos: Vec3, val strength: Double, val fire: Boolean) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (!ctx.world.mayInteract(ctx.caster, BlockPos(pos)))
return
ctx.world.explode(
ctx.caster,
pos.x,

View file

@ -55,7 +55,7 @@ object OpExtinguish : SpellOperator {
here.z.toDouble()
)
) // max distance to prevent runaway shenanigans
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && distFromTarget < 10) {
if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && distFromTarget < 10 && ctx.world.mayInteract(ctx.caster, here)) {
// never seen this pos in my life
val blockstate = ctx.world.getBlockState(here)
val success =

View file

@ -35,6 +35,10 @@ object OpIgnite : SpellOperator {
private data class Spell(val target: Vec3) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(target)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
// steal petra code that steals bucket code
val maxwell = Items.FIRE_CHARGE
if (maxwell is FireChargeItem) {
@ -45,7 +49,7 @@ object OpIgnite : SpellOperator {
null,
InteractionHand.MAIN_HAND,
ItemStack(maxwell.asItem()),
BlockHitResult(target, Direction.UP, BlockPos(target), false)
BlockHitResult(target, Direction.UP, pos, false)
)
)
} else {

View file

@ -39,6 +39,10 @@ object OpPlaceBlock : SpellOperator {
private data class Spell(val vec: Vec3) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(vec)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
val bstate = ctx.world.getBlockState(pos)
if (bstate.isAir || bstate.material.isReplaceable) {
val placeeSlot = ctx.getOperativeSlot { it.item is BlockItem }

View file

@ -36,6 +36,10 @@ object OpTheOnlyReasonAnyoneDownloadedPsi : SpellOperator {
override fun cast(ctx: CastingContext) {
// https://github.com/VazkiiMods/Psi/blob/master/src/main/java/vazkii/psi/common/spell/trick/PieceTrickOvergrow.java
val pos = BlockPos(target)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
val hit = BlockHitResult(Vec3.ZERO, Direction.UP, pos, false)
val save: ItemStack = ctx.caster.getItemInHand(InteractionHand.MAIN_HAND)
ctx.caster.setItemInHand(InteractionHand.MAIN_HAND, ItemStack(Items.BONE_MEAL))

View file

@ -31,11 +31,16 @@ object OpCreateLava : SpellOperator {
private data class Spell(val target: Vec3) : RenderedSpell {
override fun cast(ctx: CastingContext) {
val pos = BlockPos(target)
if (!ctx.world.mayInteract(ctx.caster, pos))
return
// Just steal bucket code lmao
val charlie = Items.LAVA_BUCKET
if (charlie is BucketItem) {
// make the player null so we don't give them a usage statistic for example
charlie.emptyContents(null, ctx.world, BlockPos(target), null)
charlie.emptyContents(null, ctx.world, pos, null)
} else {
HexMod.getLogger().warn("Items.LAVA_BUCKET wasn't a BucketItem?")
}

View file

@ -6,6 +6,7 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import net.minecraft.core.BlockPos
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.LightningBolt
import net.minecraft.world.phys.Vec3
@ -29,6 +30,9 @@ object OpLightning : SpellOperator {
private data class Spell(val target: Vec3) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (!ctx.world.mayInteract(ctx.caster, BlockPos(target)))
return
val lightning = LightningBolt(EntityType.LIGHTNING_BOLT, ctx.world)
lightning.setPosRaw(target.x, target.y, target.z)
ctx.world.addWithUUID(lightning) // why the hell is it called this it doesnt even involve a uuid

View file

@ -1,7 +1,7 @@
{
"name": "hexcasting.entry.101",
"category": "hexcasting:casting",
"icon": "hexcasting:akashic_wand",
"icon": "hexcasting:wand_akashic",
"advancement": "hexcasting:root",
"priority": true,
"pages": [