3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 08:10:11 +01:00

Add doDaylightCycle gamerule support

Dieser Commit ist enthalten in:
DoctorMacc 2020-04-12 21:13:51 -04:00
Ursprung e67ed6dc8d
Commit 746cd29a6d
2 geänderte Dateien mit 38 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -66,6 +66,12 @@
<version>8.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-long-boolean-maps</artifactId>
<version>8.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-object-long-maps</artifactId>

Datei anzeigen

@ -25,6 +25,10 @@
package org.geysermc.connector.network.translators.java.world;
import com.nukkitx.protocol.bedrock.data.GameRuleData;
import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket;
import it.unimi.dsi.fastutil.longs.Long2BooleanMap;
import it.unimi.dsi.fastutil.longs.Long2BooleanOpenHashMap;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@ -35,11 +39,38 @@ import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
@Translator(packet = ServerUpdateTimePacket.class)
public class JavaUpdateTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
// doDaylightCycle per-player for multi-world support
static Long2BooleanMap daylightCycles = new Long2BooleanOpenHashMap();
@Override
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
boolean doDayLightCycle = daylightCycles.getOrDefault(session.getPlayerEntity().getEntityId(), true);
long time = packet.getTime();
if ((!doDayLightCycle && time > 0) || (doDayLightCycle && time < 0)) {
// doDaylightCycle is different than the client and we don't know
// Time is set either way as a reference point for the current time
setTime(time, session);
setDoDayLightGamerule(session, !doDayLightCycle);
} else if (time > 0) {
// doDaylightCycle is true and we know
setTime(time, session);
}
}
private void setTime(long time, GeyserSession session) {
// https://minecraft.gamepedia.com/Day-night_cycle#24-hour_Minecraft_day
SetTimePacket setTimePacket = new SetTimePacket();
setTimePacket.setTime((int) Math.abs(packet.getTime()) % 24000);
setTimePacket.setTime((int) Math.abs(time) % 24000);
session.getUpstream().sendPacket(setTimePacket);
}
private void setDoDayLightGamerule(GeyserSession session, boolean doCycle) {
GameRulesChangedPacket gameRulesChangedPacket = new GameRulesChangedPacket();
gameRulesChangedPacket.getGameRules().add(new GameRuleData<>("dodaylightcycle", doCycle));
session.getUpstream().sendPacket(gameRulesChangedPacket);
daylightCycles.put(session.getPlayerEntity().getEntityId(), doCycle);
}
}