From c50f5a5fd29605f8e7986366a656e769cab96b1f Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 3 Aug 2024 16:33:17 +0200 Subject: [PATCH 1/4] Allow left click spam in creative --- .../src/main/kotlin/opekope2/avm_staff/util/CooldownUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 797b7a5e89fe07bb9827199ebaee13b4cdb42fcc Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 3 Aug 2024 18:04:47 +0200 Subject: [PATCH 2/4] Add gold block to staff --- .../staff/handler/GoldBlockHandler.kt | 78 +++++++++++++++++++ .../staff/handler/VanillaStaffHandlers.kt | 4 + .../opekope2/avm_staff/util/VectorUtil.kt | 7 ++ 3 files changed, 89 insertions(+) create mode 100644 StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/GoldBlockHandler.kt 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..5727dafb7 --- /dev/null +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff/handler/GoldBlockHandler.kt @@ -0,0 +1,78 @@ +/* + * 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) + } + + return EventResult.interruptTrue() + } + + 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/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 From 46461e54ec80bc302c986d09ad9560b405a6c271 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sat, 3 Aug 2024 18:56:19 +0200 Subject: [PATCH 3/4] Work around "Mismatch in destroy block pos" --- .../avm_staff/internal/staff/handler/GoldBlockHandler.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 5727dafb7..b1c8e34df 100644 --- 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 @@ -64,7 +64,8 @@ class GoldBlockHandler : StaffHandler() { world.breakBlock(pos, attacker !is PlayerEntity || !attacker.abilities.creativeMode, attacker) } - return EventResult.interruptTrue() + // "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 { From 5af3c9e3ae92e4eea94b53b45c7e4f2557ec3dda Mon Sep 17 00:00:00 2001 From: opekope2 Date: Sun, 4 Aug 2024 01:03:00 +0200 Subject: [PATCH 4/4] Bump version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"