generated from SmushyTaco/Example-Mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...od/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/SnowBlockItemHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2024 opekope2 | ||
// Staff Mod is licensed under the MIT license: https://github.com/opekope2/StaffMod/blob/main/LICENSE | ||
|
||
package opekope2.avm_staff.internal.staff_item_handler | ||
|
||
import com.mojang.serialization.Codec | ||
import net.minecraft.entity.LivingEntity | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.entity.projectile.thrown.SnowballEntity | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.sound.SoundCategory | ||
import net.minecraft.sound.SoundEvents | ||
import net.minecraft.util.Hand | ||
import net.minecraft.util.Identifier | ||
import net.minecraft.util.TypedActionResult | ||
import net.minecraft.world.World | ||
import opekope2.avm_staff.api.config.IConfiguration | ||
import opekope2.avm_staff.api.initializer.IStaffModInitializationContext | ||
import opekope2.avm_staff.api.item.StaffItemHandler | ||
|
||
class SnowBlockItemHandler : StaffItemHandler() { | ||
override val maxUseTime = 72000 | ||
|
||
override fun use( | ||
staffStack: ItemStack, | ||
world: World, | ||
user: PlayerEntity, | ||
hand: Hand | ||
): TypedActionResult<ItemStack> { | ||
user.setCurrentHand(hand) | ||
return TypedActionResult.pass(staffStack) | ||
} | ||
|
||
override fun usageTick(staffStack: ItemStack, world: World, user: LivingEntity, remainingUseTicks: Int) { | ||
if (world.isClient) return | ||
|
||
world.playSound( | ||
null, | ||
user.x, | ||
user.y, | ||
user.z, | ||
SoundEvents.ENTITY_SNOWBALL_THROW, | ||
SoundCategory.NEUTRAL, | ||
0.5f, | ||
0.4f / (world.getRandom().nextFloat() * 0.4f + 0.8f) | ||
) | ||
|
||
world.spawnEntity(SnowballEntity(world, user).apply { | ||
// TODO speed | ||
setVelocity(user, user.pitch, user.yaw, 0f, 4f, 1f) | ||
}) | ||
} | ||
|
||
// TODO | ||
private class Configuration : IConfiguration<Unit> | ||
|
||
companion object { | ||
private val CONFIG_CODEC: Codec<Configuration> = Codec.unit(::Configuration) | ||
|
||
fun registerStaffItemHandler(context: IStaffModInitializationContext) { | ||
context.registerStaffItemHandler( | ||
Identifier("snow_block"), | ||
SnowBlockItemHandler(), | ||
CONFIG_CODEC | ||
) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) 2024 opekope2 | ||
// Staff Mod is licensed under the MIT license: https://github.com/opekope2/StaffMod/blob/main/LICENSE | ||
|
||
package opekope2.avm_staff.internal.staff_item_handler | ||
|
||
import opekope2.avm_staff.api.initializer.IStaffModInitializationContext | ||
|
||
@Suppress("unused") | ||
fun register(context: IStaffModInitializationContext) { | ||
SnowBlockItemHandler.registerStaffItemHandler(context) | ||
} |
46 changes: 46 additions & 0 deletions
46
StaffMod/src/main/kotlin/opekope2/avm_staff/util/AttributeUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2024 opekope2 | ||
// Staff Mod is licensed under the MIT license: https://github.com/opekope2/StaffMod/blob/main/LICENSE | ||
|
||
@file: JvmName("AttributeUtil") | ||
|
||
package opekope2.avm_staff.util | ||
|
||
import net.minecraft.entity.attribute.EntityAttributeModifier | ||
import net.minecraft.item.Item | ||
|
||
private const val PLAYER_BASE_ATTACK_DAMAGE = 1.0 | ||
private const val PLAYER_BASE_ATTACK_SPEED = 4.0 | ||
|
||
/** | ||
* Creates an [EntityAttributeModifier], which changes the attack damage to [totalAttackDamage] after subtracting the | ||
* player's base attack damage. | ||
* | ||
* @param totalAttackDamage The desired amount of damage in half hearts | ||
*/ | ||
fun attackDamage(totalAttackDamage: Double): EntityAttributeModifier = EntityAttributeModifier( | ||
Item.ATTACK_DAMAGE_MODIFIER_ID, | ||
"Weapon modifier", | ||
totalAttackDamage - PLAYER_BASE_ATTACK_DAMAGE, | ||
EntityAttributeModifier.Operation.ADDITION | ||
) | ||
|
||
/** | ||
* Creates an [EntityAttributeModifier], which changes the attack speed to [totalAttackSpeed] after subtracting the | ||
* player's base attack speed. | ||
* | ||
* @param totalAttackSpeed The desired attack speed in attack/second | ||
*/ | ||
fun attackSpeed(totalAttackSpeed: Double): EntityAttributeModifier = EntityAttributeModifier( | ||
Item.ATTACK_SPEED_MODIFIER_ID, | ||
"Weapon modifier", | ||
totalAttackSpeed - PLAYER_BASE_ATTACK_SPEED, | ||
EntityAttributeModifier.Operation.ADDITION | ||
) | ||
|
||
/** | ||
* Creates an [EntityAttributeModifier], which changes the attack speed to the reciprocal of [totalEquipTime] after | ||
* subtracting the player's base attack speed. | ||
* | ||
* @param totalEquipTime The desired equip time in seconds | ||
*/ | ||
fun equipTime(totalEquipTime: Double): EntityAttributeModifier = attackSpeed(1.0 / totalEquipTime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters