Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be in this PR, but I think this logic should be refactored out into a common helper to be referenced by both OpBlink and OpTeleport, both to reduce duplication in our code and to make it available for use by addons.

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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -100,43 +105,13 @@ object OpTeleport : SpellAction {
return
}

val playersToUpdate = mutableListOf<ServerPlayer>()
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<ServerPlayer>().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)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ private static <T> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading