3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 00:23:03 +01:00
Dieser Commit ist enthalten in:
Camotoy 2024-10-21 01:19:18 -04:00
Ursprung 93d96ef5a4
Commit 04128907b4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
4 geänderte Dateien mit 37 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -53,7 +53,7 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
if (!session.isSpawned()) { if (!session.isSpawned()) {
// The server sends an absolute teleport everytime the player is respawned // The server sends an absolute teleport everytime the player is respawned
Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f pos = packet.getPosition().toFloat();
entity.setPosition(pos); entity.setPosition(pos);
entity.setYaw(packet.getYaw()); entity.setYaw(packet.getYaw());
entity.setPitch(packet.getPitch()); entity.setPitch(packet.getPitch());
@ -76,9 +76,9 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
session.sendUpstreamPacket(movePlayerPacket); session.sendUpstreamPacket(movePlayerPacket);
session.setSpawned(true); session.setSpawned(true);
// Make sure the player moves away from (0, 32767, 0) before accepting movement packets // Make sure the player moves away from (0, 32767, 0) before accepting movement packets
session.setUnconfirmedTeleport(new TeleportCache(packet.getX(), packet.getY(), packet.getZ(), packet.getPitch(), packet.getYaw(), packet.getTeleportId())); session.setUnconfirmedTeleport(new TeleportCache(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ(), packet.getYRot(), packet.getXRot(), packet.getId())); // TODO
acceptTeleport(session, packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch(), packet.getTeleportId()); acceptTeleport(session, packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ(), packet.getYRot(), packet.getXRot(), packet.getId());
if (session.getServerRenderDistance() > 32 && !session.isEmulatePost1_13Logic()) { if (session.getServerRenderDistance() > 32 && !session.isEmulatePost1_13Logic()) {
// See DimensionUtils for an explanation // See DimensionUtils for an explanation
@ -92,23 +92,23 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
ChunkUtils.updateChunkPosition(session, pos.toInt()); ChunkUtils.updateChunkPosition(session, pos.toInt());
if (session.getGeyser().getConfig().isDebugMode()) { if (session.getGeyser().getConfig().isDebugMode()) {
session.getGeyser().getLogger().debug("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ()); session.getGeyser().getLogger().debug("Spawned player at " + packet.getPosition());
} }
return; return;
} }
// If coordinates are relative, then add to the existing coordinate // If coordinates are relative, then add to the existing coordinate
double newX = packet.getX() + double newX = packet.getX() +
(packet.getRelative().contains(PositionElement.X) ? entity.getPosition().getX() : 0); (packet.getRelatives().contains(PositionElement.X) ? entity.getPosition().getX() : 0);
double newY = packet.getY() + double newY = packet.getY() +
(packet.getRelative().contains(PositionElement.Y) ? entity.getPosition().getY() - EntityDefinitions.PLAYER.offset() : 0); (packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - EntityDefinitions.PLAYER.offset() : 0);
double newZ = packet.getZ() + double newZ = packet.getZ() +
(packet.getRelative().contains(PositionElement.Z) ? entity.getPosition().getZ() : 0); (packet.getRelatives().contains(PositionElement.Z) ? entity.getPosition().getZ() : 0);
float newPitch = packet.getPitch() + (packet.getRelative().contains(PositionElement.PITCH) ? entity.getPitch() : 0); float newPitch = packet.getPitch() + (packet.getRelatives().contains(PositionElement.X_ROT) ? entity.getPitch() : 0);
float newYaw = packet.getYaw() + (packet.getRelative().contains(PositionElement.YAW) ? entity.getYaw() : 0); float newYaw = packet.getYaw() + (packet.getRelatives().contains(PositionElement.Y_ROT) ? entity.getYaw() : 0);
int id = packet.getTeleportId(); int id = packet.getId();
session.getGeyser().getLogger().debug("Teleport (" + id + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.offset()) + " " + entity.getPosition().getZ()); session.getGeyser().getLogger().debug("Teleport (" + id + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.offset()) + " " + entity.getPosition().getZ());
@ -135,7 +135,7 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
ServerboundAcceptTeleportationPacket teleportConfirmPacket = new ServerboundAcceptTeleportationPacket(id); ServerboundAcceptTeleportationPacket teleportConfirmPacket = new ServerboundAcceptTeleportationPacket(id);
session.sendDownstreamGamePacket(teleportConfirmPacket); session.sendDownstreamGamePacket(teleportConfirmPacket);
// Servers (especially ones like Hypixel) expect exact coordinates given back to them. // Servers (especially ones like Hypixel) expect exact coordinates given back to them.
ServerboundMovePlayerPosRotPacket positionPacket = new ServerboundMovePlayerPosRotPacket(false, x, y, z, yaw, pitch); ServerboundMovePlayerPosRotPacket positionPacket = new ServerboundMovePlayerPosRotPacket(false, false, x, y, z, yaw, pitch);
session.sendDownstreamGamePacket(positionPacket); session.sendDownstreamGamePacket(positionPacket);
} }
} }

