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

324 Zeilen
12 KiB
Diff

2021-12-13 16:45:58 +01:00
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)
2021-12-13 20:51:18 +01:00
+++ b/src/main/java/net/minecraft/server/WorldServer.java (date 1639424761201)
2021-12-13 16:45:58 +01:00
@@ -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 {
2021-12-13 20:51:18 +01:00
@@ -161,6 +151,7 @@
2021-12-13 16:45:58 +01:00
2021-12-13 20:51:18 +01:00
public void doTick(BooleanSupplier booleansupplier) {
GameProfilerFiller gameprofilerfiller = this.getMethodProfiler();
+ currentlyFrozen = freezed; // Do not Change freezed mid tick!
this.ticking = true;
gameprofilerfiller.enter("world border");
@@ -308,7 +299,7 @@
2021-12-13 16:45:58 +01:00
this.getChunkProvider().tick(booleansupplier);
gameprofilerfiller.exitEnter("tickPending");
timings.doTickPending.startTiming(); // Spigot
- if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
2021-12-13 20:51:18 +01:00
+ if (!currentlyFrozen && this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
2021-12-13 16:45:58 +01:00
this.nextTickListBlock.b();
this.nextTickListFluid.b();
}
2021-12-13 20:51:18 +01:00
@@ -322,7 +313,9 @@
gameprofilerfiller.exitEnter("blockEvents");
timings.doSounds.startTiming(); // Spigot
- this.ad();
+ if (!currentlyFrozen) {
+ this.ad();
+ }
timings.doSounds.stopTiming(); // Spigot
this.ticking = false;
gameprofilerfiller.exitEnter("entities");
@@ -332,18 +325,28 @@
2021-12-13 16:45:58 +01:00
this.resetEmptyTime();
}
+ lastFreezed = false;
2021-12-13 20:51:18 +01:00
+ if (!currentlyFrozen && !physicsTick.isEmpty()) {
2021-12-13 16:45:58 +01:00
+ 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;
+ }
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen && !(entity instanceof EntityPlayer)) {
+ continue;
}
2021-12-13 16:45:58 +01:00
// CraftBukkit end
this.a((entity1) -> {
2021-12-13 20:51:18 +01:00
@@ -415,7 +418,9 @@
gameprofilerfiller.exit();
timings.tickEntities.stopTiming(); // Spigot
- this.tickBlockEntities();
+ if (!currentlyFrozen) {
+ this.tickBlockEntities();
+ }
}
gameprofilerfiller.exit();
@@ -428,6 +433,7 @@
2021-12-13 16:45:58 +01:00
}
public void a(Chunk chunk, int i) {
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen) return;
2021-12-13 16:45:58 +01:00
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.d();
2021-12-13 20:51:18 +01:00
@@ -584,6 +590,7 @@
2021-12-13 16:45:58 +01:00
}
private void a(NextTickListEntry<FluidType> nextticklistentry) {
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen) return;
2021-12-13 16:45:58 +01:00
Fluid fluid = this.getFluid(nextticklistentry.a);
if (fluid.getType() == nextticklistentry.b()) {
2021-12-13 20:51:18 +01:00
@@ -593,6 +600,7 @@
2021-12-13 16:45:58 +01:00
}
private void b(NextTickListEntry<Block> nextticklistentry) {
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen) return;
2021-12-13 16:45:58 +01:00
IBlockData iblockdata = this.getType(nextticklistentry.a);
if (iblockdata.getBlock() == nextticklistentry.b()) {
2021-12-13 20:51:18 +01:00
@@ -602,6 +610,36 @@
2021-12-13 16:45:58 +01:00
}
public void entityJoinedWorld(Entity entity) {
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen && !(entity instanceof EntityPlayer) && !(entity instanceof EntityItem)) {
2021-12-13 16:45:58 +01:00
+ PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(entity.getId(), new Vec3D(0, 0, 0));
+ PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(entity);
2021-12-13 20:51:18 +01:00
+ PacketPlayOutEntityMetadata packetPlayOutEntityMetadata;
2021-12-13 16:45:58 +01:00
+ if (entity instanceof EntityTNTPrimed) {
2021-12-13 20:51:18 +01:00
+ EntityTNTPrimed entityTNTPrimed = new EntityTNTPrimed(EntityTypes.TNT, this);
+ entityTNTPrimed.setNoGravity(true);
+ entityTNTPrimed.setPosition(entity.locX(), entity.locY(), entity.locZ());
+ entityTNTPrimed.setFuseTicks(((EntityTNTPrimed) entity).getFuseTicks());
+ packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(entity.getId(), entityTNTPrimed.getDataWatcher(), true);
+ } else {
+ packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true);
2021-12-13 16:45:58 +01:00
+ }
+ 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)) {
2021-12-13 20:51:18 +01:00
@@ -1315,6 +1353,12 @@
@Override
public void playBlockAction(BlockPosition blockposition, Block block, int i, int j) {
+ if (!currentlyFrozen) {
+ physicsTick.put(blockposition, () -> {
+ this.I.add(new BlockActionData(blockposition, block, i, j));
+ });
+ return;
+ }
this.I.add(new BlockActionData(blockposition, block, i, j));
}
2021-12-13 16:45:58 +01:00
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)
2021-12-13 20:51:18 +01:00
+++ b/src/main/java/net/minecraft/server/World.java (date 1639417061068)
2021-12-13 16:45:58 +01:00
@@ -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 {
2021-12-13 20:51:18 +01:00
@@ -76,6 +70,11 @@
2021-12-13 16:45:58 +01:00
private org.spigotmc.TickLimiter tileLimiter;
private int tileTickPosition;
+ public boolean freezed = false;
2021-12-13 20:51:18 +01:00
+ protected boolean currentlyFrozen = false;
2021-12-13 16:45:58 +01:00
+ protected boolean lastFreezed = false;
+ protected Map<BlockPosition, Runnable> physicsTick = new LinkedHashMap();
+
public CraftWorld getWorld() {
return this.world;
}
2021-12-13 20:51:18 +01:00
@@ -322,8 +321,15 @@
2021-12-13 16:45:58 +01:00
}
}
// CraftBukkit end
- iblockdata.a(this, blockposition, j);
- iblockdata.b(this, blockposition, j);
2021-12-13 20:51:18 +01:00
+ if (!currentlyFrozen) {
2021-12-13 16:45:58 +01:00
+ 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);
2021-12-13 20:51:18 +01:00
@@ -418,6 +424,14 @@
2021-12-13 16:45:58 +01:00
}
public void a(BlockPosition blockposition, Block block, BlockPosition blockposition1) {
2021-12-13 20:51:18 +01:00
+ if (currentlyFrozen) {
2021-12-13 16:45:58 +01:00
+ if (!isClientSide) {
+ physicsTick.put(blockposition, () -> {
+ this.a(blockposition, block, blockposition1);
+ });
+ }
+ return;
+ }
if (!this.isClientSide) {
IBlockData iblockdata = this.getType(blockposition);
2021-12-13 20:51:18 +01:00
@@ -1193,7 +1207,9 @@
}
protected void a() {
- this.a(this.worldData.getTime() + 1L);
+ if (!currentlyFrozen) {
+ this.a(this.worldData.getTime() + 1L);
+ }
if (this.worldData.v().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)) {
this.setDayTime(this.worldData.getDayTime() + 1L);
}
@@ -1226,7 +1242,16 @@
}
public void playBlockAction(BlockPosition blockposition, Block block, int i, int j) {
- this.getType(blockposition).a(this, blockposition, i, j);
+ /*
+ if (!currentlyFrozen) {
+ physicsTick.put(blockposition, () -> {
+ this.getType(blockposition).a(this, blockposition, i, j);
+ });
+ return;
+ }
+ */
+ IBlockData iblockdata = this.getType(blockposition); // Block of Position
+ iblockdata.a(this, blockposition, i, j);
}
@Override