Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia 1.19.4-1.20.2 support #2309

Draft
wants to merge 81 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
de92aee
Initial experimental work on Folia support
SirYwell Mar 7, 2023
1fc2f90
Improve block tracing performance
SirYwell Mar 8, 2023
72b9a8b
Throw exception if player is retired to ensure task always finishes
SirYwell Mar 9, 2023
c193f75
Add folia support
TheMeinerLP Mar 30, 2023
d092e36
Add run folia task
TheMeinerLP Apr 2, 2023
40affbe
Port taskmanager for folia
TheMeinerLP Apr 2, 2023
668d5f5
Fix tasks manager
TheMeinerLP Apr 2, 2023
49f038e
Fix port for folia
TheMeinerLP Apr 2, 2023
d6ce47f
Build back to paper adapter
TheMeinerLP Apr 2, 2023
38661e3
Add special adapter load for folia
TheMeinerLP Apr 2, 2023
723f720
Add folia adapter
TheMeinerLP Apr 2, 2023
9f3e114
Fix package for classes
TheMeinerLP Apr 2, 2023
6ddba75
Fix package for classes
TheMeinerLP Apr 2, 2023
af92230
Improve search for folia adapter
TheMeinerLP Apr 2, 2023
7030213
Fix shading of folia adapters
TheMeinerLP Apr 2, 2023
5a8814d
Add runFolia with snapshot version of run paper
TheMeinerLP Apr 2, 2023
22d9a48
Fix regen command
TheMeinerLP Apr 2, 2023
677651f
Fix UnsupportedOperationException on disable
TheMeinerLP Apr 2, 2023
c0e1388
Use new method to check of is running on "main thread"
TheMeinerLP Apr 3, 2023
9d06640
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
2b46e19
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
67333d1
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
9a3f3e7
Improve scheduling for chunk data of regen
TheMeinerLP Apr 3, 2023
ac7bee4
Fix compass tool
TheMeinerLP Apr 3, 2023
cc06f5d
Fix duplicated import
TheMeinerLP May 31, 2023
b9b5cef
Add folia check
TheMeinerLP Jun 6, 2023
ff42306
Implements method handles for folia
TheMeinerLP Jun 6, 2023
c7316a9
Implements method handles for folia
TheMeinerLP Jun 6, 2023
b4adbac
Implements method handles for folia
TheMeinerLP Jun 6, 2023
faaf515
Add folia workaround
TheMeinerLP Jun 18, 2023
6156633
Fix reflections and casting
TheMeinerLP Jun 18, 2023
4c71d14
Fix access to world data
TheMeinerLP Jun 18, 2023
59a6594
Remove folia search path
TheMeinerLP Jun 18, 2023
e38f3bf
Remove duplicated code
TheMeinerLP Jun 18, 2023
3e4490a
Add multi folia run task support
TheMeinerLP Jun 18, 2023
e754f35
Add comment out folia dependency
TheMeinerLP Jun 18, 2023
048735e
Add sync at method for chunks
TheMeinerLP Jun 18, 2023
946b08e
Implement folia support
TheMeinerLP Jun 18, 2023
0f2d710
Initial experimental work on Folia support
SirYwell Mar 7, 2023
002bb72
Improve block tracing performance
SirYwell Mar 8, 2023
14a057e
Throw exception if player is retired to ensure task always finishes
SirYwell Mar 9, 2023
e8eb006
Add folia support
TheMeinerLP Mar 30, 2023
d6f1d28
Add run folia task
TheMeinerLP Apr 2, 2023
fb91ff4
Port taskmanager for folia
TheMeinerLP Apr 2, 2023
46bcbc8
Fix tasks manager
TheMeinerLP Apr 2, 2023
cebaaea
Fix port for folia
TheMeinerLP Apr 2, 2023
c840a9c
Build back to paper adapter
TheMeinerLP Apr 2, 2023
a45887c
Add special adapter load for folia
TheMeinerLP Apr 2, 2023
ce5bfa1
Add folia adapter
TheMeinerLP Apr 2, 2023
80ad773
Fix package for classes
TheMeinerLP Apr 2, 2023
ed5abad
Fix package for classes
TheMeinerLP Apr 2, 2023
3300bb2
Improve search for folia adapter
TheMeinerLP Apr 2, 2023
47f3ac6
Fix shading of folia adapters
TheMeinerLP Apr 2, 2023
2cdfac0
Add runFolia with snapshot version of run paper
TheMeinerLP Apr 2, 2023
232a0ea
Fix regen command
TheMeinerLP Apr 2, 2023
5653712
Fix UnsupportedOperationException on disable
TheMeinerLP Apr 2, 2023
9d09322
Use new method to check of is running on "main thread"
TheMeinerLP Apr 3, 2023
de98bf8
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
e1fd9b8
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
7bca6ef
Implement dirty workaround for get data from right ticking region
TheMeinerLP Apr 3, 2023
9ac3bcc
Improve scheduling for chunk data of regen
TheMeinerLP Apr 3, 2023
c841222
Fix compass tool
TheMeinerLP Apr 3, 2023
efc43b5
Fix duplicated import
TheMeinerLP May 31, 2023
535b26b
Add folia check
TheMeinerLP Jun 6, 2023
3e88790
Implements method handles for folia
TheMeinerLP Jun 6, 2023
e89e5c1
Implements method handles for folia
TheMeinerLP Jun 6, 2023
f066939
Implements method handles for folia
TheMeinerLP Jun 6, 2023
296baf0
Add folia workaround
TheMeinerLP Jun 18, 2023
e1ca178
Fix reflections and casting
TheMeinerLP Jun 18, 2023
fcfdc03
Fix access to world data
TheMeinerLP Jun 18, 2023
903a697
Remove folia search path
TheMeinerLP Jun 18, 2023
ffd9159
Remove duplicated code
TheMeinerLP Jun 18, 2023
dc77ce9
Add multi folia run task support
TheMeinerLP Jun 18, 2023
9875ad7
Add comment out folia dependency
TheMeinerLP Jun 18, 2023
4818f37
Add sync at method for chunks
TheMeinerLP Jun 18, 2023
d7bdaf0
Implement folia support
TheMeinerLP Jun 18, 2023
dea40d1
Merge remote-tracking branch 'origin/feature/folia/1-20-update' into …
TheMeinerLP Dec 3, 2023
84c5692
Fix compiling
TheMeinerLP Dec 3, 2023
80ebe64
Improve API design and reduce duplicate code
TheMeinerLP Dec 3, 2023
f05c3e1
I did it!
Yomamaeatstoes Dec 9, 2023
15c5baa
Merge pull request #9 from Yomamaeatstoes/feature/folia/1-20-update
TheMeinerLP Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.ajoberstar.grgit.Grgit
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import xyz.jpenilla.runpaper.task.RunServer
import java.net.URI
import java.time.format.DateTimeFormatter
import xyz.jpenilla.runpaper.task.RunServer

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
Expand Down Expand Up @@ -84,7 +84,7 @@ allprojects {

applyCommonConfiguration()
val supportedVersions = listOf("1.17.1", "1.18.2", "1.19.4", "1.20", "1.20.2")

val foliaSupportedVersions = listOf("1.19.4", "1.20.1", "1.20.2")
tasks {
supportedVersions.forEach {
register<RunServer>("runServer-$it") {
Expand All @@ -102,6 +102,17 @@ tasks {
.toTypedArray())

}
foliaSupportedVersions.forEach {
register<RunServer>("runFolia-$it") {
downloadsApiService.set(xyz.jpenilla.runtask.service.DownloadsAPIService.folia(project))
minecraftVersion(it)
group = "run paper"
runDirectory.set(file("run-folia-$it"))
pluginJars(*project(":worldedit-bukkit").getTasksByName("shadowJar", false).map { (it as Jar).archiveFile }
.toTypedArray())
}
}

}

nexusPublishing {
Expand Down
10 changes: 9 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ include("worldedit-libs")
listOf("1_17_1", "1_18_2", "1_19_4", "1_20", "1_20_2").forEach {
include("worldedit-bukkit:adapters:adapter-$it")
}

listOf("bukkit", "core", "cli").forEach {
include("worldedit-libs:$it")
include("worldedit-$it")
Expand All @@ -21,5 +20,14 @@ dependencyResolutionManagement {
}
}
}
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = "jmp repository"
url = uri("https://repo.jpenilla.xyz/snapshots")
}
}
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.bukkit.entity.Player;

