Skip to content

Commit 94b07ea

Browse files
authored
Cleanup MinecraftProtocolTest (#698)
* Cleanup MinecraftProtocolTest * Use try-with-resources.
1 parent bb2b414 commit 94b07ea

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
1010
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
1111
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
12-
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
12+
import com.github.steveice10.opennbt.NBTIO;
1313
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
14-
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
15-
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
16-
import com.github.steveice10.opennbt.tag.builtin.IntTag;
17-
import com.github.steveice10.opennbt.tag.builtin.ListTag;
18-
import com.github.steveice10.opennbt.tag.builtin.StringTag;
1914
import com.github.steveice10.packetlib.Server;
2015
import com.github.steveice10.packetlib.Session;
2116
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
@@ -28,7 +23,12 @@
2823
import org.junit.BeforeClass;
2924
import org.junit.Test;
3025

26+
import java.io.DataInput;
27+
import java.io.DataInputStream;
28+
import java.io.IOException;
29+
import java.io.InputStream;
3130
import java.util.concurrent.CountDownLatch;
31+
import java.util.zip.GZIPInputStream;
3232

3333
import static com.github.steveice10.mc.protocol.MinecraftConstants.SERVER_COMPRESSION_THRESHOLD;
3434
import static com.github.steveice10.mc.protocol.MinecraftConstants.SERVER_INFO_BUILDER_KEY;
@@ -51,7 +51,7 @@ public class MinecraftProtocolTest {
5151
null,
5252
false
5353
);
54-
private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, GameMode.SURVIVAL, GameMode.SURVIVAL, 1, new String[]{"minecraft:world"}, getDimensionTag(), "overworld", "minecraft:world", 100, 0, 16, 16, false, false, false, false, null);
54+
private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, GameMode.SURVIVAL, GameMode.SURVIVAL, 1, new String[]{"minecraft:world"}, loadLoginRegistry(), "overworld", "minecraft:world", 100, 0, 16, 16, false, false, false, false, null);
5555

5656
private static Server server;
5757

@@ -142,45 +142,13 @@ public void disconnected(DisconnectedEvent event) {
142142
}
143143
}
144144

145-
private static CompoundTag getDimensionTag() {
146-
CompoundTag overworldTag = getOverworldTag();
147-
CompoundTag tag = new CompoundTag("minecraft:dimension_type");
148-
tag.put(new StringTag("type", "minecraft:dimension_type"));
149-
ListTag list = new ListTag("value");
150-
list.add(overworldTag);
151-
tag.put(list);
152-
return tag;
153-
}
154-
155-
private static CompoundTag getOverworldTag() {
156-
CompoundTag overworldTag = new CompoundTag("");
157-
CompoundTag element = new CompoundTag("element");
158-
element.put(new FloatTag("ambient_light", 0f));
159-
element.put(new ByteTag("bed_works", (byte) 1));
160-
element.put(new DoubleTag("coordinate_scale", 1d));
161-
element.put(new StringTag("effects", "minecraft:overworld"));
162-
element.put(new ByteTag("has_ceiling", (byte) 0));
163-
element.put(new ByteTag("has_raids", (byte) 1));
164-
element.put(new ByteTag("has_skylight", (byte) 1));
165-
element.put(new IntTag("height", 384));
166-
element.put(new StringTag("infiniburn", "#minecraft:infiniburn_overworld"));
167-
element.put(new IntTag("logical_height", 384));
168-
element.put(new IntTag("min_y", -64));
169-
element.put(new IntTag("monster_spawner_block_light_limit", 0));
170-
CompoundTag spawnLightLevel = new CompoundTag("monster_spawn_light_level");
171-
spawnLightLevel.put(new StringTag("type", "minecraft:uniform"));
172-
CompoundTag value = new CompoundTag("value");
173-
value.put(new IntTag("max_inclusive", 7));
174-
value.put(new IntTag("min_inclusive", 0));
175-
spawnLightLevel.put(value);
176-
element.put(spawnLightLevel);
177-
element.put(new ByteTag("natural", (byte) 1));
178-
element.put(new ByteTag("piglin_safe", (byte) 0));
179-
element.put(new ByteTag("respawn_anchor_works", (byte) 0));
180-
element.put(new ByteTag("ultrawarm", (byte) 0));
181-
overworldTag.put(element);
182-
overworldTag.put(new IntTag("id", 0));
183-
overworldTag.put(new StringTag("name", "minecraft:overworld"));
184-
return overworldTag;
145+
public static CompoundTag loadLoginRegistry() {
146+
try (InputStream inputStream = MinecraftProtocolTest.class.getClassLoader().getResourceAsStream("login_registry.nbt");
147+
DataInputStream stream = new DataInputStream(new GZIPInputStream(inputStream))) {
148+
return (CompoundTag) NBTIO.readTag((DataInput) stream);
149+
} catch (IOException e) {
150+
e.printStackTrace();
151+
throw new AssertionError("Unable to load login registry.");
152+
}
185153
}
186154
}
2.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)