Skip to content

Commit 7f1b697

Browse files
authored
Merge branch 'master' into feature/1.21.20
2 parents 402ea10 + 61ae5de commit 7f1b697

File tree

12 files changed

+79
-72
lines changed

12 files changed

+79
-72
lines changed

core/src/main/java/org/geysermc/geyser/command/defaults/DumpCommand.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,31 @@ public DumpCommand(GeyserImpl geyser, String name, String description, String pe
6363
this.geyser = geyser;
6464
}
6565

66-
@Override
67-
public void register(CommandManager<GeyserCommandSource> manager) {
68-
manager.command(baseBuilder(manager)
69-
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
70-
// parse suggestions here
71-
List<String> inputs = new ArrayList<>();
72-
while (input.hasRemainingInput()) {
73-
inputs.add(input.readStringSkipWhitespace());
74-
}
75-
76-
if (inputs.size() <= 2) {
77-
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
78-
}
79-
80-
// the rest of the input after `geyser dump` is for this argument
81-
inputs = inputs.subList(2, inputs.size());
82-
83-
// don't suggest any words they have already typed
84-
List<String> suggestions = new ArrayList<>();
85-
SUGGESTIONS.forEach(suggestions::add);
86-
suggestions.removeAll(inputs);
87-
return suggestions;
88-
}))
89-
.handler(this::execute));
90-
}
66+
@Override
67+
public void register(CommandManager<GeyserCommandSource> manager) {
68+
manager.command(baseBuilder(manager)
69+
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
70+
// parse suggestions here
71+
List<String> inputs = new ArrayList<>();
72+
while (input.hasRemainingInput()) {
73+
inputs.add(input.readStringSkipWhitespace());
74+
}
75+
76+
if (inputs.size() <= 2) {
77+
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
78+
}
79+
80+
// the rest of the input after `geyser dump` is for this argument
81+
inputs = inputs.subList(2, inputs.size());
82+
83+
// don't suggest any words they have already typed
84+
List<String> suggestions = new ArrayList<>();
85+
SUGGESTIONS.forEach(suggestions::add);
86+
suggestions.removeAll(inputs);
87+
return suggestions;
88+
}))
89+
.handler(this::execute));
90+
}
9191

