@@ -44,38 +44,39 @@ class ExcavationFocus : IWandFocus {
44
44
private var blockState: BlockState ? = null
45
45
46
46
override fun onUsingFocusTick (stack : ItemStack , level : Level , player : Player ) {
47
- if (level.isClientSide) {
48
- val client = Minecraft .getInstance()
49
- val maxReach = 10.0
50
- val tickDelta = 1.0f
51
- val includeFluids = false
52
-
53
- val hit: HitResult ? = client.cameraEntity?.pick(maxReach, tickDelta, includeFluids)
54
-
55
- if (hit != null ) {
56
- if (hit.type == HitResult .Type .BLOCK ) {
57
- val blockHit = hit as BlockHitResult
58
- val blockPos = blockHit.blockPos
59
- val newState = client.level?.getBlockState(blockPos) ? : return
60
-
61
- if (blockState != newState) {
62
- this .breakTime = 0
63
- this .breakProgress = - 1
64
- }
47
+ val maxReach = 10.0
48
+ val tickDelta = 1.0f
49
+ val includeFluids = false
50
+
51
+ val hit: HitResult ? = player.pick(maxReach, tickDelta, includeFluids)
52
+
53
+ if (hit != null ) {
54
+ if (hit.type == HitResult .Type .BLOCK ) {
55
+ val blockHit = hit as BlockHitResult
56
+ val blockPos = blockHit.blockPos
57
+ val newState = level.getBlockState(blockPos) ? : return
58
+
59
+ if (blockState != newState) {
60
+ this .breakTime = 0
61
+ this .breakProgress = - 1
62
+ }
65
63
66
- blockState = newState
64
+ blockState = newState
67
65
68
66
69
- val pos = getProjectileSpawnPos(player, InteractionHand .MAIN_HAND , 1.5f , 0.6f )
67
+ val pos = getProjectileSpawnPos(player, InteractionHand .MAIN_HAND , 1.5f , 0.6f )
68
+ if (level.isClientSide) {
70
69
spawnChargeParticles(player.level(), player, pos, 0.5f )
71
70
spec(level, player.lookAngle.normalize(), pos, SpiritTypeRegistry .EARTHEN_SPIRIT , level.random)
71
+ }
72
72
73
- if (! VoidBoundApi .canPlayerBreakBlock(level, player, blockPos)) {
74
- ParticleEngineMixinLogic .logic(level, blockPos, blockState!! , level.random, hit.direction)
75
- return
76
- }
73
+ if (! VoidBoundApi .canPlayerBreakBlock(level, player, blockPos)) {
74
+ ParticleEngineMixinLogic .logic(level, blockPos, blockState!! , level.random, hit.direction)
75
+ return
76
+ }
77
77
78
- timeToBreak = (20 * blockState!! .getDestroySpeed(level, blockPos))
78
+ timeToBreak = (20 * blockState!! .getDestroySpeed(level, blockPos))
79
+ if (level.isClientSide) {
79
80
val coordPos: List <Vec3 > = VoidBoundPosUtils .getFaceCoords(level, blockState!! , blockPos)
80
81
for (pos1 in coordPos) {
81
82
val lightSpecs: ParticleEffectSpawner =
@@ -86,9 +87,12 @@ class ExcavationFocus : IWandFocus {
86
87
lightSpecs.spawnParticles()
87
88
lightSpecs.spawnParticles()
88
89
}
89
- this .breakTime++
90
- val progress: Int = (this .breakTime / this .timeToBreak!! .toFloat() * 10 ).toInt()
90
+ }
91
+
92
+ this .breakTime++
93
+ val progress: Int = (this .breakTime / this .timeToBreak!! .toFloat() * 10 ).toInt()
91
94
95
+ if (level.isClientSide) {
92
96
VoidBoundPacketRegistry .VOID_BOUND_CHANNEL .sendToServer(
93
97
ExcavationPacket (
94
98
blockPos,
@@ -97,20 +101,20 @@ class ExcavationFocus : IWandFocus {
97
101
progress
98
102
)
99
103
)
104
+ }
100
105
101
- if (breakTime % 6 == 0 ) {
102
- level.playSound(player, blockPos, blockState!! .soundType.breakSound, SoundSource .BLOCKS )
103
- }
106
+ if (breakTime % 6 == 0 && level.isClientSide ) {
107
+ level.playSound(player, blockPos, blockState!! .soundType.breakSound, SoundSource .BLOCKS )
108
+ }
104
109
105
- if (progress != this .breakProgress) {
106
- this .breakProgress = progress
107
- }
108
- level.destroyBlockProgress(player.id + ExcavationPacket .generatePosHash(blockPos), blockPos, progress)
110
+ if (progress != this .breakProgress) {
111
+ this .breakProgress = progress
112
+ }
113
+ level.destroyBlockProgress(player.id + ExcavationPacket .generatePosHash(blockPos), blockPos, progress)
109
114
110
- if (this .breakTime >= this .timeToBreak!! ) {
111
- this .breakTime = 0
112
- this .breakProgress = - 1
113
- }
115
+ if (this .breakTime >= this .timeToBreak!! ) {
116
+ this .breakTime = 0
117
+ this .breakProgress = - 1
114
118
}
115
119
}
116
120
}
0 commit comments