Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +01:00
Add doDaylightCycle gamerule support
Dieser Commit ist enthalten in:
Ursprung
e67ed6dc8d
Commit
746cd29a6d
@ -66,6 +66,12 @@
|
|||||||
<version>8.3.1</version>
|
<version>8.3.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.nukkitx.fastutil</groupId>
|
||||||
|
<artifactId>fastutil-long-boolean-maps</artifactId>
|
||||||
|
<version>8.3.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.nukkitx.fastutil</groupId>
|
<groupId>com.nukkitx.fastutil</groupId>
|
||||||
<artifactId>fastutil-object-long-maps</artifactId>
|
<artifactId>fastutil-object-long-maps</artifactId>
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.java.world;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import org.geysermc.connector.network.translators.Translator;
|
import org.geysermc.connector.network.translators.Translator;
|
||||||
@ -35,11 +39,38 @@ import com.nukkitx.protocol.bedrock.packet.SetTimePacket;
|
|||||||
@Translator(packet = ServerUpdateTimePacket.class)
|
@Translator(packet = ServerUpdateTimePacket.class)
|
||||||
public class JavaUpdateTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
|
public class JavaUpdateTimeTranslator extends PacketTranslator<ServerUpdateTimePacket> {
|
||||||
|
|
||||||
|
// doDaylightCycle per-player for multi-world support
|
||||||
|
static Long2BooleanMap daylightCycles = new Long2BooleanOpenHashMap();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerUpdateTimePacket packet, GeyserSession session) {
|
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
|
// https://minecraft.gamepedia.com/Day-night_cycle#24-hour_Minecraft_day
|
||||||
SetTimePacket setTimePacket = new SetTimePacket();
|
SetTimePacket setTimePacket = new SetTimePacket();
|
||||||
setTimePacket.setTime((int) Math.abs(packet.getTime()) % 24000);
|
setTimePacket.setTime((int) Math.abs(time) % 24000);
|
||||||
session.getUpstream().sendPacket(setTimePacket);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren