1
1
package dev.sterner.common.item.tool.ichor
2
2
3
+ import com.mojang.datafixers.util.Pair
4
+ import dev.sterner.api.VoidBoundApi
5
+ import dev.sterner.api.item.ItemAbility
3
6
import dev.sterner.common.item.tool.GalesEdgeItem.Companion.ascend
7
+ import dev.sterner.mixin.HoeItemTillablesAccessor
8
+ import net.minecraft.core.BlockPos
9
+ import net.minecraft.core.NonNullList
10
+ import net.minecraft.server.level.ServerLevel
11
+ import net.minecraft.sounds.SoundEvents
12
+ import net.minecraft.sounds.SoundSource
13
+ import net.minecraft.tags.BlockTags
14
+ import net.minecraft.world.Containers
4
15
import net.minecraft.world.InteractionHand
16
+ import net.minecraft.world.InteractionResult
5
17
import net.minecraft.world.InteractionResultHolder
6
18
import net.minecraft.world.entity.LivingEntity
7
19
import net.minecraft.world.entity.player.Player
20
+ import net.minecraft.world.item.HoeItem
8
21
import net.minecraft.world.item.ItemStack
9
22
import net.minecraft.world.item.Tier
23
+ import net.minecraft.world.item.context.UseOnContext
10
24
import net.minecraft.world.level.Level
25
+ import net.minecraft.world.level.block.Block
26
+ import net.minecraft.world.level.block.state.BlockState
27
+ import net.minecraft.world.phys.BlockHitResult
11
28
import team.lodestar.lodestone.systems.item.tools.magic.MagicSwordItem
29
+ import java.util.function.Consumer
30
+ import java.util.function.Predicate
12
31
13
32
class IchoriumVorpal (tier : Tier , attackDamageModifier : Int , attackSpeedModifier : Float , magicDamage : Float , properties : Properties ) : MagicSwordItem(tier, attackDamageModifier,
14
33
attackSpeedModifier,
@@ -21,12 +40,93 @@ class IchoriumVorpal(tier: Tier, attackDamageModifier: Int, attackSpeedModifier:
21
40
}
22
41
23
42
override fun use (level : Level , player : Player , usedHand : InteractionHand ): InteractionResultHolder <ItemStack > {
24
- player.startUsingItem(usedHand)
43
+ if (VoidBoundApi .getActiveAbility(player.mainHandItem) != ItemAbility .HARVEST ) {
44
+ player.startUsingItem(usedHand)
45
+ }
46
+
25
47
return super .use(level, player, usedHand)
26
48
}
27
49
50
+ override fun useOn (context : UseOnContext ): InteractionResult {
51
+ val player = context.player
52
+
53
+ if (player!! .isShiftKeyDown) {
54
+ return super .useOn(context)
55
+ }
56
+ if (VoidBoundApi .getActiveAbility(player.mainHandItem) == ItemAbility .HARVEST ) {
57
+ for (xx in - 1 .. 1 ) {
58
+ for (zz in - 1 .. 1 ) {
59
+ useHoeOn(
60
+ UseOnContext (
61
+ player, player.usedItemHand,
62
+ BlockHitResult (
63
+ context.clickLocation,
64
+ context.horizontalDirection,
65
+ context.clickedPos.offset(xx, 0 , zz),
66
+ context.isInside
67
+ )
68
+ )
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ return InteractionResult .SUCCESS
75
+ }
76
+
77
+
78
+ fun useHoeOn (context : UseOnContext ): InteractionResult {
79
+ val level = context.level
80
+ val blockPos = context.clickedPos
81
+ val pair = HoeItemTillablesAccessor .getTILLABLES()[level.getBlockState(blockPos).block] as Pair <Predicate <UseOnContext >, Consumer <UseOnContext >>?
82
+ if (pair == null ) {
83
+ return InteractionResult .PASS
84
+ } else {
85
+ val predicate = pair.first
86
+ val consumer = pair.second
87
+ if (predicate.test(context)) {
88
+ val player = context.player
89
+ level.playSound(player, blockPos, SoundEvents .HOE_TILL , SoundSource .BLOCKS , 1.0f , 1.0f )
90
+ if (! level.isClientSide) {
91
+ consumer.accept(context)
92
+ if (player != null ) {
93
+ context.itemInHand.hurtAndBreak(
94
+ 1 , player
95
+ ) { playerx: Player ->
96
+ playerx.broadcastBreakEvent(
97
+ context.hand
98
+ )
99
+ }
100
+ }
101
+ }
102
+
103
+ return InteractionResult .sidedSuccess(level.isClientSide)
104
+ } else {
105
+ return InteractionResult .PASS
106
+ }
107
+ }
108
+ }
109
+
110
+ override fun mineBlock (
111
+ stack : ItemStack ,
112
+ level : Level ,
113
+ state : BlockState ,
114
+ pos : BlockPos ,
115
+ miningEntity : LivingEntity
116
+ ): Boolean {
117
+ if (level is ServerLevel && state.`is `(BlockTags .CROPS )) {
118
+ val list = NonNullList .create<ItemStack >()
119
+ list.addAll(Block .getDrops(state, level, pos, null , miningEntity, stack))
120
+ Containers .dropContents(level, pos, list)
121
+ }
122
+ return super .mineBlock(stack, level, state, pos, miningEntity)
123
+ }
124
+
28
125
override fun onUseTick (level : Level , player : LivingEntity , stack : ItemStack , remainingUseDuration : Int ) {
29
- ascend(player, stack, this .getUseDuration(stack) - remainingUseDuration)
126
+ if (VoidBoundApi .getActiveAbility(player.mainHandItem) != ItemAbility .HARVEST ) {
127
+ ascend(player, stack, this .getUseDuration(stack) - remainingUseDuration)
128
+ }
129
+
30
130
super .onUseTick(level, player, stack, remainingUseDuration)
31
131
}
32
132
0 commit comments