diff --git a/src/main/java/io/akarin/server/core/AkarinAsyncScheduler.java b/src/main/java/io/akarin/server/core/AkarinAsyncScheduler.java index 051a9caca..ea505fe5a 100644 --- a/src/main/java/io/akarin/server/core/AkarinAsyncScheduler.java +++ b/src/main/java/io/akarin/server/core/AkarinAsyncScheduler.java @@ -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 diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java index 5ce18f54c..9c2a58554 100644 --- a/src/main/java/net/minecraft/server/BlockPosition.java +++ b/src/main/java/net/minecraft/server/BlockPosition.java @@ -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); diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 59a77409a..23a59a9af 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -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) { diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index 5e4baf4cf..08284ca81 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -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(); diff --git a/work/Paper b/work/Paper index 3eeec2ec1..def003392 160000 --- a/work/Paper +++ b/work/Paper @@ -1 +1 @@ -Subproject commit 3eeec2ec1176e421b9e9391138e64906300f4eae +Subproject commit def003392986c54fdc63fc3f425607998fa5013c