use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker in project DirtMultiversion by DirtPowered.
the class MovementPackets method registerTranslators.
@Override
public void registerTranslators() {
// entity
addTranslator(0x14, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x14, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)) });
}
});
// entity relative move
addTranslator(0x15, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
int entityId = data.read(Type.INT, 0);
double y = data.read(Type.BYTE, 2) / 32.0D;
boolean onGround = !(y < 0.0D);
groundTracker.setGroundStateFor(entityId, onGround);
return PacketUtil.createPacket(0x15, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), set(Type.BOOLEAN, onGround) });
}
});
// entity look
addTranslator(0x16, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
int entityId = data.read(Type.INT, 0);
boolean onGround = groundTracker.isOnGround(entityId);
return PacketUtil.createPacket(0x16, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), set(Type.BOOLEAN, onGround) });
}
});
// entity look move
addTranslator(0x17, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
int entityId = data.read(Type.INT, 0);
double y = data.read(Type.BYTE, 2) / 32.0D;
boolean onGround = !(y < 0.0D);
groundTracker.setGroundStateFor(entityId, onGround);
return PacketUtil.createPacket(0x17, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), set(Type.BOOLEAN, onGround) });
}
});
// entity teleport
addTranslator(0x18, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
OnGroundTracker groundTracker = storage.get(OnGroundTracker.class);
int entityId = data.read(Type.INT, 0);
boolean onGround = groundTracker.isOnGround(entityId);
return PacketUtil.createPacket(0x18, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), set(Type.BOOLEAN, onGround) });
}
});
// entity head look
addTranslator(0x19, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x19, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1) });
}
});
// position and look
addTranslator(0x08, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x08, new TypeHolder[] { data.read(0), set(Type.DOUBLE, data.read(Type.DOUBLE, 1) - 1.62D), data.read(2), data.read(3), data.read(4), set(Type.BYTE, (byte) 0) });
}
});
// player
addTranslator(0x03, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage s = session.getStorage();
if (s.hasObject(PlayerMovementTracker.class)) {
s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
}
return PacketUtil.createPacket(0x03, new TypeHolder[] { set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 0).byteValue()) });
}
});
// player position
addTranslator(0x04, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage s = session.getStorage();
if (s.hasObject(PlayerMovementTracker.class)) {
s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
}
return PacketUtil.createPacket(0x04, new TypeHolder[] { data.read(0), data.read(1), // stance
set(Type.DOUBLE, data.read(Type.DOUBLE, 1) + 1.62D), data.read(2), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 3).byteValue()) });
}
});
// player look
addTranslator(0x05, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage s = session.getStorage();
if (s.hasObject(PlayerMovementTracker.class)) {
s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
}
return PacketUtil.createPacket(0x05, new TypeHolder[] { data.read(0), data.read(1), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 2).byteValue()) });
}
});
// player pos look
addTranslator(0x06, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage s = session.getStorage();
if (s.hasObject(PlayerMovementTracker.class)) {
s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
}
return PacketUtil.createPacket(0x06, new TypeHolder[] { data.read(0), data.read(1), set(Type.DOUBLE, data.read(Type.DOUBLE, 1) + 1.62D), data.read(2), data.read(3), data.read(4), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 5).byteValue()) });
}
});
}
use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker in project DirtMultiversion by DirtPowered.
the class ProtocolRelease47To5 method onConnect.
@Override
public void onConnect(ServerSession session) {
ProtocolStorage storage = session.getStorage();
storage.set(OnGroundTracker.class, new OnGroundTracker());
storage.set(WindowTypeTracker.class, new WindowTypeTracker());
storage.set(QuickBarTracker.class, new QuickBarTracker());
// additional block storage (for nether portal rotation fix)
storage.set(PortalFrameCache.class, new PortalFrameCache());
if (session.getMain().getConfiguration().enableViaVersion()) {
// it's not needed for 1.8->1.7, but ViaVersion will need that to fix issues
// with eating, entering portals, effects (potions)
storage.set(PlayerMovementTracker.class, new PlayerMovementTracker());
}
// check if 1.6 entity tracker exists - if not, create one
if (!storage.hasObject(EntityTracker.class)) {
storage.set(V1_7EntityTracker.class, new V1_7EntityTracker());
}
// fixes block hardness inconsistencies
if (session.getMain().getConfiguration().getServerVersion() == MinecraftVersion.B1_7_3) {
storage.set(BlockMiningTimeFixer.class, new BlockMiningTimeFixer(session));
}
}
Aggregations