Clean up & Format

This commit is contained in:
LOOHP 2024-03-25 22:03:24 +00:00
parent 01d2a3e528
commit 8ec7d322d8
11 changed files with 720 additions and 748 deletions

12
pom.xml
View File

@ -24,7 +24,7 @@
<groupId>com.loohp</groupId> <groupId>com.loohp</groupId>
<artifactId>Limbo</artifactId> <artifactId>Limbo</artifactId>
<name>Limbo</name> <name>Limbo</name>
<version>0.7.7-ALPHA</version> <version>0.7.8-ALPHA</version>
<description>Standalone Limbo Minecraft Server.</description> <description>Standalone Limbo Minecraft Server.</description>
<url>https://github.com/LOOHP/Limbo</url> <url>https://github.com/LOOHP/Limbo</url>
@ -260,31 +260,31 @@
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId> <artifactId>adventure-text-serializer-gson</artifactId>
<version>4.15.0-SNAPSHOT</version> <version>4.17.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId> <artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.15.0-SNAPSHOT</version> <version>4.17.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId> <artifactId>adventure-text-serializer-plain</artifactId>
<version>4.15.0-SNAPSHOT</version> <version>4.17.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId> <artifactId>adventure-api</artifactId>
<version>4.15.0-SNAPSHOT</version> <version>4.17.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-nbt</artifactId> <artifactId>adventure-nbt</artifactId>
<version>4.15.0-SNAPSHOT</version> <version>4.17.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -123,8 +123,7 @@ public final class Limbo {
Thread t1 = new Thread(() -> { Thread t1 = new Thread(() -> {
try { try {
GUI.main(); GUI.main();
} catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
}); });
@ -161,8 +160,6 @@ public final class Limbo {
private final PermissionsManager permissionManager; private final PermissionsManager permissionManager;
private final File pluginFolder; private final File pluginFolder;
private final File internalDataFolder;
private final DimensionRegistry dimensionRegistry; private final DimensionRegistry dimensionRegistry;
private final Tick tick; private final Tick tick;
@ -210,19 +207,14 @@ public final class Limbo {
console.sendMessage("Starting Limbo server in bungeecord mode!"); console.sendMessage("Starting Limbo server in bungeecord mode!");
} }
internalDataFolder = new File("internal_data"); String mappingName = "mapping.json";
if (!internalDataFolder.exists()) { InputStream mappingStream = getClass().getClassLoader().getResourceAsStream(mappingName);
internalDataFolder.mkdirs();
}
console.sendMessage("Loading packet id mappings from mapping.json ...");
InputStream mappingStream = getClass().getClassLoader().getResourceAsStream("mapping.json");
if (mappingStream == null) { if (mappingStream == null) {
console.sendMessage("Failed to load mapping.json from jar!"); throw new RuntimeException("Failed to load " + mappingName + " from jar!");
System.exit(1);
} }
console.sendMessage("Loading packet id mappings...");
InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8); InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8);
JSONObject json = (JSONObject) new JSONParser().parse(reader); JSONObject json = (JSONObject) new JSONParser().parse(reader);
reader.close(); reader.close();
@ -346,8 +338,7 @@ public final class Limbo {
loadPluginsMethod.setAccessible(true); loadPluginsMethod.setAccessible(true);
loadPluginsMethod.invoke(pluginManager); loadPluginsMethod.invoke(pluginManager);
loadPluginsMethod.setAccessible(false); loadPluginsMethod.setAccessible(false);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -392,10 +383,6 @@ public final class Limbo {
return permissionManager; return permissionManager;
} }
public File getInternalDataFolder() {
return internalDataFolder;
}
public EventsManager getEventsManager() { public EventsManager getEventsManager() {
return eventsManager; return eventsManager;
} }

View File

@ -41,13 +41,61 @@ import com.loohp.limbo.inventory.AnvilInventory;
import com.loohp.limbo.inventory.Inventory; import com.loohp.limbo.inventory.Inventory;
import com.loohp.limbo.inventory.ItemStack; import com.loohp.limbo.inventory.ItemStack;
import com.loohp.limbo.location.Location; import com.loohp.limbo.location.Location;
import com.loohp.limbo.network.protocol.packets.*; import com.loohp.limbo.network.protocol.packets.ClientboundFinishConfigurationPacket;
import com.loohp.limbo.network.protocol.packets.ClientboundRegistryDataPacket;
import com.loohp.limbo.network.protocol.packets.Packet;
import com.loohp.limbo.network.protocol.packets.PacketHandshakingIn;
import com.loohp.limbo.network.protocol.packets.PacketIn;
import com.loohp.limbo.network.protocol.packets.PacketLoginInLoginStart;
import com.loohp.limbo.network.protocol.packets.PacketLoginInPluginMessaging;
import com.loohp.limbo.network.protocol.packets.PacketLoginOutDisconnect;
import com.loohp.limbo.network.protocol.packets.PacketLoginOutLoginSuccess;
import com.loohp.limbo.network.protocol.packets.PacketLoginOutPluginMessaging;
import com.loohp.limbo.network.protocol.packets.PacketOut;
import com.loohp.limbo.network.protocol.packets.PacketPlayInBlockDig;
import com.loohp.limbo.network.protocol.packets.PacketPlayInBlockPlace;
import com.loohp.limbo.network.protocol.packets.PacketPlayInChat;
import com.loohp.limbo.network.protocol.packets.PacketPlayInCloseWindow;
import com.loohp.limbo.network.protocol.packets.PacketPlayInHeldItemChange;
import com.loohp.limbo.network.protocol.packets.PacketPlayInItemName;
import com.loohp.limbo.network.protocol.packets.PacketPlayInKeepAlive;
import com.loohp.limbo.network.protocol.packets.PacketPlayInPickItem;
import com.loohp.limbo.network.protocol.packets.PacketPlayInPluginMessaging;
import com.loohp.limbo.network.protocol.packets.PacketPlayInPosition;
import com.loohp.limbo.network.protocol.packets.PacketPlayInPositionAndLook;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameStateChange;
import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket;
import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket.Action; import com.loohp.limbo.network.protocol.packets.ServerboundResourcePackPacket.Action;
import com.loohp.limbo.network.protocol.packets.PacketPlayInRotation;
import com.loohp.limbo.network.protocol.packets.PacketPlayInSetCreativeSlot;
import com.loohp.limbo.network.protocol.packets.PacketPlayInTabComplete;
import com.loohp.limbo.network.protocol.packets.PacketPlayInUseItem;
import com.loohp.limbo.network.protocol.packets.PacketPlayInWindowClick;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutDeclareCommands;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutDisconnect;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutHeldItemChange;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutKeepAlive;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutLogin;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerAbilities;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerAbilities.PlayerAbilityFlags; import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerAbilities.PlayerAbilityFlags;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoAction; import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoAction;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoData; import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoData;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoData.PlayerInfoDataAddPlayer.PlayerSkinProperty; import com.loohp.limbo.network.protocol.packets.PacketPlayOutPlayerInfo.PlayerInfoData.PlayerInfoDataAddPlayer.PlayerSkinProperty;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPluginMessaging;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutPositionAndLook;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutSpawnPosition;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutTabComplete;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutTabComplete.TabCompleteMatches; import com.loohp.limbo.network.protocol.packets.PacketPlayOutTabComplete.TabCompleteMatches;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutUpdateViewPosition;
import com.loohp.limbo.network.protocol.packets.PacketStatusInPing;
import com.loohp.limbo.network.protocol.packets.PacketStatusInRequest;
import com.loohp.limbo.network.protocol.packets.PacketStatusOutPong;
import com.loohp.limbo.network.protocol.packets.PacketStatusOutResponse;
import com.loohp.limbo.network.protocol.packets.ServerboundChatCommandPacket;
import com.loohp.limbo.network.protocol.packets.ServerboundFinishConfigurationPacket;
import com.loohp.limbo.network.protocol.packets.ServerboundLoginAcknowledgedPacket;
import com.loohp.limbo.player.Player; import com.loohp.limbo.player.Player;
import com.loohp.limbo.player.PlayerInteractManager; import com.loohp.limbo.player.PlayerInteractManager;
import com.loohp.limbo.player.PlayerInventory; import com.loohp.limbo.player.PlayerInventory;
@ -565,6 +613,10 @@ public class ClientConnection extends Thread {
String str = (properties.isLogPlayerIPAddresses() ? inetAddress.getHostName() : "<ip address withheld>") + ":" + clientSocket.getPort() + "|" + player.getName() + "(" + player.getUniqueId() + ")"; String str = (properties.isLogPlayerIPAddresses() ? inetAddress.getHostName() : "<ip address withheld>") + ":" + clientSocket.getPort() + "|" + player.getName() + "(" + player.getUniqueId() + ")";
Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Player had connected to the Limbo server!"); Limbo.getInstance().getConsole().sendMessage("[/" + str + "] <-> Player had connected to the Limbo server!");
PacketPlayOutGameStateChange gameEvent = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.LEVEL_CHUNKS_LOAD_START, 0);
sendPacket(gameEvent);
player.playerInteractManager.update();
PacketPlayOutDeclareCommands declare = DeclareCommands.getDeclareCommandsPacket(player); PacketPlayOutDeclareCommands declare = DeclareCommands.getDeclareCommandsPacket(player);
if (declare != null) { if (declare != null) {
sendPacket(declare); sendPacket(declare);
@ -584,7 +636,7 @@ public class ClientConnection extends Thread {
Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player)); Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player));
if (properties.isAllowFlight()) { if (properties.isAllowFlight()) {
PacketPlayOutGameState state = new PacketPlayOutGameState(3, player.getGamemode().getId()); PacketPlayOutGameStateChange state = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.CHANGE_GAME_MODE, player.getGamemode().getId());
sendPacket(state); sendPacket(state);
} }
@ -604,12 +656,7 @@ public class ClientConnection extends Thread {
// PLAYER LIST HEADER AND FOOTER CODE CONRIBUTED BY GAMERDUCK123 // PLAYER LIST HEADER AND FOOTER CODE CONRIBUTED BY GAMERDUCK123
player.sendPlayerListHeaderAndFooter(properties.getTabHeader(), properties.getTabFooter()); player.sendPlayerListHeaderAndFooter(properties.getTabHeader(), properties.getTabFooter());
// Start waiting for level chunks
PacketPlayOutGameEvent gameEvent = new PacketPlayOutGameEvent((byte) 13, 0);
sendPacket(gameEvent);
ready = true; ready = true;
player.playerInteractManager.update();
keepAliveTask = new TimerTask() { keepAliveTask = new TimerTask() {
@Override @Override

View File

@ -1,56 +0,0 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.loohp.limbo.network.protocol.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class PacketPlayOutGameState extends PacketOut {
private final int reason;
private final float value;
public PacketPlayOutGameState(int reason, float value) {
this.reason = reason;
this.value = value;
}
public int getReason() {
return reason;
}
public float getValue() {
return value;
}
@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(reason);
output.writeFloat(value);
return buffer.toByteArray();
}
}

View File

@ -1,8 +1,8 @@
/* /*
* This file is part of Limbo. * This file is part of Limbo.
* *
* Copyright (C) 2022. LoohpJames <jamesloohp@gmail.com> * Copyright (C) 2024. LoohpJames <jamesloohp@gmail.com>
* Copyright (C) 2022. Contributors * Copyright (C) 2024. Contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,17 +23,44 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
public class PacketPlayOutGameEvent extends PacketOut { public class PacketPlayOutGameStateChange extends PacketOut {
private byte event; public enum GameStateChangeEvent {
NO_RESPAWN_BLOCK_AVAILABLE(0),
START_RAINING(1),
STOP_RAINING(2),
CHANGE_GAME_MODE(3),
WIN_GAME(4),
DEMO_EVENT(5),
ARROW_HIT_PLAYER(6),
RAIN_LEVEL_CHANGE(7),
THUNDER_LEVEL_CHANGE(8),
PUFFER_FISH_STING(9),
GUARDIAN_ELDER_EFFECT(10),
IMMEDIATE_RESPAWN(11),
LIMITED_CRAFTING(12),
LEVEL_CHUNKS_LOAD_START(13);
private final int id;
GameStateChangeEvent(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
private GameStateChangeEvent event;
private float value; private float value;
public PacketPlayOutGameEvent(byte event, float value) { public PacketPlayOutGameStateChange(GameStateChangeEvent event, float value) {
this.event = event; this.event = event;
this.value = value; this.value = value;
} }
public int getEvent() { public GameStateChangeEvent getEvent() {
return event; return event;
} }
@ -46,7 +73,7 @@ public class PacketPlayOutGameEvent extends PacketOut {
DataOutputStream output = new DataOutputStream(buffer); DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass())); output.writeByte(Packet.getPlayOut().get(getClass()));
output.writeByte(Byte.toUnsignedInt(event)); output.writeByte(event.getId());
output.writeFloat(value); output.writeFloat(value);
return buffer.toByteArray(); return buffer.toByteArray();

View File

@ -45,7 +45,7 @@ import com.loohp.limbo.network.protocol.packets.ClientboundSetTitlesAnimationPac
import com.loohp.limbo.network.protocol.packets.ClientboundSystemChatPacket; import com.loohp.limbo.network.protocol.packets.ClientboundSystemChatPacket;
import com.loohp.limbo.network.protocol.packets.PacketOut; import com.loohp.limbo.network.protocol.packets.PacketOut;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutCloseWindow; import com.loohp.limbo.network.protocol.packets.PacketPlayOutCloseWindow;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameState; import com.loohp.limbo.network.protocol.packets.PacketPlayOutGameStateChange;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutHeldItemChange; import com.loohp.limbo.network.protocol.packets.PacketPlayOutHeldItemChange;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutNamedSoundEffect; import com.loohp.limbo.network.protocol.packets.PacketPlayOutNamedSoundEffect;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutOpenWindow; import com.loohp.limbo.network.protocol.packets.PacketPlayOutOpenWindow;
@ -151,7 +151,7 @@ public class Player extends LivingEntity implements CommandSender, InventoryHold
public void setGamemode(GameMode gamemode) { public void setGamemode(GameMode gamemode) {
if (!this.gamemode.equals(gamemode)) { if (!this.gamemode.equals(gamemode)) {
try { try {
PacketPlayOutGameState state = new PacketPlayOutGameState(3, gamemode.getId()); PacketPlayOutGameStateChange state = new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GameStateChangeEvent.CHANGE_GAME_MODE, gamemode.getId());
clientConnection.sendPacket(state); clientConnection.sendPacket(state);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -30,7 +30,6 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityDestroy;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata; import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutSpawnEntity; import com.loohp.limbo.network.protocol.packets.PacketPlayOutSpawnEntity;
import com.loohp.limbo.network.protocol.packets.PacketPlayOutUnloadChunk; import com.loohp.limbo.network.protocol.packets.PacketPlayOutUnloadChunk;
import com.loohp.limbo.utils.GameMode;
import com.loohp.limbo.world.ChunkPosition; import com.loohp.limbo.world.ChunkPosition;
import com.loohp.limbo.world.World; import com.loohp.limbo.world.World;
import net.querz.mca.Chunk; import net.querz.mca.Chunk;
@ -52,13 +51,11 @@ public class PlayerInteractManager {
private Set<Entity> entities; private Set<Entity> entities;
private Map<ChunkPosition, Chunk> currentViewing; private Map<ChunkPosition, Chunk> currentViewing;
private final Map<ChunkPosition, Chunk> chunkUpdates;
public PlayerInteractManager() { public PlayerInteractManager() {
this.player = null; this.player = null;
this.entities = new HashSet<>(); this.entities = new HashSet<>();
this.currentViewing = new HashMap<>(); this.currentViewing = new HashMap<>();
this.chunkUpdates = new HashMap<>();
} }
protected void setPlayer(Player player) { protected void setPlayer(Player player) {
@ -74,7 +71,7 @@ public class PlayerInteractManager {
} }
public void update() throws IOException { public void update() throws IOException {
if (player.clientConnection.getClientState() != ClientConnection.ClientState.PLAY && !player.clientConnection.isReady()) { if (player.clientConnection.getClientState() != ClientConnection.ClientState.PLAY) {
return; return;
} }
@ -121,32 +118,20 @@ public class PlayerInteractManager {
} }
} }
for (ChunkPosition chunkPos : currentViewing.keySet()) { for (Entry<ChunkPosition, Chunk> entry : currentViewing.entrySet()) {
ChunkPosition chunkPos = entry.getKey();
if (!chunksInRange.containsKey(chunkPos)) { if (!chunksInRange.containsKey(chunkPos)) {
PacketPlayOutUnloadChunk packet = new PacketPlayOutUnloadChunk(chunkPos.getChunkX(), chunkPos.getChunkZ()); PacketPlayOutUnloadChunk packet = new PacketPlayOutUnloadChunk(chunkPos.getChunkX(), chunkPos.getChunkZ());
player.clientConnection.sendPacket(packet); player.clientConnection.sendPacket(packet);
} }
} }
// add chunk candidates for updating
chunkUpdates.clear();
chunkUpdates.putAll(chunksInRange);
// blocks cannot be broken, so once we've sent all of them, don't update them anymore
if (getPlayer().getGamemode() == GameMode.ADVENTURE) {
for (ChunkPosition chunkPos : currentViewing.keySet()) {
chunkUpdates.remove(chunkPos);
}
}
// if we don't have any chunk updates, don't send any packets
if (chunkUpdates.isEmpty()) return;
int counter = 0; int counter = 0;
ClientboundChunkBatchStartPacket chunkBatchStartPacket = new ClientboundChunkBatchStartPacket(); ClientboundChunkBatchStartPacket chunkBatchStartPacket = new ClientboundChunkBatchStartPacket();
player.clientConnection.sendPacket(chunkBatchStartPacket); player.clientConnection.sendPacket(chunkBatchStartPacket);
for (Entry<ChunkPosition, Chunk> entry : chunkUpdates.entrySet()) { for (Entry<ChunkPosition, Chunk> entry : chunksInRange.entrySet()) {
ChunkPosition chunkPos = entry.getKey(); ChunkPosition chunkPos = entry.getKey();
if (!currentViewing.containsKey(chunkPos)) {
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ()); Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
if (chunk == null) { if (chunk == null) {
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), entry.getValue(), world.getEnvironment(), Collections.emptyList(), Collections.emptyList()); ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), entry.getValue(), world.getEnvironment(), Collections.emptyList(), Collections.emptyList());
@ -167,6 +152,7 @@ public class PlayerInteractManager {
player.clientConnection.sendPacket(chunkdata); player.clientConnection.sendPacket(chunkdata);
} }
counter++; counter++;
}
} }
ClientboundChunkBatchFinishedPacket chunkBatchFinishedPacket = new ClientboundChunkBatchFinishedPacket(counter); ClientboundChunkBatchFinishedPacket chunkBatchFinishedPacket = new ClientboundChunkBatchFinishedPacket(counter);
player.clientConnection.sendPacket(chunkBatchFinishedPacket); player.clientConnection.sendPacket(chunkBatchFinishedPacket);

View File

@ -48,20 +48,17 @@ public class Registry {
static { static {
String name = "registries.json"; String name = "registries.json";
File file = new File(Limbo.getInstance().getInternalDataFolder(), name);
if (!file.exists()) {
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(name)) {
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
Map<Key, Integer> blockEntityType = new HashMap<>(); Map<Key, Integer> blockEntityType = new HashMap<>();
Key defaultItemKey = null; Key defaultItemKey = null;
BiMap<Key, Integer> itemIds = HashBiMap.create(); BiMap<Key, Integer> itemIds = HashBiMap.create();
Map<Key, Integer> menuIds = new HashMap<>(); Map<Key, Integer> menuIds = new HashMap<>();
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(name);
if (inputStream == null) {
throw new RuntimeException("Failed to load " + name + " from jar!");
}
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
JSONObject json = (JSONObject) new JSONParser().parse(reader); JSONObject json = (JSONObject) new JSONParser().parse(reader);
JSONObject blockEntityJson = (JSONObject) ((JSONObject) json.get("minecraft:block_entity_type")).get("entries"); JSONObject blockEntityJson = (JSONObject) ((JSONObject) json.get("minecraft:block_entity_type")).get("entries");

View File

@ -37,24 +37,16 @@ public class DimensionRegistry {
private CompoundTag defaultTag; private CompoundTag defaultTag;
private CompoundTag codec; private CompoundTag codec;
private File reg;
public DimensionRegistry() { public DimensionRegistry() {
this.defaultTag = new CompoundTag(); this.defaultTag = new CompoundTag();
String name = "dimension_registry.json"; String name = "dimension_registry.json";
File file = new File(Limbo.getInstance().getInternalDataFolder(), name);
if (!file.exists()) {
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(name)) {
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
this.reg = file; InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(name);
if (inputStream == null) {
try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(reg.toPath()), StandardCharsets.UTF_8)) { throw new RuntimeException("Failed to load " + name + " from jar!");
}
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
JSONObject json = (JSONObject) new JSONParser().parse(reader); JSONObject json = (JSONObject) new JSONParser().parse(reader);
CompoundTag tag = CustomNBTUtils.getCompoundTagFromJson((JSONObject) json.get("value")); CompoundTag tag = CustomNBTUtils.getCompoundTagFromJson((JSONObject) json.get("value"));
defaultTag = tag; defaultTag = tag;
@ -64,10 +56,6 @@ public class DimensionRegistry {
} }
} }
public File getFile() {
return reg;
}
public void resetCodec() { public void resetCodec() {
codec = defaultTag.clone(); codec = defaultTag.clone();
} }

View File

@ -30,6 +30,8 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,17 +43,12 @@ public class GeneratedBlockDataMappings {
static { static {
String block = "blocks.json"; String block = "blocks.json";
File file = new File(Limbo.getInstance().getInternalDataFolder(), block); InputStream inputStream = Limbo.class.getClassLoader().getResourceAsStream(block);
if (!file.exists()) { if (inputStream == null) {
try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(block)) { throw new RuntimeException("Failed to load " + block + " from jar!");
Files.copy(in, file.toPath());
} catch (IOException e) {
e.printStackTrace();
} }
} try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
globalPalette = (JSONObject) new JSONParser().parse(reader);
try {
globalPalette = (JSONObject) new JSONParser().parse(new FileReader(file));
} catch (IOException | ParseException e) { } catch (IOException | ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -43,12 +43,12 @@
"PacketPlayOutLogin": "0x29", "PacketPlayOutLogin": "0x29",
"PacketPlayOutPositionAndLook": "0x3E", "PacketPlayOutPositionAndLook": "0x3E",
"PacketPlayOutSpawnPosition": "0x54", "PacketPlayOutSpawnPosition": "0x54",
"PacketPlayOutGameEvent": "0x20",
"ClientboundSystemChatPacket": "0x69", "ClientboundSystemChatPacket": "0x69",
"PacketPlayOutPlayerAbilities": "0x36", "PacketPlayOutPlayerAbilities": "0x36",
"ClientboundLevelChunkWithLightPacket": "0x25", "ClientboundLevelChunkWithLightPacket": "0x25",
"PacketPlayOutUnloadChunk": "0x1F", "PacketPlayOutUnloadChunk": "0x1F",
"PacketPlayOutKeepAlive": "0x15", "PacketPlayOutKeepAlive": "0x15",
"PacketPlayOutGameStateChange": "0x20",
"PacketPlayOutPlayerInfo": "0x3C", "PacketPlayOutPlayerInfo": "0x3C",
"PacketPlayOutUpdateViewPosition": "0x52", "PacketPlayOutUpdateViewPosition": "0x52",
"PacketPlayOutDisconnect": "0x1B", "PacketPlayOutDisconnect": "0x1B",
@ -56,7 +56,6 @@
"PacketPlayOutTabComplete": "0x10", "PacketPlayOutTabComplete": "0x10",
"PacketPlayOutDeclareCommands": "0x11", "PacketPlayOutDeclareCommands": "0x11",
"PacketPlayOutRespawn": "0x45", "PacketPlayOutRespawn": "0x45",
"PacketPlayOutGameState": "0x20",
"PacketPlayOutEntityDestroy": "0x40", "PacketPlayOutEntityDestroy": "0x40",
"PacketPlayOutEntityMetadata": "0x56", "PacketPlayOutEntityMetadata": "0x56",
"PacketPlayOutSpawnEntity": "0x01", "PacketPlayOutSpawnEntity": "0x01",