From 767da2159b9651f131ae826b3602b1ff5303e48f Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Wed, 30 Jul 2025 14:48:21 -0400 Subject: [PATCH 1/4] Reenable passenger stack teleporting --- .../petrak/hexcasting/common/casting/actions/spells/OpBlink.kt | 2 +- .../common/casting/actions/spells/great/OpTeleport.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt index f7fd817308..545f87abe8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt @@ -27,7 +27,7 @@ object OpBlink : SpellAction { val delta = args.getDouble(1, argc) env.assertEntityInRange(target) - if (!target.canChangeDimensions() || target.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) + if (target.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) throw MishapImmuneEntity(target) val dvec = target.lookAngle.scale(delta) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt index c349aa0bba..d33252024e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt @@ -36,7 +36,7 @@ object OpTeleport : SpellAction { val delta = args.getVec3(1, argc) env.assertEntityInRange(teleportee) - if (!teleportee.canChangeDimensions() || teleportee.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) + if (teleportee.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) throw MishapImmuneEntity(teleportee) val targetPos = teleportee.position().add(delta) From 19d34ad4cbc57dad30becdab362567865d4bb4ad Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Wed, 30 Jul 2025 14:49:11 -0400 Subject: [PATCH 2/4] Move immune-riders check to execute() so it can mishap --- .../common/casting/actions/spells/OpBlink.kt | 6 ++++++ .../common/casting/actions/spells/great/OpTeleport.kt | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt index 545f87abe8..e13b7b3eb8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/OpBlink.kt @@ -30,6 +30,12 @@ object OpBlink : SpellAction { if (target.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) throw MishapImmuneEntity(target) + if (target.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)) { + val immunePassengers = target.passengers.filter { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) } + if (!immunePassengers.isEmpty()) + throw MishapImmuneEntity(immunePassengers.get(0)) + } + val dvec = target.lookAngle.scale(delta) val endPos = target.position().add(dvec) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt index d33252024e..230b99767d 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt @@ -39,6 +39,12 @@ object OpTeleport : SpellAction { if (teleportee.type.`is`(HexTags.Entities.CANNOT_TELEPORT)) throw MishapImmuneEntity(teleportee) + if (teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)) { + val immunePassengers = teleportee.passengers.filter { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) } + if (!immunePassengers.isEmpty()) + throw MishapImmuneEntity(immunePassengers.get(0)) + } + val targetPos = teleportee.position().add(delta) if (!HexConfig.server().canTeleportInThisDimension(env.world.dimension())) throw MishapBadLocation(targetPos, "bad_dimension") @@ -103,10 +109,6 @@ object OpTeleport : SpellAction { val playersToUpdate = mutableListOf() val target = teleportee.position().add(delta) - val cannotTeleport = teleportee.passengers.any { it.type.`is`(HexTags.Entities.CANNOT_TELEPORT) } - if (cannotTeleport) - return - // A "sticky" entity teleports itself and its riders val sticky = teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS) From 5716f664a33f5451d8b4ca83bec69a92554b81ab Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Wed, 30 Jul 2025 14:49:48 -0400 Subject: [PATCH 3/4] Use vanilla teleportTo instead of reimplementing all its functionality --- .../actions/spells/great/OpTeleport.kt | 35 ++------------ .../hexcasting/common/msgs/MsgBlinkS2C.java | 46 ------------------- .../fabric/network/FabricPacketHandler.java | 2 - .../forge/network/ForgePacketHandler.java | 2 - 4 files changed, 4 insertions(+), 81 deletions(-) delete mode 100644 Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgBlinkS2C.java diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt index 230b99767d..e5cc06820f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/spells/great/OpTeleport.kt @@ -12,7 +12,6 @@ import at.petrak.hexcasting.api.casting.mishaps.MishapImmuneEntity import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.api.mod.HexConfig import at.petrak.hexcasting.api.mod.HexTags -import at.petrak.hexcasting.common.msgs.MsgBlinkS2C import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos import net.minecraft.server.level.ServerLevel @@ -106,39 +105,13 @@ object OpTeleport : SpellAction { return } - val playersToUpdate = mutableListOf() val target = teleportee.position().add(delta) // A "sticky" entity teleports itself and its riders - val sticky = teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS) - - // TODO: this probably does funky things with stacks of passengers. I doubt this will come up in practice - // though - if (sticky) { - teleportee.stopRiding() - teleportee.indirectPassengers.filterIsInstance().forEach(playersToUpdate::add) - // this handles teleporting the passengers - teleportee.teleportTo(target.x, target.y, target.z) - } else { - // Snap everyone off the stacks - teleportee.stopRiding() + // This is the default behavior for teleportTo(), so we remove the riders if the teleportee *isn't* sticky + teleportee.stopRiding() + if (!teleportee.type.`is`(HexTags.Entities.STICKY_TELEPORTERS)) teleportee.passengers.forEach(Entity::stopRiding) - if (teleportee is ServerPlayer) { - playersToUpdate.add(teleportee) - } else { - teleportee.setPos(teleportee.position().add(delta)) - } - } - - for (player in playersToUpdate) { - // See TeleportCommand - val chunkPos = ChunkPos(BlockPos.containing(delta)) - // the `1` is apparently for "distance." i'm not sure what it does but this is what - // /tp does - world.chunkSource.addRegionTicket(TicketType.POST_TELEPORT, chunkPos, 1, player.id) - player.connection.resetPosition() - player.setPos(target) - IXplatAbstractions.INSTANCE.sendPacketToPlayer(player, MsgBlinkS2C(delta)) - } + teleportee.teleportTo(target.x, target.y, target.z) } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgBlinkS2C.java b/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgBlinkS2C.java deleted file mode 100644 index ab75bc20ed..0000000000 --- a/Common/src/main/java/at/petrak/hexcasting/common/msgs/MsgBlinkS2C.java +++ /dev/null @@ -1,46 +0,0 @@ -package at.petrak.hexcasting.common.msgs; - -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.phys.Vec3; - -import static at.petrak.hexcasting.api.HexAPI.modLoc; - -/** - * Sent server->client to synchronize OpBlink when the target is a player. - */ -public record MsgBlinkS2C(Vec3 addedPosition) implements IMessage { - public static final ResourceLocation ID = modLoc("blink"); - - @Override - public ResourceLocation getFabricId() { - return ID; - } - - public static MsgBlinkS2C deserialize(ByteBuf buffer) { - var buf = new FriendlyByteBuf(buffer); - var x = buf.readDouble(); - var y = buf.readDouble(); - var z = buf.readDouble(); - return new MsgBlinkS2C(new Vec3(x, y, z)); - } - - @Override - public void serialize(FriendlyByteBuf buf) { - buf.writeDouble(this.addedPosition.x); - buf.writeDouble(this.addedPosition.y); - buf.writeDouble(this.addedPosition.z); - } - - public static void handle(MsgBlinkS2C self) { - Minecraft.getInstance().execute(new Runnable() { - @Override - public void run() { - var player = Minecraft.getInstance().player; - player.setPos(player.position().add(self.addedPosition())); - } - }); - } -} diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java index 3a6b1af179..5403421243 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/network/FabricPacketHandler.java @@ -27,8 +27,6 @@ private static ServerPlayNetworking.PlayChannelHandler makeServerBoundHandle public static void initClient() { ClientPlayNetworking.registerGlobalReceiver(MsgNewSpellPatternS2C.ID, makeClientBoundHandler(MsgNewSpellPatternS2C::deserialize, MsgNewSpellPatternS2C::handle)); - ClientPlayNetworking.registerGlobalReceiver( - MsgBlinkS2C.ID, makeClientBoundHandler(MsgBlinkS2C::deserialize, MsgBlinkS2C::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgCastParticleS2C.ID, makeClientBoundHandler(MsgCastParticleS2C::deserialize, MsgCastParticleS2C::handle)); ClientPlayNetworking.registerGlobalReceiver(MsgOpenSpellGuiS2C.ID, diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java b/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java index 78485aa6f9..abf74064e8 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/network/ForgePacketHandler.java @@ -39,8 +39,6 @@ public static void init() { // Server -> client NETWORK.registerMessage(messageIdx++, MsgNewSpellPatternS2C.class, MsgNewSpellPatternS2C::serialize, MsgNewSpellPatternS2C::deserialize, makeClientBoundHandler(MsgNewSpellPatternS2C::handle)); - NETWORK.registerMessage(messageIdx++, MsgBlinkS2C.class, MsgBlinkS2C::serialize, - MsgBlinkS2C::deserialize, makeClientBoundHandler(MsgBlinkS2C::handle)); NETWORK.registerMessage(messageIdx++, MsgSentinelStatusUpdateAck.class, MsgSentinelStatusUpdateAck::serialize, MsgSentinelStatusUpdateAck::deserialize, makeClientBoundHandler(MsgSentinelStatusUpdateAck::handle)); NETWORK.registerMessage(messageIdx++, MsgPigmentUpdateAck.class, MsgPigmentUpdateAck::serialize, From b1c748ef7354231859377362003483f923070944 Mon Sep 17 00:00:00 2001 From: Robotgiggle Date: Wed, 30 Jul 2025 14:50:11 -0400 Subject: [PATCH 4/4] Add boss tags and fishing_bobber to cannot_teleport --- .../tags/entity_types/cannot_teleport.json | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Common/src/main/resources/data/hexcasting/tags/entity_types/cannot_teleport.json b/Common/src/main/resources/data/hexcasting/tags/entity_types/cannot_teleport.json index e84ae30eeb..b7da45515e 100644 --- a/Common/src/main/resources/data/hexcasting/tags/entity_types/cannot_teleport.json +++ b/Common/src/main/resources/data/hexcasting/tags/entity_types/cannot_teleport.json @@ -25,12 +25,19 @@ "id": "create:seat", "required": false }, - "minecraft:wither", + { + "id": "#forge:bosses", + "required": false + }, + { + "id": "#c:bosses", + "required": false + }, "minecraft:end_crystal", - "minecraft:ender_dragon", "minecraft:item_frame", "minecraft:painting", "minecraft:leash_knot", - "minecraft:marker" + "minecraft:marker", + "minecraft:fishing_bobber" ] }