add more block protection hooks

Port of 96e4569b24
This commit is contained in:
yrsegal@gmail.com 2022-07-24 21:45:46 -04:00
parent 8f6bddb25c
commit 1424cff844
6 changed files with 107 additions and 89 deletions

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.api.spell.iota.Iota
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.particles.ParticleTypes
@ -60,6 +61,13 @@ object OpDestroyWater : SpellAction {
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(
@ -102,6 +110,7 @@ object OpDestroyWater : SpellAction {
}
}
}
}
if (successes > 0) {
ctx.world.playSound(

View file

@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.spell.getBlockPos
import at.petrak.hexcasting.api.spell.iota.Iota
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
@ -34,7 +35,9 @@ object OpEdifySapling : SpellAction {
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

@ -5,6 +5,7 @@ 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.ktxt.UseOnContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.particles.ParticleTypes
@ -55,6 +56,7 @@ object OpExtinguish : SpellAction {
) {
// 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 -> {
@ -62,7 +64,8 @@ object OpExtinguish : SpellAction {
}
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(
@ -105,6 +108,7 @@ object OpExtinguish : SpellAction {
}
}
}
}
if (successes > 0) {
ctx.world.playSound(

View file

@ -9,6 +9,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getBlockPos
import at.petrak.hexcasting.api.spell.iota.Iota
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
@ -36,12 +37,13 @@ object OpIgnite : SpellAction {
private data class Spell(val pos: BlockPos) : RenderedSpell {
override fun cast(ctx: CastingContext) {
// TODO should we do these checks in the action part of the spell
if (!ctx.world.mayInteract(ctx.caster, pos))
return
// steal petra code that steals bucket code
val maxwell = Items.FIRE_CHARGE
// TODO should we do these checks in the action part of the spell
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(

View file

@ -97,7 +97,7 @@ tasks.withType(JavaCompile) {
source(project(":Common").sourceSets.main.allSource)
}
compileKotlin {
source(project(":Common").sourceSets.main.allSource)
source(project(":Common").sourceSets.main.kotlin)
}
sourcesJar {

View file

@ -155,10 +155,10 @@ tasks.withType(JavaCompile) {
source(project(":Common").sourceSets.main.allSource)
}
compileKotlin {
source(project(":Common").sourceSets.main.allSource)
source(project(":Common").sourceSets.main.kotlin)
}
compileTestKotlin {
source(project(":Common").sourceSets.main.allSource)
source(project(":Common").sourceSets.main.kotlin)
}