Skip to content

Commit

Permalink
EntityTag.fake_move
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 1, 2022
1 parent f8f6dd0 commit 54f3a1e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Expand Up @@ -292,6 +292,10 @@ else if (337.5 <= yaw && yaw < 360.0) {

public abstract void move(Entity entity, Vector vector);

public void fakeMove(Entity entity, Vector vector) {
throw new UnsupportedOperationException();
}

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

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

// <--[mechanism]
// @object EntityTag
// @name fake_move
// @input LocationTag
// @description
// Causes an entity to broadcast a fake movement packet in the direction of the velocity vector specified.
// The vector value must be in the range [-8,8] on each of X, Y, and Z.
// -->
if (mechanism.matches("fake_move") && mechanism.requireObject(LocationTag.class)) {
NMSHandler.entityHelper.fakeMove(getBukkitEntity(), mechanism.valueAsType(LocationTag.class).toVector());
}

// <--[mechanism]
// @object EntityTag
// @name interact_with
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.interfaces.PacketHelper;
import com.denizenscript.denizen.nms.v1_18.ReflectionMappingsInfo;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
Expand All @@ -12,6 +13,7 @@
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -612,6 +614,17 @@ public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(MoverType.SELF, new Vec3(vector.getX(), vector.getY(), vector.getZ()));
}

@Override
public void fakeMove(Entity entity, Vector vector) {
long x = ClientboundMoveEntityPacket.entityToPacket(vector.getX());
long y = ClientboundMoveEntityPacket.entityToPacket(vector.getY());
long z = ClientboundMoveEntityPacket.entityToPacket(vector.getZ());
ClientboundMoveEntityPacket packet = new ClientboundMoveEntityPacket.Pos(entity.getEntityId(), (short) x, (short) y, (short) z, entity.isOnGround());
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 54f3a1e

Please sign in to comment.