add more block protection hooks

This commit is contained in:
yrsegal@gmail.com 2022-07-24 20:30:58 -04:00
parent 54f0007315
commit 96e4569b24
4 changed files with 90 additions and 75 deletions

View file

@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.particles.ParticleTypes
@ -58,6 +59,13 @@ object OpDestroyWater : SpellOperator {
val fluid = ctx.world.getFluidState(here)
if (fluid != Fluids.EMPTY.defaultFluidState()) {
val blockstate = ctx.world.getBlockState(here)
if (IXplatAbstractions.INSTANCE.isBreakingAllowed(
ctx.world,
here,
blockstate,
ctx.caster
)
) {
val material = blockstate.material
val success =
if (blockstate.block is BucketPickup && !(blockstate.block as BucketPickup).pickupBlock(
@ -100,6 +108,7 @@ object OpDestroyWater : SpellOperator {
}
}
}
}
if (successes > 0) {
ctx.world.playSound(

View file

@ -1,14 +1,11 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.getChecked
import at.petrak.hexcasting.api.spell.ParticleSpray
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.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapBadBlock
import at.petrak.hexcasting.common.misc.AkashicTreeGrower
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.tags.BlockTags
import net.minecraft.world.phys.Vec3
@ -37,7 +34,9 @@ object OpEdifySapling : SpellOperator {
private data class Spell(val pos: BlockPos) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (!ctx.world.mayInteract(ctx.caster, pos))
val blockstate = ctx.world.getBlockState(pos)
if (!ctx.world.mayInteract(ctx.caster, pos) ||
!IXplatAbstractions.INSTANCE.isBreakingAllowed(ctx.world, pos, blockstate, ctx.caster))
return
val bs = ctx.world.getBlockState(pos)

View file

@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
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.core.particles.ParticleTypes
@ -56,6 +57,7 @@ object OpExtinguish : SpellOperator {
) {
// never seen this pos in my life
val blockstate = ctx.world.getBlockState(here)
if (IXplatAbstractions.INSTANCE.isBreakingAllowed(ctx.world, here, blockstate, ctx.caster)) {
val success =
when (blockstate.block) {
is BaseFireBlock -> {
@ -63,7 +65,8 @@ object OpExtinguish : SpellOperator {
}
is CampfireBlock -> {
if (blockstate.getValue(CampfireBlock.LIT)) { // check if campfire is lit before putting it out
val wilson = Items.WOODEN_SHOVEL // summon shovel from the ether to do our bidding
val wilson =
Items.WOODEN_SHOVEL // summon shovel from the ether to do our bidding
val hereVec = Vec3.atCenterOf(here)
wilson.useOn(
UseOnContext(
@ -106,6 +109,7 @@ object OpExtinguish : SpellOperator {
}
}
}
}
if (successes > 0) {
ctx.world.playSound(

View file

@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.misc.ManaConstants
import at.petrak.hexcasting.api.spell.*
import at.petrak.hexcasting.api.spell.casting.CastingContext
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.world.InteractionHand
@ -33,11 +34,13 @@ 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 (!ctx.world.mayInteract(ctx.caster, pos) || !IXplatAbstractions.INSTANCE.isPlacingAllowed(ctx.world, pos, ItemStack(maxwell), ctx.caster))
return
if (maxwell is FireChargeItem) {
// help
maxwell.useOn(
@ -45,7 +48,7 @@ object OpIgnite : SpellOperator {
ctx.world,
null,
InteractionHand.MAIN_HAND,
ItemStack(maxwell.asItem()),
ItemStack(maxwell),
BlockHitResult(target, Direction.UP, pos, false)
)
)