Skip to content

Commit

Permalink
EntityTag.reset_client_location
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 4, 2022
1 parent a9e43dc commit 3e407d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Expand Up @@ -305,6 +305,10 @@ public void fakeMove(Entity entity, Vector vector) {
throw new UnsupportedOperationException();
}

public void clientResetLoc(Entity entity) {
throw new UnsupportedOperationException();
}

public abstract void teleport(Entity entity, Location loc);

public abstract BoundingBox getBoundingBox(Entity entity);
Expand Down
Expand Up @@ -3474,6 +3474,17 @@ public void adjust(Mechanism mechanism) {
NMSHandler.entityHelper.fakeMove(getBukkitEntity(), mechanism.valueAsType(LocationTag.class).toVector());
}

// <--[mechanism]
// @object EntityTag
// @name reset_client_location
// @input None
// @description
// Causes an entity to broadcast a fake teleport packet to its own location, forcibly resetting its location for clients.
// -->
if (mechanism.matches("reset_client_location")) {
NMSHandler.entityHelper.clientResetLoc(getBukkitEntity());
}

// <--[mechanism]
// @object EntityTag
// @name interact_with
Expand Down
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerLookAtPacket;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -633,6 +634,14 @@ public void fakeMove(Entity entity, Vector vector) {
}
}

@Override
public void clientResetLoc(Entity entity) {
ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(((CraftEntity) entity).getHandle());
for (Player player : getPlayersThatSee(entity)) {
PacketHelperImpl.send(player, packet);
}
}

@Override
public void teleport(Entity entity, Location loc) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
Expand Down

0 comments on commit 3e407d8

Please sign in to comment.