Skip to content

Commit

Permalink
Merge Staff Mod 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
opekope2 authored Aug 8, 2024
2 parents 3d1ae6a + 5af3c9e commit f5248ef
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit f5248ef

Please sign in to comment.