import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -555,6 +556,11 @@ protected ServerLevel getServerLevel(final World world) {
return ((CraftWorld) world).getHandle();
}

@Override
protected MethodHandle getCurrentWorldData() {
return null;
}

@Override
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
// Quickly add each entity to a list copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public synchronized net.minecraft.world.level.block.state.BlockState setBlockSta
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void run(Object value) {
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static LevelChunk ensureLoaded(ServerLevel serverLevel, int chunkX, int c
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
Expand All @@ -219,7 +219,7 @@ public static LevelChunk ensureLoaded(ServerLevel serverLevel, int chunkX, int c
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.bukkit.entity.Player;

import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -547,6 +548,11 @@ protected ServerLevel getServerLevel(final World world) {
return ((CraftWorld) world).getHandle();
}

@Override
protected MethodHandle getCurrentWorldData() {
return null;
}

@Override
public List<org.bukkit.entity.Entity> getEntities(org.bukkit.World world) {
// Quickly add each entity to a list copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public synchronized net.minecraft.world.level.block.state.BlockState setBlockSta
net.minecraft.world.level.block.state.BlockState blockState
) {
int currentTick = MinecraftServer.currentTick;
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return levelChunk.setBlockState(blockPos, blockState,
this.sideEffectSet != null && this.sideEffectSet.shouldApply(SideEffect.UPDATE)
);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void run(Object value) {
}
}
};
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
runnableVal.run();
} else {
TaskManager.taskManager().sync(runnableVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static LevelChunk ensureLoaded(ServerLevel serverLevel, int chunkX, int c
if (nmsChunk != null) {
return nmsChunk;
}
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
} else {
Expand All @@ -235,7 +235,7 @@ public static LevelChunk ensureLoaded(ServerLevel serverLevel, int chunkX, int c
return nmsChunk;
}
// Avoid "async" methods from the main thread.
if (Fawe.isMainThread()) {
if (Fawe.isTickThread()) {
return serverLevel.getChunk(chunkX, chunkZ);
}
CompletableFuture<org.bukkit.Chunk> future = serverLevel.getWorld().getChunkAtAsync(chunkX, chunkZ, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
private final Field chunkProviderExecutorField;
private final Watchdog watchdog;

private final Boolean folia;

// ------------------------------------------------------------------------
// Code that may break between versions of Minecraft
// ------------------------------------------------------------------------
Expand All @@ -186,6 +188,16 @@ public PaperweightAdapter() throws NoSuchFieldException, NoSuchMethodException {
throw new UnsupportedClassVersionError("Not 1.19.4!");
}

boolean isFolia = false;
try {
// Assume API is present
Class.forName("io.papermc.paper.threadedregions.scheduler.EntityScheduler");
isFolia = true;
} catch (Exception unused) {

}
this.folia = isFolia;

serverWorldsField = CraftServer.class.getDeclaredField("worlds");
serverWorldsField.setAccessible(true);

Expand Down Expand Up @@ -222,6 +234,10 @@ public PaperweightAdapter() throws NoSuchFieldException, NoSuchMethodException {
}
}

public Boolean isFolia() {
return folia;
}

@Override
public DataFixer getDataFixer() {
return PaperweightDataConverters.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_19_R3.PaperweightAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3.regen.PaperweightRegen;
Expand Down Expand Up @@ -77,6 +78,7 @@
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState;
import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
Expand All @@ -85,6 +87,8 @@
import org.bukkit.entity.Player;

import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -487,29 +491,6 @@ public org.bukkit.inventory.ItemStack adapt(BaseItemStack baseItemStack) {
return CraftItemStack.asCraftMirror(stack);
}

@Override
protected void preCaptureStates(final ServerLevel serverLevel) {
serverLevel.captureTreeGeneration = true;
serverLevel.captureBlockStates = true;
}

@Override
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
return new ArrayList<>(serverLevel.capturedBlockStates.values());
}

@Override
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
serverLevel.capturedBlockStates.clear();
}

@Override
protected ServerLevel getServerLevel(final World world) {
return ((CraftWorld) world).getHandle();
}

@Override
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
Expand Down Expand Up @@ -611,4 +592,76 @@ private boolean wasAccessibleSinceLastSave(ChunkHolder holder) {
return true;
}

@Override
protected void preCaptureStates(final ServerLevel serverLevel) {
if (this.isFolia()) {
try {
var data = currentWorldData.invoke(serverLevel);
captureBlockStates.setBoolean(data, true);
captureTreeGeneration.setBoolean(data, true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
} else {
serverLevel.captureTreeGeneration = true;
serverLevel.captureBlockStates = true;
}

}

@Override
protected List<org.bukkit.block.BlockState> getCapturedBlockStatesCopy(final ServerLevel serverLevel) {
return new ArrayList<>(serverLevel.capturedBlockStates.values());
}

// Folia - Start
@Override
protected void postCaptureBlockStates(final ServerLevel serverLevel) {
if (this.isFolia()) {
try {
var data = currentWorldData.invoke(serverLevel);
captureBlockStates.setBoolean(data, false);
captureTreeGeneration.setBoolean(data, false);
((Map<BlockPos, CraftBlockState>) capturedBlockStates.get(data)).clear();
} catch (Throwable e) {
throw new RuntimeException(e);
}
} else {
serverLevel.captureBlockStates = false;
serverLevel.captureTreeGeneration = false;
serverLevel.capturedBlockStates.clear();
}
}

// Folia - End

@Override
protected ServerLevel getServerLevel(final World world) {
return ((CraftWorld) world).getHandle();
}

// Folia - Start
@Override
protected MethodHandle getCurrentWorldData() {
if (this.isFolia()) {
Method getCurrentWorldData;
try {
getCurrentWorldData = ServerLevel.class.getSuperclass().getDeclaredMethod(
"getCurrentWorldData"
);
} catch (NoSuchMethodException e) {
return null;
}
getCurrentWorldData.setAccessible(true);

try {
currentWorldData = MethodHandles.lookup().unreflect(getCurrentWorldData);
} catch (IllegalAccessException e) {
}
}
return null;
}

// Folia - End

}
Loading