Skip to content

Commit 5716f66

Browse files
committed
Use vanilla teleportTo instead of reimplementing all its functionality
1 parent 19d34ad commit 5716f66

File tree

4 files changed

+4
-81
lines changed

4 files changed

+4
-81
lines changed

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import at.petrak.hexcasting.api.casting.mishaps.MishapImmuneEntity
1212
import at.petrak.hexcasting.api.misc.MediaConstants
1313
import at.petrak.hexcasting.api.mod.HexConfig
1414
import at.petrak.hexcasting.api.mod.HexTags
15-
import at.petrak.hexcasting.common.msgs.MsgBlinkS2C
1615
import at.petrak.hexcasting.xplat.IXplatAbstractions
1716
import net.minecraft.core.BlockPos
1817
import net.minecraft.server.level.ServerLevel
@@ -106,39 +105,13 @@ object OpTeleport : SpellAction {
106105
return
107106
}
108107

109-
val playersToUpdate = mutableListOf<ServerPlayer>()
110108
val target = teleportee.position().add(delta)
111109

112110
// A "sticky" entity teleports itself and its riders
113-
val sticky = teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)
114-
115-
// TODO: this probably does funky things with stacks of passengers. I doubt this will come up in practice
116-
// though
117-
if (sticky) {
118-
teleportee.stopRiding()
119-
teleportee.indirectPassengers.filterIsInstance<ServerPlayer>().forEach(playersToUpdate::add)
120-
// this handles teleporting the passengers
121-
teleportee.teleportTo(target.x, target.y, target.z)
122-
} else {
123-
// Snap everyone off the stacks
124-
teleportee.stopRiding()
111+
// This is the default behavior for teleportTo(), so we remove the riders if the teleportee *isn't* sticky
112+
teleportee.stopRiding()
113+
if (!teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS))
125114
teleportee.passengers.forEach(Entity::stopRiding)
126-
if (teleportee is ServerPlayer) {
127-
playersToUpdate.add(teleportee)
128-
} else {
129-
teleportee.setPos(teleportee.position().add(delta))
130-
}
131-
}
132-
133-
for (player in playersToUpdate) {
134-
// See TeleportCommand
135-
val chunkPos = ChunkPos(BlockPos.containing(delta))
136-
// the `1` is apparently for "distance." i'm not sure what it does but this is what
137-
// /tp does
138-
world.chunkSource.addRegionTicket(TicketType.POST_TELEPORT, chunkPos, 1, player.id)
139-
player.connection.resetPosition()
140-
player.setPos(target)
141-
IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, MsgBlinkS2C(delta))
142-
}
115+
teleportee.teleportTo(target.x, target.y, target.z)
143116
}
144117
}

Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgBlinkS2C.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ private static <T> ServerPlayNetworking.PlayChannelHandler makeServerBoundHandle
2727
public static void initClient() {
2828
ClientPlayNetworking.registerGlobalReceiver(MsgNewSpellPatternS2C.ID,
2929
makeClientBoundHandler(MsgNewSpellPatternS2C::deserialize, MsgNewSpellPatternS2C::handle));
30-
ClientPlayNetworking.registerGlobalReceiver(
31-
MsgBlinkS2C.ID, makeClientBoundHandler(MsgBlinkS2C::deserialize, MsgBlinkS2C::handle));
3230
ClientPlayNetworking.registerGlobalReceiver(MsgCastParticleS2C.ID,
3331
makeClientBoundHandler(MsgCastParticleS2C::deserialize, MsgCastParticleS2C::handle));
3432
ClientPlayNetworking.registerGlobalReceiver(MsgOpenSpellGuiS2C.ID,

Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public static void init() {
3939
// Server -> client
4040
NETWORK.registerMessage(messageIdx++, MsgNewSpellPatternS2C.class, MsgNewSpellPatternS2C::serialize,
4141
MsgNewSpellPatternS2C::deserialize, makeClientBoundHandler(MsgNewSpellPatternS2C::handle));
42-
NETWORK.registerMessage(messageIdx++, MsgBlinkS2C.class, MsgBlinkS2C::serialize,
43-
MsgBlinkS2C::deserialize, makeClientBoundHandler(MsgBlinkS2C::handle));
4442
NETWORK.registerMessage(messageIdx++, MsgSentinelStatusUpdateAck.class, MsgSentinelStatusUpdateAck::serialize,
4543
MsgSentinelStatusUpdateAck::deserialize, makeClientBoundHandler(MsgSentinelStatusUpdateAck::handle));
4644
NETWORK.registerMessage(messageIdx++, MsgPigmentUpdateAck.class, MsgPigmentUpdateAck::serialize,

0 commit comments

Comments
 (0)