Skip to content

Commit

Permalink
port some patches (PaperMC#5837)
Browse files Browse the repository at this point in the history
  • Loading branch information
kickash32 authored Jun 15, 2021
1 parent 8755b39 commit b26ba5b
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 247 deletions.
File renamed without changes.

This file was deleted.

31 changes: 0 additions & 31 deletions patches/removed/1.17/0290-PreSpawnerSpawnEvent.patch

This file was deleted.

This file was deleted.

29 changes: 29 additions & 0 deletions patches/server/0290-PreSpawnerSpawnEvent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Phoenix616 <[email protected]>
Date: Tue, 18 Sep 2018 23:53:23 +0100
Subject: [PATCH] PreSpawnerSpawnEvent

This adds a separate event before an entity is spawned by a spawner
which contains the location of the spawner too similarly to how the
SpawnerSpawnEvent gets called instead of the CreatureSpawnEvent for
spawners.

diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index c741f8e4a4b67d1bfed2d1bac36856c5688bb161..9228c0bc797fb95c8ac949bdc568eadafee84a80 100644
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
@@ -138,11 +138,11 @@ public abstract class BaseSpawner {

org.bukkit.entity.EntityType type = org.bukkit.entity.EntityType.fromName(key);
if (type != null) {
- com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event;
- event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
+ com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent event;
+ event = new com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent(
net.minecraft.server.MCUtil.toLocation(world, d0, d1, d2),
type,
- org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER
+ net.minecraft.server.MCUtil.toLocation(world, pos)
);
if (!event.callEvent()) {
flag = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <[email protected]>
Date: Fri, 29 May 2020 20:29:02 -0400
Subject: [PATCH] Synchronize PalettedContainer instead of ReentrantLock

Mojang has flaws in their logic about chunks being concurrently
wrote to. So we constantly see crashes around multiple threads writing.

Additionally, java has optimized synchronization so well that its
in many times faster than trying to manage read wrote locks for low
contention situations.

And this is extremely a low contention situation.

diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
index 5ac948b5b82f3144cdf402af440251cb8c7369d7..d8b7a7d9aa3ef47aa4e222c6ca85e83ce21f2444 100644
--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -36,16 +36,18 @@ public class PalettedContainer<T> implements PaletteResize<T> {
private final DebugBuffer<Pair<Thread, StackTraceElement[]>> traces = null;

public void acquire() {
+ /* // Paper start - disable this - use proper synchronization
if (this.traces != null) {
Thread thread = Thread.currentThread();
this.traces.push(Pair.of(thread, thread.getStackTrace()));
}

ThreadingDetector.checkAndLock(this.lock, this.traces, "PalettedContainer");
+ */ // Paper end
}

public void release() {
- this.lock.release();
+ //this.lock.release(); // Paper - disable this
}

public PalettedContainer(Palette<T> fallbackPalette, IdMapper<T> idList, Function<CompoundTag, T> elementDeserializer, Function<T, CompoundTag> elementSerializer, T defaultElement) {
@@ -96,7 +98,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
return this.palette.idFor(objectAdded);
}

- public T getAndSet(int x, int y, int z, T value) {
+ public synchronized T getAndSet(int x, int y, int z, T value) { // Paper - synchronize
Object var6;
try {
this.acquire();
@@ -120,7 +122,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
return (T)(object == null ? this.defaultValue : object);
}

- public void set(int i, int j, int k, T object) {
+ public synchronized void set(int i, int j, int k, T object) { // Paper - synchronize
try {
this.acquire();
this.set(getIndex(i, j, k), object);
@@ -144,7 +146,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
return (T)(object == null ? this.defaultValue : object);
}

- public void read(FriendlyByteBuf buf) {
+ public synchronized void read(FriendlyByteBuf buf) { // Paper - synchronize
try {
this.acquire();
int i = buf.readByte();
@@ -161,7 +163,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}

public void writeDataPaletteBlock(FriendlyByteBuf packetDataSerializer) { this.write(packetDataSerializer); } // Paper - OBFHELPER
- public void write(FriendlyByteBuf buf) {
+ public synchronized void write(FriendlyByteBuf buf) { // Paper - synchronize
try {
this.acquire();
buf.writeByte(this.bits);
@@ -173,7 +175,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {

}

- public void read(ListTag paletteNbt, long[] data) {
+ public synchronized void read(ListTag paletteNbt, long[] data) { // Paper - synchronize
try {
this.acquire();
int i = Math.max(4, Mth.ceillog2(paletteNbt.size()));
@@ -206,7 +208,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {

}

- public void write(CompoundTag nbt, String paletteKey, String dataKey) {
+ public synchronized void write(CompoundTag nbt, String paletteKey, String dataKey) { // Paper - synchronize
try {
this.acquire();
HashMapPalette<T> hashMapPalette = new HashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer);
Loading

0 comments on commit b26ba5b

Please sign in to comment.