Datei anzeigen

@ -26,20 +26,15 @@
package org.geysermc.geyser.translator.protocol.java.level; package org.geysermc.geyser.translator.protocol.java.level;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket;
import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.geyser.level.block.type.Block;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.ChunkUtils;
import org.geysermc.geyser.util.SoundUtils; import org.geysermc.geyser.util.SoundUtils;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.ExplosionInteraction;
import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundExplodePacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundExplodePacket;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -49,53 +44,33 @@ public class JavaExplodeTranslator extends PacketTranslator<ClientboundExplodePa
@Override @Override
public void translate(GeyserSession session, ClientboundExplodePacket packet) { public void translate(GeyserSession session, ClientboundExplodePacket packet) {
// todo 1.20.3 handle the 4 new fields Vector3f vector = packet.getCenter().toFloat();
LevelEventGenericPacket levelEventPacket = new LevelEventGenericPacket(); LevelEventGenericPacket levelEventPacket = new LevelEventGenericPacket();
levelEventPacket.setType(LevelEvent.PARTICLE_BLOCK_EXPLOSION); levelEventPacket.setType(LevelEvent.PARTICLE_BLOCK_EXPLOSION);
NbtMapBuilder builder = NbtMap.builder(); NbtMapBuilder builder = NbtMap.builder();
builder.putFloat("originX", (float) packet.getX()); builder.putFloat("originX", (float) packet.getCenter().getX());
builder.putFloat("originY", (float) packet.getY()); builder.putFloat("originY", (float) packet.getCenter().getY());
builder.putFloat("originZ", (float) packet.getZ()); builder.putFloat("originZ", (float) packet.getCenter().getZ());
builder.putFloat("radius", packet.getRadius());
builder.putInt("size", packet.getExploded().size()); // As of Bedrock 1.21 - particles will only be created by the above packet if there are blocks to blow up?
// As of 1.21, KEEP means no block actions are run. TRIGGER_BLOCK will run some actions, like buttons can be pressed // Not sure if the packet does anything - sending it just in case, because BDS still sends it.
if (packet.getBlockInteraction() != ExplosionInteraction.KEEP && packet.getBlockInteraction() != ExplosionInteraction.TRIGGER_BLOCK) { // TODO move out of packet translator class
int i = 0; var particleCreator = JavaLevelParticlesTranslator.createParticle(session, packet.getExplosionParticle());
for (Vector3i position : packet.getExploded()) { if (particleCreator != null) {
Vector3i pos = Vector3i.from(packet.getX() + position.getX(), packet.getY() + position.getY(), packet.getZ() + position.getZ()); session.sendUpstreamPacket(particleCreator.apply(vector));
ChunkUtils.updateBlock(session, Block.JAVA_AIR_ID, pos);
builder.putFloat("pos" + i + "x", pos.getX());
builder.putFloat("pos" + i + "y", pos.getY());
builder.putFloat("pos" + i + "z", pos.getZ());
i++;
}
} else {
// As of Bedrock 1.21 - particles will only be created by the above packet if there are blocks to blow up?
// Not sure if the packet does anything - sending it just in case, because BDS still sends it.
// TODO move out of packet translator class
Particle particle;
if (!(packet.getRadius() < 2f) && packet.getBlockInteraction() != ExplosionInteraction.KEEP) {
particle = packet.getLargeExplosionParticles();
} else {
particle = packet.getSmallExplosionParticles();
}
var particleCreator = JavaLevelParticlesTranslator.createParticle(session, particle);
if (particleCreator != null) {
session.sendUpstreamPacket(particleCreator.apply(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())));
}
} }
levelEventPacket.setTag(builder.build()); levelEventPacket.setTag(builder.build());
session.sendUpstreamPacket(levelEventPacket); session.sendUpstreamPacket(levelEventPacket);
Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
ThreadLocalRandom random = ThreadLocalRandom.current(); ThreadLocalRandom random = ThreadLocalRandom.current();
float pitch = (1.0f + (random.nextFloat() - random.nextFloat()) * 0.2f) * 0.7f; // As of 1.21, Explosion#finalizeExplosion float pitch = (1.0f + (random.nextFloat() - random.nextFloat()) * 0.2f) * 0.7f; // As of 1.21, Explosion#finalizeExplosion
SoundUtils.playSound(session, packet.getExplosionSound(), pos, 4.0f, pitch); SoundUtils.playSound(session, packet.getExplosionSound(), vector, 4.0f, pitch);
if (packet.getPushX() != 0f || packet.getPushY() != 0f || packet.getPushZ() != 0f) { if (packet.getPlayerKnockback() != null) {
SetEntityMotionPacket motionPacket = new SetEntityMotionPacket(); SetEntityMotionPacket motionPacket = new SetEntityMotionPacket();
motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
motionPacket.setMotion(Vector3f.from(packet.getPushX(), packet.getPushY(), packet.getPushZ())); motionPacket.setMotion(packet.getPlayerKnockback().toFloat());
session.sendUpstreamPacket(motionPacket); session.sendUpstreamPacket(motionPacket);
} }
} }

