fix: account for spigot having private PalettedContainer#get(int) (#2910)

This commit is contained in:
Jordan 2024-09-14 09:47:07 +01:00 committed by GitHub
parent 766a5d6da2
commit 19370a3549
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 88 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -179,8 +180,18 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
biomes[layer] = new Holder[64]; biomes[layer] = new Holder[64];
} }
if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) { if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) {
if (PaperLib.isPaper()) {
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
biomes[layer][i] = palettedContainer.get(i); biomes[layer][i] = palettedContainer.get(i); // Only public on paper
}
} else {
try {
for (int i = 0; i < 64; i++) {
biomes[layer][i] = (Holder<Biome>) PaperweightPlatformAdapter.PALETTED_CONTAINER_GET.invoke(i);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
} }
} else { } else {
LOGGER.error( LOGGER.error(

View File

@ -123,6 +123,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static Field LEVEL_CHUNK_ENTITIES; private static Field LEVEL_CHUNK_ENTITIES;
private static Field SERVER_LEVEL_ENTITY_MANAGER; private static Field SERVER_LEVEL_ENTITY_MANAGER;
static final MethodHandle PALETTED_CONTAINER_GET;
static { static {
final MethodHandles.Lookup lookup = MethodHandles.lookup(); final MethodHandles.Lookup lookup = MethodHandles.lookup();
try { try {
@ -212,6 +214,13 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} catch (NoSuchFieldException ignored) { } catch (NoSuchFieldException ignored) {
} }
POST_CHUNK_REWRITE = chunkRewrite; POST_CHUNK_REWRITE = chunkRewrite;
Method palettedContaienrGet = PalettedContainer.class.getDeclaredMethod(
Refraction.pickName("get", "a"),
int.class
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);
} catch (RuntimeException | Error e) { } catch (RuntimeException | Error e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {

View File

@ -15,6 +15,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -179,8 +180,18 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
biomes[layer] = new Holder[64]; biomes[layer] = new Holder[64];
} }
if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) { if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) {
if (PaperLib.isPaper()) {
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
biomes[layer][i] = palettedContainer.get(i); biomes[layer][i] = palettedContainer.get(i); // Only public on paper
}
} else {
try {
for (int i = 0; i < 64; i++) {
biomes[layer][i] = (Holder<Biome>) PaperweightPlatformAdapter.PALETTED_CONTAINER_GET.invoke(i);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
} }
} else { } else {
LOGGER.error( LOGGER.error(

View File

@ -123,6 +123,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static Field LEVEL_CHUNK_ENTITIES; private static Field LEVEL_CHUNK_ENTITIES;
private static Field SERVER_LEVEL_ENTITY_MANAGER; private static Field SERVER_LEVEL_ENTITY_MANAGER;
static final MethodHandle PALETTED_CONTAINER_GET;
static { static {
final MethodHandles.Lookup lookup = MethodHandles.lookup(); final MethodHandles.Lookup lookup = MethodHandles.lookup();
try { try {
@ -212,6 +214,13 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} catch (NoSuchFieldException ignored) { } catch (NoSuchFieldException ignored) {
} }
POST_CHUNK_REWRITE = chunkRewrite; POST_CHUNK_REWRITE = chunkRewrite;
Method palettedContaienrGet = PalettedContainer.class.getDeclaredMethod(
Refraction.pickName("get", "a"),
int.class
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);
} catch (RuntimeException | Error e) { } catch (RuntimeException | Error e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {

View File

@ -15,6 +15,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -180,8 +181,18 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
biomes[layer] = new Holder[64]; biomes[layer] = new Holder[64];
} }
if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) { if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) {
if (PaperLib.isPaper()) {
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
biomes[layer][i] = palettedContainer.get(i); biomes[layer][i] = palettedContainer.get(i); // Only public on paper
}
} else {
try {
for (int i = 0; i < 64; i++) {
biomes[layer][i] = (Holder<Biome>) PaperweightPlatformAdapter.PALETTED_CONTAINER_GET.invoke(i);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
} }
} else { } else {
LOGGER.error( LOGGER.error(

View File

@ -121,6 +121,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static Field LEVEL_CHUNK_ENTITIES; private static Field LEVEL_CHUNK_ENTITIES;
private static Field SERVER_LEVEL_ENTITY_MANAGER; private static Field SERVER_LEVEL_ENTITY_MANAGER;
static final MethodHandle PALETTED_CONTAINER_GET;
static { static {
final MethodHandles.Lookup lookup = MethodHandles.lookup(); final MethodHandles.Lookup lookup = MethodHandles.lookup();
try { try {
@ -210,6 +212,13 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} catch (NoSuchFieldException ignored) { } catch (NoSuchFieldException ignored) {
} }
POST_CHUNK_REWRITE = chunkRewrite; POST_CHUNK_REWRITE = chunkRewrite;
Method palettedContaienrGet = PalettedContainer.class.getDeclaredMethod(
Refraction.pickName("get", "a"),
int.class
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);
} catch (RuntimeException | Error e) { } catch (RuntimeException | Error e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {

View File

@ -15,6 +15,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -180,8 +181,18 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
biomes[layer] = new Holder[64]; biomes[layer] = new Holder[64];
} }
if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) { if (biomeData instanceof PalettedContainer<Holder<Biome>> palettedContainer) {
if (PaperLib.isPaper()) {
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
biomes[layer][i] = palettedContainer.get(i); biomes[layer][i] = palettedContainer.get(i); // Only public on paper
}
} else {
try {
for (int i = 0; i < 64; i++) {
biomes[layer][i] = (Holder<Biome>) PaperweightPlatformAdapter.PALETTED_CONTAINER_GET.invoke(i);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
} }
} else { } else {
LOGGER.error( LOGGER.error(

View File

@ -119,6 +119,8 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static Method PAPER_CHUNK_GEN_ALL_ENTITIES; private static Method PAPER_CHUNK_GEN_ALL_ENTITIES;
private static Field SERVER_LEVEL_ENTITY_MANAGER; private static Field SERVER_LEVEL_ENTITY_MANAGER;
static final MethodHandle PALETTED_CONTAINER_GET;
static { static {
final MethodHandles.Lookup lookup = MethodHandles.lookup(); final MethodHandles.Lookup lookup = MethodHandles.lookup();
try { try {
@ -195,6 +197,13 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
SERVER_LEVEL_ENTITY_MANAGER = ServerLevel.class.getDeclaredField(Refraction.pickName("entityManager", "N")); SERVER_LEVEL_ENTITY_MANAGER = ServerLevel.class.getDeclaredField(Refraction.pickName("entityManager", "N"));
SERVER_LEVEL_ENTITY_MANAGER.setAccessible(true); SERVER_LEVEL_ENTITY_MANAGER.setAccessible(true);
} }
Method palettedContaienrGet = PalettedContainer.class.getDeclaredMethod(
Refraction.pickName("get", "a"),
int.class
);
palettedContaienrGet.setAccessible(true);
PALETTED_CONTAINER_GET = lookup.unreflect(palettedContaienrGet);
} catch (RuntimeException | Error e) { } catch (RuntimeException | Error e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {