Skip to content

Commit

Permalink
1.1.6: UpdateTags fix, chunk-radius-send-on-spawn config option
Browse files Browse the repository at this point in the history
  • Loading branch information
hevav committed Jan 29, 2023
1 parent 12bec03 commit 285d387
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Test server: [``ely.su``](https://hotmc.ru/minecraft-server-203216)
<dependency>
<groupId>net.elytrium.limboapi</groupId>
<artifactId>api</artifactId>
<version>1.1.4</version>
<version>1.1.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -70,7 +70,7 @@ Test server: [``ely.su``](https://hotmc.ru/minecraft-server-203216)
}
dependencies {
compileOnly("net.elytrium.limboapi:api:1.1.3")
compileOnly("net.elytrium.limboapi:api:1.1.6")
}
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface VirtualBlock {

short getBlockID(ProtocolVersion version);

boolean isSupportedOn(ProtocolVersion version);

boolean isSupportedOn(WorldVersion version);

short getBlockStateID(ProtocolVersion version);

boolean isSolid();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
apply(plugin: "org.cadixdev.licenser")

setGroup("net.elytrium.limboapi")
setVersion("1.1.5")
setVersion("1.1.6")

compileJava {
getOptions().setEncoding("UTF-8")
Expand Down
12 changes: 11 additions & 1 deletion plugin/src/main/java/net/elytrium/limboapi/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ public static class MAIN {

public int SIMULATION_DISTANCE = 9;

@Comment({
"How many chunks we should send when a player spawns.",
" 0 = send no chunks on spawn.",
" 1 = send only the spawn chunk.",
" 2 = send the spawn chunk and chunks next to the spawn chunk.",
" 3 = send the spawn chunk, chunks next to the spawn chunk and next to these chunks.",
" and so on.."
})
public int CHUNK_RADIUS_SEND_ON_SPAWN = 2;

@Comment("How many chunks we should send per tick")
public int CHUNKS_PER_TICK = 8;
public int CHUNKS_PER_TICK = 16;

@Create
public MESSAGES MESSAGES;
Expand Down
52 changes: 39 additions & 13 deletions plugin/src/main/java/net/elytrium/limboapi/server/LimboImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -126,7 +127,8 @@ public class LimboImpl implements Limbo {
private PreparedPacket joinPackets;
private PreparedPacket fastRejoinPackets;
private PreparedPacket safeRejoinPackets;
private List<PreparedPacket> chunks;
private PreparedPacket firstChunks;
private List<PreparedPacket> delayedChunks;
private PreparedPacket respawnPackets;
private boolean shouldRespawn = true;
private boolean shouldUpdateTags = true;
Expand Down Expand Up @@ -173,7 +175,8 @@ protected void refresh() {
this.addPostJoin(this.fastRejoinPackets);
this.addPostJoin(this.safeRejoinPackets);

this.chunks = this.createChunksPackets();
this.firstChunks = this.createFirstChunks();
this.delayedChunks = this.createDelayedChunksPackets();
this.respawnPackets = this.plugin.createPreparedPacket()
.prepare(
this.createPlayerPosAndLook(
Expand Down Expand Up @@ -344,16 +347,14 @@ public void respawnPlayer(Player player) {
MinecraftConnection connection = ((ConnectedPlayer) player).getConnection();

connection.delayedWrite(this.respawnPackets);
if (this.firstChunks != null) {
connection.write(this.firstChunks);
}

int packetIndex = 0;
for (PreparedPacket chunk : this.chunks) {
for (PreparedPacket chunk : this.delayedChunks) {
connection.eventLoop().schedule(() -> connection.write(chunk), (++packetIndex) * 50L, TimeUnit.MILLISECONDS);
}

// We should send first chunks without scheduling
if (this.chunks.size() != 0) {
connection.write(this.chunks.get(0));
}
}

@Override
Expand Down Expand Up @@ -479,7 +480,8 @@ private void localDispose() {
this.fastRejoinPackets.release();
this.safeRejoinPackets.release();
this.respawnPackets.release();
this.chunks.forEach(PreparedPacket::release);
this.firstChunks.release();
this.delayedChunks.forEach(PreparedPacket::release);
}

// From Velocity.
Expand Down Expand Up @@ -582,21 +584,45 @@ private AvailableCommands createAvailableCommandsPacket() {
}
}

private List<PreparedPacket> createChunksPackets() {
private PreparedPacket createFirstChunks() {
PreparedPacket packet = this.plugin.createPreparedPacket();
List<List<VirtualChunk>> orderedChunks = this.world.getOrderedChunks();
if (orderedChunks.size() == 0) {

int chunkCounter = 0;
for (List<VirtualChunk> chunksWithSameDistance : orderedChunks) {
if (++chunkCounter > Settings.IMP.MAIN.CHUNK_RADIUS_SEND_ON_SPAWN) {
break;
}

for (VirtualChunk chunk : chunksWithSameDistance) {
packet.prepare(this.createChunkData(chunk, this.world.getDimension()));
}
}

return packet.build();
}

private List<PreparedPacket> createDelayedChunksPackets() {
List<List<VirtualChunk>> orderedChunks = this.world.getOrderedChunks();
if (orderedChunks.size() <= Settings.IMP.MAIN.CHUNK_RADIUS_SEND_ON_SPAWN) {
return List.of();
}

List<PreparedPacket> packets = new LinkedList<>();
PreparedPacket packet = this.plugin.createPreparedPacket();
int chunkCounter = 0;

for (List<VirtualChunk> chunksWithSameDistance : orderedChunks) {
for (VirtualChunk chunk : chunksWithSameDistance) {
Iterator<List<VirtualChunk>> distanceIterator = orderedChunks.listIterator();
for (int i = 0; i < Settings.IMP.MAIN.CHUNK_RADIUS_SEND_ON_SPAWN; i++) {
distanceIterator.next();
}

while (distanceIterator.hasNext()) {
for (VirtualChunk chunk : distanceIterator.next()) {
if (++chunkCounter > Settings.IMP.MAIN.CHUNKS_PER_TICK) {
packets.add(packet.build());
packet = this.plugin.createPreparedPacket();
chunkCounter = 0;
}

packet.prepare(this.createChunkData(chunk, this.world.getDimension()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,24 @@ public short getID(ProtocolVersion version) {

@Override
public short getBlockID(WorldVersion version) {
return LEGACY_BLOCK_IDS_MAP.get(this.blockID).getOrDefault(version, this.blockID);
return LEGACY_BLOCK_IDS_MAP.get(this.blockID).get(version);
}

@Override
public short getBlockID(ProtocolVersion version) {
return this.getBlockID(WorldVersion.from(version));
}

@Override
public boolean isSupportedOn(WorldVersion version) {
return LEGACY_BLOCK_IDS_MAP.get(this.blockID).containsKey(version);
}

@Override
public boolean isSupportedOn(ProtocolVersion version) {
return this.isSupportedOn(WorldVersion.from(version));
}

@Override
public short getBlockStateID(ProtocolVersion version) {
return MODERN_BLOCK_STATE_IDS_MAP.get(version).getOrDefault(this.blockStateID, this.blockStateID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public static void init() {
LinkedTreeMap.class
);

fluids.forEach((id, protocolId) -> {
FLUIDS.put(id, Integer.valueOf(protocolId));
});
fluids.forEach((id, protocolId) -> FLUIDS.put(id, Integer.valueOf(protocolId)));

LinkedTreeMap<String, LinkedTreeMap<String, List<String>>> tags = gson.fromJson(
new InputStreamReader(
Expand Down Expand Up @@ -82,7 +80,9 @@ private static UpdateTagsPacket localGetTagsForVersion(LinkedTreeMap<String, Lin
case "minecraft:block": {
defaultTagList.forEach((tagName, blockList) ->
tagList.put(tagName, blockList.stream()
.map(e -> (int) SimpleBlock.fromModernID(e, Map.of()).getBlockID(version))
.map(e -> SimpleBlock.fromModernID(e, Map.of()))
.filter(e -> e.isSupportedOn(version))
.map(e -> (int) e.getBlockID(version))
.collect(Collectors.toList())));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ private static int getBiomeIndex(int posX, int posY, int posZ) {
private static int getSectionIndex(int posY) {
return posY >> 4;
}

@Override
public String toString() {
return "SimpleChunk{"
+ "posX=" + this.posX
+ ", posZ=" + this.posZ
+ '}';
}
}

0 comments on commit 285d387

Please sign in to comment.