Datei anzeigen

@ -132,10 +132,11 @@ public class JavaLevelParticlesTranslator extends PacketTranslator<ClientboundLe
} }
case DUST, DUST_COLOR_TRANSITION -> { //TODO case DUST, DUST_COLOR_TRANSITION -> { //TODO
DustParticleData data = (DustParticleData) particle.getData(); DustParticleData data = (DustParticleData) particle.getData();
int r = (int) (data.getRed() * 255); // int r = (int) (data.getRed() * 255);
int g = (int) (data.getGreen() * 255); // int g = (int) (data.getGreen() * 255);
int b = (int) (data.getBlue() * 255); // int b = (int) (data.getBlue() * 255);
int rgbData = ((0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); // int rgbData = ((0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
int rgbData = data.getColor(); // TEST
return (position) -> { return (position) -> {
LevelEventPacket packet = new LevelEventPacket(); LevelEventPacket packet = new LevelEventPacket();
packet.setType(ParticleType.FALLING_DUST); packet.setType(ParticleType.FALLING_DUST);

Datei anzeigen

@ -36,11 +36,9 @@ public class JavaSetTimeTranslator extends PacketTranslator<ClientboundSetTimePa
@Override @Override
public void translate(GeyserSession session, ClientboundSetTimePacket packet) { public void translate(GeyserSession session, ClientboundSetTimePacket packet) {
session.setWorldTicks(packet.getWorldAge()); session.setWorldTicks(packet.getGameTime());
// Bedrock sends a GameRulesChangedPacket if there is no daylight cycle long time = packet.getDayTime();
// Java just sends a negative long if there is no daylight cycle
long time = packet.getTime();
// https://minecraft.wiki/w/Day-night_cycle#24-hour_Minecraft_day // https://minecraft.wiki/w/Day-night_cycle#24-hour_Minecraft_day
SetTimePacket setTimePacket = new SetTimePacket(); SetTimePacket setTimePacket = new SetTimePacket();
@ -49,12 +47,10 @@ public class JavaSetTimeTranslator extends PacketTranslator<ClientboundSetTimePa
// (Last verified behavior: Bedrock 1.18.12 / Java 1.18.2) // (Last verified behavior: Bedrock 1.18.12 / Java 1.18.2)
setTimePacket.setTime((int) (Math.abs(time) % (24000 * 8))); setTimePacket.setTime((int) (Math.abs(time) % (24000 * 8)));
session.sendUpstreamPacket(setTimePacket); session.sendUpstreamPacket(setTimePacket);
if (!session.isDaylightCycle() && time >= 0) {
// Client thinks there is no daylight cycle but there is // We need to send a gamerule if this changed
session.setDaylightCycle(true); if (session.isDaylightCycle() != packet.isTickDayTime()) {
} else if (session.isDaylightCycle() && time < 0) { session.setDaylightCycle(packet.isTickDayTime());
// Client thinks there is daylight cycle but there isn't
session.setDaylightCycle(false);
} }
} }
} }