3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +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()) {
// 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.setYaw(packet.getYaw());
entity.setPitch(packet.getPitch());
@ -76,9 +76,9 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
session.sendUpstreamPacket(movePlayerPacket);
session.setSpawned(true);
// 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()) {
// See DimensionUtils for an explanation
@ -92,23 +92,23 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
ChunkUtils.updateChunkPosition(session, pos.toInt());
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;
}
// If coordinates are relative, then add to the existing coordinate
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() +
(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() +
(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 newYaw = packet.getYaw() + (packet.getRelative().contains(PositionElement.YAW) ? entity.getYaw() : 0);
float newPitch = packet.getPitch() + (packet.getRelatives().contains(PositionElement.X_ROT) ? entity.getPitch() : 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());
@ -135,7 +135,7 @@ public class JavaPlayerPositionTranslator extends PacketTranslator<ClientboundPl
ServerboundAcceptTeleportationPacket teleportConfirmPacket = new ServerboundAcceptTeleportationPacket(id);
session.sendDownstreamGamePacket(teleportConfirmPacket);
// 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);
}
}

Datei anzeigen

@ -26,20 +26,15 @@
package org.geysermc.geyser.translator.protocol.java.level;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket;
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.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.ChunkUtils;
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 java.util.concurrent.ThreadLocalRandom;
@ -49,53 +44,33 @@ public class JavaExplodeTranslator extends PacketTranslator<ClientboundExplodePa
@Override
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();
levelEventPacket.setType(LevelEvent.PARTICLE_BLOCK_EXPLOSION);
NbtMapBuilder builder = NbtMap.builder();
builder.putFloat("originX", (float) packet.getX());
builder.putFloat("originY", (float) packet.getY());
builder.putFloat("originZ", (float) packet.getZ());
builder.putFloat("radius", packet.getRadius());
builder.putInt("size", packet.getExploded().size());
// As of 1.21, KEEP means no block actions are run. TRIGGER_BLOCK will run some actions, like buttons can be pressed
if (packet.getBlockInteraction() != ExplosionInteraction.KEEP && packet.getBlockInteraction() != ExplosionInteraction.TRIGGER_BLOCK) {
int i = 0;
for (Vector3i position : packet.getExploded()) {
Vector3i pos = Vector3i.from(packet.getX() + position.getX(), packet.getY() + position.getY(), packet.getZ() + position.getZ());
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())));
}
builder.putFloat("originX", (float) packet.getCenter().getX());
builder.putFloat("originY", (float) packet.getCenter().getY());
builder.putFloat("originZ", (float) packet.getCenter().getZ());
// 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
var particleCreator = JavaLevelParticlesTranslator.createParticle(session, packet.getExplosionParticle());
if (particleCreator != null) {
session.sendUpstreamPacket(particleCreator.apply(vector));
}
levelEventPacket.setTag(builder.build());
session.sendUpstreamPacket(levelEventPacket);
Vector3f pos = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
ThreadLocalRandom random = ThreadLocalRandom.current();
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();
motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
motionPacket.setMotion(Vector3f.from(packet.getPushX(), packet.getPushY(), packet.getPushZ()));
motionPacket.setMotion(packet.getPlayerKnockback().toFloat());
session.sendUpstreamPacket(motionPacket);
}
}

Datei anzeigen

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

Datei anzeigen

@ -36,11 +36,9 @@ public class JavaSetTimeTranslator extends PacketTranslator<ClientboundSetTimePa
@Override
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
// Java just sends a negative long if there is no daylight cycle
long time = packet.getTime();
long time = packet.getDayTime();
// https://minecraft.wiki/w/Day-night_cycle#24-hour_Minecraft_day
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)
setTimePacket.setTime((int) (Math.abs(time) % (24000 * 8)));
session.sendUpstreamPacket(setTimePacket);
if (!session.isDaylightCycle() && time >= 0) {
// Client thinks there is no daylight cycle but there is
session.setDaylightCycle(true);
} else if (session.isDaylightCycle() && time < 0) {
// Client thinks there is daylight cycle but there isn't
session.setDaylightCycle(false);
// We need to send a gamerule if this changed
if (session.isDaylightCycle() != packet.isTickDayTime()) {
session.setDaylightCycle(packet.isTickDayTime());
}
}
}