Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ghost_chu
2019-03-29 19:43:06 +08:00
5 changed files with 68 additions and 15 deletions

View File

@@ -2,6 +2,8 @@ package io.akarin.server.core;
import java.util.List;
import javax.swing.text.html.parser.Entity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -10,10 +12,12 @@ import com.google.common.collect.Iterables;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.EnumDifficulty;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.PacketPlayOutPlayerInfo;
import net.minecraft.server.PacketPlayOutUpdateTime;
import net.minecraft.server.World;
import net.minecraft.server.WorldServer;
public class AkarinAsyncScheduler extends Thread {
@@ -55,10 +59,10 @@ public class AkarinAsyncScheduler extends Thread {
}
}
// Send time updates to everyone, it will get the right time from the world the player is in.
for (final WorldServer world : server.getWorlds()) {
final boolean doDaylight = world.getGameRules().getBoolean("doDaylightCycle");
final long dayTime = world.getDayTime();
for (WorldServer world : server.getWorlds()) {
// Send time updates to everyone, it will get the right time from the world the player is in.
boolean doDaylight = world.getGameRules().getBoolean("doDaylightCycle");
long dayTime = world.getDayTime();
long worldTime = world.getTime();
final PacketPlayOutUpdateTime worldPacket = new PacketPlayOutUpdateTime(worldTime, dayTime, doDaylight);
for (EntityHuman entityhuman : world.players) {
@@ -71,6 +75,27 @@ public class AkarinAsyncScheduler extends Thread {
new PacketPlayOutUpdateTime(worldTime, playerTime, doDaylight);
entityplayer.playerConnection.sendPacket(packet); // Add support for per player time
}
// Hardcore difficulty lock
if (world.getWorldData().isHardcore() && world.getDifficulty() != EnumDifficulty.HARD) {
world.getWorldData().setDifficulty(EnumDifficulty.HARD);
}
// Sleeping time management
if (world.everyoneDeeplySleeping()) {
if (world.getGameRules().getBoolean("doDaylightCycle")) {
long i = world.worldData.getDayTime() + 24000L;
world.worldData.setDayTime(i - i % 24000L);
}
if (world.getGameRules().getBoolean("doWeatherCycle")) {
world.clearWeather();
}
}
// Random light updates
world.randomLightUpdates();
}
// Send player latency update packets

View File

@@ -20,6 +20,20 @@ public class BlockPosition extends BaseBlockPosition {
private static final long i = (1L << BlockPosition.c) - 1L;
private static final long j = (1L << BlockPosition.f) - 1L;
private static final long k = (1L << BlockPosition.d) - 1L;
// Akarin start
protected BlockPosition shiftX(int x) {
this.x = this.x + x;
return this;
}
protected BlockPosition shiftY(int y) {
this.y = this.y + y;
return this;
}
protected BlockPosition shiftZ(int z) {
this.z = this.z + z;
return this;
}
// Akarin end
public BlockPosition(int i, int j, int k) {
super(i, j, k);

View File

@@ -641,12 +641,12 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
public void applyPhysics(BlockPosition blockposition, Block block) {
if (captureBlockStates) { return; } // Paper - Cancel all physics during placement
this.a(blockposition.west(), block, blockposition);
this.a(blockposition.east(), block, blockposition);
this.a(blockposition.down(), block, blockposition);
this.a(blockposition.up(), block, blockposition);
this.a(blockposition.north(), block, blockposition);
this.a(blockposition.south(), block, blockposition);
this.a(blockposition.shiftX(-1), block, blockposition); // Akarin - west
this.a(blockposition.shiftX(2), block, blockposition); // Akarin - east
this.a(blockposition.shiftX(-1).shiftY(-1), block, blockposition); // Akarin - down
this.a(blockposition.shiftY(2), block, blockposition); // Akarin - up
this.a(blockposition.shiftY(-1).shiftZ(-1), block, blockposition); // Akarin - north
this.a(blockposition.shiftZ(2), block, blockposition); // Akarin - south
}
public void a(BlockPosition blockposition, Block block, EnumDirection enumdirection) {

View File

@@ -14,6 +14,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -254,17 +255,25 @@ public class WorldServer extends World implements IAsyncTaskHandler {
public void doTick(BooleanSupplier booleansupplier) {
this.P = true;
super.doTick(booleansupplier);
// Akarin start
/*
if (this.getWorldData().isHardcore() && this.getDifficulty() != EnumDifficulty.HARD) {
this.getWorldData().setDifficulty(EnumDifficulty.HARD);
}
*/
// Akarin end
this.chunkProvider.getChunkGenerator().getWorldChunkManager().tick();
if (this.everyoneDeeplySleeping()) {
// Akarin start
/*
if (this.getGameRules().getBoolean("doDaylightCycle")) {
long i = this.worldData.getDayTime() + 24000L;
this.worldData.setDayTime(i - i % 24000L);
}
*/
// Akarin end
this.i();
}
@@ -381,12 +390,17 @@ public class WorldServer extends World implements IAsyncTaskHandler {
entityhuman.a(false, false, true);
}
// Akarin start
/*
if (this.getGameRules().getBoolean("doWeatherCycle")) {
this.b();
}
*/
// Akarin end
}
public void clearWeather() { this.b(); } // Akarin - OBFHLPER
private void b() {
// CraftBukkit start
this.worldData.setStorm(false);
@@ -443,25 +457,25 @@ public class WorldServer extends World implements IAsyncTaskHandler {
return this.getChunkProvider().isLoaded(i, j);
}
public void randomLightUpdates() { this.l(); } // Akarin - OBFHELPER
protected void l() {
//this.methodProfiler.enter(* // Akarin - remove caller
if (spigotConfig.randomLightUpdates && !this.players.isEmpty()) { // Spigot
int i = this.random.nextInt(this.players.size());
int i = ThreadLocalRandom.current().nextInt(this.players.size()); // Akarin - ThreadLocalRandom
EntityHuman entityhuman = (EntityHuman) this.players.get(i);
AkarinAsyncExecutor.scheduleAsyncTask(() -> { // Akarin
if (entityhuman == null) return;
int j = MathHelper.floor(entityhuman.locX) + this.random.nextInt(11) - 5;
int k = MathHelper.floor(entityhuman.locY) + this.random.nextInt(11) - 5;
int l = MathHelper.floor(entityhuman.locZ) + this.random.nextInt(11) - 5;
this.r(new BlockPosition(j, k, l));
}); // Akarin
}
//this.methodProfiler.exit(); // Akarin - remove caller
}
protected void n_() {
this.l();
//this.l(); // Akarin
if (this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
Iterator iterator = this.manager.b();