diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/GoldBlockHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/GoldBlockHandler.kt new file mode 100644 index 000000000..b1c8e34df --- /dev/null +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/GoldBlockHandler.kt @@ -0,0 +1,79 @@ +/* + * AvM Staff Mod + * Copyright (c) 2024 opekope2 + * + * This mod is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This mod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this mod. If not, see . + */ + +package opekope2.avm_staff.internal.staff.handler + +import dev.architectury.event.EventResult +import net.minecraft.block.Blocks +import net.minecraft.component.type.AttributeModifierSlot +import net.minecraft.component.type.AttributeModifiersComponent +import net.minecraft.entity.LivingEntity +import net.minecraft.entity.attribute.EntityAttributes +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.item.ItemStack +import net.minecraft.util.Hand +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction +import net.minecraft.util.math.Vec3i +import net.minecraft.world.World +import opekope2.avm_staff.api.staff.StaffAttributeModifiersComponentBuilder +import opekope2.avm_staff.api.staff.StaffHandler +import opekope2.avm_staff.util.* + +class GoldBlockHandler : StaffHandler() { + override val attributeModifiers: AttributeModifiersComponent + get() = ATTRIBUTE_MODIFIERS + + override fun attackBlock( + staffStack: ItemStack, + world: World, + attacker: LivingEntity, + target: BlockPos, + side: Direction, + hand: Hand + ): EventResult { + if (world.isClient) return EventResult.pass() + if (attacker is PlayerEntity && attacker.isAttackCoolingDown) return EventResult.pass() + + val facing = attacker.facing.vector + val (x, y, z) = facing + val signedOne = x + y + z + val perpendiculars = Vec3i(x - signedOne, y - signedOne, z - signedOne) + + for (pos in BlockPos.iterate(target.subtract(perpendiculars), target.add(perpendiculars).add(facing))) { + if (!pos.isWithinDistance(target, 1.5)) continue // 3x3x3 except for corners + + val hardness = world.getBlockState(pos).getHardness(world, pos) + if (hardness == -1f || hardness > Blocks.OBSIDIAN.hardness) continue + + world.breakBlock(pos, attacker !is PlayerEntity || !attacker.abilities.creativeMode, attacker) + } + + // "Mismatch in destroy block pos" in server logs if I interrupt on server but not on client side. Nothing bad should happen, right? + return EventResult.pass() + } + + private companion object { + private val ATTRIBUTE_MODIFIERS = StaffAttributeModifiersComponentBuilder() + .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, attackDamage(14.0), AttributeModifierSlot.MAINHAND) + .add(EntityAttributes.GENERIC_ATTACK_SPEED, attackSpeed(1.0), AttributeModifierSlot.MAINHAND) + .addDefault(EntityAttributes.PLAYER_ENTITY_INTERACTION_RANGE) + .addDefault(EntityAttributes.PLAYER_BLOCK_INTERACTION_RANGE) + .build() + } +} diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt index e1d5003cd..b5a2c8819 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/VanillaStaffHandlers.kt @@ -74,6 +74,8 @@ fun registerVanillaStaffHandlers() { FurnaceHandler(RecipeType.SMOKING, SoundEvents.BLOCK_SMOKER_SMOKE) ) + GOLD_BLOCK.registerHandler(GoldBlockHandler()) + LIGHTNING_ROD.registerHandler(LightningRodHandler()) MAGMA_BLOCK.registerHandler(MagmaBlockHandler()) @@ -135,6 +137,8 @@ fun registerVanillaStaffItemRenderers() { BLAST_FURNACE.registerStaffItemRenderer(FurnaceHandler.FurnaceStaffItemRenderer(Blocks.BLAST_FURNACE)) SMOKER.registerStaffItemRenderer(FurnaceHandler.FurnaceStaffItemRenderer(Blocks.SMOKER)) + GOLD_BLOCK.registerStaffItemRenderer(Blocks.GOLD_BLOCK) + LIGHTNING_ROD.registerStaffItemRenderer(LightningRodHandler.LightningRodStaffItemRenderer()) MAGMA_BLOCK.registerStaffItemRenderer(Blocks.MAGMA_BLOCK) diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/CooldownUtil.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/CooldownUtil.kt index 1dba99a89..0d31eb7b2 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/CooldownUtil.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/CooldownUtil.kt @@ -34,4 +34,4 @@ fun PlayerEntity.isItemCoolingDown(item: Item) = itemCooldownManager.isCoolingDo * Checks if the player's attack is on cooldown. */ val PlayerEntity.isAttackCoolingDown: Boolean - get() = getAttackCooldownProgress(0f) < 1f + get() = !abilities.creativeMode && getAttackCooldownProgress(0f) < 1f diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/VectorUtil.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/VectorUtil.kt index 82133b793..cdc753c2e 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/util/VectorUtil.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/util/VectorUtil.kt @@ -22,9 +22,16 @@ package opekope2.avm_staff.util import net.minecraft.util.math.Vec3d +import net.minecraft.util.math.Vec3i import org.joml.Vector3f import org.joml.Vector3fc +inline operator fun Vec3i.component1(): Int = x + +inline operator fun Vec3i.component2(): Int = y + +inline operator fun Vec3i.component3(): Int = z + inline operator fun Vec3d.component1(): Double = x inline operator fun Vec3d.component2(): Double = y diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4eb45c30e..aa725f69d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] java = "21" # Don't forget to update *.mixins.json kotlin = "1.9.23" -staff-mod = "0.16.2" +staff-mod = "0.17.0" architectury-plugin = "3.4-SNAPSHOT" architectury-loom = "1.6-SNAPSHOT" yarn = "1.20.6+build.2"