Merge branch 'master' into new-block-api

This commit is contained in:
TheMode 2021-07-09 00:29:31 +02:00
commit 295b3e24dd
4 changed files with 59 additions and 58 deletions

View File

@ -13,10 +13,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up JDK 11 - name: Set up JDK 16
uses: actions/setup-java@v1 uses: actions/setup-java@v2
with: with:
java-version: 11 distribution: 'adopt'
java-version: 16
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Setup gradle cache - name: Setup gradle cache

View File

@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.locks.LockSupport;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.LongConsumer; import java.util.function.LongConsumer;
@ -25,9 +26,6 @@ import java.util.function.LongConsumer;
*/ */
public final class UpdateManager { public final class UpdateManager {
private final ScheduledExecutorService updateExecutionService = Executors.newSingleThreadScheduledExecutor(r ->
new Thread(r, MinecraftServer.THREAD_NAME_TICK_SCHEDULER));
private volatile boolean stopRequested; private volatile boolean stopRequested;
// TODO make configurable // TODO make configurable
@ -49,13 +47,9 @@ public final class UpdateManager {
protected void start() { protected void start() {
final ConnectionManager connectionManager = MinecraftServer.getConnectionManager(); final ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
updateExecutionService.scheduleAtFixedRate(() -> { new Thread(() -> {
while (!stopRequested) {
try { try {
if (stopRequested) {
updateExecutionService.shutdown();
return;
}
long currentTime = System.nanoTime(); long currentTime = System.nanoTime();
final long tickStart = System.currentTimeMillis(); final long tickStart = System.currentTimeMillis();
@ -83,7 +77,6 @@ public final class UpdateManager {
final double tickTimeMs = tickTime / 1e6D; final double tickTimeMs = tickTime / 1e6D;
final TickMonitor tickMonitor = new TickMonitor(tickTimeMs, acquisitionTimeMs); final TickMonitor tickMonitor = new TickMonitor(tickTimeMs, acquisitionTimeMs);
this.tickMonitors.forEach(consumer -> consumer.accept(tickMonitor)); this.tickMonitors.forEach(consumer -> consumer.accept(tickMonitor));
Acquirable.resetAcquiringTime(); Acquirable.resetAcquiringTime();
} }
@ -93,10 +86,13 @@ public final class UpdateManager {
.map(player -> (NettyPlayerConnection) player.getPlayerConnection()) .map(player -> (NettyPlayerConnection) player.getPlayerConnection())
.forEach(NettyPlayerConnection::flush)); .forEach(NettyPlayerConnection::flush));
// Disable thread until next tick
LockSupport.parkNanos((long) ((MinecraftServer.TICK_MS * 1e6) - tickTime));
} catch (Exception e) { } catch (Exception e) {
MinecraftServer.getExceptionManager().handleException(e); MinecraftServer.getExceptionManager().handleException(e);
} }
}, 0, MinecraftServer.TICK_MS, TimeUnit.MILLISECONDS); }
}, MinecraftServer.THREAD_NAME_TICK_SCHEDULER).start();
} }
/** /**

View File

@ -36,7 +36,7 @@ public class ExplosionPacket implements ServerPacket {
y = reader.readFloat(); y = reader.readFloat();
z = reader.readFloat(); z = reader.readFloat();
radius = reader.readFloat(); radius = reader.readFloat();
int recordCount = reader.readInt() * 3; int recordCount = reader.readVarInt() * 3;
records = reader.readBytes(recordCount); records = reader.readBytes(recordCount);
playerMotionX = reader.readFloat(); playerMotionX = reader.readFloat();
playerMotionY = reader.readFloat(); playerMotionY = reader.readFloat();

View File

@ -73,12 +73,16 @@ public class MapDataPacket implements ComponentHoldingServerPacket {
locked = reader.readBoolean(); locked = reader.readBoolean();
trackingPosition = reader.readBoolean(); trackingPosition = reader.readBoolean();
if (trackingPosition) {
int iconCount = reader.readVarInt(); int iconCount = reader.readVarInt();
icons = new Icon[iconCount]; icons = new Icon[iconCount];
for (int i = 0; i < iconCount; i++) { for (int i = 0; i < iconCount; i++) {
icons[i] = new Icon(); icons[i] = new Icon();
icons[i].read(reader); icons[i].read(reader);
} }
} else {
icons = new Icon[0];
}
columns = reader.readByte(); columns = reader.readByte();
if (columns <= 0) { if (columns <= 0) {