@@ -13,15 +13,25 @@ import com.mojang.brigadier.CommandDispatcher
13
13
import com.mojang.brigadier.arguments.StringArgumentType
14
14
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
15
15
import com.mojang.brigadier.context.CommandContext
16
+ import net.minecraft.client.Minecraft
16
17
import net.minecraft.command.CommandSource
17
18
import net.minecraft.command.Commands
18
19
import net.minecraft.entity.player.ServerPlayerEntity
20
+ import net.minecraft.particles.ParticleTypes
21
+ import net.minecraft.potion.Effect
22
+ import net.minecraft.potion.EffectInstance
23
+ import net.minecraft.util.SoundCategory
24
+ import net.minecraft.util.SoundEvents
19
25
import net.minecraft.world.dimension.DimensionType
26
+ import net.minecraftforge.api.distmarker.Dist
27
+ import net.minecraftforge.fml.DistExecutor
20
28
import org.apache.logging.log4j.LogManager
29
+ import kotlin.random.Random
21
30
22
31
object WarpCommand {
23
32
private val aliases = listOf (" warp" , " ewarp" )
24
33
private val logger = LogManager .getLogger()
34
+ private val random = Random
25
35
26
36
fun register (dispatcher : CommandDispatcher <CommandSource >) {
27
37
logger.info(" Register \" /warp\" command" )
@@ -91,5 +101,78 @@ object WarpCommand {
91
101
sendMsg(" warps" , player.commandSource, " warp.not_found" , warp.name)
92
102
logger.info(" Player ${player.name.string} try teleport to not exist warp ${warp.name} " )
93
103
}
104
+ val effectEnabled = WarpModelUtils .warpModel.addResistanceEffect
105
+ val effectDuration = WarpModelUtils .warpModel.resistanceEffectDuration
106
+ if (effectEnabled) {
107
+ val effect = Effect .get(11 )!!
108
+ val effectInstance = EffectInstance (effect, effectDuration, 5 )
109
+ player.addPotionEffect(effectInstance)
110
+ }
111
+
112
+ if (WarpModelUtils .warpModel.enableTeleportSound) {
113
+ DistExecutor .runWhenOn(Dist .CLIENT ) {
114
+ Runnable {
115
+ Minecraft .getInstance().world.playSound(
116
+ xPos, yPos + player.eyeHeight.toDouble(), zPos,
117
+ SoundEvents .ENTITY_ENDERMAN_TELEPORT ,
118
+ SoundCategory .HOSTILE ,
119
+ 1.0f , 1.0f , false
120
+ )
121
+ player.entity.playSound(
122
+ SoundEvents .ENTITY_ENDERMAN_TELEPORT ,
123
+ 1.0f , 1.0f
124
+ )
125
+ }
126
+ }
127
+
128
+ DistExecutor .runWhenOn(Dist .DEDICATED_SERVER ) {
129
+ Runnable {
130
+ player.world.playSound(
131
+ null , xPos, yPos + player.eyeHeight.toDouble(), zPos,
132
+ SoundEvents .ENTITY_ENDERMAN_TELEPORT ,
133
+ SoundCategory .HOSTILE ,
134
+ 1.0f , 1.0f
135
+ )
136
+ }
137
+ }
138
+ }
139
+
140
+ if (WarpModelUtils .warpModel.enableTeleportEffect) {
141
+ DistExecutor .runWhenOn(Dist .CLIENT ) {
142
+ Runnable {
143
+ for (i in 0 .. 200 ) {
144
+ Minecraft .getInstance().world.addParticle(
145
+ ParticleTypes .PORTAL ,
146
+ xPos + (random.nextDouble() - 0.5 ) * player.width.toDouble(),
147
+ yPos + random.nextDouble() * player.height.toDouble() - 0.25 ,
148
+ zPos + (random.nextDouble() - 0.5 ) * player.width.toDouble(),
149
+ (random.nextDouble() - 0.5 ) * 2.0 ,
150
+ - random.nextDouble(),
151
+ (random.nextDouble() - 0.5 ) * 2.0
152
+ )
153
+ }
154
+ if (player.world.isRemote) spawnServerParticles(player)
155
+ }
156
+ }
157
+ DistExecutor .runWhenOn(Dist .DEDICATED_SERVER ) {
158
+ Runnable {
159
+ spawnServerParticles(player)
160
+ }
161
+ }
162
+ }
163
+ }
164
+
165
+ private fun spawnServerParticles (player : ServerPlayerEntity ) {
166
+ for (i in 0 .. 200 ) {
167
+ player.serverWorld.spawnParticle(
168
+ ParticleTypes .PORTAL ,
169
+ player.posX + (random.nextDouble() - 0.5 ) * player.width.toDouble(),
170
+ player.posY + random.nextDouble() * player.height.toDouble() - 0.25 ,
171
+ player.posZ + (random.nextDouble() - 0.5 ) * player.width.toDouble(),
172
+ 1 ,
173
+ - 0.006 , - 0.006 , 0.0 ,
174
+ (random.nextDouble() - 0.5 ) * 2.0
175
+ )
176
+ }
94
177
}
95
178
}
0 commit comments