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..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 @@ -27,9 +27,15 @@ 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) + 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 c349aa0bba..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 @@ -36,9 +35,15 @@ 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) + 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") @@ -100,43 +105,13 @@ object OpTeleport : SpellAction { return } - 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) - - // 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/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" ] } 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,