Skip to content

Commit 0f6f110

Browse files
committed
Added sound and particles when teleported on warp.
Signed-off-by: Pavel Erokhin (MairwunNx) <[email protected]>
1 parent 62d8c28 commit 0f6f110

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/warps/commands/WarpCommand.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@ import com.mojang.brigadier.CommandDispatcher
1313
import com.mojang.brigadier.arguments.StringArgumentType
1414
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
1515
import com.mojang.brigadier.context.CommandContext
16+
import net.minecraft.client.Minecraft
1617
import net.minecraft.command.CommandSource
1718
import net.minecraft.command.Commands
1819
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
1925
import net.minecraft.world.dimension.DimensionType
26+
import net.minecraftforge.api.distmarker.Dist
27+
import net.minecraftforge.fml.DistExecutor
2028
import org.apache.logging.log4j.LogManager
29+
import kotlin.random.Random
2130

2231
object WarpCommand {
2332
private val aliases = listOf("warp", "ewarp")
2433
private val logger = LogManager.getLogger()
34+
private val random = Random
2535

2636
fun register(dispatcher: CommandDispatcher<CommandSource>) {
2737
logger.info("Register \"/warp\" command")
@@ -91,5 +101,78 @@ object WarpCommand {
91101
sendMsg("warps", player.commandSource, "warp.not_found", warp.name)
92102
logger.info("Player ${player.name.string} try teleport to not exist warp ${warp.name}")
93103
}
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+
}
94177
}
95178
}

src/main/kotlin/com/mairwunnx/projectessentials/warps/models/WarpModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import kotlinx.serialization.Serializable
55

66
@Serializable
77
data class WarpModel(
8+
var addResistanceEffect: Boolean = true,
9+
var resistanceEffectDuration: Int = 200,
10+
var enableTeleportSound: Boolean = true,
11+
var enableTeleportEffect: Boolean = true,
812
var warps: MutableList<Warp> = mutableListOf()
913
) {
1014
@Serializable

0 commit comments

Comments
 (0)