Fix entities glitching out and teleporting to the wrong location

This commit is contained in:
Redned 2019-09-14 23:19:13 -05:00 committed by RednedEpic
parent 4c9636b041
commit c606119c1d
5 changed files with 76 additions and 5 deletions

View file

@ -34,7 +34,7 @@ Links:
- [x] NBT data
- [ ] Inventory movement (transactions)
- [x] Player movement support
- [x] Entity support (Experimental)
- [x] Entity support
- [ ] Chunks (Experimental)
- [x] Block translation (may be missing mappings)
- [ ] Block updates

View file

@ -106,6 +106,8 @@ public class Entity {
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(geyserId);
session.getUpstream().sendPacket(removeEntityPacket);
valid = false;
}
public void moveRelative(double relX, double relY, double relZ, float pitch, float yaw) {
@ -113,11 +115,11 @@ public class Entity {
}
public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) {
if (relX == 0 && relY != 0 && relZ != 0 && position.getX() == 0 && position.getY() == 0)
if (relX == 0 && relY == 0 && relZ == 0 && position.getX() == 0 && position.getY() == 0)
return;
this.rotation = rotation;
this.position = new Vector3f(position.getX() + relX, position.getX() + relY, position.getX() + relZ);
this.position = new Vector3f(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
this.movePending = true;
}
@ -126,7 +128,7 @@ public class Entity {
}
public void moveAbsolute(Vector3f position, Vector3f rotation) {
if (position.getX() == 0 && position.getX() != 0 && position.getX() != 0 && rotation.getX() == 0 && rotation.getY() == 0)
if (position.getX() == 0 && position.getX() == 0 && position.getX() == 0 && rotation.getX() == 0 && rotation.getY() == 0)
return;
this.position = position;
@ -138,6 +140,9 @@ public class Entity {
public EntityDataDictionary getMetadata() {
EntityFlags flags = new EntityFlags();
flags.setFlag(EntityFlag.HAS_GRAVITY, true);
flags.setFlag(EntityFlag.HAS_COLLISION, true);
flags.setFlag(EntityFlag.CAN_SHOW_NAME, true);
flags.setFlag(EntityFlag.NO_AI, false);
EntityDataDictionary dictionary = new EntityDataDictionary();
dictionary.put(EntityData.NAMETAG, "");

View file

@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
@ -78,6 +79,7 @@ import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
import org.geysermc.connector.network.translators.java.JavaRespawnTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityAnimationTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityDestroyTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityHeadLookTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityMetadataTranslator;
@ -143,6 +145,7 @@ public class TranslatorsInit {
Registry.registerJava(ServerRespawnPacket.class, new JavaRespawnTranslator());
Registry.registerJava(ServerSpawnPositionPacket.class, new JavaSpawnPositionTranslator());
Registry.registerJava(ServerEntityAnimationPacket.class, new JavaEntityAnimationTranslator());
Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator());
Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator());
Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator());

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaEntityAnimationTranslator extends PacketTranslator<ServerEntityAnimationPacket> {
@Override
public void translate(ServerEntityAnimationPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
AnimatePacket animatePacket = new AnimatePacket();
animatePacket.setRuntimeEntityId(entity.getGeyserId());
switch (packet.getAnimation()) {
case SWING_ARM:
animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
break;
case CRITICAL_HIT:
animatePacket.setAction(AnimatePacket.Action.CRITICAL_HIT);
break;
case ENCHANTMENT_CRITICAL_HIT:
animatePacket.setAction(AnimatePacket.Action.MAGIC_CRITICAL_HIT);
break;
case LEAVE_BED:
animatePacket.setAction(AnimatePacket.Action.WAKE_UP);
break;
}
session.getUpstream().sendPacket(animatePacket);
}
}

View file

@ -26,7 +26,6 @@
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;