Skip to content

Commit 21a2b25

Browse files
committed
added very small chance fo dropping mainhand item #90
1 parent 9a2e6bb commit 21a2b25

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

src/main/kotlin/dev/sterner/witchery/core/registry/WitcheryPayloads.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ object WitcheryPayloads {
105105
) { payload, ctx ->
106106
payload.handleOnClient(ctx)
107107
}
108+
registrar.playToClient(
109+
DropItemS2CPayload.ID,
110+
DropItemS2CPayload.STREAM_CODEC
111+
) { payload, ctx ->
112+
payload.handleOnClient(ctx)
113+
}
108114
registrar.playToClient(
109115
OptimizedSelectiveSyncPayload.ID,
110116
OptimizedSelectiveSyncPayload.STREAM_CODEC

src/main/kotlin/dev/sterner/witchery/features/curse/CurseOfMisfortune.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package dev.sterner.witchery.features.curse
33
import dev.sterner.witchery.core.api.Curse
44
import dev.sterner.witchery.core.api.WitcheryApi
55
import dev.sterner.witchery.core.registry.WitcheryCurseRegistry
6+
import dev.sterner.witchery.network.DropItemS2CPayload
7+
import net.minecraft.client.gui.screens.Screen
8+
import net.minecraft.server.level.ServerPlayer
9+
import net.minecraft.world.InteractionHand
610
import net.minecraft.world.effect.MobEffectInstance
711
import net.minecraft.world.effect.MobEffects
812
import net.minecraft.world.entity.player.Player
913
import net.minecraft.world.level.Level
14+
import net.neoforged.neoforge.network.PacketDistributor
1015

1116
class CurseOfMisfortune : Curse() {
1217

@@ -40,20 +45,26 @@ class CurseOfMisfortune : Curse() {
4045
player.addEffect(MobEffectInstance(MobEffects.DIG_SLOWDOWN, effectDuration, 0))
4146
}
4247
if (level.random.nextDouble() < effectChance) {
43-
player.addEffect(MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, effectDuration, 0))
48+
player.addEffect(MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, effectDuration * 2, 0))
4449
}
4550
if (level.random.nextDouble() < effectChance) {
4651
player.addEffect(MobEffectInstance(MobEffects.BLINDNESS, effectDuration, 0))
4752
}
4853
if (level.random.nextDouble() < effectChance) {
49-
player.addEffect(MobEffectInstance(MobEffects.WEAKNESS, effectDuration, 0))
54+
player.addEffect(MobEffectInstance(MobEffects.WEAKNESS, effectDuration * 2, 0))
5055
}
5156
if (level.random.nextDouble() < effectChance) {
5257
player.addEffect(MobEffectInstance(MobEffects.GLOWING, effectDuration, 0))
5358
}
5459
if (level.random.nextDouble() < effectChance) {
5560
player.addEffect(MobEffectInstance(MobEffects.DARKNESS, effectDuration, 0))
5661
}
62+
63+
if (level.random.nextDouble() < 0.005 * witchPowerAmplifier) {
64+
if (!player.mainHandItem.isEmpty && player is ServerPlayer) {
65+
PacketDistributor.sendToPlayer(player, DropItemS2CPayload())
66+
}
67+
}
5768
}
5869

5970
super.onTickCurse(level, player, catBoosted)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package dev.sterner.witchery.network
2+
3+
import dev.sterner.witchery.Witchery
4+
import net.minecraft.client.Minecraft
5+
import net.minecraft.network.RegistryFriendlyByteBuf
6+
import net.minecraft.network.codec.StreamCodec
7+
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
8+
import net.minecraft.sounds.SoundEvents
9+
import net.minecraft.world.InteractionHand
10+
import net.neoforged.neoforge.network.handling.IPayloadContext
11+
12+
class DropItemS2CPayload() : CustomPacketPayload {
13+
14+
constructor(friendlyByteBuf: RegistryFriendlyByteBuf) : this()
15+
16+
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> {
17+
return ID
18+
}
19+
20+
private fun write(friendlyByteBuf: RegistryFriendlyByteBuf?) {}
21+
22+
fun handleOnClient(ctx: IPayloadContext) {
23+
val client = Minecraft.getInstance()
24+
client.execute {
25+
val player = client.player ?: return@execute
26+
27+
if (!player.isSpectator && player.drop(false)) {
28+
player.swing(InteractionHand.MAIN_HAND)
29+
player.playSound(SoundEvents.ARMADILLO_SCUTE_DROP)
30+
}
31+
}
32+
}
33+
34+
companion object {
35+
val ID: CustomPacketPayload.Type<DropItemS2CPayload> =
36+
CustomPacketPayload.Type(Witchery.id("drop_item"))
37+
38+
val STREAM_CODEC: StreamCodec<in RegistryFriendlyByteBuf?, DropItemS2CPayload> =
39+
CustomPacketPayload.codec(
40+
{ payload, buf -> payload.write(buf) },
41+
{ DropItemS2CPayload() }
42+
)
43+
}
44+
}

0 commit comments

Comments
 (0)