9292
@Override
9393
public void execute(CommandContext<GeyserCommandSource> context) {
@@ -113,13 +113,15 @@ public void execute(CommandContext<GeyserCommandSource> context) {
113113
source.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collecting", source.locale()));
114114
String dumpData;
115115
try {
116+
DumpInfo dump = new DumpInfo(geyser, addLog);
117+
116118
if (offlineDump) {
117119
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
118120
// Make arrays easier to read
119121
prettyPrinter.indentArraysWith(new DefaultIndenter(" ", "\n"));
120-
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(new DumpInfo(addLog));
122+
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(dump);
121123
} else {
122-
dumpData = MAPPER.writeValueAsString(new DumpInfo(addLog));
124+
dumpData = MAPPER.writeValueAsString(dump);
123125
}
124126
} catch (IOException e) {
125127
source.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collect_error", source.locale()));

core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class DumpInfo {
8181
private final FlagsInfo flagsInfo;
8282
private final List<ExtensionInfo> extensionInfo;
8383

84-
public DumpInfo(boolean addLog) {
84+
public DumpInfo(GeyserImpl geyser, boolean addLog) {
8585
this.versionInfo = new VersionInfo();
8686

8787
this.cpuCount = Runtime.getRuntime().availableProcessors();
@@ -91,7 +91,7 @@ public DumpInfo(boolean addLog) {
9191

9292
this.gitInfo = new GitInfo(GeyserImpl.BUILD_NUMBER, GeyserImpl.COMMIT.substring(0, 7), GeyserImpl.COMMIT, GeyserImpl.BRANCH, GeyserImpl.REPOSITORY);
9393

94-
this.config = GeyserImpl.getInstance().getConfig();
94+
this.config = geyser.getConfig();
9595
this.floodgate = new Floodgate();
9696

9797
String md5Hash = "unknown";
@@ -107,7 +107,7 @@ public DumpInfo(boolean addLog) {
107107
//noinspection UnstableApiUsage
108108
sha256Hash = byteSource.hash(Hashing.sha256()).toString();
109109
} catch (Exception e) {
110-
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
110+
if (this.config.isDebugMode()) {
111111
e.printStackTrace();
112112
}
113113
}
@@ -116,18 +116,22 @@ public DumpInfo(boolean addLog) {
116116
this.ramInfo = new RamInfo();
117117

118118
if (addLog) {
119-
this.logsInfo = new LogsInfo();
119+
this.logsInfo = new LogsInfo(geyser);
120120
}
121121

122122
this.userPlatforms = new Object2IntOpenHashMap<>();
123-
for (GeyserSession session : GeyserImpl.getInstance().getSessionManager().getAllSessions()) {
123+
for (GeyserSession session : geyser.getSessionManager().getAllSessions()) {
124124
DeviceOs device = session.getClientData().getDeviceOs();
125125
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
126126
}
127127

128-
this.connectionAttempts = GeyserImpl.getInstance().getGeyserServer().getConnectionAttempts();
128+
if (geyser.getGeyserServer() != null) {
129+
this.connectionAttempts = geyser.getGeyserServer().getConnectionAttempts();
130+
} else {
131+
this.connectionAttempts = 0; // Fallback if Geyser failed to fully startup
132+
}
129133

130-
this.bootstrapInfo = GeyserImpl.getInstance().getBootstrap().getDumpInfo();
134+
this.bootstrapInfo = geyser.getBootstrap().getDumpInfo();
131135

132136
this.flagsInfo = new FlagsInfo();
133137

@@ -244,10 +248,10 @@ public static class Floodgate {
244248
public static class LogsInfo {
245249
private String link;
246250

247-
public LogsInfo() {
251+
public LogsInfo(GeyserImpl geyser) {
248252
try {
249253
Map<String, String> fields = new HashMap<>();
250-
fields.put("content", FileUtils.readAllLines(GeyserImpl.getInstance().getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
254+
fields.put("content", FileUtils.readAllLines(geyser.getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
251255

252256
JsonNode logData = GeyserImpl.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields));
253257

core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private boolean isBelowVoidFloor() {
321321

322322
public int voidFloorPosition() {
323323
// The void floor is offset about 40 blocks below the bottom of the world
324-
BedrockDimension bedrockDimension = session.getChunkCache().getBedrockDimension();
324+
BedrockDimension bedrockDimension = session.getBedrockDimension();
325325
return bedrockDimension.minY() - 40;
326326
}
327327

core/src/main/java/org/geysermc/geyser/level/JavaDimension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
* Represents the information we store from the current Java dimension
3535
* @param piglinSafe Whether piglins and hoglins are safe from conversion in this dimension.
3636
* This controls if they have the shaking effect applied in the dimension.
37+
* @param bedrockId the Bedrock dimension ID of this dimension.
38+
* As a Java dimension can be null in some login cases (e.g. GeyserConnect), make sure the player
39+
* is logged in before utilizing this field.
3740
*/
3841
public record JavaDimension(int minY, int maxY, boolean piglinSafe, double worldCoordinateScale, int bedrockId, boolean isNetherLike) {
3942

@@ -46,7 +49,7 @@ public static JavaDimension read(RegistryEntryContext entry) {
4649
// Set if piglins/hoglins should shake
4750
boolean piglinSafe = dimension.getBoolean("piglin_safe");
4851
// Load world coordinate scale for the world border
49-
double coordinateScale = dimension.getDouble("coordinate_scale");
52+
double coordinateScale = dimension.getNumber("coordinate_scale").doubleValue(); // FIXME see if we can change this in the NBT library itself.
5053

5154
boolean isNetherLike;
5255
// Cache the Bedrock version of this dimension, and base it off the ID - THE ID CAN CHANGE!!!

core/src/main/java/org/geysermc/geyser/session/GeyserSession.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
138138
import org.geysermc.geyser.item.Items;
139139
import org.geysermc.geyser.item.type.BlockItem;
140+
import org.geysermc.geyser.level.BedrockDimension;
140141
import org.geysermc.geyser.level.JavaDimension;
141142
import org.geysermc.geyser.level.physics.CollisionManager;
142143
import org.geysermc.geyser.network.netty.LocalSession;
@@ -386,6 +387,13 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
386387
@MonotonicNonNull
387388
@Setter
388389
private JavaDimension dimensionType = null;
390+
/**
391+
* Which dimension Bedrock understands themselves to be in.
392+
* This should only be set after the ChangeDimensionPacket is sent, or
393+
* right before the StartGamePacket is sent.
394+
*/
395+
@Setter
396+
private BedrockDimension bedrockDimension = BedrockDimension.OVERWORLD;
389397

390398
@Setter
391399
private int breakingBlock;
@@ -1547,7 +1555,7 @@ private void startGame() {
15471555
startGamePacket.setRotation(Vector2f.from(1, 1));
15481556

15491557
startGamePacket.setSeed(-1L);
1550-
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(chunkCache.getBedrockDimension()));
1558+
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(bedrockDimension));
15511559
startGamePacket.setGeneratorId(1);
15521560
startGamePacket.setLevelGameType(GameType.SURVIVAL);
15531561
startGamePacket.setDifficulty(1);

core/src/main/java/org/geysermc/geyser/session/cache/ChunkCache.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,14 @@
2525

2626
package org.geysermc.geyser.session.cache;
2727

28-
import org.geysermc.geyser.level.block.type.Block;
29-
import org.geysermc.mcprotocollib.protocol.data.game.chunk.DataPalette;
3028
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
3129
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
32-
import lombok.Getter;
3330
import lombok.Setter;
34-
import org.geysermc.geyser.level.BedrockDimension;
35-
import org.geysermc.geyser.level.block.BlockStateValues;
31+
import org.geysermc.geyser.level.block.type.Block;
3632
import org.geysermc.geyser.level.chunk.GeyserChunk;
3733
import org.geysermc.geyser.session.GeyserSession;
3834
import org.geysermc.geyser.util.MathUtils;
35+
import org.geysermc.mcprotocollib.protocol.data.game.chunk.DataPalette;
3936

4037
public class ChunkCache {
4138
private final boolean cache;
@@ -46,13 +43,6 @@ public class ChunkCache {
4643
@Setter
4744
private int heightY;
4845

49-
/**
50-
* Which dimension Bedrock understands themselves to be in.
51-
*/
52-
@Getter
53-
@Setter
54-
private BedrockDimension bedrockDimension = BedrockDimension.OVERWORLD;
55-
5646
public ChunkCache(GeyserSession session) {
5747
this.cache = !session.getGeyser().getWorldManager().hasOwnChunkCache(); // To prevent Spigot from initializing
5848
chunks = cache ? new Long2ObjectOpenHashMap<>() : null;

core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginTranslator.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,17 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
6464

6565
PlayerSpawnInfo spawnInfo = packet.getCommonPlayerSpawnInfo();
6666
JavaDimension newDimension = session.getRegistryCache().dimensions().byId(spawnInfo.getDimension());
67-
boolean forceDimSwitch = false;
6867

6968
// If the player is already initialized and a join game packet is sent, they
7069
// are swapping servers
7170
if (session.isSpawned()) {
72-
int fakeDim = DimensionUtils.getTemporaryDimension(session.getDimensionType().bedrockId(), newDimension.bedrockId());
73-
DimensionUtils.fastSwitchDimension(session, fakeDim);
74-
forceDimSwitch = true;
71+
int fakeDim = DimensionUtils.getTemporaryDimension(DimensionUtils.javaToBedrock(session.getBedrockDimension()), newDimension.bedrockId());
72+
if (fakeDim != newDimension.bedrockId()) {
73+
// The player's current dimension and new dimension are the same
74+
// We want a dimension switch to clear old chunks out, so switch to a dimension that isn't the one we're currently in.
75+
// Another dimension switch will be required to switch back
76+
DimensionUtils.fastSwitchDimension(session, fakeDim);
77+
}
7578

7679
session.getWorldCache().removeScoreboard();
7780

@@ -80,23 +83,16 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
8083
// Remove extra hearts, hunger, etc.
8184
entity.resetAttributes();
8285
entity.resetMetadata();
83-
} else if (session.getUpstream().isInitialized()) {
84-
if (newDimension.bedrockId() == 0) {
85-
// A dimension switch will not happen, so make sure we initialized the dimension choice.
86-
// Otherwise, the dimension switch will fill these values in.
87-
session.setDimensionType(newDimension);
88-
DimensionUtils.setBedrockDimension(session, newDimension.bedrockId());
89-
}
9086
}
9187

88+
session.setDimensionType(newDimension);
9289
session.setWorldName(spawnInfo.getWorldName());
9390
session.setLevels(Arrays.stream(packet.getWorldNames()).map(Key::asString).toArray(String[]::new));
9491
session.setGameMode(spawnInfo.getGameMode());
9592

9693
boolean needsSpawnPacket = !session.isSentSpawnPacket();
9794
if (needsSpawnPacket) {
9895
// The player has yet to spawn so let's do that using some of the information in this Java packet
99-
session.setDimensionType(newDimension);
10096
DimensionUtils.setBedrockDimension(session, newDimension.bedrockId());
10197
session.connect();
10298

@@ -131,7 +127,7 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
131127
}
132128
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket(register, Constants.PLUGIN_MESSAGE.getBytes(StandardCharsets.UTF_8)));
133129

134-
if (newDimension != session.getDimensionType() || forceDimSwitch) {
130+
if (DimensionUtils.javaToBedrock(session.getBedrockDimension()) != newDimension.bedrockId()) {
135131
DimensionUtils.switchDimension(session, newDimension);
136132
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.isNetherLike()) {
137133
// If the player is spawning into the "fake" nether, send them some fog

core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaHorseScreenOpenTranslator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package org.geysermc.geyser.translator.protocol.java.inventory;
2727

28+
import org.geysermc.geyser.entity.type.living.animal.horse.SkeletonHorseEntity;
29+
import org.geysermc.geyser.entity.type.living.animal.horse.ZombieHorseEntity;
2830
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundHorseScreenOpenPacket;
2931
import org.cloudburstmc.nbt.NbtMap;
3032
import org.cloudburstmc.nbt.NbtMapBuilder;
@@ -140,7 +142,9 @@ public void translate(GeyserSession session, ClientboundHorseScreenOpenPacket pa
140142
} else {
141143
inventoryTranslator = new HorseInventoryTranslator(slotCount);
142144
slots.add(SADDLE_SLOT);
143-
slots.add(ARMOR_SLOT);
145+
if (!(entity instanceof SkeletonHorseEntity || entity instanceof ZombieHorseEntity)) {
146+
slots.add(ARMOR_SLOT);
147+
}
144148
}
145149

146150
// Build the NbtMap that sets the icons for Bedrock (e.g. sets the saddle outline on the saddle slot)

core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
9999
BitSet waterloggedPaletteIds = new BitSet();
100100
BitSet bedrockOnlyBlockEntityIds = new BitSet();
101101

102-
BedrockDimension bedrockDimension = session.getChunkCache().getBedrockDimension();
102+
BedrockDimension bedrockDimension = session.getBedrockDimension();
103103
int maxBedrockSectionY = (bedrockDimension.height() >> 4) - 1;
104104

105105
int sectionCount;
@@ -509,7 +509,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
509509
levelChunkPacket.setChunkX(packet.getX());
510510
levelChunkPacket.setChunkZ(packet.getZ());
511511
levelChunkPacket.setData(Unpooled.wrappedBuffer(payload));
512-
levelChunkPacket.setDimension(DimensionUtils.javaToBedrock(session.getChunkCache().getBedrockDimension()));
512+
levelChunkPacket.setDimension(DimensionUtils.javaToBedrock(session.getBedrockDimension()));
513513
session.sendUpstreamPacket(levelChunkPacket);
514514

515515
for (Map.Entry<Vector3i, ItemFrameEntity> entry : session.getItemFrameCache().entrySet()) {

core/src/main/java/org/geysermc/geyser/util/ChunkUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static void updateBlockClientSide(GeyserSession session, BlockState block
149149
}
150150

151151
public static void sendEmptyChunk(GeyserSession session, int chunkX, int chunkZ, boolean forceUpdate) {
152-
BedrockDimension bedrockDimension = session.getChunkCache().getBedrockDimension();
152+
BedrockDimension bedrockDimension = session.getBedrockDimension();
153153
int bedrockSubChunkCount = bedrockDimension.height() >> 4;
154154

155155
byte[] payload;
@@ -167,7 +167,7 @@ public static void sendEmptyChunk(GeyserSession session, int chunkX, int chunkZ,
167167
byteBuf.readBytes(payload);
168168

169169
LevelChunkPacket data = new LevelChunkPacket();
170-
data.setDimension(DimensionUtils.javaToBedrock(session.getChunkCache().getBedrockDimension()));
170+
data.setDimension(DimensionUtils.javaToBedrock(session.getBedrockDimension()));
171171
data.setChunkX(chunkX);
172172
data.setChunkZ(chunkZ);
173173
data.setSubChunksLength(0);
@@ -214,7 +214,7 @@ public static void loadDimension(GeyserSession session) {
214214
throw new RuntimeException("Maximum Y must be a multiple of 16!");
215215
}
216216

217-
BedrockDimension bedrockDimension = session.getChunkCache().getBedrockDimension();
217+
BedrockDimension bedrockDimension = session.getBedrockDimension();
218218
// Yell in the console if the world height is too height in the current scenario
219219
// The constraints change depending on if the player is in the overworld or not, and if experimental height is enabled
220220
// (Ignore this for the Nether. We can't change that at the moment without the workaround. :/ )

0 commit comments

Comments
 (0)