Archiviert
13
0
Dieses Repository wurde am 2021-12-14 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
SteamSpigot/Spigot/SteamWar-Patches/TickFreeze.patch
2021-12-13 16:45:58 +01:00

261 Zeilen
10 KiB
Diff

Index: src/main/java/net/minecraft/server/WorldServer.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
--- a/src/main/java/net/minecraft/server/WorldServer.java (revision 571772e5fd38f66c11220ce29cd15d70e8da46f6)
+++ b/src/main/java/net/minecraft/server/WorldServer.java (date 1639394168874)
@@ -14,38 +14,28 @@
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.file.Files;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Queue;
-import java.util.Random;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.Executor;
-import java.util.function.BooleanSupplier;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-
-// CraftBukkit start
-import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.WeatherType;
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.server.MapInitializeEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.world.TimeSkipEvent;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.file.Files;
+import java.util.*;
+import java.util.concurrent.Executor;
+import java.util.function.BooleanSupplier;
+import java.util.function.Predicate;
+import java.util.logging.Level;
+import java.util.stream.Collectors;
// CraftBukkit end
public class WorldServer extends World {
@@ -303,12 +293,14 @@
}
this.N();
- this.a();
+ if (!freezed) {
+ this.a();
+ }
gameprofilerfiller.exitEnter("chunkSource");
this.getChunkProvider().tick(booleansupplier);
gameprofilerfiller.exitEnter("tickPending");
timings.doTickPending.startTiming(); // Spigot
- if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
+ if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES && !freezed) {
this.nextTickListBlock.b();
this.nextTickListFluid.b();
}
@@ -332,19 +324,29 @@
this.resetEmptyTime();
}
+ lastFreezed = false;
+ if (!freezed && !physicsTick.isEmpty()) {
+ Map<BlockPosition, Runnable> physicsTickList = new LinkedHashMap<>(physicsTick);
+ physicsTick.clear();
+ physicsTickList.forEach((blockPosition, runnable) -> runnable.run());
+ lastFreezed = true;
+ }
+
if (flag3 || this.emptyTime++ < 300) {
timings.tickEntities.startTiming(); // Spigot
this.worldProvider.j();
gameprofilerfiller.enter("global");
Entity entity;
-
for (i = 0; i < this.globalEntityList.size(); ++i) {
entity = (Entity) this.globalEntityList.get(i);
// CraftBukkit start - Fixed an NPE
if (entity == null) {
continue;
}
+ if (freezed && !(entity instanceof EntityPlayer)) {
+ continue;
+ }
// CraftBukkit end
this.a((entity1) -> {
++entity1.ticksLived;
@@ -428,6 +430,7 @@
}
public void a(Chunk chunk, int i) {
+ if (freezed) return;
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.d();
@@ -584,6 +587,7 @@
}
private void a(NextTickListEntry<FluidType> nextticklistentry) {
+ if (freezed) return;
Fluid fluid = this.getFluid(nextticklistentry.a);
if (fluid.getType() == nextticklistentry.b()) {
@@ -593,6 +597,7 @@
}
private void b(NextTickListEntry<Block> nextticklistentry) {
+ if (freezed) return;
IBlockData iblockdata = this.getType(nextticklistentry.a);
if (iblockdata.getBlock() == nextticklistentry.b()) {
@@ -602,6 +607,37 @@
}
public void entityJoinedWorld(Entity entity) {
+ if (freezed && !(entity instanceof EntityPlayer) && !(entity instanceof EntityItem)) {
+ PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(entity.getId(), new Vec3D(0, 0, 0));
+ PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(entity);
+ entity.setNoGravity(true);
+ if (entity instanceof EntityTNTPrimed) {
+ EntityTNTPrimed entitytntprimed = (EntityTNTPrimed) entity;
+ entitytntprimed.setInvisible(true);
+ }
+ PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true);
+ if (entity instanceof EntityTNTPrimed) {
+ EntityTNTPrimed entitytntprimed = (EntityTNTPrimed) entity;
+ entitytntprimed.setInvisible(false);
+ }
+ entity.setNoGravity(false);
+ players.forEach(entityPlayer -> {
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityVelocity);
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityTeleport);
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityMetadata);
+ });
+ return;
+ }
+ if (lastFreezed && !(entity instanceof EntityPlayer) && !(entity instanceof EntityItem)) {
+ PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(entity);
+ PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(entity);
+ PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true);
+ players.forEach(entityPlayer -> {
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityVelocity);
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityTeleport);
+ entityPlayer.playerConnection.sendPacket(packetPlayOutEntityMetadata);
+ });
+ }
if (entity instanceof EntityHuman || this.getChunkProvider().a(entity)) {
// Spigot start
if (!org.spigotmc.ActivationRange.checkIfActive(entity)) {
Index: src/main/java/net/minecraft/server/World.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
--- a/src/main/java/net/minecraft/server/World.java (revision 571772e5fd38f66c11220ce29cd15d70e8da46f6)
+++ b/src/main/java/net/minecraft/server/World.java (date 1639348240863)
@@ -1,29 +1,23 @@
package net.minecraft.server;
import com.google.common.collect.Lists;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.function.BiFunction;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Supplier;
-
-// CraftBukkit start
-import java.util.HashMap;
-import java.util.Map;
import org.bukkit.Bukkit;
-import org.bukkit.craftbukkit.SpigotTimings; // Spigot
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.SpigotTimings;
import org.bukkit.craftbukkit.block.CapturedBlockState;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
// CraftBukkit end
public abstract class World implements GeneratorAccess, AutoCloseable {
@@ -76,6 +70,10 @@
private org.spigotmc.TickLimiter tileLimiter;
private int tileTickPosition;
+ public boolean freezed = false;
+ protected boolean lastFreezed = false;
+ protected Map<BlockPosition, Runnable> physicsTick = new LinkedHashMap();
+
public CraftWorld getWorld() {
return this.world;
}
@@ -322,8 +320,15 @@
}
}
// CraftBukkit end
- iblockdata.a(this, blockposition, j);
- iblockdata.b(this, blockposition, j);
+ if (!freezed) {
+ iblockdata.a(this, blockposition, j);
+ iblockdata.b(this, blockposition, j);
+ } else {
+ physicsTick.put(blockposition, () -> {
+ iblockdata.a(this, blockposition, j);
+ iblockdata.b(this, blockposition, j);
+ });
+ }
}
this.a(blockposition, iblockdata1, iblockdata2);
@@ -418,6 +423,14 @@
}
public void a(BlockPosition blockposition, Block block, BlockPosition blockposition1) {
+ if (freezed) {
+ if (!isClientSide) {
+ physicsTick.put(blockposition, () -> {
+ this.a(blockposition, block, blockposition1);
+ });
+ }
+ return;
+ }
if (!this.isClientSide) {
IBlockData iblockdata = this.getType(blockposition);