Skip to content

Commit 9920237

Browse files
Fix various issues with Blink and GTP (#916)
2 parents a0a5a50 + b1c748e commit 9920237

File tree

6 files changed

+28
-90
lines changed

6 files changed

+28
-90
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ object OpBlink : SpellAction {
2727
val delta = args.getDouble(1, argc)
2828
env.assertEntityInRange(target)
2929

30-
if (!target.canChangeDimensions() || target.type.`is`(HexTags.Entities.CANNOT_TELEPORT))
30+
if (target.type.`is`(HexTags.Entities.CANNOT_TELEPORT))
3131
throw MishapImmuneEntity(target)
3232

33+
if (target.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)) {
34+
val immunePassengers = target.passengers.filter { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) }
35+
if (!immunePassengers.isEmpty())
36+
throw MishapImmuneEntity(immunePassengers.get(0))
37+
}
38+
3339
val dvec = target.lookAngle.scale(delta)
3440
val endPos = target.position().add(dvec)
3541

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

Lines changed: 11 additions & 36 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
@@ -36,9 +35,15 @@ object OpTeleport : SpellAction {
3635
val delta = args.getVec3(1, argc)
3736
env.assertEntityInRange(teleportee)
3837

39-
if (!teleportee.canChangeDimensions() || teleportee.type.`is`(HexTags.Entities.CANNOT_TELEPORT))
38+
if (teleportee.type.`is`(HexTags.Entities.CANNOT_TELEPORT))
4039
throw MishapImmuneEntity(teleportee)
4140

41+
if (teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)) {
42+
val immunePassengers = teleportee.passengers.filter { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) }
43+
if (!immunePassengers.isEmpty())
44+
throw MishapImmuneEntity(immunePassengers.get(0))
45+
}
46+
4247
val targetPos = teleportee.position().add(delta)
4348
if (!HexConfig.server().canTeleportInThisDimension(env.world.dimension()))
4449
throw MishapBadLocation(targetPos, "bad_dimension")
@@ -100,43 +105,13 @@ object OpTeleport : SpellAction {
100105
return
101106
}
102107

103-
val playersToUpdate = mutableListOf<ServerPlayer>()
104108
val target = teleportee.position().add(delta)
105109

106-
val cannotTeleport = teleportee.passengers.any { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) }
107-
if (cannotTeleport)
108-
return
109-
110110
// A "sticky" entity teleports itself and its riders
111-
val sticky = teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)
112-
113-
// TODO: this probably does funky things with stacks of passengers. I doubt this will come up in practice
114-
// though
115-
if (sticky) {
116-
teleportee.stopRiding()
117-
teleportee.indirectPassengers.filterIsInstance<ServerPlayer>().forEach(playersToUpdate::add)
118-
// this handles teleporting the passengers
119-
teleportee.teleportTo(target.x, target.y, target.z)
120-
} else {
121-
// Snap everyone off the stacks
122-
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))
123114
teleportee.passengers.forEach(Entity::stopRiding)
124-
if (teleportee is ServerPlayer) {
125-
playersToUpdate.add(teleportee)
126-
} else {
127-
teleportee.setPos(teleportee.position().add(delta))
128-
}
129-
}
130-
131-
for (player in playersToUpdate) {
132-
// See TeleportCommand
133-
val chunkPos = ChunkPos(BlockPos.containing(delta))
134-
// the `1` is apparently for "distance." i'm not sure what it does but this is what
135-
// /tp does
136-
world.chunkSource.addRegionTicket(TicketType.POST_TELEPORT, chunkPos, 1, player.id)
137-
player.connection.resetPosition()
138-
player.setPos(target)
139-
IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, MsgBlinkS2C(delta))
140-
}
115+
teleportee.teleportTo(target.x, target.y, target.z)
141116
}
142117
}

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

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

Common/src/main/resources/data/hexcasting/tags/entity_types/cannot_teleport.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525
"id": "create:seat",
2626
"required": false
2727
},
28-
"minecraft:wither",
28+
{
29+
"id": "#forge:bosses",
30+
"required": false
31+
},
32+
{
33+
"id": "#c:bosses",
34+
"required": false
35+
},
2936
"minecraft:end_crystal",
30-
"minecraft:ender_dragon",
3137
"minecraft:item_frame",
3238
"minecraft:painting",
3339
"minecraft:leash_knot",
34-
"minecraft:marker"
40+
"minecraft:marker",
41+
"minecraft:fishing_bobber"
3542
]
3643
}

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)