Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration

plugins {
id("buildlogic.adapter")
}

paperweight {
reobfArtifactConfiguration = ReobfArtifactConfiguration.MOJANG_PRODUCTION
}
24 changes: 24 additions & 0 deletions build-logic/src/main/kotlin/buildlogic.adapter-reobf.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import io.papermc.paperweight.userdev.ReobfArtifactConfiguration

plugins {
id("buildlogic.adapter")
}

paperweight {
reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
}
}

tasks.named("assemble") {
dependsOn("reobfJar")
}

tasks
.withType<JavaCompile>()
.matching { it.name == "compileJava" || it.name == "compileTestJava" }
.configureEach {
// We use Java 21 for most of the pre-existing adapters.
options.release.set(21)
}
31 changes: 9 additions & 22 deletions build-logic/src/main/kotlin/buildlogic.adapter.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ plugins {
id("io.papermc.paperweight.userdev")
}

val requiresReobfJar = project.name.startsWith("adapter-1_")

paperweight {
injectPaperRepository = false
reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
}

repositories {
maven {
name = "PaperMC"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
name = "EngineHub Repository"
url = uri("https://maven.enginehub.org/repo/")
Expand All @@ -28,13 +17,14 @@ repositories {
}
}
maven {
name = "IntellectualSites"
url = uri("https://repo.intellectualsites.dev/repository/maven-all/")
name = "PaperMC"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
name = "FabricMC (Yarn)"
url = uri("https://maven.fabricmc.net/#yarn-only")
}
mavenCentral()
afterEvaluate {
killNonEngineHubRepositories()
}
}

dependencies {
Expand All @@ -45,6 +35,9 @@ dependencies {
version { strictly(stringyLibs.getVersion("adventure").strictVersion) }
because("Ensure a consistent version of adventure is used.")
}
"remapper"("net.fabricmc:tiny-remapper:[${stringyLibs.getVersion("minimumTinyRemapper")},)") {
because("Need remapper to support Java 21")
}
}
}

Expand All @@ -53,12 +46,6 @@ java {
disableAutoTargetJvm()
}

tasks.named("assemble") {
if (requiresReobfJar) {
dependsOn("reobfJar")
}
}

tasks.named<Javadoc>("javadoc") {
enabled = false
}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ log4j = "2.17.1"
gson = "2.11.0"
snakeyaml = "2.2"

# Minimum versions we apply to make dependencies support newer Java
minimumTinyRemapper = "0.8.11"

# Plugins
dummypermscompat = "1.10"
worldguard-bukkit = "7.0.17"
Expand Down
3 changes: 1 addition & 2 deletions worldedit-bukkit/adapters/adapter-1_21/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")

id("buildlogic.adapter-reobf")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-reobf")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-reobf")

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-reobf")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-reobf")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-reobf")
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion worldedit-bukkit/adapters/adapter-26.1/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-mojmap")
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion worldedit-bukkit/adapters/adapter-26.2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension

plugins {
id("buildlogic.adapter")
id("buildlogic.adapter-mojmap")
}

// workaround LeafPile providing wrong snakeyaml version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private synchronized boolean init() {
public Collection<String> getRegisteredDefaultBlockStates() {
ArrayList<String> states = new ArrayList<>();
for (final Block block : BuiltInRegistries.BLOCK) {
states.add(block.defaultBlockState().asBlockData().getAsString());
states.add(PlatformCompat.fromData(block.defaultBlockState()).getAsString());
}
return states;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void updateNeighbors(
if (craftWorld != null) {
BlockPhysicsEvent event = new BlockPhysicsEvent(
craftWorld.getBlockAt(blockPos.getX(), blockPos.getY(), blockPos.getZ()),
newState.asBlockData()
PlatformCompat.fromData(newState)
);
level.getCraftServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.mojang.serialization.DataResult;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.v26_2.PaperweightBlockMaterial;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.world.biome.BiomeType;
Expand Down Expand Up @@ -112,31 +111,28 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
static {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
try {
fieldData = PalettedContainer.class.getDeclaredField(Refraction.pickName("data", "b"));
fieldData = PalettedContainer.class.getDeclaredField("data");
fieldData.setAccessible(true);

Class<?> dataClazz = fieldData.getType();
dataConstructor = dataClazz.getDeclaredConstructors()[0];
dataConstructor.setAccessible(true);

fieldStorage = dataClazz.getDeclaredField(Refraction.pickName("storage", "b"));
fieldStorage = dataClazz.getDeclaredField("storage");
fieldStorage.setAccessible(true);
fieldPalette = dataClazz.getDeclaredField(Refraction.pickName("palette", "c"));
fieldPalette = dataClazz.getDeclaredField("palette");
fieldPalette.setAccessible(true);

//noinspection JavaLangInvokeHandleSignature - method is obfuscated
//noinspection JavaLangInvokeHandleSignature - signature differs between Paper and Spigot
palettedContainerUnpackSpigot = PaperSupport.isPaper() ? null : lookup.findStatic(
PalettedContainer.class,
"a", // unpack
MethodType.methodType(DataResult.class, Strategy.class, PalettedContainerRO.PackedData.class)
PalettedContainer.class,
"unpack",
MethodType.methodType(DataResult.class, Strategy.class, PalettedContainerRO.PackedData.class)
);

fieldTickingFluidCount = LevelChunkSection.class.getDeclaredField(Refraction.pickName(
"tickingFluidCount",
"g"
));
fieldTickingFluidCount = LevelChunkSection.class.getDeclaredField("tickingFluidCount");
fieldTickingFluidCount.setAccessible(true);
fieldTickingBlockCount = LevelChunkSection.class.getDeclaredField(Refraction.pickName("tickingBlockCount", "f"));
fieldTickingBlockCount = LevelChunkSection.class.getDeclaredField("tickingBlockCount");
fieldTickingBlockCount.setAccessible(true);
Field tmpFieldBiomes;
try {
Expand All @@ -148,21 +144,16 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldBiomes = tmpFieldBiomes;
fieldBiomes.setAccessible(true);

Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(
Refraction.pickName(
"getVisibleChunkIfPresent",
"b"
), long.class
);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod("getVisibleChunkIfPresent", long.class);
getVisibleChunkIfPresent.setAccessible(true);
methodGetVisibleChunk = lookup.unreflect(getVisibleChunkIfPresent);

if (!PaperSupport.isPaper()) {
fieldThreadingDetector = PalettedContainer.class.getDeclaredField(Refraction.pickName("threadingDetector", "d"));
fieldThreadingDetector = PalettedContainer.class.getDeclaredField("threadingDetector");
fieldThreadingDetector.setAccessible(true);
fieldLock = ThreadingDetector.class.getDeclaredField(Refraction.pickName("lock", "c"));
fieldLock = ThreadingDetector.class.getDeclaredField("lock");
fieldLock.setAccessible(true);
SERVER_LEVEL_ENTITY_MANAGER = ServerLevel.class.getDeclaredField(Refraction.pickName("entityManager", "M"));
SERVER_LEVEL_ENTITY_MANAGER = ServerLevel.class.getDeclaredField("entityManager");
SERVER_LEVEL_ENTITY_MANAGER.setAccessible(true);
} else {
// in paper, the used methods are synchronized properly
Expand All @@ -171,29 +162,21 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
}

Method removeGameEventListener = LevelChunk.class.getDeclaredMethod(
Refraction.pickName("removeGameEventListener", "a"),
"removeGameEventListener",
BlockEntity.class,
ServerLevel.class
);
removeGameEventListener.setAccessible(true);
methodRemoveGameEventListener = lookup.unreflect(removeGameEventListener);

Method removeBlockEntityTicker = LevelChunk.class.getDeclaredMethod(
Refraction.pickName(
"removeBlockEntityTicker",
"k"
), BlockPos.class
);
Method removeBlockEntityTicker = LevelChunk.class.getDeclaredMethod("removeBlockEntityTicker", BlockPos.class);
removeBlockEntityTicker.setAccessible(true);
methodremoveTickingBlockEntity = lookup.unreflect(removeBlockEntityTicker);

fieldRemove = BlockEntity.class.getDeclaredField(Refraction.pickName("remove", "p"));
fieldRemove = BlockEntity.class.getDeclaredField("remove");
fieldRemove.setAccessible(true);

Method palettedContainerGet = PalettedContainer.class.getDeclaredMethod(
Refraction.pickName("get", "a"),
int.class
);
Method palettedContainerGet = PalettedContainer.class.getDeclaredMethod("get", int.class);
palettedContainerGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContainerGet);
} catch (RuntimeException | Error e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v26_2;

import com.fastasyncworldedit.bukkit.util.PaperSupport;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import net.minecraft.world.level.block.state.BlockState;
import org.apache.logging.log4j.Logger;
import org.bukkit.craftbukkit.block.data.CraftBlockData;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public final class PlatformCompat {

private static final Logger LOGGER = LogManagerCompat.getLogger();

private static final MethodHandle SPIGOT__CRAFT_BLOCK_DATA__FROM_DATA;

static {
MethodHandle tmpSpigotCraftBlockDataFromData = null;
if (!PaperSupport.isPaper()) {
try {
//noinspection JavaLangInvokeHandleSignature (not available on Paper)
tmpSpigotCraftBlockDataFromData = MethodHandles.lookup().findStatic(
CraftBlockData.class,
"fromData",
MethodType.methodType(CraftBlockData.class, BlockState.class)
);
} catch (NoSuchMethodException | IllegalAccessException e) {
LOGGER.error("Failed to lookup CraftBlockData#fromData(BlockState)", e);
}
}
SPIGOT__CRAFT_BLOCK_DATA__FROM_DATA = tmpSpigotCraftBlockDataFromData;
}

/**
* Adapts a {@link BlockState} to a {@link CraftBlockData} using platform-specific methods.
* On Paper {@code BlockState#asBlockData()} is used, on Spigot {@code CraftBlockData#fromData(BlockState)} is used.
* <p>
* Uses reflection on Spigot, as Paper dropped the Spigot method (-> Can't be directly called).
*
* @param state the {@link BlockState} to adapt.
* @return the {@link CraftBlockData}
*/
public static CraftBlockData fromData(BlockState state) {
if (SPIGOT__CRAFT_BLOCK_DATA__FROM_DATA == null) {
return state.asBlockData();
}
try {
return (CraftBlockData) SPIGOT__CRAFT_BLOCK_DATA__FROM_DATA.invokeExact(state);
} catch (Throwable throwable) {
throw new RuntimeException("Caught unexpected Exception while converting BlockState to CraftBlockData", throwable);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fastasyncworldedit.bukkit.adapter.BukkitBlockMaterial;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v26_2.PaperweightGetBlocks;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v26_2.PlatformCompat;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
Expand All @@ -38,7 +39,7 @@ public PaperweightBlockMaterial(Block block) {
}

public PaperweightBlockMaterial(Block block, BlockState blockState) {
super(block, blockState, blockState.asBlockData());
super(block, blockState, PlatformCompat.fromData(blockState));
}

@Override
Expand Down
Loading
Loading