Make 1.18 to be effectively in a usable state (#1452)

* Update swathes of easy-to-update-sort-of-code.
 - Untested
 - Should compile but NMF broken something
 - Several todos:
  - biome history//better support (move to biome sections in core)
  - regen (haha lol no thanks, someone else can do that)
  - probably actually do the palette stuff that probably won't work in PaperweightPlatformAdapter

* ci: Provide basic Jenkinsfile for ghprb pipeline

* build: Update paperweight

* upstream: Update Upstream

de6fa17 Add getBrush helper for use with instanceof pattern matching (1926)

* FAWE will now load on startup

* it....works?

* Begin to allow biome edits (and fix biomes reverting to plains upon editing blocks)

* Add new blocks/block properties

* Only create biome palette if supplies is null

* Fix biome operations

* Finally get removing BlockID done (major version change allows it)

* refactor!: Drop PlotSquared v4

Fawe 2.0.0 and newer requires Java 17, PlotSquared v4 supports 1.13 and 1.14, Fawe wont work on these versions nevertheless and refuses to load due Java version incompatiblities with older versions. Newer versions can use PlotSquared v6.

* docs: Update readme

* Added and removed some comments

* Added and removed some comments

* refactor: Rename worldedit configuration

* build: Re-add 1.17 module

This the a very nasty commit

* chore: Implement missing methods

* build: Update paperweight

* upstream: Update upstream

6df194e Remove finalize, use a Cleaner instead (1943)
9843a4f Fix snapshots in 1.18 (1959)

* ci: Escape workflows

* build: Update paperweight to 1.18.1

* build: Update Paster

* Fix compilation

* Bump to 1.18.1

* Do both 1.18 and 1.18.1

Co-authored-by: Alex <mc.cache@web.de>

* Fix single-block lookups

* Reserve ordinals 0 through 3 for air/"reserved"

* Create block palette data with values

* Fix classpath for testing for starlight

* Correctly use block rather than sky light layer [not used in paper]

Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
Jordan 2021-12-20 21:12:04 +00:00 committed by GitHub
parent c697eb8d41
commit d6e3c331d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 2447 additions and 3052 deletions

View File

@ -29,7 +29,7 @@ body:
description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first. description: Which server version version you using? If your server version is not listed, it is not supported. Update to a supported version first.
multiple: false multiple: false
options: options:
- '1.18' - '1.18.1'
- '1.17.1' - '1.17.1'
- '1.16.5' - '1.16.5'
- '1.15.2' - '1.15.2'

2
.github/stale.yml vendored
View File

@ -1,4 +1,4 @@
daysUntilStale: 60 daysUntilStale: 30
daysUntilClose: 7 daysUntilClose: 7
only: issues only: issues
exemptLabels: exemptLabels:

View File

@ -1,47 +1,47 @@
name: "build" name: build
on: ["pull_request", "push"] on: [pull_request, push]
jobs: jobs:
build: build:
runs-on: "ubuntu-latest" runs-on: ubuntu-latest
steps: steps:
- name: "Checkout Repository" - name: Checkout Repository
uses: "actions/checkout@v2.4.0" uses: actions/checkout@v2.4.0
- name : "Validate Gradle Wrapper" - name : Validate Gradle Wrapper
uses : "gradle/wrapper-validation-action@v1.0.4" uses : gradle/wrapper-validation-action@v1.0.4
- name: "Setup Java" - name: Setup Java
uses: "actions/setup-java@v2.3.1" uses: actions/setup-java@v2.3.1
with: with:
distribution: "temurin" distribution: temurin
cache: 'gradle' cache: gradle
java-version: "17" java-version: 17
- name: "Clean Build" - name: Clean Build
run: "./gradlew clean build --no-daemon" run: ./gradlew clean build --no-daemon
- name: "Determine release status" - name: Determine release status
if: "${{ runner.os == 'Linux' }}" if: ${{ runner.os == 'Linux' }}
run: | run: |
if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then
echo "STATUS=snapshot" >> $GITHUB_ENV echo "STATUS=snapshot" >> $GITHUB_ENV
else else
echo "STATUS=release" >> $GITHUB_ENV echo "STATUS=release" >> $GITHUB_ENV
fi fi
- name: "Publish Release" - name: Publish Release
if: "${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}" if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}
run: "./gradlew publishToSonatype closeSonatypeStagingRepository" run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
env: env:
ORG_GRADLE_PROJECT_sonatypeUsername: "${{ secrets.SONATYPE_USERNAME }}" ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: "${{ secrets.SONATYPE_PASSWORD }}" ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: "${{ secrets.SIGNING_KEY }}" ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: "${{ secrets.SIGNING_PASSWORD }}" ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
- name: "Publish Snapshot" - name: Publish Snapshot
if: "${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}" if: ${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: "./gradlew publishToSonatype" run: ./gradlew publishToSonatype
env: env:
ORG_GRADLE_PROJECT_sonatypeUsername: "${{ secrets.SONATYPE_USERNAME }}" ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: "${{ secrets.SONATYPE_PASSWORD }}" ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
- name: "Archive Artifacts" - name: Archive Artifacts
uses: "actions/upload-artifact@v2.2.4" uses: actions/upload-artifact@v2.2.4
with: with:
name: "FastAsyncWorldEdit-Bukkit-SNAPSHOT" name: FastAsyncWorldEdit-Bukkit-SNAPSHOT
path: "worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar" path: worldedit-bukkit/build/libs/FastAsyncWorldEdit-Bukkit-*.jar

View File

@ -1,4 +1,4 @@
name: "draft release" name: draft release
on: on:
push: push:
@ -7,8 +7,8 @@ on:
jobs: jobs:
update_release_draft: update_release_draft:
runs-on: "ubuntu-latest" runs-on: ubuntu-latest
steps: steps:
- uses: "release-drafter/release-drafter@v5.15.0" - uses: release-drafter/release-drafter@v5.15.0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,12 +1,12 @@
Compiling Compiling
========= =========
You can compile FastAsyncWorldEdit as long as you have some version of Java greater than or equal to 16 installed. Gradle will download JDK 16 specifically if needed, You can compile FastAsyncWorldEdit as long as you have some version of Java greater than or equal to 17 installed. Gradle will download JDK 17 specifically if needed,
but it needs some version of Java to bootstrap from. but it needs some version of Java to bootstrap from.
Note that if you have JRE 8 installed, Gradle will currently attempt to use that to compile, which will not work. It is easiest to uninstall JRE 8 and replace it with JDK 16. Note that if you have JRE 8 installed, Gradle will currently attempt to use that to compile, which will not work. It is easiest to uninstall JRE 8 and replace it with JDK 16.
You can get the JDK 16 [here](https://adoptium.net/). You can get the JDK 17 [here](https://adoptium.net/).
The build process uses Gradle, which you do *not* need to download. FastAsyncWorldEdit is a multi-module project with three active modules: The build process uses Gradle, which you do *not* need to download. FastAsyncWorldEdit is a multi-module project with three active modules:
@ -44,7 +44,7 @@ If you want to use FastAsyncWorldEdit, use the `FastAsyncWorldEdit-<identifier>`
## Other commands ## Other commands
* `gradlew idea` will generate an [IntelliJ IDEA](http://www.jetbrains.com/idea/) module for each folder. * `gradlew idea` will generate an [IntelliJ IDEA](https://www.jetbrains.com/idea/) module for each folder.
_Possibly broken_: _Possibly broken_:
* `gradlew eclipse` will generate an [Eclipse](https://www.eclipse.org/downloads/) project for each folder. * `gradlew eclipse` will generate an [Eclipse](https://www.eclipse.org/downloads/) project for each folder.

10
Jenkinsfile vendored
View File

@ -1,10 +0,0 @@
pipeline {
agent any
stages {
stage('Build pull request') {
steps {
sh './gradlew clean build'
}
}
}
}

View File

@ -12,7 +12,7 @@ FastAsyncWorldEdit is a fork of WorldEdit that has huge speed and memory improve
* Use it in creative, survival in single player or on your server. * Use it in creative, survival in single player or on your server.
* Use it on your Minecraft server to fix grieving and mistakes. * Use it on your Minecraft server to fix grieving and mistakes.
Java Edition required. FastAsyncWorldEdit is compatible with Bukkit, Spigot, Paper, and Tuinity. Java Edition required. FastAsyncWorldEdit is compatible with Bukkit, Spigot and Paper.
## Download FastAsyncWorldEdit ## Download FastAsyncWorldEdit
* Spigot: https://www.spigotmc.org/resources/fast-async-worldedit.13932/ * Spigot: https://www.spigotmc.org/resources/fast-async-worldedit.13932/

View File

@ -31,7 +31,7 @@ dependencies {
implementation(gradleApi()) implementation(gradleApi())
implementation("org.ajoberstar.grgit:grgit-gradle:4.1.1") implementation("org.ajoberstar.grgit:grgit-gradle:4.1.1")
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.1") implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.1")
implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.3.0-SNAPSHOT") implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.3.2")
} }
kotlin { kotlin {

View File

@ -62,7 +62,6 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/", "https://javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/",
"https://jd.adventure.kyori.net/api/4.9.3/", "https://jd.adventure.kyori.net/api/4.9.3/",
"https://javadoc.io/doc/org.apache.logging.log4j/log4j-api/2.14.1/", "https://javadoc.io/doc/org.apache.logging.log4j/log4j-api/2.14.1/",
"https://javadoc.io/doc/com.google.guava/guava/31.0.1/",
"https://www.antlr.org/api/Java/", "https://www.antlr.org/api/Java/",
"https://docs.enginehub.org/javadoc/org.enginehub.piston/core/0.5.7/", "https://docs.enginehub.org/javadoc/org.enginehub.piston/core/0.5.7/",
"https://docs.enginehub.org/javadoc/org.enginehub.piston/default-impl/0.5.7/", "https://docs.enginehub.org/javadoc/org.enginehub.piston/default-impl/0.5.7/",

View File

@ -3,10 +3,10 @@
fastutil = "8.5.6" fastutil = "8.5.6"
log4j = "2.17.0" log4j = "2.17.0"
guava = "31.0.1-jre" guava = "31.0.1-jre"
gson = "2.8.8" gson = "2.8.9"
# Platform expectations # Platform expectations
paper = "1.18-R0.1-SNAPSHOT" paper = "1.18.1-R0.1-SNAPSHOT"
# Plugins # Plugins
vault = "1.7.1" vault = "1.7.1"
@ -20,7 +20,6 @@ residence = "4.5._13.1"
towny = "0.97.5.0" towny = "0.97.5.0"
protocollib = "4.7.0" protocollib = "4.7.0"
plotsquaredV6 = "6.2.0" plotsquaredV6 = "6.2.0"
plotsquaredV4 = "4.514"
redprotect = "1.9.6" redprotect = "1.9.6"
# Third party # Third party
@ -28,7 +27,7 @@ flow-math = "1.0.3"
paperlib = "1.0.8-SNAPSHOT" paperlib = "1.0.8-SNAPSHOT"
bstats = "2.2.1" bstats = "2.2.1"
serverlib = "2.3.1" serverlib = "2.3.1"
paster = "1.1.1" paster = "1.1.3"
sparsebitset = "1.2" sparsebitset = "1.2"
parallelgzip = "1.0.5" parallelgzip = "1.0.5"
adventure = "4.9.3" adventure = "4.9.3"
@ -80,7 +79,6 @@ towny = { group = "com.github.TownyAdvanced", name = "Towny", version.ref = "tow
protocollib = { group = "com.comphenix.protocol", name = "ProtocolLib", version.ref = "protocollib" } protocollib = { group = "com.comphenix.protocol", name = "ProtocolLib", version.ref = "protocollib" }
plotsquaredV6Bukkit = { group = "com.plotsquared", name = "PlotSquared-Bukkit", version.ref = "plotsquaredV6" } plotsquaredV6Bukkit = { group = "com.plotsquared", name = "PlotSquared-Bukkit", version.ref = "plotsquaredV6" }
plotsquaredV6Core = { group = "com.plotsquared", name = "PlotSquared-Core", version.ref = "plotsquaredV6" } plotsquaredV6Core = { group = "com.plotsquared", name = "PlotSquared-Core", version.ref = "plotsquaredV6" }
plotsquaredV4 = { group = "com.github.intellectualsites.plotsquared", name = "PlotSquared-API", version.ref = "plotsquaredV4" }
redprotect = { group = "net.fabiozumbi12", name = "redprotect", version.ref = "redprotect" } redprotect = { group = "net.fabiozumbi12", name = "redprotect", version.ref = "redprotect" }
# Third Party # Third Party

View File

@ -3,7 +3,7 @@ rootProject.name = "FastAsyncWorldEdit"
include("worldedit-libs") include("worldedit-libs")
include("worldedit-bukkit:adapters:adapter-legacy") include("worldedit-bukkit:adapters:adapter-legacy")
// include("worldedit-bukkit:adapters:adapter-1_17_1") include("worldedit-bukkit:adapters:adapter-1_17_1")
include("worldedit-bukkit:adapters:adapter-1_18") include("worldedit-bukkit:adapters:adapter-1_18")
listOf("bukkit", "core", "cli").forEach { listOf("bukkit", "core", "cli").forEach {

View File

@ -15,12 +15,25 @@ plugins {
} }
repositories { repositories {
mavenCentral()
maven { maven {
name = "PaperMC" name = "PaperMC"
url = uri("https://papermc.io/repo/repository/maven-public/") url = uri("https://papermc.io/repo/repository/maven-public/")
content {
includeModule("io.papermc", "paperlib")
} }
maven {
name = "Athion"
url = uri("https://ci.athion.net/plugin/repository/tools/")
content {
includeModule("io.papermc", "paper-server")
}
}
maven {
name = "OSS Sonatype Snapshots"
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
maven {
name = "Mojang"
url = uri("https://libraries.minecraft.net/")
} }
} }
@ -28,6 +41,23 @@ artifacts {
add("default", file("./src/main/resources/worldedit-adapter-1.17.1.jar")) add("default", file("./src/main/resources/worldedit-adapter-1.17.1.jar"))
} }
dependencies { java {
compileOnly(libs.paperlib) toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
configurations.all {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT")
compileOnly(project(":worldedit-bukkit"))
compileOnly(project(":worldedit-core"))
compileOnly("io.papermc:paper-server:1_17_r1_2")
compileOnly(libs.paperlib)
compileOnly("com.mojang:datafixerupper:4.0.26")
compileOnly("com.mojang:authlib:2.3.31")
compileOnly("com.mojang:brigadier:1.0.18")
compileOnly("io.netty:netty-all:4.1.25.Final")
} }

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe; package com.sk89q.worldedit.bukkit.adapter.ext.fawe;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -35,8 +36,10 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction; import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.PaperweightFaweAdapter;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog; import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -316,9 +319,31 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId); return combinedId == 0 && state.getBlockType() != BlockTypes.AIR ? OptionalInt.empty() : OptionalInt.of(combinedId);
} }
@Deprecated
@Override @Override
public BaseBlock getBlock(Location location) { public BlockState getBlock(Location location) {
checkNotNull(location); Preconditions.checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
final ServerLevel handle = craftWorld.getHandle();
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z);
final CraftBlockData blockData = chunk.getBlockState(blockPos).createCraftBlockData();
BlockState state = BukkitAdapter.adapt(blockData);
if (state == null) {
org.bukkit.block.Block bukkitBlock = location.getBlock();
state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
return state;
}
@Override
public BaseBlock getFullBlock(Location location) {
BlockState state = getBlock(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld()); CraftWorld craftWorld = ((CraftWorld) location.getWorld());
int x = location.getBlockX(); int x = location.getBlockX();
@ -328,19 +353,11 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
final ServerLevel handle = craftWorld.getHandle(); final ServerLevel handle = craftWorld.getHandle();
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4); LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z); final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
int internalId = Block.getId(blockData);
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
if (state == null) {
org.bukkit.block.Block bukkitBlock = location.getBlock();
state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
// Read the NBT data // Read the NBT data
BlockEntity te = chunk.getBlockEntity(blockPos); BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) { if (te != null) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag tag = te.save(new net.minecraft.nbt.CompoundTag());
readTileEntityIntoTag(te, tag); // Load data
//FAWE start - BinaryTag //FAWE start - BinaryTag
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag)); return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
//FAWE end //FAWE end
@ -748,8 +765,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft
BlockPos pos = new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()); BlockPos pos = new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ());
ChunkAccess chunk = chunks.get(new ChunkPos(pos)); ChunkAccess chunk = chunks.get(new ChunkPos(pos));
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(pos); final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(pos);
int internalId = Block.getId(blockData); BlockStateHolder<?> state = ((PaperweightFaweAdapter) WorldEditPlugin
BlockStateHolder<?> state = BlockStateIdAccess.getBlockStateById(internalId); .getInstance()
.getBukkitImplAdapter()).adapt(blockData);
Objects.requireNonNull(state); Objects.requireNonNull(state);
BlockEntity blockEntity = chunk.getBlockEntity(pos); BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) { if (blockEntity != null) {

View File

@ -230,9 +230,24 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
return Registry.BLOCK.get(new ResourceLocation(blockType.getNamespace(), blockType.getResource())); return Registry.BLOCK.get(new ResourceLocation(blockType.getNamespace(), blockType.getResource()));
} }
@SuppressWarnings("deprecation") @Deprecated
@Override @Override
public BaseBlock getBlock(Location location) { public BlockState getBlock(Location location) {
Preconditions.checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
final ServerLevel handle = craftWorld.getHandle();
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
return adapt(blockData);
}
@Override
public BaseBlock getFullBlock(final Location location) {
Preconditions.checkNotNull(location); Preconditions.checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld()); CraftWorld craftWorld = ((CraftWorld) location.getWorld());
@ -240,18 +255,22 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
int y = location.getBlockY(); int y = location.getBlockY();
int z = location.getBlockZ(); int z = location.getBlockZ();
final ServerLevel serverLevel = craftWorld.getHandle(); final ServerLevel handle = craftWorld.getHandle();
LevelChunk levelChunk = serverLevel.getChunk(x >> 4, z >> 4); LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z); final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
BlockState state = adapt(blockData);
if (state == null) {
org.bukkit.block.Block bukkitBlock = location.getBlock(); org.bukkit.block.Block bukkitBlock = location.getBlock();
BlockState state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
if (state.getBlockType().getMaterial().hasContainer()) { if (state.getBlockType().getMaterial().hasContainer()) {
// Read the NBT data // Read the NBT data
BlockEntity blockEntity = levelChunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK); BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) { if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); //TODO 1.18 recheck logic, I may skipped loading - NMF
blockEntity.save(tag); // readTileEntityIntoTag - load data net.minecraft.nbt.CompoundTag tag = blockEntity.save(new net.minecraft.nbt.CompoundTag());
return state.toBaseBlock((CompoundTag) toNative(tag)); return state.toBaseBlock((CompoundTag) toNative(tag));
} }
} }

View File

@ -25,7 +25,6 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import io.papermc.paper.event.block.BeaconDeactivatedEvent; import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -151,7 +150,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (light != null) { if (light != null) {
lightUpdate = true; lightUpdate = true;
try { try {
fillLightNibble(light, LightLayer.SKY, minSectionPosition, maxSectionPosition); fillLightNibble(light, LightLayer.BLOCK, minSectionPosition, maxSectionPosition);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -546,17 +545,18 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
// Biomes // Biomes
BiomeType[] biomes = set.getBiomes(); BiomeType[][] biomes = set.getBiomes();
if (biomes != null) { if (biomes != null) {
// set biomes // set biomes
ChunkBiomeContainer currentBiomes = nmsChunk.getBiomes(); ChunkBiomeContainer currentBiomes = nmsChunk.getBiomes();
if (createCopy) { if (createCopy) {
copy.storeBiomes(currentBiomes); copy.storeBiomes(currentBiomes);
} }
for (int y = 0, i = 0; y < 64; y++) { for (int layer = 0; layer < 16; layer++) {
for (int y = 0, i = 0; y < 4; y++) {
for (int z = 0; z < 4; z++) { for (int z = 0; z < 4; z++) {
for (int x = 0; x < 4; x++, i++) { for (int x = 0; x < 4; x++, i++) {
final BiomeType biome = biomes[i]; final BiomeType biome = biomes[layer][i];
if (biome != null) { if (biome != null) {
Biome nmsBiome = Biome nmsBiome =
nmsWorld.registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).get( nmsWorld.registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).get(
@ -564,7 +564,8 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (nmsBiome == null) { if (nmsBiome == null) {
throw new NullPointerException("BiomeBase null for BiomeType " + biome.getId()); throw new NullPointerException("BiomeBase null for BiomeType " + biome.getId());
} }
currentBiomes.setBiome(x, y, z, nmsBiome); currentBiomes.setBiome(x, (layer << 2) + y, z, nmsBiome);
}
} }
} }
} }
@ -925,7 +926,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) { private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) {
if (ibd == null) { if (ibd == null) {
return BlockTypes.AIR.getDefaultState().getOrdinalChar(); return 1;
} else { } else {
return adapter.adaptToChar(ibd); return adapter.adaptToChar(ibd);
} }

View File

@ -12,7 +12,6 @@ repositories {
} }
dependencies { dependencies {
paperDevBundle("1.18-rc3-R0.1-20211129.221606-5") //TODO 1.18 switch to mainline paperDevBundle("1.18.1-R0.1-20211218.091106-15")
compileOnly(libs.paperlib) compileOnly(libs.paperlib)
compileOnly(libs.paper)
} }

View File

@ -30,27 +30,15 @@ import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic; import com.mojang.serialization.Dynamic;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.EndTag;
import com.sk89q.jnbt.FloatTag;
import com.sk89q.jnbt.IntArrayTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongArrayTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.NBTConstants;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction; import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.PaperweightFaweAdapter;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog; import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -70,6 +58,20 @@ import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.util.io.file.SafeFiles;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -142,6 +144,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.spigotmc.SpigotConfig; import org.spigotmc.SpigotConfig;
import org.spigotmc.WatchdogThread; import org.spigotmc.WatchdogThread;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -163,12 +166,11 @@ import java.util.concurrent.ForkJoinPool;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
public final class PaperweightAdapter implements BukkitImplAdapter { public final class PaperweightAdapter implements BukkitImplAdapter<net.minecraft.nbt.Tag> {
private final Logger logger = Logger.getLogger(getClass().getCanonicalName()); private final Logger logger = Logger.getLogger(getClass().getCanonicalName());
@ -186,8 +188,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
CraftServer.class.cast(Bukkit.getServer()); CraftServer.class.cast(Bukkit.getServer());
int dataVersion = CraftMagicNumbers.INSTANCE.getDataVersion(); int dataVersion = CraftMagicNumbers.INSTANCE.getDataVersion();
if (dataVersion != 2860) { if (dataVersion != 2860 && dataVersion != 2865) {
throw new UnsupportedClassVersionError("Not 1.18!"); throw new UnsupportedClassVersionError("Not 1.18 or 1.18.1!");
} }
serverWorldsField = CraftServer.class.getDeclaredField("worlds"); serverWorldsField = CraftServer.class.getDeclaredField("worlds");
@ -321,9 +323,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
final ServerLevel handle = craftWorld.getHandle(); final ServerLevel handle = craftWorld.getHandle();
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4); LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z); final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos); final CraftBlockData blockData = chunk.getBlockState(blockPos).createCraftBlockData();
int internalId = Block.getId(blockData); BlockState state = BukkitAdapter.adapt(blockData);
BlockState state = BlockStateIdAccess.getBlockStateById(internalId);
if (state == null) { if (state == null) {
org.bukkit.block.Block bukkitBlock = location.getBlock(); org.bukkit.block.Block bukkitBlock = location.getBlock();
state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
@ -349,7 +350,9 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
BlockEntity te = chunk.getBlockEntity(blockPos); BlockEntity te = chunk.getBlockEntity(blockPos);
if (te != null) { if (te != null) {
net.minecraft.nbt.CompoundTag tag = te.saveWithId(); net.minecraft.nbt.CompoundTag tag = te.saveWithId();
return state.toBaseBlock((CompoundTag) toNative(tag)); //FAWE start - BinaryTag
return state.toBaseBlock((CompoundBinaryTag) toNativeBinary(tag));
//FAWE end
} }
return state.toBaseBlock(); return state.toBaseBlock();
@ -357,8 +360,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
@Override @Override
public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) { public WorldNativeAccess<?, ?, ?> createWorldNativeAccess(org.bukkit.World world) {
return new PaperweightWorldNativeAccess(this, return new PaperweightWorldNativeAccess(
new WeakReference<>(((CraftWorld) world).getHandle())); this,
new WeakReference<>(((CraftWorld) world).getHandle())
);
} }
private static net.minecraft.core.Direction adapt(Direction face) { private static net.minecraft.core.Direction adapt(Direction face) {
@ -482,11 +487,25 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
if (state instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) { if (state instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) {
property = new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues())); property = new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else if (state instanceof DirectionProperty) { } else if (state instanceof DirectionProperty) {
property = new DirectionalProperty(state.getName(), property = new DirectionalProperty(
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList())); state.getName(),
(List<Direction>) state
.getPossibleValues()
.stream()
.map(e -> Direction.valueOf(((StringRepresentable) e)
.getSerializedName()
.toUpperCase(Locale.ROOT)))
.collect(Collectors.toList())
);
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) { } else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
property = new EnumProperty(state.getName(), property = new EnumProperty(
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList())); state.getName(),
(List<String>) state
.getPossibleValues()
.stream()
.map(e -> ((StringRepresentable) e).getSerializedName())
.collect(Collectors.toList())
);
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) { } else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
property = new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues())); property = new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else { } else {
@ -499,13 +518,13 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} }
@Override @Override
public void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData) { public void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData) {
((CraftPlayer) player).getHandle().networkManager.send(ClientboundBlockEntityDataPacket.create( ((CraftPlayer) player).getHandle().networkManager.send(ClientboundBlockEntityDataPacket.create(
new StructureBlockEntity( new StructureBlockEntity(
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
Blocks.STRUCTURE_BLOCK.defaultBlockState() Blocks.STRUCTURE_BLOCK.defaultBlockState()
), ),
__ -> (net.minecraft.nbt.CompoundTag) fromNative(nbtData) __ -> (net.minecraft.nbt.CompoundTag) fromNativeBinary(nbtData)
)); ));
} }
@ -550,7 +569,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} }
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stack); fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stack);
fakePlayer.absMoveTo(position.getBlockX(), position.getBlockY(), position.getBlockZ(), fakePlayer.absMoveTo(position.getBlockX(), position.getBlockY(), position.getBlockZ(),
(float) face.toVector().toYaw(), (float) face.toVector().toPitch()); (float) face.toVector().toYaw(), (float) face.toVector().toPitch()
);
final BlockPos blockPos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); final BlockPos blockPos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
final Vec3 blockVec = Vec3.atLowerCornerOf(blockPos); final Vec3 blockVec = Vec3.atLowerCornerOf(blockPos);
@ -559,7 +579,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
UseOnContext context = new UseOnContext(fakePlayer, InteractionHand.MAIN_HAND, rayTrace); UseOnContext context = new UseOnContext(fakePlayer, InteractionHand.MAIN_HAND, rayTrace);
InteractionResult result = stack.useOn(context, InteractionHand.MAIN_HAND); InteractionResult result = stack.useOn(context, InteractionHand.MAIN_HAND);
if (result != InteractionResult.SUCCESS) { if (result != InteractionResult.SUCCESS) {
if (worldServer.getBlockState(blockPos).use(worldServer, fakePlayer, InteractionHand.MAIN_HAND, rayTrace).consumesAction()) { if (worldServer
.getBlockState(blockPos)
.use(worldServer, fakePlayer, InteractionHand.MAIN_HAND, rayTrace)
.consumesAction()) {
result = InteractionResult.SUCCESS; result = InteractionResult.SUCCESS;
} else { } else {
result = stack.getItem().use(worldServer, fakePlayer, InteractionHand.MAIN_HAND).getResult(); result = stack.getItem().use(worldServer, fakePlayer, InteractionHand.MAIN_HAND).getResult();
@ -573,7 +596,10 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
public boolean canPlaceAt(org.bukkit.World world, BlockVector3 position, BlockState blockState) { public boolean canPlaceAt(org.bukkit.World world, BlockVector3 position, BlockState blockState) {
int internalId = BlockStateIdAccess.getBlockStateId(blockState); int internalId = BlockStateIdAccess.getBlockStateId(blockState);
net.minecraft.world.level.block.state.BlockState blockData = Block.stateById(internalId); net.minecraft.world.level.block.state.BlockState blockData = Block.stateById(internalId);
return blockData.canSurvive(((CraftWorld) world).getHandle(), new BlockPos(position.getX(), position.getY(), position.getZ())); return blockData.canSurvive(
((CraftWorld) world).getHandle(),
new BlockPos(position.getX(), position.getY(), position.getZ())
);
} }
@Override @Override
@ -591,7 +617,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
Environment env = bukkitWorld.getEnvironment(); Environment env = bukkitWorld.getEnvironment();
ChunkGenerator gen = bukkitWorld.getGenerator(); ChunkGenerator gen = bukkitWorld.getGenerator();
Path tempDir = Files.createTempDirectory("WorldEditWorldGen"); Path tempDir = Files.createTempDirectory("FastAsyncWorldEditWorldGen");
LevelStorageSource levelStorage = LevelStorageSource.createDefault(tempDir); LevelStorageSource levelStorage = LevelStorageSource.createDefault(tempDir);
ResourceKey<LevelStem> worldDimKey = getWorldDimKey(env); ResourceKey<LevelStem> worldDimKey = getWorldDimKey(env);
try (LevelStorageSource.LevelStorageAccess session = levelStorage.createAccess("worldeditregentempworld", worldDimKey)) { try (LevelStorageSource.LevelStorageAccess session = levelStorage.createAccess("worldeditregentempworld", worldDimKey)) {
@ -675,7 +701,11 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Dynamic<net.minecraft.nbt.Tag> recursivelySetSeed(Dynamic<net.minecraft.nbt.Tag> dynamic, long seed, Set<Dynamic<net.minecraft.nbt.Tag>> seen) { private Dynamic<net.minecraft.nbt.Tag> recursivelySetSeed(
Dynamic<net.minecraft.nbt.Tag> dynamic,
long seed,
Set<Dynamic<net.minecraft.nbt.Tag>> seen
) {
if (!seen.add(dynamic)) { if (!seen.add(dynamic)) {
return dynamic; return dynamic;
} }
@ -699,7 +729,8 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld, RegenOptions options) throws WorldEditException { private void regenForWorld(Region region, Extent extent, ServerLevel serverWorld, RegenOptions options) throws
WorldEditException {
List<CompletableFuture<ChunkAccess>> chunkLoadings = submitChunkLoadTasks(region, serverWorld); List<CompletableFuture<ChunkAccess>> chunkLoadings = submitChunkLoadTasks(region, serverWorld);
BlockableEventLoop<Runnable> executor; BlockableEventLoop<Runnable> executor;
try { try {
@ -728,13 +759,16 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
BlockPos pos = new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()); BlockPos pos = new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ());
ChunkAccess chunk = chunks.get(new ChunkPos(pos)); ChunkAccess chunk = chunks.get(new ChunkPos(pos));
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(pos); final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(pos);
int internalId = Block.getId(blockData); BlockStateHolder<?> state = ((PaperweightFaweAdapter) WorldEditPlugin
BlockStateHolder<?> state = BlockStateIdAccess.getBlockStateById(internalId); .getInstance()
.getBukkitImplAdapter()).adapt(blockData);
Objects.requireNonNull(state); Objects.requireNonNull(state);
BlockEntity blockEntity = chunk.getBlockEntity(pos); BlockEntity blockEntity = chunk.getBlockEntity(pos);
if (blockEntity != null) { if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId(); net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
state = state.toBaseBlock(((CompoundTag) toNative(tag))); //FAWE start - BinaryTag
state = state.toBaseBlock(((CompoundBinaryTag) toNativeBinary(tag)));
//FAWE end
} }
extent.setBlock(vec, state.toBaseBlock()); extent.setBlock(vec, state.toBaseBlock());
if (options.shouldRegenBiomes()) { if (options.shouldRegenBiomes()) {
@ -818,48 +852,50 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
* @param foreign non-native NMS NBT structure * @param foreign non-native NMS NBT structure
* @return native WorldEdit NBT structure * @return native WorldEdit NBT structure
*/ */
Tag toNative(net.minecraft.nbt.Tag foreign) { //FAWE start - BinaryTag
@Override
public BinaryTag toNativeBinary(net.minecraft.nbt.Tag foreign) {
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
if (foreign instanceof net.minecraft.nbt.CompoundTag) { if (foreign instanceof net.minecraft.nbt.CompoundTag) {
Map<String, Tag> values = new HashMap<>(); Map<String, BinaryTag> values = new HashMap<>();
Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys(); Set<String> foreignKeys = ((net.minecraft.nbt.CompoundTag) foreign).getAllKeys();
for (String str : foreignKeys) { for (String str : foreignKeys) {
net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str); net.minecraft.nbt.Tag base = ((net.minecraft.nbt.CompoundTag) foreign).get(str);
values.put(str, toNative(base)); values.put(str, toNativeBinary(base));
} }
return new CompoundTag(values); return CompoundBinaryTag.from(values);
} else if (foreign instanceof net.minecraft.nbt.ByteTag) { } else if (foreign instanceof net.minecraft.nbt.ByteTag) {
return new ByteTag(((net.minecraft.nbt.ByteTag) foreign).getAsByte()); return ByteBinaryTag.of(((net.minecraft.nbt.ByteTag) foreign).getAsByte());
} else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) { } else if (foreign instanceof net.minecraft.nbt.ByteArrayTag) {
return new ByteArrayTag(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray()); return ByteArrayBinaryTag.of(((net.minecraft.nbt.ByteArrayTag) foreign).getAsByteArray());
} else if (foreign instanceof net.minecraft.nbt.DoubleTag) { } else if (foreign instanceof net.minecraft.nbt.DoubleTag) {
return new DoubleTag(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble()); return DoubleBinaryTag.of(((net.minecraft.nbt.DoubleTag) foreign).getAsDouble());
} else if (foreign instanceof net.minecraft.nbt.FloatTag) { } else if (foreign instanceof net.minecraft.nbt.FloatTag) {
return new FloatTag(((net.minecraft.nbt.FloatTag) foreign).getAsFloat()); return FloatBinaryTag.of(((net.minecraft.nbt.FloatTag) foreign).getAsFloat());
} else if (foreign instanceof net.minecraft.nbt.IntTag) { } else if (foreign instanceof net.minecraft.nbt.IntTag) {
return new IntTag(((net.minecraft.nbt.IntTag) foreign).getAsInt()); return IntBinaryTag.of(((net.minecraft.nbt.IntTag) foreign).getAsInt());
} else if (foreign instanceof net.minecraft.nbt.IntArrayTag) { } else if (foreign instanceof net.minecraft.nbt.IntArrayTag) {
return new IntArrayTag(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray()); return IntArrayBinaryTag.of(((net.minecraft.nbt.IntArrayTag) foreign).getAsIntArray());
} else if (foreign instanceof net.minecraft.nbt.LongArrayTag) { } else if (foreign instanceof net.minecraft.nbt.LongArrayTag) {
return new LongArrayTag(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray()); return LongArrayBinaryTag.of(((net.minecraft.nbt.LongArrayTag) foreign).getAsLongArray());
} else if (foreign instanceof net.minecraft.nbt.ListTag) { } else if (foreign instanceof net.minecraft.nbt.ListTag) {
try { try {
return toNativeList((net.minecraft.nbt.ListTag) foreign); return toNativeList((net.minecraft.nbt.ListTag) foreign);
} catch (Throwable e) { } catch (Throwable e) {
logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e); logger.log(Level.WARNING, "Failed to convert net.minecraft.nbt.ListTag", e);
return new ListTag(ByteTag.class, new ArrayList<ByteTag>()); return ListBinaryTag.empty();
} }
} else if (foreign instanceof net.minecraft.nbt.LongTag) { } else if (foreign instanceof net.minecraft.nbt.LongTag) {
return new LongTag(((net.minecraft.nbt.LongTag) foreign).getAsLong()); return LongBinaryTag.of(((net.minecraft.nbt.LongTag) foreign).getAsLong());
} else if (foreign instanceof net.minecraft.nbt.ShortTag) { } else if (foreign instanceof net.minecraft.nbt.ShortTag) {
return new ShortTag(((net.minecraft.nbt.ShortTag) foreign).getAsShort()); return ShortBinaryTag.of(((net.minecraft.nbt.ShortTag) foreign).getAsShort());
} else if (foreign instanceof net.minecraft.nbt.StringTag) { } else if (foreign instanceof net.minecraft.nbt.StringTag) {
return new StringTag(foreign.getAsString()); return StringBinaryTag.of(foreign.getAsString());
} else if (foreign instanceof net.minecraft.nbt.EndTag) { } else if (foreign instanceof net.minecraft.nbt.EndTag) {
return new EndTag(); return EndBinaryTag.get();
} else { } else {
throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName());
} }
@ -873,16 +909,14 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
* @throws SecurityException on error * @throws SecurityException on error
* @throws IllegalArgumentException on error * @throws IllegalArgumentException on error
*/ */
private ListTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException { private ListBinaryTag toNativeList(net.minecraft.nbt.ListTag foreign) throws SecurityException, IllegalArgumentException {
List<Tag> values = new ArrayList<>(); ListBinaryTag.Builder values = ListBinaryTag.builder();
int type = foreign.getElementType();
for (net.minecraft.nbt.Tag tag : foreign) { for (net.minecraft.nbt.Tag tag : foreign) {
values.add(toNative(tag)); values.add(toNativeBinary(tag));
} }
Class<? extends Tag> cls = NBTConstants.getClassFromType(type); return values.build();
return new ListTag(cls, values);
} }
/** /**
@ -891,50 +925,51 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
* @param foreign structure to convert * @param foreign structure to convert
* @return non-native structure * @return non-native structure
*/ */
net.minecraft.nbt.Tag fromNative(Tag foreign) { @Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
if (foreign == null) { if (foreign == null) {
return null; return null;
} }
if (foreign instanceof CompoundTag) { if (foreign instanceof CompoundBinaryTag) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign) for (String key : ((CompoundBinaryTag) foreign).keySet()) {
.getValue().entrySet()) { tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
tag.put(entry.getKey(), fromNative(entry.getValue()));
} }
return tag; return tag;
} else if (foreign instanceof ByteTag) { } else if (foreign instanceof ByteBinaryTag) {
return net.minecraft.nbt.ByteTag.valueOf(((ByteTag) foreign).getValue()); return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
} else if (foreign instanceof ByteArrayTag) { } else if (foreign instanceof ByteArrayBinaryTag) {
return new net.minecraft.nbt.ByteArrayTag(((ByteArrayTag) foreign).getValue()); return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
} else if (foreign instanceof DoubleTag) { } else if (foreign instanceof DoubleBinaryTag) {
return net.minecraft.nbt.DoubleTag.valueOf(((DoubleTag) foreign).getValue()); return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
} else if (foreign instanceof FloatTag) { } else if (foreign instanceof FloatBinaryTag) {
return net.minecraft.nbt.FloatTag.valueOf(((FloatTag) foreign).getValue()); return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
} else if (foreign instanceof IntTag) { } else if (foreign instanceof IntBinaryTag) {
return net.minecraft.nbt.IntTag.valueOf(((IntTag) foreign).getValue()); return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
} else if (foreign instanceof IntArrayTag) { } else if (foreign instanceof IntArrayBinaryTag) {
return new net.minecraft.nbt.IntArrayTag(((IntArrayTag) foreign).getValue()); return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
} else if (foreign instanceof LongArrayTag) { } else if (foreign instanceof LongArrayBinaryTag) {
return new net.minecraft.nbt.LongArrayTag(((LongArrayTag) foreign).getValue()); return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
} else if (foreign instanceof ListTag) { } else if (foreign instanceof ListBinaryTag) {
net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag(); net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
ListTag foreignList = (ListTag) foreign; ListBinaryTag foreignList = (ListBinaryTag) foreign;
for (Tag t : foreignList.getValue()) { for (BinaryTag t : foreignList) {
tag.add(fromNative(t)); tag.add(fromNativeBinary(t));
} }
return tag; return tag;
} else if (foreign instanceof LongTag) { } else if (foreign instanceof LongBinaryTag) {
return net.minecraft.nbt.LongTag.valueOf(((LongTag) foreign).getValue()); return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
} else if (foreign instanceof ShortTag) { } else if (foreign instanceof ShortBinaryTag) {
return net.minecraft.nbt.ShortTag.valueOf(((ShortTag) foreign).getValue()); return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
} else if (foreign instanceof StringTag) { } else if (foreign instanceof StringBinaryTag) {
return net.minecraft.nbt.StringTag.valueOf(((StringTag) foreign).getValue()); return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
} else if (foreign instanceof EndTag) { } else if (foreign instanceof EndBinaryTag) {
return net.minecraft.nbt.EndTag.INSTANCE; return net.minecraft.nbt.EndTag.INSTANCE;
} else { } else {
throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName()); throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());
} }
} }
//FAWE end
@Override @Override
public boolean supportsWatchdog() { public boolean supportsWatchdog() {
@ -947,6 +982,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} }
private class SpigotWatchdog implements Watchdog { private class SpigotWatchdog implements Watchdog {
private final Field instanceField; private final Field instanceField;
private final Field lastTickField; private final Field lastTickField;
@ -971,9 +1007,11 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
logger.log(Level.WARNING, "Failed to tick watchdog", e); logger.log(Level.WARNING, "Failed to tick watchdog", e);
} }
} }
} }
private static class MojangWatchdog implements Watchdog { private static class MojangWatchdog implements Watchdog {
private final DedicatedServer server; private final DedicatedServer server;
private final Field tickField; private final Field tickField;
@ -993,9 +1031,11 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
} catch (IllegalAccessException ignored) { } catch (IllegalAccessException ignored) {
} }
} }
} }
private static class NoOpWorldLoadListener implements ChunkProgressListener { private static class NoOpWorldLoadListener implements ChunkProgressListener {
@Override @Override
public void updateSpawnPos(ChunkPos spawnPos) { public void updateSpawnPos(ChunkPos spawnPos) {
} }
@ -1015,5 +1055,7 @@ public final class PaperweightAdapter implements BukkitImplAdapter {
@Override @Override
public void setChunkRadius(int radius) { public void setChunkRadius(int radius) {
} }
} }
} }

View File

@ -34,7 +34,7 @@ import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerBuilder; import com.mojang.datafixers.DataFixerBuilder;
import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic; import com.mojang.serialization.Dynamic;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -49,6 +49,7 @@ import net.minecraft.world.item.DyeColor;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
@ -62,31 +63,31 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
/** /**
* Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2) * Handles converting all Pre 1.13.2 data using the Legacy DataFix System (ported to 1.13.2)
* * <p>
* We register a DFU Fixer per Legacy Data Version and apply the fixes using legacy strategy * We register a DFU Fixer per Legacy Data Version and apply the fixes using legacy strategy
* which is safer, faster and cleaner code. * which is safer, faster and cleaner code.
* * <p>
* The pre DFU code did not fail when the Source version was unknown. * The pre DFU code did not fail when the Source version was unknown.
* * <p>
* This class also provides util methods for converting compounds to wrap the update call to * This class also provides util methods for converting compounds to wrap the update call to
* receive the source version in the compound * receive the source version in the compound
*/ */
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer { class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.worldedit.world.DataFixer {
//FAWE start - BinaryTag
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T fixUp(FixType<T> type, T original, int srcVer) { public <T> T fixUp(FixType<T> type, T original, int srcVer) {
if (type == FixTypes.CHUNK) { if (type == FixTypes.CHUNK) {
return (T) fixChunk((CompoundTag) original, srcVer); return (T) fixChunk((CompoundBinaryTag) original, srcVer);
} else if (type == FixTypes.BLOCK_ENTITY) { } else if (type == FixTypes.BLOCK_ENTITY) {
return (T) fixBlockEntity((CompoundTag) original, srcVer); return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
} else if (type == FixTypes.ENTITY) { } else if (type == FixTypes.ENTITY) {
return (T) fixEntity((CompoundTag) original, srcVer); return (T) fixEntity((CompoundBinaryTag) original, srcVer);
} else if (type == FixTypes.BLOCK_STATE) { } else if (type == FixTypes.BLOCK_STATE) {
return (T) fixBlockState((String) original, srcVer); return (T) fixBlockState((String) original, srcVer);
} else if (type == FixTypes.ITEM_TYPE) { } else if (type == FixTypes.ITEM_TYPE) {
@ -97,28 +98,34 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return original; return original;
} }
private CompoundTag fixChunk(CompoundTag originalChunk, int srcVer) { private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(originalChunk); net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(originalChunk);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer); net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
return (CompoundTag) adapter.toNative(fixed); return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
} }
private CompoundTag fixBlockEntity(CompoundTag origTileEnt, int srcVer) { private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(origTileEnt); net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origTileEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer); net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
return (CompoundTag) adapter.toNative(fixed); return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
} }
private CompoundTag fixEntity(CompoundTag origEnt, int srcVer) { private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative(origEnt); net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeBinary(origEnt);
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer); net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
return (CompoundTag) adapter.toNative(fixed); return (CompoundBinaryTag) adapter.toNativeBinary(fixed);
} }
//FAWE end
private String fixBlockState(String blockState, int srcVer) { private String fixBlockState(String blockState, int srcVer) {
net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState); net.minecraft.nbt.CompoundTag stateNBT = stateToNBT(blockState);
Dynamic<net.minecraft.nbt.Tag> dynamic = new Dynamic<>(OPS_NBT, stateNBT); Dynamic<net.minecraft.nbt.Tag> dynamic = new Dynamic<>(OPS_NBT, stateNBT);
net.minecraft.nbt.CompoundTag fixed = (net.minecraft.nbt.CompoundTag) INSTANCE.fixer.update(References.BLOCK_STATE, dynamic, srcVer, DATA_VERSION).getValue(); net.minecraft.nbt.CompoundTag fixed = (net.minecraft.nbt.CompoundTag) INSTANCE.fixer.update(
References.BLOCK_STATE,
dynamic,
srcVer,
DATA_VERSION
).getValue();
return nbtToState(fixed); return nbtToState(fixed);
} }
@ -128,7 +135,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
if (tagCompound.contains("Properties", 10)) { if (tagCompound.contains("Properties", 10)) {
sb.append('['); sb.append('[');
net.minecraft.nbt.CompoundTag props = tagCompound.getCompound("Properties"); net.minecraft.nbt.CompoundTag props = tagCompound.getCompound("Properties");
sb.append(props.getAllKeys().stream().map(k -> k + "=" + props.getString(k).replace("\"", "")).collect(Collectors.joining(","))); sb.append(props
.getAllKeys()
.stream()
.map(k -> k + "=" + props.getString(k).replace("\"", ""))
.collect(Collectors.joining(",")));
sb.append(']'); sb.append(']');
} }
return sb.toString(); return sb.toString();
@ -220,6 +231,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private class WrappedDataFixer implements DataFixer { private class WrappedDataFixer implements DataFixer {
private final DataFixer realFixer; private final DataFixer realFixer;
WrappedDataFixer(DataFixer realFixer) { WrappedDataFixer(DataFixer realFixer) {
@ -240,7 +252,12 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return realFixer.update(type, dynamic, sourceVer, targetVer); return realFixer.update(type, dynamic, sourceVer, targetVer);
} }
private net.minecraft.nbt.CompoundTag convert(LegacyType type, net.minecraft.nbt.CompoundTag cmp, int sourceVer, int desiredVersion) { private net.minecraft.nbt.CompoundTag convert(
LegacyType type,
net.minecraft.nbt.CompoundTag cmp,
int sourceVer,
int desiredVersion
) {
List<DataConverter> converters = PaperweightDataConverters.this.converters.get(type); List<DataConverter> converters = PaperweightDataConverters.this.converters.get(type);
if (converters != null && !converters.isEmpty()) { if (converters != null && !converters.isEmpty()) {
for (DataConverter converter : converters) { for (DataConverter converter : converters) {
@ -265,6 +282,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
public Schema getSchema(int i) { public Schema getSchema(int i) {
return realFixer.getSchema(i); return realFixer.getSchema(i);
} }
} }
public static net.minecraft.nbt.CompoundTag convert(LegacyType type, net.minecraft.nbt.CompoundTag cmp) { public static net.minecraft.nbt.CompoundTag convert(LegacyType type, net.minecraft.nbt.CompoundTag cmp) {
@ -275,7 +293,12 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return convert(type.getDFUType(), cmp, sourceVer); return convert(type.getDFUType(), cmp, sourceVer);
} }
public static net.minecraft.nbt.CompoundTag convert(LegacyType type, net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public static net.minecraft.nbt.CompoundTag convert(
LegacyType type,
net.minecraft.nbt.CompoundTag cmp,
int sourceVer,
int targetVer
) {
return convert(type.getDFUType(), cmp, sourceVer, targetVer); return convert(type.getDFUType(), cmp, sourceVer, targetVer);
} }
@ -288,16 +311,25 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return convert(type, cmp, sourceVer, DATA_VERSION); return convert(type, cmp, sourceVer, DATA_VERSION);
} }
public static net.minecraft.nbt.CompoundTag convert(TypeReference type, net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public static net.minecraft.nbt.CompoundTag convert(
TypeReference type,
net.minecraft.nbt.CompoundTag cmp,
int sourceVer,
int targetVer
) {
if (sourceVer >= targetVer) { if (sourceVer >= targetVer) {
return cmp; return cmp;
} }
return (net.minecraft.nbt.CompoundTag) INSTANCE.fixer.update(type, new Dynamic<>(OPS_NBT, cmp), sourceVer, targetVer).getValue(); return (net.minecraft.nbt.CompoundTag) INSTANCE.fixer
.update(type, new Dynamic<>(OPS_NBT, cmp), sourceVer, targetVer)
.getValue();
} }
public interface DataInspector { public interface DataInspector {
net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer); net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer);
} }
public interface DataConverter { public interface DataConverter {
@ -305,6 +337,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
int getDataVersion(); int getDataVersion();
net.minecraft.nbt.CompoundTag convert(net.minecraft.nbt.CompoundTag cmp); net.minecraft.nbt.CompoundTag convert(net.minecraft.nbt.CompoundTag cmp);
} }
@ -582,7 +615,13 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return key; return key;
} }
private static void convertCompound(LegacyType type, net.minecraft.nbt.CompoundTag cmp, String key, int sourceVer, int targetVer) { private static void convertCompound(
LegacyType type,
net.minecraft.nbt.CompoundTag cmp,
String key,
int sourceVer,
int targetVer
) {
cmp.put(key, convert(type, cmp.getCompound(key), sourceVer, targetVer)); cmp.put(key, convert(type, cmp.getCompound(key), sourceVer, targetVer));
} }
@ -658,6 +697,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorBlockEntity implements DataInspector { private static class DataInspectorBlockEntity implements DataInspector {
@ -840,6 +880,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
@ -859,7 +900,12 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
abstract net.minecraft.nbt.CompoundTag inspectChecked(net.minecraft.nbt.CompoundTag nbttagcompound, int sourceVer, int targetVer); abstract net.minecraft.nbt.CompoundTag inspectChecked(
net.minecraft.nbt.CompoundTag nbttagcompound,
int sourceVer,
int targetVer
);
} }
private static class DataInspectorItemList extends DataInspectorTagged { private static class DataInspectorItemList extends DataInspectorTagged {
@ -878,6 +924,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return nbttagcompound; return nbttagcompound;
} }
} }
private static class DataInspectorItem extends DataInspectorTagged { private static class DataInspectorItem extends DataInspectorTagged {
@ -896,6 +943,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return nbttagcompound; return nbttagcompound;
} }
} }
private static class DataConverterMaterialId implements DataConverter { private static class DataConverterMaterialId implements DataConverter {
@ -1296,6 +1344,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterBanner implements DataConverter { private static class DataConverterBanner implements DataConverter {
@ -1342,6 +1391,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterPotionId implements DataConverter { private static class DataConverterPotionId implements DataConverter {
@ -1619,7 +1669,15 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
private static class DataConverterMinecart implements DataConverter { private static class DataConverterMinecart implements DataConverter {
private static final List<String> a = Lists.newArrayList("MinecartRideable", "MinecartChest", "MinecartFurnace", "MinecartTNT", "MinecartSpawner", "MinecartHopper", "MinecartCommandBlock"); private static final List<String> a = Lists.newArrayList(
"MinecartRideable",
"MinecartChest",
"MinecartFurnace",
"MinecartTNT",
"MinecartSpawner",
"MinecartHopper",
"MinecartCommandBlock"
);
DataConverterMinecart() { DataConverterMinecart() {
} }
@ -1643,6 +1701,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterMobSpawner implements DataConverter { private static class DataConverterMobSpawner implements DataConverter {
@ -1687,6 +1746,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
} }
private static class DataConverterUUID implements DataConverter { private static class DataConverterUUID implements DataConverter {
@ -1705,11 +1765,47 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterHealth implements DataConverter { private static class DataConverterHealth implements DataConverter {
private static final Set<String> a = Sets.newHashSet("ArmorStand", "Bat", "Blaze", "CaveSpider", "Chicken", "Cow", "Creeper", "EnderDragon", "Enderman", "Endermite", "EntityHorse", "Ghast", "Giant", "Guardian", "LavaSlime", "MushroomCow", "Ozelot", "Pig", "PigZombie", "Rabbit", "Sheep", "Shulker", "Silverfish", "Skeleton", "Slime", "SnowMan", "Spider", "Squid", "Villager", "VillagerGolem", "Witch", "WitherBoss", "Wolf", "Zombie"); private static final Set<String> a = Sets.newHashSet(
"ArmorStand",
"Bat",
"Blaze",
"CaveSpider",
"Chicken",
"Cow",
"Creeper",
"EnderDragon",
"Enderman",
"Endermite",
"EntityHorse",
"Ghast",
"Giant",
"Guardian",
"LavaSlime",
"MushroomCow",
"Ozelot",
"Pig",
"PigZombie",
"Rabbit",
"Sheep",
"Shulker",
"Silverfish",
"Skeleton",
"Slime",
"SnowMan",
"Spider",
"Squid",
"Villager",
"VillagerGolem",
"Witch",
"WitherBoss",
"Wolf",
"Zombie"
);
DataConverterHealth() { DataConverterHealth() {
} }
@ -1738,6 +1834,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterSaddle implements DataConverter { private static class DataConverterSaddle implements DataConverter {
@ -1762,6 +1859,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterHanging implements DataConverter { private static class DataConverterHanging implements DataConverter {
@ -1800,6 +1898,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterDropChances implements DataConverter { private static class DataConverterDropChances implements DataConverter {
@ -1823,13 +1922,15 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
if (cmp.contains("ArmorDropChances", 9)) { if (cmp.contains("ArmorDropChances", 9)) {
nbttaglist = cmp.getList("ArmorDropChances", 5); nbttaglist = cmp.getList("ArmorDropChances", 5);
if (nbttaglist.size() == 4 && nbttaglist.getFloat(0) == 0.0F && nbttaglist.getFloat(1) == 0.0F && nbttaglist.getFloat(2) == 0.0F && nbttaglist.getFloat(3) == 0.0F) { if (nbttaglist.size() == 4 && nbttaglist.getFloat(0) == 0.0F && nbttaglist.getFloat(1) == 0.0F && nbttaglist.getFloat(
2) == 0.0F && nbttaglist.getFloat(3) == 0.0F) {
cmp.remove("ArmorDropChances"); cmp.remove("ArmorDropChances");
} }
} }
return cmp; return cmp;
} }
} }
private static class DataConverterRiding implements DataConverter { private static class DataConverterRiding implements DataConverter {
@ -1865,6 +1966,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
nbttagcompound.remove("Riding"); nbttagcompound.remove("Riding");
return nbttagcompound1; return nbttagcompound1;
} }
} }
private static class DataConverterBook implements DataConverter { private static class DataConverterBook implements DataConverter {
@ -1933,6 +2035,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterCookedFish implements DataConverter { private static class DataConverterCookedFish implements DataConverter {
@ -1953,6 +2056,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterZombie implements DataConverter { private static class DataConverterZombie implements DataConverter {
@ -1995,6 +2099,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
private int convert(int i) { private int convert(int i) {
return i >= 0 && i < 6 ? i : -1; return i >= 0 && i < 6 ? i : -1;
} }
} }
private static class DataConverterVBO implements DataConverter { private static class DataConverterVBO implements DataConverter {
@ -2010,6 +2115,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
cmp.putString("useVbo", "true"); cmp.putString("useVbo", "true");
return cmp; return cmp;
} }
} }
private static class DataConverterGuardian implements DataConverter { private static class DataConverterGuardian implements DataConverter {
@ -2032,6 +2138,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterSkeleton implements DataConverter { private static class DataConverterSkeleton implements DataConverter {
@ -2060,6 +2167,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterZombieType implements DataConverter { private static class DataConverterZombieType implements DataConverter {
@ -2098,6 +2206,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterHorse implements DataConverter { private static class DataConverterHorse implements DataConverter {
@ -2140,6 +2249,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterTileEntity implements DataConverter { private static class DataConverterTileEntity implements DataConverter {
@ -2302,7 +2412,8 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
public net.minecraft.nbt.CompoundTag convert(net.minecraft.nbt.CompoundTag cmp) { public net.minecraft.nbt.CompoundTag convert(net.minecraft.nbt.CompoundTag cmp) {
String s = cmp.getString("id"); String s = cmp.getString("id");
if ("minecraft:potion".equals(s) || "minecraft:splash_potion".equals(s) || "minecraft:lingering_potion".equals(s) || "minecraft:tipped_arrow".equals(s)) { if ("minecraft:potion".equals(s) || "minecraft:splash_potion".equals(s) || "minecraft:lingering_potion".equals(s) || "minecraft:tipped_arrow".equals(
s)) {
net.minecraft.nbt.CompoundTag nbttagcompound1 = cmp.getCompound("tag"); net.minecraft.nbt.CompoundTag nbttagcompound1 = cmp.getCompound("tag");
if (!nbttagcompound1.contains("Potion", 8)) { if (!nbttagcompound1.contains("Potion", 8)) {
@ -2316,6 +2427,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterShulker implements DataConverter { private static class DataConverterShulker implements DataConverter {
@ -2334,6 +2446,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterShulkerBoxItem implements DataConverter { private static class DataConverterShulkerBoxItem implements DataConverter {
@ -2375,6 +2488,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterShulkerBoxBlock implements DataConverter { private static class DataConverterShulkerBoxBlock implements DataConverter {
@ -2393,6 +2507,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterLang implements DataConverter { private static class DataConverterLang implements DataConverter {
@ -2411,6 +2526,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterTotem implements DataConverter { private static class DataConverterTotem implements DataConverter {
@ -2429,6 +2545,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterBedBlock implements DataConverter { private static class DataConverterBedBlock implements DataConverter {
@ -2476,6 +2593,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterBedItem implements DataConverter { private static class DataConverterBedItem implements DataConverter {
@ -2494,12 +2612,14 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataConverterSignText implements DataConverter { private static class DataConverterSignText implements DataConverter {
public static final Gson a = new GsonBuilder().registerTypeAdapter(Component.class, new JsonDeserializer() { public static final Gson a = new GsonBuilder().registerTypeAdapter(Component.class, new JsonDeserializer() {
MutableComponent a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { MutableComponent a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws
JsonParseException {
if (jsonelement.isJsonPrimitive()) { if (jsonelement.isJsonPrimitive()) {
return new TextComponent(jsonelement.getAsString()); return new TextComponent(jsonelement.getAsString());
} else if (jsonelement.isJsonArray()) { } else if (jsonelement.isJsonArray()) {
@ -2509,7 +2629,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
while (iterator.hasNext()) { while (iterator.hasNext()) {
JsonElement jsonelement1 = (JsonElement) iterator.next(); JsonElement jsonelement1 = (JsonElement) iterator.next();
MutableComponent ichatbasecomponent1 = this.a(jsonelement1, jsonelement1.getClass(), jsondeserializationcontext); MutableComponent ichatbasecomponent1 = this.a(
jsonelement1,
jsonelement1.getClass(),
jsondeserializationcontext
);
if (ichatbasecomponent == null) { if (ichatbasecomponent == null) {
ichatbasecomponent = ichatbasecomponent1; ichatbasecomponent = ichatbasecomponent1;
@ -2524,7 +2648,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
} }
} }
public Object deserialize(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { public Object deserialize(
JsonElement jsonelement,
Type type,
JsonDeserializationContext jsondeserializationcontext
) throws JsonParseException {
return this.a(jsonelement, type, jsondeserializationcontext); return this.a(jsonelement, type, jsondeserializationcontext);
} }
}).create(); }).create();
@ -2590,9 +2718,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
nbttagcompound.putString(s, Component.Serializer.toJson(object)); nbttagcompound.putString(s, Component.Serializer.toJson(object));
} }
} }
private static class DataInspectorPlayerVehicle implements DataInspector { private static class DataInspectorPlayerVehicle implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
if (cmp.contains("RootVehicle", 10)) { if (cmp.contains("RootVehicle", 10)) {
@ -2605,9 +2735,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorLevelPlayer implements DataInspector { private static class DataInspectorLevelPlayer implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
if (cmp.contains("Player", 10)) { if (cmp.contains("Player", 10)) {
@ -2616,9 +2748,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorStructure implements DataInspector { private static class DataInspectorStructure implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
net.minecraft.nbt.ListTag nbttaglist; net.minecraft.nbt.ListTag nbttaglist;
@ -2649,9 +2783,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorChunks implements DataInspector { private static class DataInspectorChunks implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
if (cmp.contains("Level", 10)) { if (cmp.contains("Level", 10)) {
@ -2663,7 +2799,15 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
nbttaglist = nbttagcompound1.getList("Entities", 10); nbttaglist = nbttagcompound1.getList("Entities", 10);
for (j = 0; j < nbttaglist.size(); ++j) { for (j = 0; j < nbttaglist.size(); ++j) {
nbttaglist.set(j, convert(LegacyType.ENTITY, (net.minecraft.nbt.CompoundTag) nbttaglist.get(j), sourceVer, targetVer)); nbttaglist.set(
j,
convert(
LegacyType.ENTITY,
(net.minecraft.nbt.CompoundTag) nbttaglist.get(j),
sourceVer,
targetVer
)
);
} }
} }
@ -2671,16 +2815,26 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
nbttaglist = nbttagcompound1.getList("TileEntities", 10); nbttaglist = nbttagcompound1.getList("TileEntities", 10);
for (j = 0; j < nbttaglist.size(); ++j) { for (j = 0; j < nbttaglist.size(); ++j) {
nbttaglist.set(j, convert(LegacyType.BLOCK_ENTITY, (net.minecraft.nbt.CompoundTag) nbttaglist.get(j), sourceVer, targetVer)); nbttaglist.set(
j,
convert(
LegacyType.BLOCK_ENTITY,
(net.minecraft.nbt.CompoundTag) nbttaglist.get(j),
sourceVer,
targetVer
)
);
} }
} }
} }
return cmp; return cmp;
} }
} }
private static class DataInspectorEntityPassengers implements DataInspector { private static class DataInspectorEntityPassengers implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
if (cmp.contains("Passengers", 9)) { if (cmp.contains("Passengers", 9)) {
@ -2693,9 +2847,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorPlayer implements DataInspector { private static class DataInspectorPlayer implements DataInspector {
@Override @Override
public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) { public net.minecraft.nbt.CompoundTag inspect(net.minecraft.nbt.CompoundTag cmp, int sourceVer, int targetVer) {
convertItems(cmp, "Inventory", sourceVer, targetVer); convertItems(cmp, "Inventory", sourceVer, targetVer);
@ -2710,9 +2866,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorVillagers implements DataInspector { private static class DataInspectorVillagers implements DataInspector {
ResourceLocation entityVillager = getKey("EntityVillager"); ResourceLocation entityVillager = getKey("EntityVillager");
@Override @Override
@ -2736,9 +2894,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorMobSpawnerMinecart implements DataInspector { private static class DataInspectorMobSpawnerMinecart implements DataInspector {
ResourceLocation entityMinecartMobSpawner = getKey("EntityMinecartMobSpawner"); ResourceLocation entityMinecartMobSpawner = getKey("EntityMinecartMobSpawner");
ResourceLocation tileEntityMobSpawner = getKey("TileEntityMobSpawner"); ResourceLocation tileEntityMobSpawner = getKey("TileEntityMobSpawner");
@ -2753,9 +2913,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorMobSpawnerMobs implements DataInspector { private static class DataInspectorMobSpawnerMobs implements DataInspector {
ResourceLocation tileEntityMobSpawner = getKey("TileEntityMobSpawner"); ResourceLocation tileEntityMobSpawner = getKey("TileEntityMobSpawner");
@Override @Override
@ -2776,9 +2938,11 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
private static class DataInspectorCommandBlock implements DataInspector { private static class DataInspectorCommandBlock implements DataInspector {
ResourceLocation tileEntityCommand = getKey("TileEntityCommand"); ResourceLocation tileEntityCommand = getKey("TileEntityCommand");
@Override @Override
@ -2791,5 +2955,7 @@ class PaperweightDataConverters extends DataFixerBuilder implements com.sk89q.wo
return cmp; return cmp;
} }
} }
} }

View File

@ -37,7 +37,11 @@ import java.util.OptionalInt;
import java.util.UUID; import java.util.UUID;
class PaperweightFakePlayer extends ServerPlayer { class PaperweightFakePlayer extends ServerPlayer {
private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(UUID.nameUUIDFromBytes("worldedit".getBytes()), "[WorldEdit]");
private static final GameProfile FAKE_WORLDEDIT_PROFILE = new GameProfile(
UUID.nameUUIDFromBytes("worldedit".getBytes()),
"[WorldEdit]"
);
private static final Vec3 ORIGIN = new Vec3(0.0D, 0.0D, 0.0D); private static final Vec3 ORIGIN = new Vec3(0.0D, 0.0D, 0.0D);
PaperweightFakePlayer(ServerLevel world) { PaperweightFakePlayer(ServerLevel world) {
@ -95,4 +99,5 @@ class PaperweightFakePlayer extends ServerPlayer {
@Override @Override
public void openTextEdit(SignBlockEntity sign) { public void openTextEdit(SignBlockEntity sign) {
} }
} }

View File

@ -19,29 +19,29 @@
package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R1; package com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R1;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.wna.WorldNativeAccess; import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Objects; import java.util.Objects;
import javax.annotation.Nullable;
public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> { public class PaperweightWorldNativeAccess implements
WorldNativeAccess<LevelChunk, net.minecraft.world.level.block.state.BlockState, BlockPos> {
private static final int UPDATE = 1; private static final int UPDATE = 1;
private static final int NOTIFY = 2; private static final int NOTIFY = 2;
@ -83,12 +83,19 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
@Nullable @Nullable
@Override @Override
public net.minecraft.world.level.block.state.BlockState setBlockState(LevelChunk chunk, BlockPos position, net.minecraft.world.level.block.state.BlockState state) { public net.minecraft.world.level.block.state.BlockState setBlockState(
LevelChunk chunk,
BlockPos position,
net.minecraft.world.level.block.state.BlockState state
) {
return chunk.setBlockState(position, state, false, this.sideEffectSet.shouldApply(SideEffect.UPDATE)); return chunk.setBlockState(position, state, false, this.sideEffectSet.shouldApply(SideEffect.UPDATE));
} }
@Override @Override
public net.minecraft.world.level.block.state.BlockState getValidBlockForPosition(net.minecraft.world.level.block.state.BlockState block, BlockPos position) { public net.minecraft.world.level.block.state.BlockState getValidBlockForPosition(
net.minecraft.world.level.block.state.BlockState block,
BlockPos position
) {
return Block.updateFromNeighbourShapes(block, getWorld(), position); return Block.updateFromNeighbourShapes(block, getWorld(), position);
} }
@ -103,19 +110,17 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public boolean updateTileEntity(BlockPos position, CompoundTag tag) { public boolean updateTileEntity(final BlockPos position, final CompoundBinaryTag tag) {
// We will assume that the tile entity was created for us
BlockEntity tileEntity = getWorld().getBlockEntity(position);
if (tileEntity == null) {
return false; return false;
} }
Tag nativeTag = adapter.fromNative(tag);
PaperweightAdapter.readTagIntoTileEntity((net.minecraft.nbt.CompoundTag) nativeTag, tileEntity);
return true;
}
@Override @Override
public void notifyBlockUpdate(LevelChunk chunk, BlockPos position, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) { public void notifyBlockUpdate(
LevelChunk chunk,
BlockPos position,
net.minecraft.world.level.block.state.BlockState oldState,
net.minecraft.world.level.block.state.BlockState newState
) {
if (chunk.getSections()[getWorld().getSectionIndex(position.getY())] != null) { if (chunk.getSections()[getWorld().getSectionIndex(position.getY())] != null) {
getWorld().sendBlockUpdated(position, oldState, newState, UPDATE | NOTIFY); getWorld().sendBlockUpdated(position, oldState, newState, UPDATE | NOTIFY);
} }
@ -134,7 +139,11 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public void notifyNeighbors(BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) { public void notifyNeighbors(
BlockPos pos,
net.minecraft.world.level.block.state.BlockState oldState,
net.minecraft.world.level.block.state.BlockState newState
) {
ServerLevel world = getWorld(); ServerLevel world = getWorld();
if (sideEffectSet.shouldApply(SideEffect.EVENTS)) { if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
world.updateNeighborsAt(pos, oldState.getBlock()); world.updateNeighborsAt(pos, oldState.getBlock());
@ -158,14 +167,22 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public void updateNeighbors(BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState, int recursionLimit) { public void updateNeighbors(
BlockPos pos,
net.minecraft.world.level.block.state.BlockState oldState,
net.minecraft.world.level.block.state.BlockState newState,
int recursionLimit
) {
ServerLevel world = getWorld(); ServerLevel world = getWorld();
// a == updateNeighbors // a == updateNeighbors
// b == updateDiagonalNeighbors // b == updateDiagonalNeighbors
oldState.updateIndirectNeighbourShapes(world, pos, NOTIFY, recursionLimit); oldState.updateIndirectNeighbourShapes(world, pos, NOTIFY, recursionLimit);
if (sideEffectSet.shouldApply(SideEffect.EVENTS)) { if (sideEffectSet.shouldApply(SideEffect.EVENTS)) {
CraftWorld craftWorld = world.getWorld(); CraftWorld craftWorld = world.getWorld();
BlockPhysicsEvent event = new BlockPhysicsEvent(craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), CraftBlockData.fromData(newState)); BlockPhysicsEvent event = new BlockPhysicsEvent(
craftWorld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()),
CraftBlockData.fromData(newState)
);
world.getCraftServer().getPluginManager().callEvent(event); world.getCraftServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
@ -176,7 +193,17 @@ public class PaperweightWorldNativeAccess implements WorldNativeAccess<LevelChun
} }
@Override @Override
public void onBlockStateChange(BlockPos pos, net.minecraft.world.level.block.state.BlockState oldState, net.minecraft.world.level.block.state.BlockState newState) { public void onBlockStateChange(
BlockPos pos,
net.minecraft.world.level.block.state.BlockState oldState,
net.minecraft.world.level.block.state.BlockState newState
) {
getWorld().onBlockStateChange(pos, oldState, newState); getWorld().onBlockStateChange(pos, oldState, newState);
} }
@Override
public void flush() {
}
} }

View File

@ -51,8 +51,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
); );
tile = tileEntity == null tile = tileEntity == null
? null ? null
: new PaperweightLazyCompoundTag(Suppliers.memoize(() -> tileEntity.save(new net.minecraft.nbt.CompoundTag()))); : new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId));
// TODO 1.18 save -> saveAdditional
} }
public Block getBlock() { public Block getBlock() {

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1;
import ca.spottedleaf.starlight.common.light.StarLightEngine;
import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter; import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter;
import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter; import com.fastasyncworldedit.bukkit.adapter.IDelegateBukkitImplAdapter;
import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory; import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
@ -22,7 +23,6 @@ import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R1.PaperweightAdapter; import com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_18_R1.PaperweightAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.nbt.PaperweightLazyCompoundTag; import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R1.regen.PaperweightRegen;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
@ -55,7 +55,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry; import net.minecraft.core.WritableRegistry;
import net.minecraft.nbt.IntTag; import net.minecraft.nbt.IntTag;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
@ -229,9 +229,24 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
return Registry.BLOCK.get(new ResourceLocation(blockType.getNamespace(), blockType.getResource())); return Registry.BLOCK.get(new ResourceLocation(blockType.getNamespace(), blockType.getResource()));
} }
@SuppressWarnings("deprecation") @Deprecated
@Override @Override
public BaseBlock getBlock(Location location) { public BlockState getBlock(Location location) {
Preconditions.checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld());
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
final ServerLevel handle = craftWorld.getHandle();
LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
return adapt(blockData);
}
@Override
public BaseBlock getFullBlock(final Location location) {
Preconditions.checkNotNull(location); Preconditions.checkNotNull(location);
CraftWorld craftWorld = ((CraftWorld) location.getWorld()); CraftWorld craftWorld = ((CraftWorld) location.getWorld());
@ -239,19 +254,21 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
int y = location.getBlockY(); int y = location.getBlockY();
int z = location.getBlockZ(); int z = location.getBlockZ();
final ServerLevel serverLevel = craftWorld.getHandle(); final ServerLevel handle = craftWorld.getHandle();
LevelChunk levelChunk = serverLevel.getChunk(x >> 4, z >> 4); LevelChunk chunk = handle.getChunk(x >> 4, z >> 4);
final BlockPos blockPos = new BlockPos(x, y, z); final BlockPos blockPos = new BlockPos(x, y, z);
final net.minecraft.world.level.block.state.BlockState blockData = chunk.getBlockState(blockPos);
BlockState state = adapt(blockData);
if (state == null) {
org.bukkit.block.Block bukkitBlock = location.getBlock(); org.bukkit.block.Block bukkitBlock = location.getBlock();
BlockState state = BukkitAdapter.adapt(bukkitBlock.getBlockData()); state = BukkitAdapter.adapt(bukkitBlock.getBlockData());
}
if (state.getBlockType().getMaterial().hasContainer()) { if (state.getBlockType().getMaterial().hasContainer()) {
// Read the NBT data // Read the NBT data
BlockEntity blockEntity = levelChunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK); BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);
if (blockEntity != null) { if (blockEntity != null) {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag tag = blockEntity.saveWithId();
//TODO save -> saveAdditional
blockEntity.save(tag); // readTileEntityIntoTag - load data
return state.toBaseBlock((CompoundTag) toNative(tag)); return state.toBaseBlock((CompoundTag) toNative(tag));
} }
} }
@ -305,12 +322,6 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
if (existing == blockState) { if (existing == blockState) {
return true; return true;
} }
if (section == null) {
if (blockState.isAir()) {
return true;
}
levelChunkSections[y4] = section = new LevelChunkSection(y4 << 4);
}
levelChunk.setBlockState(blockPos, blockState, false); levelChunk.setBlockState(blockPos, blockState, false);
} }
if (update) { if (update) {
@ -482,7 +493,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
stream.filter(entityPlayer -> checkPlayer == null || entityPlayer == checkPlayer) stream.filter(entityPlayer -> checkPlayer == null || entityPlayer == checkPlayer)
.forEach(entityPlayer -> { .forEach(entityPlayer -> {
synchronized (chunkPacket) { synchronized (chunkPacket) {
ClientboundLevelChunkPacketData nmsPacket = (ClientboundLevelChunkPacketData) chunkPacket.getNativePacket(); ClientboundLevelChunkWithLightPacket nmsPacket = (ClientboundLevelChunkWithLightPacket) chunkPacket.getNativePacket();
if (nmsPacket == null) { if (nmsPacket == null) {
nmsPacket = mapUtil.create(this, chunkPacket); nmsPacket = mapUtil.create(this, chunkPacket);
chunkPacket.setNativePacket(nmsPacket); chunkPacket.setNativePacket(nmsPacket);
@ -600,7 +611,8 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
@Override @Override
public boolean regenerate(org.bukkit.World bukkitWorld, Region region, Extent target, RegenOptions options) throws Exception { public boolean regenerate(org.bukkit.World bukkitWorld, Region region, Extent target, RegenOptions options) throws Exception {
return new PaperweightRegen(bukkitWorld, region, target, options).regenerate(); // return new PaperweightRegen(bukkitWorld, region, target, options).regenerate();
return false;
} }
@Override @Override
@ -644,7 +656,7 @@ public final class PaperweightFaweAdapter extends CachedBukkitAdapter implements
@Override @Override
public RelighterFactory getRelighterFactory() { public RelighterFactory getRelighterFactory() {
try { try {
Class.forName("ca.spottedleaf.starlight.light.StarLightEngine"); Class.forName("ca.spottedleaf.starlight.common.light.StarLightEngine");
if (PaperweightStarlightRelighter.isUsable()) { if (PaperweightStarlightRelighter.isUsable()) {
return new PaperweightStarlightRelighterFactory(); return new PaperweightStarlightRelighterFactory();
} }

View File

@ -275,8 +275,21 @@ public class PaperweightFaweWorldNativeAccess implements WorldNativeAccess<Level
cachedChunksToSend.clear(); cachedChunksToSend.clear();
} }
private record CachedChange(LevelChunk levelChunk, BlockPos blockPos, private static final class CachedChange {
net.minecraft.world.level.block.state.BlockState blockState) {
private final LevelChunk levelChunk;
private final BlockPos blockPos;
private final net.minecraft.world.level.block.state.BlockState blockState;
private CachedChange(
LevelChunk levelChunk,
BlockPos blockPos,
net.minecraft.world.level.block.state.BlockState blockState
) {
this.levelChunk = levelChunk;
this.blockPos = blockPos;
this.blockState = blockState;
}
} }

View File

@ -25,7 +25,6 @@ import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import io.papermc.paper.event.block.BeaconDeactivatedEvent; import io.papermc.paper.event.block.BeaconDeactivatedEvent;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -36,14 +35,15 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.BitStorage; import net.minecraft.util.BitStorage;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.entity.BeaconBlockEntity; import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkBiomeContainer;
import net.minecraft.world.level.chunk.DataLayer; import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.world.level.chunk.HashMapPalette; import net.minecraft.world.level.chunk.HashMapPalette;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
@ -60,7 +60,6 @@ import org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -86,9 +85,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ()); private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private static final Function<BlockEntity, CompoundTag> nmsTile2We = private static final Function<BlockEntity, CompoundTag> nmsTile2We =
tileEntity -> new PaperweightLazyCompoundTag(Suppliers.memoize( tileEntity -> new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId));
//TODO save -> saveAdditional
() -> tileEntity.save(new net.minecraft.nbt.CompoundTag())));
private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin
.getInstance() .getInstance()
.getBukkitImplAdapter()); .getBukkitImplAdapter());
@ -100,6 +97,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private final int maxHeight; private final int maxHeight;
private final int minSectionPosition; private final int minSectionPosition;
private final int maxSectionPosition; private final int maxSectionPosition;
private final Registry<Biome> biomeRegistry;
private LevelChunkSection[] sections; private LevelChunkSection[] sections;
private LevelChunk levelChunk; private LevelChunk levelChunk;
private DataLayer[] blockLight; private DataLayer[] blockLight;
@ -124,6 +122,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
this.maxSectionPosition = maxHeight >> 4; this.maxSectionPosition = maxHeight >> 4;
this.skyLight = new DataLayer[getSectionCount()]; this.skyLight = new DataLayer[getSectionCount()];
this.blockLight = new DataLayer[getSectionCount()]; this.blockLight = new DataLayer[getSectionCount()];
this.biomeRegistry = serverLevel.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
} }
public int getChunkX() { public int getChunkX() {
@ -154,7 +153,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (light != null) { if (light != null) {
lightUpdate = true; lightUpdate = true;
try { try {
fillLightNibble(light, LightLayer.SKY, minSectionPosition, maxSectionPosition); fillLightNibble(light, LightLayer.BLOCK, minSectionPosition, maxSectionPosition);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -194,19 +193,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Override @Override
public BiomeType getBiomeType(int x, int y, int z) { public BiomeType getBiomeType(int x, int y, int z) {
ChunkBiomeContainer index = getChunk().getBiomes(); LevelChunkSection section = getSections(false)[(y >> 4) - getMinSectionPosition()];
Biome biomes = null; Biome biomes = section.getNoiseBiome(x >> 2, (y & 15) >> 2, z >> 2);
if (y == -1) { return PaperweightPlatformAdapter.adapt(biomes, serverLevel);
for (y = serverLevel.getMinBuildHeight(); y < serverLevel.getMaxBuildHeight(); y += 4) {
biomes = index.getNoiseBiome(x >> 2, y >> 2, z >> 2);
if (biomes != null) {
break;
}
}
} else {
biomes = index.getNoiseBiome(x >> 2, y >> 2, z >> 2);
}
return biomes != null ? PaperweightPlatformAdapter.adapt(biomes, serverLevel) : null;
} }
@Override @Override
@ -217,12 +206,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (dataLayer != null) { if (dataLayer != null) {
lightUpdate = true; lightUpdate = true;
synchronized (dataLayer) { synchronized (dataLayer) {
byte[] bytes = PaperLib.isPaper() ? dataLayer.getIfSet() : dataLayer.getData(); byte[] bytes = dataLayer.getData();
if (!PaperLib.isPaper() || bytes != DataLayer.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0); Arrays.fill(bytes, (byte) 0);
} }
} }
}
if (sky) { if (sky) {
SectionPos sectionPos1 = SectionPos.of(getChunk().getPos(), layer); SectionPos sectionPos1 = SectionPos.of(getChunk().getPos(), layer);
DataLayer dataLayer1 = serverLevel DataLayer dataLayer1 = serverLevel
@ -233,14 +220,12 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (dataLayer1 != null) { if (dataLayer1 != null) {
lightUpdate = true; lightUpdate = true;
synchronized (dataLayer1) { synchronized (dataLayer1) {
byte[] bytes = PaperLib.isPaper() ? dataLayer1.getIfSet() : dataLayer1.getData(); byte[] bytes = dataLayer1.getData();
if (!PaperLib.isPaper() || bytes != DataLayer.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0); Arrays.fill(bytes, (byte) 0);
} }
} }
} }
} }
}
@Override @Override
//TODO 1.18 be CBT? //TODO 1.18 be CBT?
@ -251,7 +236,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
if (blockEntity == null) { if (blockEntity == null) {
return null; return null;
} }
return new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.save(new net.minecraft.nbt.CompoundTag()))); return new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId));
} }
@Override @Override
@ -450,18 +435,67 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
} }
} }
final BiomeType[][] biomes = set.getBiomes();
int bitMask = 0; int bitMask = 0;
synchronized (nmsChunk) { synchronized (nmsChunk) {
LevelChunkSection[] levelChunkSections = nmsChunk.getSections(); LevelChunkSection[] levelChunkSections = nmsChunk.getSections();
for (int layerNo = getMinSectionPosition(); layerNo <= getMaxSectionPosition(); layerNo++) { for (int layerNo = getMinSectionPosition(); layerNo <= getMaxSectionPosition(); layerNo++) {
int getSectionIndex = layerNo - getMinSectionPosition();
int setSectionIndex = layerNo - set.getMinSectionPosition();
if (!set.hasSection(layerNo)) { if (!set.hasSection(layerNo)) {
// No blocks, but might be biomes present. Handle this lazily.
if (biomes == null) {
continue; continue;
} }
int layer = layerNo - getMinSectionPosition(); if (layerNo < set.getMinSectionPosition() || layerNo > set.getMaxSectionPosition()) {
continue;
}
if (biomes[setSectionIndex] != null) {
synchronized (super.sectionLocks[getSectionIndex]) {
LevelChunkSection existingSection = levelChunkSections[getSectionIndex];
if (createCopy && existingSection != null) {
copy.storeBiomes(getSectionIndex, existingSection.getBiomes().copy());
}
bitMask |= 1 << layer; if (existingSection == null) {
PalettedContainer<Biome> biomeData = PaperweightPlatformAdapter.getBiomePalettedContainer(
biomes[setSectionIndex],
biomeRegistry
);
LevelChunkSection newSection = PaperweightPlatformAdapter.newChunkSection(
layerNo,
new char[4096],
fastmode,
adapter,
biomeRegistry,
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(levelChunkSections, null, newSection, getSectionIndex)) {
updateGet(nmsChunk, levelChunkSections, newSection, new char[4096], getSectionIndex);
continue;
} else {
existingSection = levelChunkSections[getSectionIndex];
if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk: {}, {} layer: {}", chunkX, chunkZ,
getSectionIndex
);
continue;
}
}
} else {
PalettedContainer<Biome> biomeData = existingSection.getBiomes();
setBiomesToPalettedContainer(biomes[setSectionIndex], biomeData);
}
}
}
continue;
}
bitMask |= 1 << getSectionIndex;
char[] tmp = set.load(layerNo); char[] tmp = set.load(layerNo);
char[] setArr = new char[4096]; char[] setArr = new char[4096];
@ -469,26 +503,44 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
// synchronise on internal section to avoid circular locking with a continuing edit if the chunk was // synchronise on internal section to avoid circular locking with a continuing edit if the chunk was
// submitted to keep loaded internal chunks to queue target size. // submitted to keep loaded internal chunks to queue target size.
synchronized (super.sectionLocks[layer]) { synchronized (super.sectionLocks[getSectionIndex]) {
LevelChunkSection newSection;
LevelChunkSection existingSection = levelChunkSections[getSectionIndex];
if (createCopy) { if (createCopy) {
char[] tmpLoad = loadPrivately(layerNo); char[] tmpLoad = loadPrivately(layerNo);
char[] copyArr = new char[4096]; char[] copyArr = new char[4096];
System.arraycopy(tmpLoad, 0, copyArr, 0, 4096); System.arraycopy(tmpLoad, 0, copyArr, 0, 4096);
copy.storeSection(layer, copyArr); copy.storeSection(getSectionIndex, copyArr);
if (biomes != null && existingSection != null) {
copy.storeBiomes(getSectionIndex, existingSection.getBiomes().copy());
}
} }
LevelChunkSection newSection;
LevelChunkSection existingSection = levelChunkSections[layer];
if (existingSection == null) { if (existingSection == null) {
newSection = PaperweightPlatformAdapter.newChunkSection(layerNo, setArr, fastmode, adapter); PalettedContainer<Biome> biomeData = biomes == null ? new PalettedContainer<>(
if (PaperweightPlatformAdapter.setSectionAtomic(levelChunkSections, null, newSection, layer)) { biomeRegistry,
updateGet(nmsChunk, levelChunkSections, newSection, setArr, layer); biomeRegistry.getOrThrow(Biomes.PLAINS),
PalettedContainer.Strategy.SECTION_BIOMES,
null
) : PaperweightPlatformAdapter.getBiomePalettedContainer(biomes[setSectionIndex], biomeRegistry);
newSection = PaperweightPlatformAdapter.newChunkSection(
layerNo,
setArr,
fastmode,
adapter,
biomeRegistry,
biomeData
);
if (PaperweightPlatformAdapter.setSectionAtomic(levelChunkSections, null, newSection, getSectionIndex)) {
updateGet(nmsChunk, levelChunkSections, newSection, setArr, getSectionIndex);
continue; continue;
} else { } else {
existingSection = levelChunkSections[layer]; existingSection = levelChunkSections[getSectionIndex];
if (existingSection == null) { if (existingSection == null) {
LOGGER.error("Skipping invalid null section. chunk: {}, {} layer: {}", chunkX, chunkZ, LOGGER.error("Skipping invalid null section. chunk: {}, {} layer: {}", chunkX, chunkZ,
+layer getSectionIndex
); );
continue; continue;
} }
@ -507,10 +559,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
this.levelChunk = nmsChunk; this.levelChunk = nmsChunk;
this.sections = null; this.sections = null;
this.reset(); this.reset();
} else if (existingSection != getSections(false)[layer]) { } else if (existingSection != getSections(false)[getSectionIndex]) {
this.sections[layer] = existingSection; this.sections[getSectionIndex] = existingSection;
this.reset(); this.reset();
} else if (!Arrays.equals(update(layer, new char[4096], true), loadPrivately(layerNo))) { } else if (!Arrays.equals(update(getSectionIndex, new char[4096], true), loadPrivately(layerNo))) {
this.reset(layerNo); this.reset(layerNo);
/*} else if (lock.isModified()) { /*} else if (lock.isModified()) {
this.reset(layerNo);*/ this.reset(layerNo);*/
@ -518,51 +570,34 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} finally { } finally {
sectionLock.writeLock().unlock(); sectionLock.writeLock().unlock();
} }
PalettedContainer<Biome> biomeData = existingSection.getBiomes();
if (biomes != null && biomes[setSectionIndex] != null) {
setBiomesToPalettedContainer(biomes[setSectionIndex], biomeData);
}
newSection = newSection =
PaperweightPlatformAdapter.newChunkSection( PaperweightPlatformAdapter.newChunkSection(
layerNo, layerNo,
this::loadPrivately, this::loadPrivately,
setArr, setArr,
fastmode, fastmode,
adapter adapter,
biomeRegistry,
biomeData
); );
if (!PaperweightPlatformAdapter.setSectionAtomic( if (!PaperweightPlatformAdapter.setSectionAtomic(
levelChunkSections, levelChunkSections,
existingSection, existingSection,
newSection, newSection,
layer getSectionIndex
)) { )) {
LOGGER.error("Skipping invalid null section. chunk: {}, {} layer: {}", chunkX, chunkZ, LOGGER.error("Skipping invalid null section. chunk: {}, {} layer: {}", chunkX, chunkZ,
+layer getSectionIndex
); );
} else { } else {
updateGet(nmsChunk, levelChunkSections, newSection, setArr, layer); updateGet(nmsChunk, levelChunkSections, newSection, setArr, getSectionIndex);
}
}
}
}
// Biomes
BiomeType[] biomes = set.getBiomes();
if (biomes != null) {
// set biomes
ChunkBiomeContainer currentBiomes = nmsChunk.getBiomes();
if (createCopy) {
copy.storeBiomes(currentBiomes);
}
for (int y = 0, i = 0; y < 64; y++) {
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 4; x++, i++) {
final BiomeType biome = biomes[i];
if (biome != null) {
Biome nmsBiome =
nmsWorld.registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).get(
ResourceLocation.tryParse(biome.getId()));
if (nmsBiome == null) {
throw new NullPointerException("BiomeBase null for BiomeType " + biome.getId());
}
currentBiomes.setBiome(x, y, z, nmsBiome);
}
} }
} }
} }
@ -665,7 +700,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
entity.load(tag); entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch); entity.absMoveTo(x, y, z, yaw, pitch);
nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
} }
} }
} }
@ -718,7 +753,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
// Set Modified // Set Modified
nmsChunk.setLightCorrect(true); // Set Modified nmsChunk.setLightCorrect(true); // Set Modified
nmsChunk.mustNotSave = false; nmsChunk.mustNotSave = false;
nmsChunk.isUnsaved(); // TODO 1.18 revisit nmsChunk.setUnsaved(true);
// send to player // send to player
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) { if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate); this.send(finalMask, finalLightUpdate);
@ -857,10 +892,17 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
lock.acquire(); lock.acquire();
final PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.getStates(); final PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.getStates();
final BitStorage bits = (BitStorage) PaperweightPlatformAdapter.fieldStorage.get(blocks); final Object dataObject = PaperweightPlatformAdapter.fieldData.get(blocks);
final Palette<BlockState> palette = (Palette<BlockState>) PaperweightPlatformAdapter.fieldPalette.get(blocks); final BitStorage bits = (BitStorage) PaperweightPlatformAdapter.fieldStorage.get(dataObject);
final int bitsPerEntry = (int) PaperweightPlatformAdapter.fieldBitsPerEntry.get(bits); if (bits instanceof ZeroBitStorage) {
Arrays.fill(data, (char) 0);
return data;
}
final Palette<BlockState> palette = (Palette<BlockState>) PaperweightPlatformAdapter.fieldPalette.get(dataObject);
final int bitsPerEntry = bits.getBits();
final long[] blockStates = bits.getRaw(); final long[] blockStates = bits.getRaw();
new BitArrayUnstretched(bitsPerEntry, 4096, blockStates).toRaw(data); new BitArrayUnstretched(bitsPerEntry, 4096, blockStates).toRaw(data);
@ -924,7 +966,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) { private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, PaperweightFaweAdapter adapter) {
if (ibd == null) { if (ibd == null) {
return BlockTypes.AIR.getDefaultState().getOrdinalChar(); return 1;
} else { } else {
return adapter.adaptToChar(ibd); return adapter.adaptToChar(ibd);
} }
@ -999,6 +1041,32 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
} }
private void setBiomesToPalettedContainer(
final BiomeType[] biomes,
PalettedContainer<Biome> data
) {
int index = 0;
if (biomes == null) {
return;
}
for (int y = 0; y < 4; y++) {
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 4; x++, index++) {
BiomeType biomeType = biomes[index];
if (biomeType == null) {
continue;
}
data.set(
x,
y,
z,
biomeRegistry.get(ResourceLocation.tryParse(biomeType.getId()))
);
}
}
}
}
@Override @Override
public boolean hasSection(int layer) { public boolean hasSection(int layer) {
layer -= getMinSectionPosition(); layer -= getMinSectionPosition();
@ -1028,8 +1096,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
try { try {
final PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocksExisting = existing.getStates(); final PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocksExisting = existing.getStates();
final Object dataObject = PaperweightPlatformAdapter.fieldData.get(blocksExisting);
//TODO this field doesn't exist in 1.18
final Palette<BlockState> palette = (Palette<BlockState>) PaperweightPlatformAdapter.fieldPalette.get( final Palette<BlockState> palette = (Palette<BlockState>) PaperweightPlatformAdapter.fieldPalette.get(
blocksExisting); dataObject);
int paletteSize; int paletteSize;
if (palette instanceof LinearPalette || palette instanceof HashMapPalette) { if (palette instanceof LinearPalette || palette instanceof HashMapPalette) {

View File

@ -18,7 +18,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.ChunkBiomeContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
@ -36,7 +36,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
private final int minHeight; private final int minHeight;
private final int maxHeight; private final int maxHeight;
private final ServerLevel serverLevel; private final ServerLevel serverLevel;
private ChunkBiomeContainer chunkBiomeContainer; private PalettedContainer<Biome>[] biomes = null;
protected PaperweightGetBlocks_Copy(ServerLevel world) { protected PaperweightGetBlocks_Copy(ServerLevel world) {
this.serverLevel = world; this.serverLevel = world;
@ -52,8 +52,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getY(),
blockEntity.getBlockPos().getZ() blockEntity.getBlockPos().getZ()
), ),
new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.save(new net.minecraft.nbt.CompoundTag()))) new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId))
//TODO 1.18 save -> saveAdditional
); );
} }
@ -142,27 +141,9 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
return minHeight >> 4; return minHeight >> 4;
} }
protected void storeBiomes(ChunkBiomeContainer chunkBiomeContainer) {
// The to do one line below is pre-paperweight and needs to be revised
// TODO revisit last parameter, BiomeStorage[] *would* be more efficient
this.chunkBiomeContainer = new ChunkBiomeContainer(chunkBiomeContainer.biomeRegistry, serverLevel,
chunkBiomeContainer.writeBiomes()
);
}
@Override @Override
public BiomeType getBiomeType(int x, int y, int z) { public BiomeType getBiomeType(int x, int y, int z) {
Biome biome = null; Biome biome = biomes[(y >> 4) - getMinSectionPosition()].get(x >> 2, (y & 15) >> 2, z >> 2);
if (y == -1) {
for (y = serverLevel.getMinBuildHeight(); y <= serverLevel.getMaxBuildHeight(); y += 4) {
biome = this.chunkBiomeContainer.getNoiseBiome(x >> 2, y >> 2, z >> 2);
if (biome != null) {
break;
}
}
} else {
biome = this.chunkBiomeContainer.getNoiseBiome(x >> 2, y >> 2, z >> 2);
}
return biome != null ? PaperweightPlatformAdapter.adapt(biome, serverLevel) : null; return biome != null ? PaperweightPlatformAdapter.adapt(biome, serverLevel) : null;
} }
@ -189,6 +170,13 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
blocks[layer] = data; blocks[layer] = data;
} }
protected void storeBiomes(int layer, PalettedContainer<Biome> biomeData) {
if (biomes == null) {
biomes = new PalettedContainer[getSectionCount()];
}
biomes[layer] = biomeData;
}
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];

View File

@ -4,16 +4,19 @@ import com.fastasyncworldedit.bukkit.adapter.MapChunkUtil;
import com.sk89q.worldedit.bukkit.adapter.Refraction; import com.sk89q.worldedit.bukkit.adapter.Refraction;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
public class PaperweightMapChunkUtil extends MapChunkUtil<ClientboundLevelChunkPacketData> { import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
//TODO un-very-break-this
public class PaperweightMapChunkUtil extends MapChunkUtil<ClientboundLevelChunkWithLightPacket> {
public PaperweightMapChunkUtil() throws NoSuchFieldException { public PaperweightMapChunkUtil() throws NoSuchFieldException {
fieldX = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("TWO_MEGABYTES", "a")); fieldX = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("TWO_MEGABYTES", "a"));
fieldZ = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("x", "b")); fieldZ = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName("x", "a"));
fieldBitMask = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("z", "c")); fieldBitMask = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName("z", "b"));
fieldHeightMap = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("availableSections", "d")); fieldHeightMap = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("heightmaps", "b"));
fieldChunkData = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("biomes", "f")); fieldChunkData = ClientboundLevelChunkWithLightPacket.class.getDeclaredField(Refraction.pickName("chunkData", "c"));
fieldBlockEntities = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("buffer", "g")); fieldBlockEntities = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("buffer", "c"));
fieldFull = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("blockEntitiesTags", "h")); fieldFull = ClientboundLevelChunkPacketData.class.getDeclaredField(Refraction.pickName("blockEntitiesData", "d"));
fieldX.setAccessible(true); fieldX.setAccessible(true);
fieldZ.setAccessible(true); fieldZ.setAccessible(true);
fieldBitMask.setAccessible(true); fieldBitMask.setAccessible(true);
@ -24,7 +27,7 @@ public class PaperweightMapChunkUtil extends MapChunkUtil<ClientboundLevelChunkP
} }
@Override @Override
public ClientboundLevelChunkPacketData createPacket() { public ClientboundLevelChunkWithLightPacket createPacket() {
// TODO ??? return new ClientboundLevelChunkPacket(); // TODO ??? return new ClientboundLevelChunkPacket();
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -5,7 +5,6 @@ import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
import com.fastasyncworldedit.bukkit.adapter.NMSAdapter; import com.fastasyncworldedit.bukkit.adapter.NMSAdapter;
import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.math.BitArrayUnstretched; import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.ReflectionUtils; import com.fastasyncworldedit.core.util.ReflectionUtils;
@ -20,68 +19,84 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.nbt.NbtUtils; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.BitStorage; import net.minecraft.util.BitStorage;
import net.minecraft.util.SimpleBitStorage;
import net.minecraft.util.ThreadingDetector;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.ChunkBiomeContainer; import net.minecraft.world.level.chunk.GlobalPalette;
import net.minecraft.world.level.chunk.HashMapPalette; import net.minecraft.world.level.chunk.HashMapPalette;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.LinearPalette; import net.minecraft.world.level.chunk.LinearPalette;
import net.minecraft.world.level.chunk.Palette; import net.minecraft.world.level.chunk.Palette;
import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.SingleValuePalette;
import net.minecraft.world.level.gameevent.GameEventDispatcher; import net.minecraft.world.level.gameevent.GameEventDispatcher;
import net.minecraft.world.level.gameevent.GameEventListener; import net.minecraft.world.level.gameevent.GameEventListener;
import org.bukkit.craftbukkit.v1_18_R1.CraftChunk; import org.bukkit.craftbukkit.v1_18_R1.CraftChunk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import sun.misc.Unsafe; import sun.misc.Unsafe;
import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream;
public final class PaperweightPlatformAdapter extends NMSAdapter { public final class PaperweightPlatformAdapter extends NMSAdapter {
public static final Field fieldData;
public static final Constructor<?> dataConstructor;
public static final Field fieldStorage; public static final Field fieldStorage;
public static final Field fieldPalette; public static final Field fieldPalette;
public static final Field fieldBits;
public static final Field fieldBitsPerEntry;
public static final Field fieldTickingFluidContent; public static final Field fieldTickingFluidContent;
public static final Field fieldTickingBlockCount; public static final Field fieldTickingBlockCount;
public static final Field fieldNonEmptyBlockCount; public static final Field fieldNonEmptyBlockCount;
private static final Field fieldBiomes;
private static final MethodHandle methodGetVisibleChunk; private static final MethodHandle methodGetVisibleChunk;
private static final int CHUNKSECTION_BASE; private static final int CHUNKSECTION_BASE;
private static final int CHUNKSECTION_SHIFT; private static final int CHUNKSECTION_SHIFT;
private static final Field fieldThreadingDetector;
private static final long fieldThreadingDetectorOffset;
private static final Field fieldLock; private static final Field fieldLock;
private static final long fieldLockOffset; private static final long fieldLockOffset;
@ -92,15 +107,18 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
static { static {
try { try {
fieldBits = PalettedContainer.class.getDeclaredField(Refraction.pickName("bits", "l")); fieldData = PalettedContainer.class.getDeclaredField(Refraction.pickName("data", "d"));
fieldBits.setAccessible(true); fieldData.setAccessible(true);
fieldStorage = PalettedContainer.class.getDeclaredField(Refraction.pickName("storage", "c"));
fieldStorage.setAccessible(true);
fieldPalette = PalettedContainer.class.getDeclaredField(Refraction.pickName("palette", "k"));
fieldPalette.setAccessible(true);
fieldBitsPerEntry = BitStorage.class.getDeclaredField(Refraction.pickName("bits", "c")); Class<?> dataClazz = fieldData.getType();
fieldBitsPerEntry.setAccessible(true); dataConstructor = dataClazz.getDeclaredConstructors()[0];
dataConstructor.setAccessible(true);
//TODO FIXME 1.18
fieldStorage = dataClazz.getDeclaredField(Refraction.pickName("storage", "b"));
fieldStorage.setAccessible(true);
fieldPalette = dataClazz.getDeclaredField(Refraction.pickName("palette", "c"));
fieldPalette.setAccessible(true);
fieldTickingFluidContent = LevelChunkSection.class.getDeclaredField(Refraction.pickName("tickingFluidCount", "h")); fieldTickingFluidContent = LevelChunkSection.class.getDeclaredField(Refraction.pickName("tickingFluidCount", "h"));
fieldTickingFluidContent.setAccessible(true); fieldTickingFluidContent.setAccessible(true);
@ -109,27 +127,27 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldNonEmptyBlockCount = LevelChunkSection.class.getDeclaredField(Refraction.pickName("nonEmptyBlockCount", "f")); fieldNonEmptyBlockCount = LevelChunkSection.class.getDeclaredField(Refraction.pickName("nonEmptyBlockCount", "f"));
fieldNonEmptyBlockCount.setAccessible(true); fieldNonEmptyBlockCount.setAccessible(true);
fieldBiomes = ChunkBiomeContainer.class.getDeclaredField(Refraction.pickName("biomes", "f"));
fieldBiomes.setAccessible(true);
Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName( Method getVisibleChunkIfPresent = ChunkMap.class.getDeclaredMethod(Refraction.pickName(
"getVisibleChunkIfPresent", "getVisibleChunkIfPresent",
"getVisibleChunk" "b"
), long.class); ), long.class);
getVisibleChunkIfPresent.setAccessible(true); getVisibleChunkIfPresent.setAccessible(true);
methodGetVisibleChunk = MethodHandles.lookup().unreflect(getVisibleChunkIfPresent); methodGetVisibleChunk = MethodHandles.lookup().unreflect(getVisibleChunkIfPresent);
Unsafe unsafe = ReflectionUtils.getUnsafe(); Unsafe unsafe = ReflectionUtils.getUnsafe();
fieldLock = PalettedContainer.class.getDeclaredField(Refraction.pickName("lock", "m")); fieldThreadingDetector = PalettedContainer.class.getDeclaredField(Refraction.pickName("threadingDetector", "f"));
fieldThreadingDetectorOffset = unsafe.objectFieldOffset(fieldThreadingDetector);
fieldLock = ThreadingDetector.class.getDeclaredField(Refraction.pickName("lock", "c"));
fieldLockOffset = unsafe.objectFieldOffset(fieldLock); fieldLockOffset = unsafe.objectFieldOffset(fieldLock);
fieldGameEventDispatcherSections = LevelChunk.class.getDeclaredField(Refraction.pickName( fieldGameEventDispatcherSections = LevelChunk.class.getDeclaredField(Refraction.pickName(
"gameEventDispatcherSections", "x")); "gameEventDispatcherSections", "t"));
fieldGameEventDispatcherSections.setAccessible(true); fieldGameEventDispatcherSections.setAccessible(true);
Method removeBlockEntityTicker = LevelChunk.class.getDeclaredMethod( Method removeBlockEntityTicker = LevelChunk.class.getDeclaredMethod(
Refraction.pickName( Refraction.pickName(
"removeBlockEntityTicker", "removeBlockEntityTicker",
"l" "m"
), BlockPos.class ), BlockPos.class
); );
removeBlockEntityTicker.setAccessible(true); removeBlockEntityTicker.setAccessible(true);
@ -166,19 +184,22 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
static DelegateSemaphore applyLock(LevelChunkSection section) { static DelegateSemaphore applyLock(LevelChunkSection section) {
//todo there has to be a better way to do this. Maybe using a() in DataPaletteBlock which acquires the lock in NMS?
try { try {
synchronized (section) { synchronized (section) {
Unsafe unsafe = ReflectionUtils.getUnsafe(); Unsafe unsafe = ReflectionUtils.getUnsafe();
PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.getStates(); PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.getStates();
Semaphore currentLock = (Semaphore) unsafe.getObject(blocks, fieldLockOffset); ThreadingDetector currentThreadingDetector = (ThreadingDetector) unsafe.getObject(blocks,
fieldThreadingDetectorOffset) ;
synchronized(currentThreadingDetector) {
Semaphore currentLock = (Semaphore) unsafe.getObject(currentThreadingDetector, fieldLockOffset);
if (currentLock instanceof DelegateSemaphore) { if (currentLock instanceof DelegateSemaphore) {
return (DelegateSemaphore) currentLock; return (DelegateSemaphore) currentLock;
} }
DelegateSemaphore newLock = new DelegateSemaphore(1, currentLock); DelegateSemaphore newLock = new DelegateSemaphore(1, currentLock);
unsafe.putObject(blocks, fieldLockOffset, newLock); unsafe.putObject(currentThreadingDetector, fieldLockOffset, newLock);
return newLock; return newLock;
} }
}
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
@ -248,21 +269,14 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
LevelChunk levelChunk = optional.get(); LevelChunk levelChunk = optional.get();
TaskManager.IMP.task(() -> { TaskManager.IMP.task(() -> {
ClientboundLevelChunkPacketData chunkPacket = new ClientboundLevelChunkPacketData(levelChunk); ClientboundLevelChunkWithLightPacket packet =
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(chunkPacket)); new ClientboundLevelChunkWithLightPacket(levelChunk, nmsWorld.getChunkSource().getLightEngine(), null, null
if (lighting) { , true, false); // last false is to not bother with x-ray
//This needs to be true otherwise Minecraft will update lighting from/at the chunk edges (bad)
boolean trustEdges = true;
ClientboundLightUpdatePacket packet =
new ClientboundLightUpdatePacket(coordIntPair, nmsWorld.getChunkSource().getLightEngine(), null, null,
trustEdges
);
nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet)); nearbyPlayers(nmsWorld, coordIntPair).forEach(p -> p.connection.send(packet));
}
}); });
} }
private static Stream<ServerPlayer> nearbyPlayers(ServerLevel serverLevel, ChunkPos coordIntPair) { private static List<ServerPlayer> nearbyPlayers(ServerLevel serverLevel, ChunkPos coordIntPair) {
return serverLevel.getChunkSource().chunkMap.getPlayers(coordIntPair, false); return serverLevel.getChunkSource().chunkMap.getPlayers(coordIntPair, false);
} }
@ -271,17 +285,19 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
*/ */
public static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection(
final int layer, final char[] blocks, boolean fastmode, final int layer, final char[] blocks, boolean fastmode,
CachedBukkitAdapter adapter CachedBukkitAdapter adapter, Registry<Biome> biomeRegistry,
@Nullable PalettedContainer<Biome> biomes
) { ) {
return newChunkSection(layer, null, blocks, fastmode, adapter); return newChunkSection(layer, null, blocks, fastmode, adapter, biomeRegistry, biomes);
} }
public static LevelChunkSection newChunkSection( public static LevelChunkSection newChunkSection(
final int layer, final Function<Integer, char[]> get, char[] set, final int layer, final Function<Integer, char[]> get, char[] set,
boolean fastmode, CachedBukkitAdapter adapter boolean fastmode, CachedBukkitAdapter adapter, Registry<Biome> biomeRegistry,
@Nullable PalettedContainer<Biome> biomes
) { ) {
if (set == null) { if (set == null) {
return newChunkSection(layer); return newChunkSection(layer, biomeRegistry, biomes);
} }
final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get(); final int[] blockToPalette = FaweCache.IMP.BLOCK_TO_PALETTE.get();
final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get(); final int[] paletteToBlock = FaweCache.IMP.PALETTE_TO_BLOCK.get();
@ -302,17 +318,18 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
int num_palette = num_palette_buffer[0]; int num_palette = num_palette_buffer[0];
// BlockStates // BlockStates
int bitsPerEntry = MathMan.log2nlz(num_palette - 1); int bitsPerEntry = MathMan.log2nlz(num_palette - 1);
if (Settings.IMP.PROTOCOL_SUPPORT_FIX || num_palette != 1) { Object configuration =
bitsPerEntry = Math.max(bitsPerEntry, 4); // Protocol support breaks <4 bits per entry PalettedContainer.Strategy.SECTION_STATES.getConfiguration(new FakeIdMapBlock(num_palette), bitsPerEntry);
} else { if (bitsPerEntry > 0 && bitsPerEntry < 5) {
bitsPerEntry = Math.max(bitsPerEntry, 1); // For some reason minecraft needs 4096 bits to store 0 entries bitsPerEntry = 4;
} } else if (bitsPerEntry > 8) {
if (bitsPerEntry > 8) {
bitsPerEntry = MathMan.log2nlz(Block.BLOCK_STATE_REGISTRY.size() - 1); bitsPerEntry = MathMan.log2nlz(Block.BLOCK_STATE_REGISTRY.size() - 1);
} }
final int blocksPerLong = MathMan.floorZero((double) 64 / bitsPerEntry); int bitsPerEntryNonZero = Math.max(bitsPerEntry, 1); // We do want to use zero sometimes
final int blocksPerLong = MathMan.floorZero((double) 64 / bitsPerEntryNonZero);
final int blockBitArrayEnd = MathMan.ceilZero((float) 4096 / blocksPerLong); final int blockBitArrayEnd = MathMan.ceilZero((float) 4096 / blocksPerLong);
if (num_palette == 1) { if (num_palette == 1) {
@ -320,53 +337,61 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
blockStates[i] = 0; blockStates[i] = 0;
} }
} else { } else {
final BitArrayUnstretched bitArray = new BitArrayUnstretched(bitsPerEntry, 4096, blockStates); final BitArrayUnstretched bitArray = new BitArrayUnstretched(bitsPerEntryNonZero, 4096, blockStates);
bitArray.fromRaw(blocksCopy); bitArray.fromRaw(blocksCopy);
} }
LevelChunkSection levelChunkSection = newChunkSection(layer);
// set palette & data bits
final PalettedContainer<net.minecraft.world.level.block.state.BlockState> dataPaletteBlocks =
levelChunkSection.getStates();
// private DataPalette<T> h;
// protected DataBits a;
final long[] bits = Arrays.copyOfRange(blockStates, 0, blockBitArrayEnd); final long[] bits = Arrays.copyOfRange(blockStates, 0, blockBitArrayEnd);
final BitStorage nmsBits = new BitStorage(bitsPerEntry, 4096, bits); final BitStorage nmsBits;
final Palette<net.minecraft.world.level.block.state.BlockState> blockStatePalettedContainer; if (bitsPerEntry == 0) {
if (bitsPerEntry <= 4) { nmsBits = new ZeroBitStorage(4096);
blockStatePalettedContainer = new LinearPalette<>(Block.BLOCK_STATE_REGISTRY, bitsPerEntry, dataPaletteBlocks,
NbtUtils::readBlockState
);
} else if (bitsPerEntry < 9) {
blockStatePalettedContainer = new HashMapPalette<>(
Block.BLOCK_STATE_REGISTRY,
bitsPerEntry,
dataPaletteBlocks,
NbtUtils::readBlockState,
NbtUtils::writeBlockState
);
} else { } else {
blockStatePalettedContainer = LevelChunkSection.GLOBAL_BLOCKSTATE_PALETTE; nmsBits = new SimpleBitStorage(bitsPerEntry, 4096, bits);
} }
final Palette<net.minecraft.world.level.block.state.BlockState> blockStatePalette;
// set palette if required List<net.minecraft.world.level.block.state.BlockState> palette;
if (bitsPerEntry < 9) { if (bitsPerEntry < 9) {
palette = new ArrayList<>();
for (int i = 0; i < num_palette; i++) { for (int i = 0; i < num_palette; i++) {
final int ordinal = paletteToBlock[i]; int ordinal = paletteToBlock[i];
blockToPalette[ordinal] = Integer.MAX_VALUE; blockToPalette[ordinal] = Integer.MAX_VALUE;
final BlockState state = BlockTypesCache.states[ordinal]; final BlockState state = BlockTypesCache.states[ordinal];
final net.minecraft.world.level.block.state.BlockState blockState = ((PaperweightBlockMaterial) state.getMaterial()).getState(); palette.add(((PaperweightBlockMaterial) state.getMaterial()).getState());
blockStatePalettedContainer.idFor(blockState);
} }
} else {
palette = List.of();
} }
// Create palette with data
final PalettedContainer<net.minecraft.world.level.block.state.BlockState> blockStatePalettedContainer =
new PalettedContainer<>(
Block.BLOCK_STATE_REGISTRY,
PalettedContainer.Strategy.SECTION_STATES,
PalettedContainer.Strategy.SECTION_STATES.getConfiguration(Block.BLOCK_STATE_REGISTRY, bitsPerEntry),
nmsBits,
palette,
null,
null
);
LevelChunkSection levelChunkSection;
try { try {
fieldStorage.set(dataPaletteBlocks, nmsBits); //fieldStorage.set(dataPaletteBlocks, nmsBits);
fieldPalette.set(dataPaletteBlocks, blockStatePalettedContainer); //fieldPalette.set(dataPaletteBlocks, blockStatePalettedContainer);
fieldBits.set(dataPaletteBlocks, bitsPerEntry); if (biomes == null) {
biomes = new PalettedContainer<>(
biomeRegistry,
biomeRegistry.getOrThrow(Biomes.PLAINS),
PalettedContainer.Strategy.SECTION_BIOMES,
null
);
}
levelChunkSection = new LevelChunkSection(layer, blockStatePalettedContainer, biomes);
setCount(ticking_blocks.size(), 4096 - air, levelChunkSection); setCount(ticking_blocks.size(), 4096 - air, levelChunkSection);
if (!fastmode) { if (!fastmode) {
ticking_blocks.forEach((pos, ordinal) -> levelChunkSection ticking_blocks.forEach((pos, ordinal) -> levelChunkSection.setBlockState(
.setBlockState(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), pos.getBlockX(),
pos.getBlockY(),
pos.getBlockZ(),
Block.stateById(ordinal) Block.stateById(ordinal)
)); ));
} }
@ -381,8 +406,123 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
} }
private static LevelChunkSection newChunkSection(int layer) { private static LevelChunkSection newChunkSection(
return new LevelChunkSection(layer); int layer, Registry<Biome> biomeRegistry,
@Nullable PalettedContainer<Biome> biomes
) {
PalettedContainer<net.minecraft.world.level.block.state.BlockState> dataPaletteBlocks = new PalettedContainer<>(
Block.BLOCK_STATE_REGISTRY,
Blocks.AIR.defaultBlockState(),
PalettedContainer.Strategy.SECTION_STATES,
null
);
PalettedContainer<Biome> biomesPalette = biomes != null ? biomes : new PalettedContainer<>(
biomeRegistry,
biomeRegistry.getOrThrow(Biomes.PLAINS),
PalettedContainer.Strategy.SECTION_BIOMES,
null
);
return new LevelChunkSection(layer, dataPaletteBlocks, biomesPalette);
}
/**
* Create a new {@link PalettedContainer<Biome>}. Should only be used if no biome container existed beforehand.
*/
public static PalettedContainer<Biome> getBiomePalettedContainer(BiomeType[] biomes, Registry<Biome> biomeRegistry) {
if (biomes == null) {
return null;
}
// Don't stream this as typically will see 1-4 biomes; stream overhead is large for the small length
Map<BiomeType, Biome> palette = new HashMap<>();
for (BiomeType biomeType : new LinkedList<>(Arrays.asList(biomes))) {
Biome biome;
if (biomeType == null) {
biome = biomeRegistry.getOrThrow(Biomes.PLAINS);
} else {
biome = biomeRegistry.get(ResourceLocation.tryParse(biomeType.getId()));
}
palette.put(biomeType, biome);
}
int biomeCount = palette.size();
int bitsPerEntry = MathMan.log2nlz(biomeCount - 1);
Object configuration = PalettedContainer.Strategy.SECTION_STATES.getConfiguration(
new FakeIdMapBiome(biomeCount),
bitsPerEntry
);
if (bitsPerEntry > 3) {
bitsPerEntry = MathMan.log2nlz(biomeRegistry.size() - 1);
}
PalettedContainer<Biome> biomePalettedContainer = new PalettedContainer<>(
biomeRegistry,
biomeRegistry.getOrThrow(Biomes.PLAINS),
PalettedContainer.Strategy.SECTION_BIOMES,
null
);
final Palette<Biome> biomePalette;
if (bitsPerEntry == 0) {
biomePalette = new SingleValuePalette<>(
biomePalettedContainer.registry,
biomePalettedContainer,
new ArrayList<>(palette.values()) // Must be modifiable
);
} else if (bitsPerEntry == 4) {
biomePalette = LinearPalette.create(
4,
biomePalettedContainer.registry,
biomePalettedContainer,
new ArrayList<>(palette.values()) // Must be modifiable
);
} else if (bitsPerEntry < 9) {
biomePalette = HashMapPalette.create(
bitsPerEntry,
biomePalettedContainer.registry,
biomePalettedContainer,
new ArrayList<>(palette.values()) // Must be modifiable
);
} else {
biomePalette = GlobalPalette.create(
bitsPerEntry,
biomePalettedContainer.registry,
biomePalettedContainer,
null // unused
);
}
int bitsPerEntryNonZero = Math.max(bitsPerEntry, 1); // We do want to use zero sometimes
final int blocksPerLong = MathMan.floorZero((double) 64 / bitsPerEntryNonZero);
final int arrayLength = MathMan.ceilZero(64f / blocksPerLong);
BitStorage bitStorage = bitsPerEntry == 0 ? new ZeroBitStorage(64) : new SimpleBitStorage(
bitsPerEntry,
64,
new long[arrayLength]
);
try {
Object data = dataConstructor.newInstance(configuration, bitStorage, biomePalette);
fieldData.set(biomePalettedContainer, data);
int index = 0;
for (int y = 0; y < 4; y++) {
for (int z = 0; z < 4; z++) {
for (int x = 0; x < 4; x++, index++) {
BiomeType biomeType = biomes[index];
if (biomeType == null) {
continue;
}
Biome biome = biomeRegistry.get(ResourceLocation.tryParse(biomeType.getId()));
if (biome == null) {
continue;
}
biomePalettedContainer.set(x, y, z, biome);
}
}
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
return biomePalettedContainer;
} }
public static void setCount(final int tickingBlockCount, final int nonEmptyBlockCount, final LevelChunkSection section) throws public static void setCount(final int tickingBlockCount, final int nonEmptyBlockCount, final LevelChunkSection section) throws
@ -392,15 +532,6 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
fieldNonEmptyBlockCount.setShort(section, (short) nonEmptyBlockCount); fieldNonEmptyBlockCount.setShort(section, (short) nonEmptyBlockCount);
} }
public static Biome[] getBiomeArray(ChunkBiomeContainer chunkBiomeContainer) {
try {
return (Biome[]) fieldBiomes.get(chunkBiomeContainer);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
public static BiomeType adapt(Biome biome, LevelAccessor levelAccessor) { public static BiomeType adapt(Biome biome, LevelAccessor levelAccessor) {
ResourceLocation resourceLocation = levelAccessor.registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getKey( ResourceLocation resourceLocation = levelAccessor.registryAccess().ownedRegistryOrThrow(Registry.BIOME_REGISTRY).getKey(
biome); biome);
@ -415,6 +546,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
static void removeBeacon(BlockEntity beacon, LevelChunk levelChunk) { static void removeBeacon(BlockEntity beacon, LevelChunk levelChunk) {
try { try {
// Do the method ourselves to avoid trying to reflect generic method parameters // Do the method ourselves to avoid trying to reflect generic method parameters
// similar to removeGameEventListener
if (levelChunk.loaded || levelChunk.level.isClientSide()) { if (levelChunk.loaded || levelChunk.level.isClientSide()) {
BlockEntity blockEntity = levelChunk.blockEntities.remove(beacon.getBlockPos()); BlockEntity blockEntity = levelChunk.blockEntities.remove(beacon.getBlockPos());
if (blockEntity != null) { if (blockEntity != null) {
@ -446,4 +578,68 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
} }
} }
static class FakeIdMapBlock implements IdMap<net.minecraft.world.level.block.state.BlockState> {
private final int size;
FakeIdMapBlock(int size) {
this.size = size;
}
@Override
public int getId(final net.minecraft.world.level.block.state.BlockState entry) {
return 0;
}
@Nullable
@Override
public net.minecraft.world.level.block.state.BlockState byId(final int index) {
return null;
}
@Override
public int size() {
return size;
}
@NotNull
@Override
public Iterator<net.minecraft.world.level.block.state.BlockState> iterator() {
return Collections.emptyIterator();
}
}
static class FakeIdMapBiome implements IdMap<Biome> {
private final int size;
FakeIdMapBiome(int size) {
this.size = size;
}
@Override
public int getId(final Biome entry) {
return 0;
}
@Nullable
@Override
public Biome byId(final int index) {
return null;
}
@Override
public int size() {
return size;
}
@NotNull
@Override
public Iterator<Biome> iterator() {
return Collections.emptyIterator();
}
}
} }

View File

@ -94,8 +94,9 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag {
public List<Tag> getList(String key) { public List<Tag> getList(String key) {
net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key);
if (tag instanceof net.minecraft.nbt.ListTag nbtList) { if (tag instanceof net.minecraft.nbt.ListTag) {
ArrayList<Tag> list = new ArrayList<>(); ArrayList<Tag> list = new ArrayList<>();
net.minecraft.nbt.ListTag nbtList = (net.minecraft.nbt.ListTag) tag;
for (net.minecraft.nbt.Tag elem : nbtList) { for (net.minecraft.nbt.Tag elem : nbtList) {
if (elem instanceof net.minecraft.nbt.CompoundTag) { if (elem instanceof net.minecraft.nbt.CompoundTag) {
list.add(new PaperweightLazyCompoundTag((net.minecraft.nbt.CompoundTag) elem)); list.add(new PaperweightLazyCompoundTag((net.minecraft.nbt.CompoundTag) elem));

View File

@ -102,7 +102,6 @@ dependencies {
compileOnly(libs.protocollib) { isTransitive = false } compileOnly(libs.protocollib) { isTransitive = false }
compileOnly(libs.plotsquaredV6Bukkit) { isTransitive = false } compileOnly(libs.plotsquaredV6Bukkit) { isTransitive = false }
compileOnly(libs.plotsquaredV6Core) { isTransitive = false } compileOnly(libs.plotsquaredV6Core) { isTransitive = false }
compileOnly(libs.plotsquaredV4) { isTransitive = false }
// Third party // Third party
compileOnly(libs.flowmath) { compileOnly(libs.flowmath) {

View File

@ -310,14 +310,12 @@ public class FaweBukkit implements IFawe, Listener {
if (plotSquared == null) { if (plotSquared == null) {
return; return;
} }
if (plotSquared.getClass().getPackage().toString().contains("intellectualsites")) { if (PlotSquared.get().getVersion().version[0] == 6) {
WEManager.IMP.addManager(new com.fastasyncworldedit.bukkit.regions.plotsquaredv4.PlotSquaredFeature());
LOGGER.info("Plugin 'PlotSquared' found. Using it now.");
} else if (PlotSquared.get().getVersion().version[0] == 6) {
WEManager.IMP.addManager(new com.fastasyncworldedit.bukkit.regions.plotsquared.PlotSquaredFeature()); WEManager.IMP.addManager(new com.fastasyncworldedit.bukkit.regions.plotsquared.PlotSquaredFeature());
LOGGER.info("Plugin 'PlotSquared' found. Using it now."); LOGGER.info("Plugin 'PlotSquared' v6 found. Using it now.");
} else { } else {
LOGGER.error("Incompatible version of PlotSquared found. Please use PlotSquared v6."); LOGGER.error("Incompatible version of PlotSquared found. Please use PlotSquared v6.");
LOGGER.info("https://www.spigotmc.org/resources/77506/");
} }
} }

View File

@ -59,7 +59,7 @@ public interface IDelegateBukkitImplAdapter<T> extends BukkitImplAdapter<T> {
} }
@Override @Override
default BaseBlock getBlock(Location location) { default BlockState getBlock(Location location) {
return getParent().getBlock(location); return getParent().getBlock(location);
} }

View File

@ -4,7 +4,6 @@ import com.fastasyncworldedit.core.FAWEPlatformAdapterImpl;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -24,8 +23,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
int num_palette = 0; int num_palette = 0;
for (int i = 0; i < 4096; i++) { for (int i = 0; i < 4096; i++) {
char ordinal = set[i]; char ordinal = set[i];
if (ordinal == BlockID.__RESERVED__) { if (ordinal == 0) {
ordinal = BlockID.AIR; ordinal = 1;
} }
int palette = blockToPalette[ordinal]; int palette = blockToPalette[ordinal];
if (palette == Integer.MAX_VALUE) { if (palette == Integer.MAX_VALUE) {
@ -43,17 +42,17 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
} }
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length); System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
} }
char lastOrdinal = BlockID.__RESERVED__; char lastOrdinal = 0;
boolean lastticking = false; boolean lastticking = false;
boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED; boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED;
for (int i = 0; i < 4096; i++) { for (int i = 0; i < 4096; i++) {
char ordinal = set[i]; char ordinal = set[i];
switch (ordinal) { switch (ordinal) {
case BlockID.__RESERVED__: case 0:
ordinal = BlockID.AIR; ordinal = 1;
case BlockID.AIR: case 1:
case BlockID.CAVE_AIR: case 2:
case BlockID.VOID_AIR: case 3:
air++; air++;
break; break;
default: default:
@ -95,13 +94,13 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
char[] getArr = null; char[] getArr = null;
for (int i = 0; i < 4096; i++) { for (int i = 0; i < 4096; i++) {
char ordinal = set[i]; char ordinal = set[i];
if (ordinal == BlockID.__RESERVED__) { if (ordinal == 0) {
if (getArr == null) { if (getArr == null) {
getArr = get.apply(layer); getArr = get.apply(layer);
} }
ordinal = getArr[i]; ordinal = getArr[i];
if (ordinal == BlockID.__RESERVED__) { if (ordinal == 0) {
ordinal = BlockID.AIR; ordinal = 1;
} }
} }
int palette = blockToPalette[ordinal]; int palette = blockToPalette[ordinal];
@ -120,24 +119,24 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
} }
System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length); System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length);
} }
char lastOrdinal = BlockID.__RESERVED__; char lastOrdinal = 0;
boolean lastticking = false; boolean lastticking = false;
boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED; boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED;
boolean tick_existing = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_EXISTING; boolean tick_existing = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_EXISTING;
for (int i = 0; i < 4096; i++) { for (int i = 0; i < 4096; i++) {
char ordinal = set[i]; char ordinal = set[i];
switch (ordinal) { switch (ordinal) {
case BlockID.__RESERVED__: { case 0: {
if (getArr == null) { if (getArr == null) {
getArr = get.apply(layer); getArr = get.apply(layer);
} }
ordinal = getArr[i]; ordinal = getArr[i];
switch (ordinal) { switch (ordinal) {
case BlockID.__RESERVED__: case 0:
ordinal = BlockID.AIR; ordinal = 1;
case BlockID.AIR: case 1:
case BlockID.CAVE_AIR: case 2:
case BlockID.VOID_AIR: case 3:
air++; air++;
break; break;
default: default:
@ -164,9 +163,9 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl {
set[i] = ordinal; set[i] = ordinal;
break; break;
} }
case BlockID.AIR: case 1:
case BlockID.CAVE_AIR: case 2:
case BlockID.VOID_AIR: case 3:
air++; air++;
break; break;
} }

View File

@ -4,9 +4,6 @@ import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.regions.FaweMask; import com.fastasyncworldedit.core.regions.FaweMask;
import com.fastasyncworldedit.core.regions.FaweMaskManager; import com.fastasyncworldedit.core.regions.FaweMaskManager;
import com.fastasyncworldedit.core.regions.filter.RegionFilter;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -62,6 +59,15 @@ public class PlotSquaredFeature extends FaweMaskManager {
*/ */
} }
/**
* Whether the player is allowed to use FAWE on a PlotSquared plot.
*
* @param player the {@link Player}
* @param plot the {@link Plot}
* @param type the {@link MaskType}
* @return {@code true} if the player is the plot owner, trusted, has the permission fawe.plotsquared.member
* or fawe.plotsquared.admin and the NoWorldeditFlag is not set; otherwise {@code false}
*/
public boolean isAllowed(Player player, Plot plot, MaskType type) { public boolean isAllowed(Player player, Plot plot, MaskType type) {
if (plot == null) { if (plot == null) {
return false; return false;

View File

@ -1,172 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import java.util.concurrent.CompletableFuture;
import static org.bukkit.Bukkit.getWorld;
public class FaweChunkManager extends ChunkManager {
private final ChunkManager parent;
public FaweChunkManager(ChunkManager parent) {
this.parent = parent;
}
@Override
public int[] countEntities(Plot plot) {
return parent.countEntities(plot);
}
@Override
public CompletableFuture loadChunk(String world, BlockVector2 loc, boolean force) {
return parent.loadChunk(world, loc, force);
}
@Override
public void unloadChunk(String world, BlockVector2 loc, boolean save) {
parent.unloadChunk(world, loc, save);
}
@Override
public void clearAllEntities(Location pos1, Location pos2) {
parent.clearAllEntities(pos1, pos2);
}
@Override
public void swap(
final Location pos1,
final Location pos2,
final Location pos3,
final Location pos4,
final Runnable whenDone
) {
if (!Settings.IMP.PLOTSQUARED_INTEGRATION.COPY_AND_SWAP) {
parent.swap(pos1, pos2, pos3, pos4, whenDone);
}
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
//todo because of the following code this should proably be in the Bukkit module
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
EditSession sessionA = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build();
EditSession sessionB = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build();
CuboidRegion regionA = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())
);
CuboidRegion regionB = new CuboidRegion(
BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()),
BlockVector3.at(pos4.getX(), pos4.getY(), pos4.getZ())
);
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
try {
Operations.completeLegacy(copyA);
Operations.completeLegacy(copyB);
sessionA.flushQueue();
sessionB.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
});
}
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
if (!Settings.IMP.PLOTSQUARED_INTEGRATION.COPY_AND_SWAP) {
return parent.copyRegion(pos1, pos2, pos3, whenDone);
}
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
EditSession from = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build();
EditSession to = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build();
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())
);
ForwardExtentCopy copy = new ForwardExtentCopy(
from,
region,
to,
BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ())
);
try {
Operations.completeLegacy(copy);
to.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
}
TaskManager.IMP.task(whenDone);
});
return true;
}
@Override
public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
try (EditSession editSession = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(pos1World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build()) {
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())
);
editSession.regenerate(region);
editSession.flushQueue();
}
TaskManager.IMP.task(whenDone);
}
});
return true;
}
}

View File

@ -1,131 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.queue.IQueueChunk;
import com.fastasyncworldedit.core.queue.IQueueExtent;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
// TODO FIXME
public class FaweLocalBlockQueue extends LocalBlockQueue {
public final IQueueExtent<IQueueChunk> instance;
private final World world;
private final BlockVector3 mutable = new MutableBlockVector3();
public FaweLocalBlockQueue(String worldName) {
super(worldName);
this.world = FaweAPI.getWorld(worldName);
instance = Fawe.get().getQueueHandler().getQueue(world);
Fawe.get().getQueueHandler().unCache();
}
@Override
public boolean next() {
if (!instance.isEmpty()) {
instance.flush();
}
return false;
}
@Override
public void startSet(boolean parallel) {
Fawe.get().getQueueHandler().startSet(parallel);
}
@Override
public void endSet(boolean parallel) {
Fawe.get().getQueueHandler().endSet(parallel);
}
@Override
public int size() {
return instance.isEmpty() ? 0 : 1;
}
@Override
public void optimize() {
}
@Override
public void setModified(long l) {
}
@Override
public long getModified() {
return instance.size();
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BlockState id) {
return instance.setBlock(x, y, z, id);
}
@Override
public boolean setBlock(int x, int y, int z, Pattern pattern) {
mutable.setComponents(x, y, z);
return pattern.apply(instance, mutable, mutable);
}
@Override
public boolean setBlock(final int x, final int y, final int z, final BaseBlock id) {
return instance.setBlock(x, y, z, id);
}
@Override
public BlockState getBlock(int x, int y, int z) {
return instance.getBlock(x, y, z);
}
@Override
public boolean setBiome(int x, int z, BiomeType biomeType) {
return instance.setBiome(x, 0, z, biomeType);
}
@Override
public String getWorld() {
return world.getId();
}
@Override
public void flush() {
instance.flush();
}
@Override
public boolean enqueue() {
boolean val = super.enqueue();
instance.enableQueue();
return val;
}
@Override
public void refreshChunk(int x, int z) {
world.refreshChunk(x, z);
}
@Override
public void fixChunkLighting(int x, int z) {
}
@Override
public void regenChunk(int x, int z) {
instance.regenerateChunk(x, z, null, null);
}
@Override
public boolean setTile(int x, int y, int z, CompoundTag tag) {
instance.setTile(x, y, z, (com.sk89q.jnbt.CompoundTag) FaweCache.IMP.asTag(tag));
return true;
}
}

View File

@ -1,154 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter;
import com.fastasyncworldedit.core.jnbt.CompressedCompoundTag;
import com.fastasyncworldedit.core.jnbt.CompressedSchematicTag;
import com.fastasyncworldedit.core.util.IOUtil;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World;
import net.jpountz.lz4.LZ4BlockInputStream;
import org.anarres.parallelgzip.ParallelGZIPOutputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import static org.bukkit.Bukkit.getWorld;
public class FaweSchematicHandler extends SchematicHandler {
@Override
public boolean restoreTile(LocalBlockQueue queue, CompoundTag compoundTag, int x, int y, int z) {
if (queue instanceof FaweLocalBlockQueue) {
queue.setTile(x, y, z, compoundTag);
return true;
}
return false;
}
@Override
public void getCompoundTag(final String world, final Set<CuboidRegion> regions, final RunnableVal<CompoundTag> whenDone) {
TaskManager.IMP.async(() -> {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
World adaptedWorld = BukkitAdapter.adapt(getWorld(world));
final CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())
);
final EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(adaptedWorld)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region, false, true);
Clipboard holder = new BlockArrayClipboard(region, clipboard);
CompressedSchematicTag tag = new CompressedSchematicTag(holder);
whenDone.run(tag);
});
}
@Override
public boolean save(CompoundTag tag, String path) {
if (tag == null) {
PlotSquared.debug("&cCannot save empty tag");
return false;
}
try {
File tmp = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), path);
tmp.getParentFile().mkdirs();
if (tag instanceof CompressedCompoundTag) {
CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
if (cTag instanceof CompressedSchematicTag) {
Clipboard clipboard = (Clipboard) cTag.getSource();
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new BufferedOutputStream(
new ParallelGZIPOutputStream(stream)))) {
new FastSchematicWriter(output).write(clipboard);
}
} else {
try (OutputStream stream = new FileOutputStream(tmp); BufferedOutputStream output = new BufferedOutputStream(
new ParallelGZIPOutputStream(stream))) {
LZ4BlockInputStream is = cTag.adapt(cTag.getSource());
IOUtil.copy(is, stream);
}
}
} else {
try (OutputStream stream = new FileOutputStream(tmp); NBTOutputStream output = new NBTOutputStream(new ParallelGZIPOutputStream(
stream))) {
Map<String, Tag> map = tag.getValue();
output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
if (tag == null) {
PlotSquared.debug("&cCannot save empty tag");
com.github.intellectualsites.plotsquared.plot.util.TaskManager.runTask(whenDone);
return;
}
CompoundTag weTag = (CompoundTag) FaweCache.IMP.asTag(tag);
if (weTag instanceof CompressedSchematicTag) {
Clipboard clipboard = ((CompressedSchematicTag) weTag).getSource();
URL url = FaweAPI.upload(clipboard, BuiltInClipboardFormat.SPONGE_SCHEMATIC);
whenDone.run(url);
return;
}
MainUtil.upload(uuid, file, "schem", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {
try (ParallelGZIPOutputStream gzip = new ParallelGZIPOutputStream(output)) {
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
Map<String, Tag> map = weTag.getValue();
nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
}

View File

@ -1,58 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.commands.SubCommand;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
@CommandDeclaration(
command = "trimchunks",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
requiredType = RequiredType.PLAYER,
category = CommandCategory.ADMINISTRATION)
public class FaweTrim extends SubCommand {
private boolean ran = false;
@Override
public boolean onCommand(final PlotPlayer plotPlayer, final String[] strings) {
if (ran) {
plotPlayer.sendMessage("Already running!");
return false;
}
if (strings.length != 2) {
plotPlayer.sendMessage(
"First make a backup of your world called <world-copy> then stand in the middle of an empty plot");
plotPlayer.sendMessage("use /plot trimall <world> <boolean-delete-unowned>");
return false;
}
if (!WorldUtil.IMP.isWorld(strings[0])) {
Captions.NOT_VALID_PLOT_WORLD.send(plotPlayer, strings[0]);
return false;
}
ran = true;
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
try {
// TODO NOT IMPLEMENTED
// PlotTrim trim = new PlotTrim(plotPlayer, plotPlayer.getPlotAreaAbs(), strings[0], Boolean.parseBoolean(strings[1]));
// Location loc = plotPlayer.getLocation();
// trim.setChunk(loc.getX() >> 4, loc.getZ() >> 4);
// trim.run();
// plotPlayer.sendMessage("Done!");
} catch (Throwable e) {
e.printStackTrace();
}
ran = false;
}
});
return true;
}
}

View File

@ -1,105 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.bukkit.Bukkit;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
@CommandDeclaration(
command = "generatebiome",
permission = "plots.generatebiome",
category = CommandCategory.APPEARANCE,
requiredType = RequiredType.NONE,
description = "Generate a biome in your plot",
aliases = {"bg", "gb"},
usage = "/plots generatebiome <biome>"
)
public class PlotSetBiome extends Command {
public PlotSetBiome() {
super(MainCommand.getInstance(), true);
}
@Override
public CompletableFuture<Boolean> execute(
final PlotPlayer player,
String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone
) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
checkTrue(plot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, "plots.admin.command.generatebiome"), Captions.NO_PLOT_PERMS);
if (plot.getRunning() != 0) {
Captions.WAIT_FOR_TIMER.send(player);
return null;
}
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final Set<CuboidRegion> regions = plot.getRegions();
BiomeRegistry biomeRegistry = WorldEdit
.getInstance()
.getPlatformManager()
.queryCapability(Capability.GAME_HOOKS)
.getRegistries()
.getBiomeRegistry();
Collection<BiomeType> knownBiomes = BiomeTypes.values();
final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
if (biome == null) {
String biomes = StringMan
.join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.getTranslated());
Captions.NEED_BIOME.send(player);
MainUtil.sendMessage(player, Captions.SUBCOMMAND_SET_OPTIONS_HEADER + biomes);
return CompletableFuture.completedFuture(false);
}
confirm.run(this, () -> {
if (plot.getRunning() != 0) {
Captions.WAIT_FOR_TIMER.send(player);
return;
}
plot.addRunning();
TaskManager.IMP.async(() -> {
EditSession session = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(Bukkit.getWorld(
plot.getArea().worldname)))
.checkMemory(false)
.allowedRegionsEverywhere()
.actor(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID())))
.limitUnlimited()
.build();
long seed = ThreadLocalRandom.current().nextLong();
for (CuboidRegion region : regions) {
session.regenerate(region, biome, seed);
}
session.flushQueue();
plot.removeRunning();
});
}, null);
return CompletableFuture.completedFuture(true);
}
}

View File

@ -1,225 +0,0 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.regions.FaweMask;
import com.fastasyncworldedit.core.regions.FaweMaskManager;
import com.fastasyncworldedit.core.regions.RegionWrapper;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection;
import com.sk89q.worldedit.world.World;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class PlotSquaredFeature extends FaweMaskManager {
private static final Logger LOGGER = LogManagerCompat.getLogger();
public PlotSquaredFeature() {
super("PlotSquared");
LOGGER.info("Optimizing PlotSquared");
if (com.fastasyncworldedit.core.configuration.Settings.IMP.ENABLED_COMPONENTS.PLOTSQUARED_V4_HOOK) {
Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS = false;
try {
setupBlockQueue();
setupSchematicHandler();
setupChunkManager();
} catch (Throwable ignored) {
LOGGER.info("Please update PlotSquared: https://www.spigotmc.org/resources/77506/");
}
if (Settings.PLATFORM.toLowerCase(Locale.ROOT).startsWith("bukkit")) {
new FaweTrim();
}
if (MainCommand.getInstance().getCommand("generatebiome") == null) {
new PlotSetBiome();
}
}
// TODO: revisit this later on
/*
try {
if (Settings.Enabled_Components.WORLDS) {
new ReplaceAll();
}
} catch (Throwable e) {
log.debug("You need to update PlotSquared to access the CFI and REPLACEALL commands");
}
*/
}
public static String getName(UUID uuid) {
return UUIDHandler.getName(uuid);
}
private void setupBlockQueue() throws RuntimeException {
// If it's going to fail, throw an error now rather than later
//QueueProvider provider = QueueProvider.of(FaweLocalBlockQueue.class, null);
//GlobalBlockQueue.IMP.setProvider(provider);
//HybridPlotManager.REGENERATIVE_CLEAR = false;
//log.debug(" - QueueProvider: " + FaweLocalBlockQueue.class);
//log.debug(" - HybridPlotManager.REGENERATIVE_CLEAR: " + HybridPlotManager.REGENERATIVE_CLEAR);
}
private void setupChunkManager() throws RuntimeException {
ChunkManager.manager = new FaweChunkManager(ChunkManager.manager);
LOGGER.info(" - ChunkManager: {}", ChunkManager.manager);
}
private void setupSchematicHandler() throws RuntimeException {
SchematicHandler.manager = new FaweSchematicHandler();
LOGGER.info(" - SchematicHandler: {}", SchematicHandler.manager);
}
public boolean isAllowed(Player player, Plot plot, MaskType type) {
if (plot == null) {
return false;
}
UUID uid = player.getUniqueId();
if (Flags.NO_WORLDEDIT.isTrue(plot)) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.noworldeditflag")
));
return false;
}
if (plot.isOwner(uid) || player.hasPermission("fawe.plotsquared.admin")) {
return true;
}
if (type != MaskType.MEMBER) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.only")
));
return false;
}
if (plot.getTrusted().contains(uid) || plot.getTrusted().contains(DBFunc.EVERYONE)) {
return true;
}
if (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE)) {
if (!player.hasPermission("fawe.plotsquared.member")) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.error.no-perm", "fawe.plotsquared.member")
));
return false;
}
if (!plot.getOwners().isEmpty() && plot.getOwners().stream().anyMatch(this::playerOnline)) {
return true;
} else {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.offline")
));
return false;
}
}
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.not.added")
));
return false;
}
private boolean playerOnline(UUID uuid) {
if (uuid == null) {
return false;
}
org.bukkit.entity.Player player = Bukkit.getPlayer(uuid);
return player != null && player.isOnline();
}
@Override
public FaweMask getMask(Player player, MaskType type) {
final PlotPlayer pp = PlotPlayer.wrap(player.getUniqueId());
if (pp == null) {
return null;
}
final Set<CuboidRegion> regions;
Plot plot = pp.getCurrentPlot();
if (isAllowed(player, plot, type)) {
regions = plot.getRegions();
} else {
plot = null;
regions = WEManager.getMask(pp);
if (regions.size() == 1) {
CuboidRegion region = regions.iterator().next();
if (region.getMinimumPoint().getX() == Integer.MIN_VALUE && region
.getMaximumPoint()
.getX() == Integer.MAX_VALUE) {
regions.clear();
}
}
}
if (regions.isEmpty()) {
return null;
}
PlotArea area = pp.getApplicablePlotArea();
int min = area != null ? area.MIN_BUILD_HEIGHT : 0;
int max = area != null ? Math.min(255, area.MAX_BUILD_HEIGHT) : 255;
final HashSet<RegionWrapper> faweRegions = new HashSet<>();
for (CuboidRegion current : regions) {
faweRegions.add(new RegionWrapper(
current.getMinimumX(),
current.getMaximumX(),
min,
max,
current.getMinimumZ(),
current.getMaximumZ()
));
}
final CuboidRegion region = regions.iterator().next();
final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
final Plot finalPlot = plot;
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(finalPlot) || regions.isEmpty()) {
return null;
}
Region maskedRegion;
if (regions.size() == 1) {
maskedRegion = new CuboidRegion(pos1, pos2);
} else {
World world = FaweAPI.getWorld(area.worldname);
List<Region> weRegions = regions.stream()
.map(r -> new CuboidRegion(
world,
BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()),
BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ())
))
.collect(Collectors.toList());
maskedRegion = new RegionIntersection(world, weRegions);
}
return new FaweMask(maskedRegion) {
@Override
public boolean isValid(Player player, MaskType type) {
if (Settings.Done.RESTRICT_BUILDING && Flags.DONE.isSet(finalPlot)) {
return false;
}
return isAllowed(player, finalPlot, type);
}
};
}
}

View File

@ -520,7 +520,7 @@ public class BukkitWorld extends AbstractWorld {
public BaseBlock getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) { if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); return adapter.getFullBlock(BukkitAdapter.adapt(getWorld(), position));
} else { } else {
return getBlock(position).toBaseBlock(); return getBlock(position).toBaseBlock();
} }

View File

@ -138,12 +138,12 @@ public class WorldEditPlugin extends JavaPlugin {
platform = new BukkitServerInterface(this, getServer()); platform = new BukkitServerInterface(this, getServer());
worldEdit.getPlatformManager().register(platform); worldEdit.getPlatformManager().register(platform);
//FAWE start - Rename config to config-legacy.yml TODO: Chose a better name in the future //FAWE start - Migrate from config-legacy to worldedit-config
createDefaultConfiguration("config-legacy.yml"); // Create the default configuration file for WorldEdit, for us it's 'config-legacy.yml' migrateLegacyConfig();
//FAWE end //FAWE end
//FAWE start - Modify WorldEdit config name //FAWE start - Modify WorldEdit config name
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config-legacy.yml"), true), this); config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "worldedit-config.yml"), true), this);
//FAWE end //FAWE end
//FAWE start - Setup permission attachments //FAWE start - Setup permission attachments
@ -422,6 +422,19 @@ public class WorldEditPlugin extends JavaPlugin {
} }
} }
private void migrateLegacyConfig() {
File legacy = new File(getDataFolder(), "config-legacy.yml");
if (legacy.exists()) {
try {
legacy.renameTo(new File(getDataFolder(), "worldedit-config.yml"));
LOGGER.info("Migrated config-legacy.yml to worldedit-config.yml");
} catch (Exception e) {
LOGGER.error("Unable to rename legacy config file", e);
}
}
createDefaultConfiguration("worldedit-config.yml");
}
private void copyDefaultConfig(InputStream input, File actual, String name) { private void copyDefaultConfig(InputStream input, File actual, String name) {
try (FileOutputStream output = new FileOutputStream(actual)) { try (FileOutputStream output = new FileOutputStream(actual)) {
byte[] buf = new byte[8192]; byte[] buf = new byte[8192];

View File

@ -106,7 +106,15 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param location the location * @param location the location
* @return the block * @return the block
*/ */
BaseBlock getBlock(Location location); BlockState getBlock(Location location);
/**
* Get the block at the given location.
*
* @param location the location
* @return the block
*/
BaseBlock getFullBlock(Location location);
/** /**
* Create a {@link WorldNativeAccess} for the given world reference. * Create a {@link WorldNativeAccess} for the given world reference.

View File

@ -10,7 +10,7 @@
# in categories, like "max-blocks-changed", are placed in the "limits" # in categories, like "max-blocks-changed", are placed in the "limits"
# category. # category.
# - If you want to check the format of this file before putting it # - If you want to check the format of this file before putting it
# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/ # into WorldEdit, paste it into https://yaml-online-parser.appspot.com/
# and see if it gives you "ERROR:". # and see if it gives you "ERROR:".
# - Lines starting with # are comments, so they are ignored. # - Lines starting with # are comments, so they are ignored.
# - If you want to allow blocks, make sure to change "disallowed-blocks" to [] # - If you want to allow blocks, make sure to change "disallowed-blocks" to []

View File

@ -118,6 +118,11 @@ public class StubServer implements Server {
return 0; return 0;
} }
@Override
public int getSimulationDistance() {
return 12;
}
@Override @Override
public @NotNull public @NotNull
String getIp() { String getIp() {
@ -465,6 +470,11 @@ public class StubServer implements Server {
} }
@Override
public boolean getHideOnlinePlayers() {
return false;
}
@Override @Override
public boolean getOnlineMode() { public boolean getOnlineMode() {
return false; return false;

View File

@ -12,7 +12,7 @@ applyPlatformAndCoreConfiguration()
dependencies { dependencies {
constraints { constraints {
implementation("org.yaml:snakeyaml") { implementation("org.yaml:snakeyaml") {
version { strictly("1.28") } version { strictly("1.30") }
because("Bukkit provides SnakeYaml") because("Bukkit provides SnakeYaml")
} }
} }
@ -37,7 +37,6 @@ dependencies {
// Plugins // Plugins
compileOnly(libs.redprotect) { isTransitive = false } compileOnly(libs.redprotect) { isTransitive = false }
compileOnly(libs.plotsquaredV4) { isTransitive = false }
compileOnly(libs.plotsquaredV6Core) { isTransitive = false } compileOnly(libs.plotsquaredV6Core) { isTransitive = false }
// ensure this is on the classpath for the AP // ensure this is on the classpath for the AP

View File

@ -63,8 +63,6 @@ public class Settings extends Config {
@Create @Create
public WEB WEB; public WEB WEB;
@Create @Create
public PLOTSQUARED_INTEGRATION PLOTSQUARED_INTEGRATION;
@Create
public EXTENT EXTENT; public EXTENT EXTENT;
@Create @Create
public EXPERIMENTAL EXPERIMENTAL; public EXPERIMENTAL EXPERIMENTAL;
@ -219,7 +217,7 @@ public class Settings extends Config {
}) })
public List<String> STRIP_NBT = new ArrayList<>(); public List<String> STRIP_NBT = new ArrayList<>();
@Comment({ @Comment({
"If the disallowed blocks listed in config-legacy.yml should be disallowed in all edits,", "If the disallowed blocks listed in worldedit-config.yml should be disallowed in all edits,",
"not just where blocks patterns are used.", "not just where blocks patterns are used.",
" - Can prevent blocks being pasted from clipboards, etc.", " - Can prevent blocks being pasted from clipboards, etc.",
" - If fast-placement is disabled, this may cause edits to be slower." " - If fast-placement is disabled, this may cause edits to be slower."
@ -486,17 +484,6 @@ public class Settings extends Config {
} }
public static class PLOTSQUARED_INTEGRATION {
@Comment({
"Only disables/enables the components with PlotSquared v4.",
"For v6, see PlotSquared settings.yml"
})
public boolean CLEAR = true;
public boolean COPY_AND_SWAP = true;
}
public static class WEB { public static class WEB {
@Comment({ @Comment({

View File

@ -1,7 +1,6 @@
package com.fastasyncworldedit.core.function.generator; package com.fastasyncworldedit.core.function.generator;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
@ -237,11 +236,8 @@ public class CavesGen extends GenBase {
BlockState material = chunk.getBlock(bx + local_x, local_y, bz + local_z); BlockState material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
BlockState materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z); BlockState materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z);
BlockType blockType = material.getBlockType(); BlockType blockType = material.getBlockType();
switch (blockType.getInternalId()) { switch (blockType.getId()) {
case BlockID.MYCELIUM: case "minecraft:mycelium", "minecraft:grass_block" -> grassFound = true;
case BlockID.GRASS:
grassFound = true;
} }
if (this.isSuitableBlock(material, materialAbove)) { if (this.isSuitableBlock(material, materialAbove)) {
if (local_y - 1 < 10) { if (local_y - 1 < 10) {
@ -281,13 +277,13 @@ public class CavesGen extends GenBase {
} }
protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) { protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) {
switch (material.getBlockType().getInternalId()) { switch (material.getBlockType().getId()) {
case BlockID.AIR: case "minecraft:air":
case BlockID.CAVE_AIR: case "minecraft:cave_air":
case BlockID.VOID_AIR: case "minecraft:void_air":
case BlockID.WATER: case "minecraft:water":
case BlockID.LAVA: case "minecraft:lava":
case BlockID.BEDROCK: case "minecraft:bedrock":
return false; return false;
default: default:
return true; return true;

View File

@ -10,7 +10,6 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -187,7 +186,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
int xx = bx + x; int xx = bx + x;
int from = blocksGet[index]; int from = blocksGet[index];
if (from == 0) { if (from == 0) {
from = BlockID.AIR; from = 1;
} }
final int combinedFrom = from; final int combinedFrom = from;
final int combinedTo = blocksSet[index]; final int combinedTo = blocksSet[index];
@ -199,22 +198,23 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
} }
} }
BiomeType[] biomes = set.getBiomes(); BiomeType[][] biomes = set.getBiomes();
if (biomes != null) { if (biomes != null) {
int index = 0;
for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) { for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
if (!set.hasBiomes(layer)) { if (!set.hasBiomes(layer)) {
continue; continue;
} }
BiomeType[] biomeSection = biomes[layer - set.getMinSectionPosition()];
int index = 0;
int yy = layer << 4; int yy = layer << 4;
for (int y = 0; y < 4; y++) { for (int y = 0; y < 16; y+= 4) {
for (int z = 0; z < 4; z++) { for (int z = 0; z < 16; z+= 4) {
for (int x = 0; x < 4; x++, index++) { for (int x = 0; x < 16; x+= 4, index++) {
BiomeType newBiome = biomes[index]; BiomeType newBiome = biomeSection[index];
if (newBiome != null) { if (newBiome != null) {
BiomeType oldBiome = get.getBiomeType(x, y, z); BiomeType oldBiome = get.getBiomeType(x, yy + y, z);
if (oldBiome != newBiome) { if (oldBiome != newBiome) {
addBiomeChange(bx + (x << 2), yy + (y << 2), bz + (z << 2), oldBiome, newBiome); addBiomeChange(bx + x, yy + y, bz + z, oldBiome, newBiome);
} }
} }
} }

View File

@ -3,7 +3,6 @@ package com.fastasyncworldedit.core.queue;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream; import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream; import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
@ -116,11 +115,11 @@ public interface IBlocks extends Trimable {
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
char ordinal = ids[i]; char ordinal = ids[i];
switch (ordinal) { switch (ordinal) {
case BlockID.__RESERVED__: case 0:
case BlockID.CAVE_AIR: case 2:
case BlockID.VOID_AIR: case 3:
ids[i] = BlockID.AIR; ids[i] = 1;
case BlockID.AIR: case 1:
continue; continue;
default: default:
nonEmpty++; nonEmpty++;
@ -140,10 +139,10 @@ public interface IBlocks extends Trimable {
for (int i = 0; i < palette.paletteToBlockLength; i++) { for (int i = 0; i < palette.paletteToBlockLength; i++) {
int ordinal = palette.paletteToBlock[i]; int ordinal = palette.paletteToBlock[i];
switch (ordinal) { switch (ordinal) {
case BlockID.__RESERVED__: case 0:
case BlockID.CAVE_AIR: case 2:
case BlockID.VOID_AIR: case 3:
case BlockID.AIR: case 1:
sectionWriter.write(0); sectionWriter.write(0);
break; break;
default: default:

View File

@ -64,7 +64,7 @@ public interface IChunkSet extends IBlocks, OutputExtent {
* *
* @return Array of biomes set * @return Array of biomes set
*/ */
BiomeType[] getBiomes(); BiomeType[][] getBiomes();
default boolean hasBiomes() { default boolean hasBiomes() {
return getBiomes() != null; return getBiomes() != null;

View File

@ -161,7 +161,7 @@ public class BitSetBlocks implements IChunkSet {
} }
@Override @Override
public BiomeType[] getBiomes() { public BiomeType[][] getBiomes() {
return null; return null;
} }

View File

@ -33,7 +33,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
return POOL.poll(); return POOL.poll();
} }
public BiomeType[] biomes; public BiomeType[][] biomes;
public char[][] light; public char[][] light;
public char[][] skyLight; public char[][] skyLight;
public BlockVector3ChunkMap<CompoundTag> tiles; public BlockVector3ChunkMap<CompoundTag> tiles;
@ -54,17 +54,19 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
} }
@Override @Override
public BiomeType[] getBiomes() { public BiomeType[][] getBiomes() {
return biomes; return biomes;
} }
@Override @Override
public BiomeType getBiomeType(int x, int y, int z) { public BiomeType getBiomeType(int x, int y, int z) {
int layer;
if (biomes == null || (y >> 4) < minSectionPosition || (y >> 4) > maxSectionPosition) { if (biomes == null || (y >> 4) < minSectionPosition || (y >> 4) > maxSectionPosition) {
return null; return null;
} else if (biomes[(layer = (y >> 4) - minSectionPosition)] == null) {
return null;
} }
y -= minSectionPosition << 4; return biomes[layer][(y & 15) >> 2 | (z >> 2) << 2 | x >> 2];
return biomes[(y >> 2) << 4 | (z >> 2) << 2 | x >> 2];
} }
@Override @Override
@ -96,10 +98,14 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
public boolean setBiome(int x, int y, int z, BiomeType biome) { public boolean setBiome(int x, int y, int z, BiomeType biome) {
updateSectionIndexRange(y >> 4); updateSectionIndexRange(y >> 4);
y -= minSectionPosition << 4; y -= minSectionPosition << 4;
int layer = (y >> 4) - minSectionPosition;
if (biomes == null) { if (biomes == null) {
biomes = new BiomeType[64 * sectionCount]; biomes = new BiomeType[sectionCount][];
biomes[layer] = new BiomeType[64];
} else if (biomes[layer] == null) {
biomes[layer] = new BiomeType[64];
} }
biomes[(y >> 2) << 4 | (z >> 2) << 2 | x >> 2] = biome; biomes[layer][(y & 12) << 2 | (z & 12) | (x & 12) >> 2] = biome;
return true; return true;
} }
@ -312,7 +318,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
if (layer < 0 || layer >= sections.length) { if (layer < 0 || layer >= sections.length) {
return false; return false;
} }
return biomes != null; return biomes != null && biomes[layer] != null;
} }
@Override @Override
@ -344,7 +350,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
sectionLocks = tmpSectionLocks; sectionLocks = tmpSectionLocks;
minSectionPosition = layer; minSectionPosition = layer;
if (biomes != null) { if (biomes != null) {
BiomeType[] tmpBiomes = new BiomeType[sectionCount * 64]; BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
System.arraycopy(biomes, 0, tmpBiomes, 64 * diff, biomes.length); System.arraycopy(biomes, 0, tmpBiomes, 64 * diff, biomes.length);
biomes = tmpBiomes; biomes = tmpBiomes;
} }
@ -376,7 +382,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
sectionLocks = tmpSectionLocks; sectionLocks = tmpSectionLocks;
maxSectionPosition = layer; maxSectionPosition = layer;
if (biomes != null) { if (biomes != null) {
BiomeType[] tmpBiomes = new BiomeType[sectionCount * 64]; BiomeType[][] tmpBiomes = new BiomeType[sectionCount][64];
System.arraycopy(biomes, 0, tmpBiomes, 0, biomes.length); System.arraycopy(biomes, 0, tmpBiomes, 0, biomes.length);
biomes = tmpBiomes; biomes = tmpBiomes;
} }

View File

@ -96,7 +96,7 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
} }
@Override @Override
public BiomeType[] getBiomes() { public BiomeType[][] getBiomes() {
// Uses set as this method is only used to retrieve biomes that have been set to the extent/chunk. // Uses set as this method is only used to retrieve biomes that have been set to the extent/chunk.
return delegate.set(this).getBiomes(); return delegate.set(this).getBiomes();
} }

View File

@ -122,7 +122,7 @@ public final class NullChunk implements IQueueChunk {
} }
@Nullable @Nullable
public BiomeType[] getBiomes() { public BiomeType[][] getBiomes() {
return null; return null;
} }

View File

@ -18,8 +18,13 @@ public class PropertyKey implements Comparable<PropertyKey> {
// constants // constants
public static final PropertyKey AGE = getOrCreate("age"); public static final PropertyKey AGE = getOrCreate("age");
public static final PropertyKey ATTACHED = getOrCreate("attached"); public static final PropertyKey ATTACHED = getOrCreate("attached");
public static final PropertyKey ATTACHMENT = getOrCreate("attachement");
public static final PropertyKey AXIS = getOrCreate("axis"); public static final PropertyKey AXIS = getOrCreate("axis");
public static final PropertyKey BERRIES = getOrCreate("berries");
public static final PropertyKey BITES = getOrCreate("bites"); public static final PropertyKey BITES = getOrCreate("bites");
public static final PropertyKey BOTTOM = getOrCreate("bottom");
public static final PropertyKey CANDLES = getOrCreate("candles");
public static final PropertyKey CHARGES = getOrCreate("charges");
public static final PropertyKey CONDITIONAL = getOrCreate("conditional"); public static final PropertyKey CONDITIONAL = getOrCreate("conditional");
public static final PropertyKey DELAY = getOrCreate("delay"); public static final PropertyKey DELAY = getOrCreate("delay");
public static final PropertyKey DISARMED = getOrCreate("disarmed"); public static final PropertyKey DISARMED = getOrCreate("disarmed");
@ -33,17 +38,22 @@ public class PropertyKey implements Comparable<PropertyKey> {
public static final PropertyKey EYE = getOrCreate("eye"); public static final PropertyKey EYE = getOrCreate("eye");
public static final PropertyKey FACE = getOrCreate("face"); public static final PropertyKey FACE = getOrCreate("face");
public static final PropertyKey FACING = getOrCreate("facing"); public static final PropertyKey FACING = getOrCreate("facing");
public static final PropertyKey FALLING = getOrCreate("falling");
public static final PropertyKey HALF = getOrCreate("half"); public static final PropertyKey HALF = getOrCreate("half");
public static final PropertyKey HANGING = getOrCreate("hanging");
public static final PropertyKey HAS_BOOK = getOrCreate("has_book");
public static final PropertyKey HAS_BOTTLE_0 = getOrCreate("has_bottle_0"); public static final PropertyKey HAS_BOTTLE_0 = getOrCreate("has_bottle_0");
public static final PropertyKey HAS_BOTTLE_1 = getOrCreate("has_bottle_1"); public static final PropertyKey HAS_BOTTLE_1 = getOrCreate("has_bottle_1");
public static final PropertyKey HAS_BOTTLE_2 = getOrCreate("has_bottle_2"); public static final PropertyKey HAS_BOTTLE_2 = getOrCreate("has_bottle_2");
public static final PropertyKey HAS_RECORD = getOrCreate("has_record"); public static final PropertyKey HAS_RECORD = getOrCreate("has_record");
public static final PropertyKey HATCH = getOrCreate("hatch"); public static final PropertyKey HATCH = getOrCreate("hatch");
public static final PropertyKey HINGE = getOrCreate("hinge"); public static final PropertyKey HINGE = getOrCreate("hinge");
public static final PropertyKey IN_WALL = getOrCreate("in_wall"); public static final PropertyKey HONEY_LEVEL = getOrCreate("honey_level");
public static final PropertyKey INSTRUMENT = getOrCreate("instrument"); public static final PropertyKey INSTRUMENT = getOrCreate("instrument");
public static final PropertyKey INVERTED = getOrCreate("inverted"); public static final PropertyKey INVERTED = getOrCreate("inverted");
public static final PropertyKey IN_WALL = getOrCreate("in_wall");
public static final PropertyKey LAYERS = getOrCreate("layers"); public static final PropertyKey LAYERS = getOrCreate("layers");
public static final PropertyKey LEAVES = getOrCreate("leaves");
public static final PropertyKey LEVEL = getOrCreate("level"); public static final PropertyKey LEVEL = getOrCreate("level");
public static final PropertyKey LIT = getOrCreate("lit"); public static final PropertyKey LIT = getOrCreate("lit");
public static final PropertyKey LOCKED = getOrCreate("locked"); public static final PropertyKey LOCKED = getOrCreate("locked");
@ -53,29 +63,30 @@ public class PropertyKey implements Comparable<PropertyKey> {
public static final PropertyKey NOTE = getOrCreate("note"); public static final PropertyKey NOTE = getOrCreate("note");
public static final PropertyKey OCCUPIED = getOrCreate("occupied"); public static final PropertyKey OCCUPIED = getOrCreate("occupied");
public static final PropertyKey OPEN = getOrCreate("open"); public static final PropertyKey OPEN = getOrCreate("open");
public static final PropertyKey ORIENTATION = getOrCreate("orientation");
public static final PropertyKey PART = getOrCreate("part"); public static final PropertyKey PART = getOrCreate("part");
public static final PropertyKey PERSISTENT = getOrCreate("persistent"); public static final PropertyKey PERSISTENT = getOrCreate("persistent");
public static final PropertyKey PICKLES = getOrCreate("pickles"); public static final PropertyKey PICKLES = getOrCreate("pickles");
public static final PropertyKey POWER = getOrCreate("power"); public static final PropertyKey POWER = getOrCreate("power");
public static final PropertyKey POWERED = getOrCreate("powered"); public static final PropertyKey POWERED = getOrCreate("powered");
public static final PropertyKey ROTATION = getOrCreate("rotation"); public static final PropertyKey ROTATION = getOrCreate("rotation");
public static final PropertyKey SCULK_SENSOR_PHASE = getOrCreate("sculk_sensor_phase");
public static final PropertyKey SHAPE = getOrCreate("shape"); public static final PropertyKey SHAPE = getOrCreate("shape");
public static final PropertyKey SHORT = getOrCreate("short"); public static final PropertyKey SHORT = getOrCreate("short");
public static final PropertyKey SIGNAL_FIRE = getOrCreate("signal_fire");
public static final PropertyKey SNOWY = getOrCreate("snowy"); public static final PropertyKey SNOWY = getOrCreate("snowy");
public static final PropertyKey SOUTH = getOrCreate("south"); public static final PropertyKey SOUTH = getOrCreate("south");
public static final PropertyKey STAGE = getOrCreate("stage"); public static final PropertyKey STAGE = getOrCreate("stage");
public static final PropertyKey TILT = getOrCreate("tilt");
public static final PropertyKey THICKNESS = getOrCreate("thickness");
public static final PropertyKey TRIGGERED = getOrCreate("triggered"); public static final PropertyKey TRIGGERED = getOrCreate("triggered");
public static final PropertyKey TYPE = getOrCreate("type"); public static final PropertyKey TYPE = getOrCreate("type");
public static final PropertyKey UNSTABLE = getOrCreate("unstable");
public static final PropertyKey UP = getOrCreate("up"); public static final PropertyKey UP = getOrCreate("up");
public static final PropertyKey VERTICAL_DIRECTION = getOrCreate("vertical_direction");
public static final PropertyKey VINE_END = getOrCreate("vine_end");
public static final PropertyKey WATERLOGGED = getOrCreate("waterlogged"); public static final PropertyKey WATERLOGGED = getOrCreate("waterlogged");
public static final PropertyKey WEST = getOrCreate("west"); public static final PropertyKey WEST = getOrCreate("west");
public static final PropertyKey UNSTABLE = getOrCreate("unstable");
public static final PropertyKey LEAVES = getOrCreate("leaves");
public static final PropertyKey ATTACHMENT = getOrCreate("attachement");
public static final PropertyKey SIGNAL_FIRE = getOrCreate("signal_fire");
public static final PropertyKey HANGING = getOrCreate("hanging");
public static final PropertyKey HAS_BOOK = getOrCreate("has_book");
public static final PropertyKey BOTTOM = getOrCreate("bottom");
private final String name; private final String name;
private final int id; private final int id;
@ -90,10 +101,6 @@ public class PropertyKey implements Comparable<PropertyKey> {
return keyList.size(); return keyList.size();
} }
public final String getName() {
return this.name;
}
public static PropertyKey getByName(CharSequence name) { public static PropertyKey getByName(CharSequence name) {
return keys.get(name); return keys.get(name);
} }
@ -116,6 +123,10 @@ public class PropertyKey implements Comparable<PropertyKey> {
}); });
} }
public final String getName() {
return this.name;
}
public int getId() { public int getId() {
return id; return id;
} }

View File

@ -1,695 +0,0 @@
package com.fastasyncworldedit.core.world.block;
/**
* An internal FAWE class used for switch statements on blocks.
* Using IDs to register items is pre 1.13 days. This class is
* deprecated for removal with replacement of namespaced IDs.
*/
@Deprecated(forRemoval = true)
public class BlockID {
public static final int __RESERVED__ = 0;
public static final int AIR = 1;
public static final int CAVE_AIR = 2;
public static final int VOID_AIR = 3;
public static final int ACACIA_BUTTON = 4;
public static final int ACACIA_DOOR = 5;
public static final int ACACIA_FENCE = 6;
public static final int ACACIA_FENCE_GATE = 7;
public static final int ACACIA_LEAVES = 8;
public static final int ACACIA_LOG = 9;
public static final int ACACIA_PLANKS = 10;
public static final int ACACIA_PRESSURE_PLATE = 11;
public static final int ACACIA_SAPLING = 12;
public static final int ACACIA_SIGN = 501;
public static final int ACACIA_SLAB = 13;
public static final int ACACIA_STAIRS = 14;
public static final int ACACIA_TRAPDOOR = 15;
public static final int ACACIA_WALL_SIGN = 565;
public static final int ACACIA_WOOD = 16;
public static final int ACTIVATOR_RAIL = 17;
public static final int ALLIUM = 18;
public static final int ANDESITE = 19;
public static final int ANDESITE_SLAB = 599;
public static final int ANDESITE_STAIRS = 600;
public static final int ANDESITE_WALL = 601;
public static final int ANVIL = 20;
public static final int ATTACHED_MELON_STEM = 21;
public static final int ATTACHED_PUMPKIN_STEM = 22;
public static final int AZURE_BLUET = 23;
public static final int BAMBOO = 602;
public static final int BAMBOO_SAPLING = 603;
public static final int BARREL = 604;
public static final int BARRIER = 24;
public static final int BEACON = 25;
public static final int BEDROCK = 26;
public static final int BEE_NEST = 677;
public static final int BEEHIVE = 678; // highest
public static final int BEETROOTS = 27;
public static final int BELL = 605;
public static final int BIRCH_BUTTON = 28;
public static final int BIRCH_DOOR = 29;
public static final int BIRCH_FENCE = 30;
public static final int BIRCH_FENCE_GATE = 31;
public static final int BIRCH_LEAVES = 32;
public static final int BIRCH_LOG = 33;
public static final int BIRCH_PLANKS = 34;
public static final int BIRCH_PRESSURE_PLATE = 35;
public static final int BIRCH_SAPLING = 36;
public static final int BIRCH_SIGN = 606;
public static final int BIRCH_SLAB = 37;
public static final int BIRCH_STAIRS = 38;
public static final int BIRCH_TRAPDOOR = 39;
public static final int BIRCH_WALL_SIGN = 607;
public static final int BIRCH_WOOD = 40;
public static final int BLACK_BANNER = 41;
public static final int BLACK_BED = 42;
public static final int BLACK_CARPET = 43;
public static final int BLACK_CONCRETE = 44;
public static final int BLACK_CONCRETE_POWDER = 45;
public static final int BLACK_GLAZED_TERRACOTTA = 46;
public static final int BLACK_SHULKER_BOX = 47;
public static final int BLACK_STAINED_GLASS = 48;
public static final int BLACK_STAINED_GLASS_PANE = 49;
public static final int BLACK_TERRACOTTA = 50;
public static final int BLACK_WALL_BANNER = 51;
public static final int BLACK_WOOL = 52;
public static final int BLAST_FURNACE = 608;
public static final int BLUE_BANNER = 53;
public static final int BLUE_BED = 54;
public static final int BLUE_CARPET = 55;
public static final int BLUE_CONCRETE = 56;
public static final int BLUE_CONCRETE_POWDER = 57;
public static final int BLUE_GLAZED_TERRACOTTA = 58;
public static final int BLUE_ICE = 59;
public static final int BLUE_ORCHID = 60;
public static final int BLUE_SHULKER_BOX = 61;
public static final int BLUE_STAINED_GLASS = 62;
public static final int BLUE_STAINED_GLASS_PANE = 63;
public static final int BLUE_TERRACOTTA = 64;
public static final int BLUE_WALL_BANNER = 65;
public static final int BLUE_WOOL = 66;
public static final int BONE_BLOCK = 67;
public static final int BOOKSHELF = 68;
public static final int BRAIN_CORAL = 69;
public static final int BRAIN_CORAL_BLOCK = 70;
public static final int BRAIN_CORAL_FAN = 71;
public static final int BRAIN_CORAL_WALL_FAN = 72;
public static final int BREWING_STAND = 73;
public static final int BRICK_SLAB = 74;
public static final int BRICK_STAIRS = 75;
public static final int BRICK_WALL = 609;
public static final int BRICKS = 76;
public static final int BROWN_BANNER = 77;
public static final int BROWN_BED = 78;
public static final int BROWN_CARPET = 79;
public static final int BROWN_CONCRETE = 80;
public static final int BROWN_CONCRETE_POWDER = 81;
public static final int BROWN_GLAZED_TERRACOTTA = 82;
public static final int BROWN_MUSHROOM = 83;
public static final int BROWN_MUSHROOM_BLOCK = 84;
public static final int BROWN_SHULKER_BOX = 85;
public static final int BROWN_STAINED_GLASS = 86;
public static final int BROWN_STAINED_GLASS_PANE = 87;
public static final int BROWN_TERRACOTTA = 88;
public static final int BROWN_WALL_BANNER = 89;
public static final int BROWN_WOOL = 90;
public static final int BUBBLE_COLUMN = 91;
public static final int BUBBLE_CORAL = 92;
public static final int BUBBLE_CORAL_BLOCK = 93;
public static final int BUBBLE_CORAL_FAN = 94;
public static final int BUBBLE_CORAL_WALL_FAN = 95;
public static final int CACTUS = 96;
public static final int CAKE = 97;
public static final int CAMPFIRE = 610;
public static final int CARROTS = 98;
public static final int CARTOGRAPHY_TABLE = 611;
public static final int CARVED_PUMPKIN = 99;
public static final int CAULDRON = 100;
public static final int CHAIN_COMMAND_BLOCK = 101;
public static final int CHEST = 102;
public static final int CHIPPED_ANVIL = 103;
public static final int CHISELED_QUARTZ_BLOCK = 104;
public static final int CHISELED_RED_SANDSTONE = 105;
public static final int CHISELED_SANDSTONE = 106;
public static final int CHISELED_STONE_BRICKS = 107;
public static final int CHORUS_FLOWER = 108;
public static final int CHORUS_PLANT = 109;
public static final int CLAY = 110;
public static final int COAL_BLOCK = 111;
public static final int COAL_ORE = 112;
public static final int COARSE_DIRT = 113;
public static final int COBBLESTONE = 114;
public static final int COBBLESTONE_SLAB = 115;
public static final int COBBLESTONE_STAIRS = 116;
public static final int COBBLESTONE_WALL = 117;
public static final int COBWEB = 118;
public static final int COCOA = 119;
public static final int COMMAND_BLOCK = 120;
public static final int COMPARATOR = 121;
public static final int COMPOSTER = 612;
public static final int CONDUIT = 122;
public static final int CORNFLOWER = 613;
public static final int CRACKED_STONE_BRICKS = 123;
public static final int CRAFTING_TABLE = 124;
public static final int CREEPER_HEAD = 125;
public static final int CREEPER_WALL_HEAD = 126;
public static final int CUT_RED_SANDSTONE = 127;
public static final int CUT_RED_SANDSTONE_SLAB = 614;
public static final int CUT_SANDSTONE = 128;
public static final int CUT_SANDSTONE_SLAB = 615;
public static final int CYAN_BANNER = 129;
public static final int CYAN_BED = 130;
public static final int CYAN_CARPET = 131;
public static final int CYAN_CONCRETE = 132;
public static final int CYAN_CONCRETE_POWDER = 133;
public static final int CYAN_GLAZED_TERRACOTTA = 134;
public static final int CYAN_SHULKER_BOX = 135;
public static final int CYAN_STAINED_GLASS = 136;
public static final int CYAN_STAINED_GLASS_PANE = 137;
public static final int CYAN_TERRACOTTA = 138;
public static final int CYAN_WALL_BANNER = 139;
public static final int CYAN_WOOL = 140;
public static final int DAMAGED_ANVIL = 141;
public static final int DANDELION = 142;
public static final int DARK_OAK_BUTTON = 143;
public static final int DARK_OAK_DOOR = 144;
public static final int DARK_OAK_FENCE = 145;
public static final int DARK_OAK_FENCE_GATE = 146;
public static final int DARK_OAK_LEAVES = 147;
public static final int DARK_OAK_LOG = 148;
public static final int DARK_OAK_PLANKS = 149;
public static final int DARK_OAK_PRESSURE_PLATE = 150;
public static final int DARK_OAK_SAPLING = 151;
public static final int DARK_OAK_SIGN = 616;
public static final int DARK_OAK_SLAB = 152;
public static final int DARK_OAK_STAIRS = 153;
public static final int DARK_OAK_TRAPDOOR = 154;
public static final int DARK_OAK_WALL_SIGN = 617;
public static final int DARK_OAK_WOOD = 155;
public static final int DARK_PRISMARINE = 156;
public static final int DARK_PRISMARINE_SLAB = 157;
public static final int DARK_PRISMARINE_STAIRS = 158;
public static final int DAYLIGHT_DETECTOR = 159;
public static final int DEAD_BRAIN_CORAL = 160;
public static final int DEAD_BRAIN_CORAL_BLOCK = 161;
public static final int DEAD_BRAIN_CORAL_FAN = 162;
public static final int DEAD_BRAIN_CORAL_WALL_FAN = 163;
public static final int DEAD_BUBBLE_CORAL = 164;
public static final int DEAD_BUBBLE_CORAL_BLOCK = 165;
public static final int DEAD_BUBBLE_CORAL_FAN = 166;
public static final int DEAD_BUBBLE_CORAL_WALL_FAN = 167;
public static final int DEAD_BUSH = 168;
public static final int DEAD_FIRE_CORAL = 169;
public static final int DEAD_FIRE_CORAL_BLOCK = 170;
public static final int DEAD_FIRE_CORAL_FAN = 171;
public static final int DEAD_FIRE_CORAL_WALL_FAN = 172;
public static final int DEAD_HORN_CORAL = 173;
public static final int DEAD_HORN_CORAL_BLOCK = 174;
public static final int DEAD_HORN_CORAL_FAN = 175;
public static final int DEAD_HORN_CORAL_WALL_FAN = 176;
public static final int DEAD_TUBE_CORAL = 177;
public static final int DEAD_TUBE_CORAL_BLOCK = 178;
public static final int DEAD_TUBE_CORAL_FAN = 179;
public static final int DEAD_TUBE_CORAL_WALL_FAN = 180;
public static final int DETECTOR_RAIL = 181;
public static final int DIAMOND_BLOCK = 182;
public static final int DIAMOND_ORE = 183;
public static final int DIORITE = 184;
public static final int DIORITE_SLAB = 618;
public static final int DIORITE_STAIRS = 619;
public static final int DIORITE_WALL = 620;
public static final int DIRT = 185;
public static final int DISPENSER = 186;
public static final int DRAGON_EGG = 187;
public static final int DRAGON_HEAD = 188;
public static final int DRAGON_WALL_HEAD = 189;
public static final int DRIED_KELP_BLOCK = 190;
public static final int DROPPER = 191;
public static final int EMERALD_BLOCK = 192;
public static final int EMERALD_ORE = 193;
public static final int ENCHANTING_TABLE = 194;
public static final int END_GATEWAY = 195;
public static final int END_PORTAL = 196;
public static final int END_PORTAL_FRAME = 197;
public static final int END_ROD = 198;
public static final int END_STONE = 199;
public static final int END_STONE_BRICK_SLAB = 621;
public static final int END_STONE_BRICK_STAIRS = 622;
public static final int END_STONE_BRICK_WALL = 623;
public static final int END_STONE_BRICKS = 200;
public static final int ENDER_CHEST = 201;
public static final int FARMLAND = 202;
public static final int FERN = 203;
public static final int FIRE = 204;
public static final int FIRE_CORAL = 205;
public static final int FIRE_CORAL_BLOCK = 206;
public static final int FIRE_CORAL_FAN = 207;
public static final int FIRE_CORAL_WALL_FAN = 208;
public static final int FLETCHING_TABLE = 624;
public static final int FLOWER_POT = 209;
public static final int FROSTED_ICE = 210;
public static final int FURNACE = 211;
public static final int GLASS = 212;
public static final int GLASS_PANE = 213;
public static final int GLOWSTONE = 214;
public static final int GOLD_BLOCK = 215;
public static final int GOLD_ORE = 216;
public static final int GRANITE = 217;
public static final int GRANITE_SLAB = 625;
public static final int GRANITE_STAIRS = 626;
public static final int GRANITE_WALL = 627;
public static final int GRASS = 218;
public static final int GRASS_BLOCK = 219;
public static final int GRASS_PATH = 220;
public static final int GRAVEL = 221;
public static final int GRAY_BANNER = 222;
public static final int GRAY_BED = 223;
public static final int GRAY_CARPET = 224;
public static final int GRAY_CONCRETE = 225;
public static final int GRAY_CONCRETE_POWDER = 226;
public static final int GRAY_GLAZED_TERRACOTTA = 227;
public static final int GRAY_SHULKER_BOX = 228;
public static final int GRAY_STAINED_GLASS = 229;
public static final int GRAY_STAINED_GLASS_PANE = 230;
public static final int GRAY_TERRACOTTA = 231;
public static final int GRAY_WALL_BANNER = 232;
public static final int GRAY_WOOL = 233;
public static final int GREEN_BANNER = 234;
public static final int GREEN_BED = 235;
public static final int GREEN_CARPET = 236;
public static final int GREEN_CONCRETE = 237;
public static final int GREEN_CONCRETE_POWDER = 238;
public static final int GREEN_GLAZED_TERRACOTTA = 239;
public static final int GREEN_SHULKER_BOX = 240;
public static final int GREEN_STAINED_GLASS = 241;
public static final int GREEN_STAINED_GLASS_PANE = 242;
public static final int GREEN_TERRACOTTA = 243;
public static final int GREEN_WALL_BANNER = 244;
public static final int GREEN_WOOL = 245;
public static final int GRINDSTONE = 628;
public static final int HAY_BLOCK = 246;
public static final int HEAVY_WEIGHTED_PRESSURE_PLATE = 247;
public static final int HOPPER = 248;
public static final int HORN_CORAL = 249;
public static final int HORN_CORAL_BLOCK = 250;
public static final int HORN_CORAL_FAN = 251;
public static final int HORN_CORAL_WALL_FAN = 252;
public static final int ICE = 253;
public static final int INFESTED_CHISELED_STONE_BRICKS = 254;
public static final int INFESTED_COBBLESTONE = 255;
public static final int INFESTED_CRACKED_STONE_BRICKS = 256;
public static final int INFESTED_MOSSY_STONE_BRICKS = 257;
public static final int INFESTED_STONE = 258;
public static final int INFESTED_STONE_BRICKS = 259;
public static final int IRON_BARS = 260;
public static final int IRON_BLOCK = 261;
public static final int IRON_DOOR = 262;
public static final int IRON_ORE = 263;
public static final int IRON_TRAPDOOR = 264;
public static final int JACK_O_LANTERN = 265;
public static final int JIGSAW = 629;
public static final int JUKEBOX = 266;
public static final int JUNGLE_BUTTON = 267;
public static final int JUNGLE_DOOR = 268;
public static final int JUNGLE_FENCE = 269;
public static final int JUNGLE_FENCE_GATE = 270;
public static final int JUNGLE_LEAVES = 271;
public static final int JUNGLE_LOG = 272;
public static final int JUNGLE_PLANKS = 273;
public static final int JUNGLE_PRESSURE_PLATE = 274;
public static final int JUNGLE_SAPLING = 275;
public static final int JUNGLE_SIGN = 630;
public static final int JUNGLE_SLAB = 276;
public static final int JUNGLE_STAIRS = 277;
public static final int JUNGLE_TRAPDOOR = 278;
public static final int JUNGLE_WALL_SIGN = 631;
public static final int JUNGLE_WOOD = 279;
public static final int KELP = 280;
public static final int KELP_PLANT = 281;
public static final int LADDER = 282;
public static final int LANTERN = 632;
public static final int LAPIS_BLOCK = 283;
public static final int LAPIS_ORE = 284;
public static final int LARGE_FERN = 285;
public static final int LAVA = 286;
public static final int LECTERN = 633;
public static final int LEVER = 287;
public static final int LIGHT_BLUE_BANNER = 288;
public static final int LIGHT_BLUE_BED = 289;
public static final int LIGHT_BLUE_CARPET = 290;
public static final int LIGHT_BLUE_CONCRETE = 291;
public static final int LIGHT_BLUE_CONCRETE_POWDER = 292;
public static final int LIGHT_BLUE_GLAZED_TERRACOTTA = 293;
public static final int LIGHT_BLUE_SHULKER_BOX = 294;
public static final int LIGHT_BLUE_STAINED_GLASS = 295;
public static final int LIGHT_BLUE_STAINED_GLASS_PANE = 296;
public static final int LIGHT_BLUE_TERRACOTTA = 297;
public static final int LIGHT_BLUE_WALL_BANNER = 298;
public static final int LIGHT_BLUE_WOOL = 299;
public static final int LIGHT_GRAY_BANNER = 300;
public static final int LIGHT_GRAY_BED = 301;
public static final int LIGHT_GRAY_CARPET = 302;
public static final int LIGHT_GRAY_CONCRETE = 303;
public static final int LIGHT_GRAY_CONCRETE_POWDER = 304;
public static final int LIGHT_GRAY_GLAZED_TERRACOTTA = 305;
public static final int LIGHT_GRAY_SHULKER_BOX = 306;
public static final int LIGHT_GRAY_STAINED_GLASS = 307;
public static final int LIGHT_GRAY_STAINED_GLASS_PANE = 308;
public static final int LIGHT_GRAY_TERRACOTTA = 309;
public static final int LIGHT_GRAY_WALL_BANNER = 310;
public static final int LIGHT_GRAY_WOOL = 311;
public static final int LIGHT_WEIGHTED_PRESSURE_PLATE = 312;
public static final int LILAC = 313;
public static final int LILY_OF_THE_VALLEY = 634;
public static final int LILY_PAD = 314;
public static final int LIME_BANNER = 315;
public static final int LIME_BED = 316;
public static final int LIME_CARPET = 317;
public static final int LIME_CONCRETE = 318;
public static final int LIME_CONCRETE_POWDER = 319;
public static final int LIME_GLAZED_TERRACOTTA = 320;
public static final int LIME_SHULKER_BOX = 321;
public static final int LIME_STAINED_GLASS = 322;
public static final int LIME_STAINED_GLASS_PANE = 323;
public static final int LIME_TERRACOTTA = 324;
public static final int LIME_WALL_BANNER = 325;
public static final int LIME_WOOL = 326;
public static final int LOOM = 635;
public static final int MAGENTA_BANNER = 327;
public static final int MAGENTA_BED = 328;
public static final int MAGENTA_CARPET = 329;
public static final int MAGENTA_CONCRETE = 330;
public static final int MAGENTA_CONCRETE_POWDER = 331;
public static final int MAGENTA_GLAZED_TERRACOTTA = 332;
public static final int MAGENTA_SHULKER_BOX = 333;
public static final int MAGENTA_STAINED_GLASS = 334;
public static final int MAGENTA_STAINED_GLASS_PANE = 335;
public static final int MAGENTA_TERRACOTTA = 336;
public static final int MAGENTA_WALL_BANNER = 337;
public static final int MAGENTA_WOOL = 338;
public static final int MAGMA_BLOCK = 339;
public static final int MELON = 340;
public static final int MELON_STEM = 341;
public static final int MOSSY_COBBLESTONE = 342;
public static final int MOSSY_COBBLESTONE_SLAB = 636;
public static final int MOSSY_COBBLESTONE_STAIRS = 637;
public static final int MOSSY_COBBLESTONE_WALL = 343;
public static final int MOSSY_STONE_BRICK_SLAB = 638;
public static final int MOSSY_STONE_BRICK_STAIRS = 639;
public static final int MOSSY_STONE_BRICK_WALL = 640;
public static final int MOSSY_STONE_BRICKS = 344;
public static final int MOVING_PISTON = 345;
public static final int MUSHROOM_STEM = 346;
public static final int MYCELIUM = 347;
public static final int NETHER_BRICK_FENCE = 348;
public static final int NETHER_BRICK_SLAB = 349;
public static final int NETHER_BRICK_STAIRS = 350;
public static final int NETHER_BRICK_WALL = 641;
public static final int NETHER_BRICKS = 351;
public static final int NETHER_PORTAL = 352;
public static final int NETHER_QUARTZ_ORE = 353;
public static final int NETHER_WART = 354;
public static final int NETHER_WART_BLOCK = 355;
public static final int NETHERRACK = 356;
public static final int NOTE_BLOCK = 357;
public static final int OAK_BUTTON = 358;
public static final int OAK_DOOR = 359;
public static final int OAK_FENCE = 360;
public static final int OAK_FENCE_GATE = 361;
public static final int OAK_LEAVES = 362;
public static final int OAK_LOG = 363;
public static final int OAK_PLANKS = 364;
public static final int OAK_PRESSURE_PLATE = 365;
public static final int OAK_SAPLING = 366;
public static final int OAK_SIGN = 642;
public static final int OAK_SLAB = 367;
public static final int OAK_STAIRS = 368;
public static final int OAK_TRAPDOOR = 369;
public static final int OAK_WALL_SIGN = 643;
public static final int OAK_WOOD = 370;
public static final int OBSERVER = 371;
public static final int OBSIDIAN = 372;
public static final int ORANGE_BANNER = 373;
public static final int ORANGE_BED = 374;
public static final int ORANGE_CARPET = 375;
public static final int ORANGE_CONCRETE = 376;
public static final int ORANGE_CONCRETE_POWDER = 377;
public static final int ORANGE_GLAZED_TERRACOTTA = 378;
public static final int ORANGE_SHULKER_BOX = 379;
public static final int ORANGE_STAINED_GLASS = 380;
public static final int ORANGE_STAINED_GLASS_PANE = 381;
public static final int ORANGE_TERRACOTTA = 382;
public static final int ORANGE_TULIP = 383;
public static final int ORANGE_WALL_BANNER = 384;
public static final int ORANGE_WOOL = 385;
public static final int OXEYE_DAISY = 386;
public static final int PACKED_ICE = 387;
public static final int PEONY = 388;
public static final int PETRIFIED_OAK_SLAB = 389;
public static final int PINK_BANNER = 390;
public static final int PINK_BED = 391;
public static final int PINK_CARPET = 392;
public static final int PINK_CONCRETE = 393;
public static final int PINK_CONCRETE_POWDER = 394;
public static final int PINK_GLAZED_TERRACOTTA = 395;
public static final int PINK_SHULKER_BOX = 396;
public static final int PINK_STAINED_GLASS = 397;
public static final int PINK_STAINED_GLASS_PANE = 398;
public static final int PINK_TERRACOTTA = 399;
public static final int PINK_TULIP = 400;
public static final int PINK_WALL_BANNER = 401;
public static final int PINK_WOOL = 402;
public static final int PISTON = 403;
public static final int PISTON_HEAD = 404;
public static final int PLAYER_HEAD = 405;
public static final int PLAYER_WALL_HEAD = 406;
public static final int PODZOL = 407;
public static final int POLISHED_ANDESITE = 408;
public static final int POLISHED_ANDESITE_SLAB = 644;
public static final int POLISHED_ANDESITE_STAIRS = 645;
public static final int POLISHED_DIORITE = 409;
public static final int POLISHED_DIORITE_SLAB = 646;
public static final int POLISHED_DIORITE_STAIRS = 647;
public static final int POLISHED_GRANITE = 410;
public static final int POLISHED_GRANITE_SLAB = 648;
public static final int POLISHED_GRANITE_STAIRS = 649;
public static final int POPPY = 411;
public static final int POTATOES = 412;
public static final int POTTED_ACACIA_SAPLING = 413;
public static final int POTTED_ALLIUM = 414;
public static final int POTTED_AZURE_BLUET = 415;
public static final int POTTED_BAMBOO = 650;
public static final int POTTED_BIRCH_SAPLING = 416;
public static final int POTTED_BLUE_ORCHID = 417;
public static final int POTTED_BROWN_MUSHROOM = 418;
public static final int POTTED_CACTUS = 419;
public static final int POTTED_CORNFLOWER = 651;
public static final int POTTED_DANDELION = 420;
public static final int POTTED_DARK_OAK_SAPLING = 421;
public static final int POTTED_DEAD_BUSH = 422;
public static final int POTTED_FERN = 423;
public static final int POTTED_JUNGLE_SAPLING = 424;
public static final int POTTED_LILY_OF_THE_VALLEY = 652;
public static final int POTTED_OAK_SAPLING = 425;
public static final int POTTED_ORANGE_TULIP = 426;
public static final int POTTED_OXEYE_DAISY = 427;
public static final int POTTED_PINK_TULIP = 428;
public static final int POTTED_POPPY = 429;
public static final int POTTED_RED_MUSHROOM = 430;
public static final int POTTED_RED_TULIP = 431;
public static final int POTTED_SPRUCE_SAPLING = 432;
public static final int POTTED_WHITE_TULIP = 433;
public static final int POTTED_WITHER_ROSE = 653;
public static final int POWERED_RAIL = 434;
public static final int PRISMARINE = 435;
public static final int PRISMARINE_BRICK_SLAB = 436;
public static final int PRISMARINE_BRICK_STAIRS = 437;
public static final int PRISMARINE_BRICKS = 438;
public static final int PRISMARINE_SLAB = 439;
public static final int PRISMARINE_STAIRS = 440;
public static final int PRISMARINE_WALL = 654;
public static final int PUMPKIN = 441;
public static final int PUMPKIN_STEM = 442;
public static final int PURPLE_BANNER = 443;
public static final int PURPLE_BED = 444;
public static final int PURPLE_CARPET = 445;
public static final int PURPLE_CONCRETE = 446;
public static final int PURPLE_CONCRETE_POWDER = 447;
public static final int PURPLE_GLAZED_TERRACOTTA = 448;
public static final int PURPLE_SHULKER_BOX = 449;
public static final int PURPLE_STAINED_GLASS = 450;
public static final int PURPLE_STAINED_GLASS_PANE = 451;
public static final int PURPLE_TERRACOTTA = 452;
public static final int PURPLE_WALL_BANNER = 453;
public static final int PURPLE_WOOL = 454;
public static final int PURPUR_BLOCK = 455;
public static final int PURPUR_PILLAR = 456;
public static final int PURPUR_SLAB = 457;
public static final int PURPUR_STAIRS = 458;
public static final int QUARTZ_BLOCK = 459;
public static final int QUARTZ_PILLAR = 460;
public static final int QUARTZ_SLAB = 461;
public static final int QUARTZ_STAIRS = 462;
public static final int RAIL = 463;
public static final int RED_BANNER = 464;
public static final int RED_BED = 465;
public static final int RED_CARPET = 466;
public static final int RED_CONCRETE = 467;
public static final int RED_CONCRETE_POWDER = 468;
public static final int RED_GLAZED_TERRACOTTA = 469;
public static final int RED_MUSHROOM = 470;
public static final int RED_MUSHROOM_BLOCK = 471;
public static final int RED_NETHER_BRICK_SLAB = 655;
public static final int RED_NETHER_BRICK_STAIRS = 656;
public static final int RED_NETHER_BRICK_WALL = 657;
public static final int RED_NETHER_BRICKS = 472;
public static final int RED_SAND = 473;
public static final int RED_SANDSTONE = 474;
public static final int RED_SANDSTONE_SLAB = 475;
public static final int RED_SANDSTONE_STAIRS = 476;
public static final int RED_SANDSTONE_WALL = 658;
public static final int RED_SHULKER_BOX = 477;
public static final int RED_STAINED_GLASS = 478;
public static final int RED_STAINED_GLASS_PANE = 479;
public static final int RED_TERRACOTTA = 480;
public static final int RED_TULIP = 481;
public static final int RED_WALL_BANNER = 482;
public static final int RED_WOOL = 483;
public static final int REDSTONE_BLOCK = 484;
public static final int REDSTONE_LAMP = 485;
public static final int REDSTONE_ORE = 486;
public static final int REDSTONE_TORCH = 487;
public static final int REDSTONE_WALL_TORCH = 488;
public static final int REDSTONE_WIRE = 489;
public static final int REPEATER = 490;
public static final int REPEATING_COMMAND_BLOCK = 491;
public static final int ROSE_BUSH = 492;
public static final int SAND = 493;
public static final int SANDSTONE = 494;
public static final int SANDSTONE_SLAB = 495;
public static final int SANDSTONE_STAIRS = 496;
public static final int SANDSTONE_WALL = 659;
public static final int SCAFFOLDING = 660;
public static final int SEA_LANTERN = 497;
public static final int SEA_PICKLE = 498;
public static final int SEAGRASS = 499;
public static final int SHULKER_BOX = 500;
public static final int SKELETON_SKULL = 502;
public static final int SKELETON_WALL_SKULL = 503;
public static final int SLIME_BLOCK = 504;
public static final int SMITHING_TABLE = 661;
public static final int SMOKER = 662;
public static final int SMOOTH_QUARTZ = 505;
public static final int SMOOTH_QUARTZ_SLAB = 663;
public static final int SMOOTH_QUARTZ_STAIRS = 664;
public static final int SMOOTH_RED_SANDSTONE = 506;
public static final int SMOOTH_RED_SANDSTONE_SLAB = 665;
public static final int SMOOTH_RED_SANDSTONE_STAIRS = 666;
public static final int SMOOTH_SANDSTONE = 507;
public static final int SMOOTH_SANDSTONE_SLAB = 667;
public static final int SMOOTH_SANDSTONE_STAIRS = 668;
public static final int SMOOTH_STONE = 508;
public static final int SMOOTH_STONE_SLAB = 669;
public static final int SNOW = 509;
public static final int SNOW_BLOCK = 510;
public static final int SOUL_SAND = 511;
public static final int SPAWNER = 512;
public static final int SPONGE = 513;
public static final int SPRUCE_BUTTON = 514;
public static final int SPRUCE_DOOR = 515;
public static final int SPRUCE_FENCE = 516;
public static final int SPRUCE_FENCE_GATE = 517;
public static final int SPRUCE_LEAVES = 518;
public static final int SPRUCE_LOG = 519;
public static final int SPRUCE_PLANKS = 520;
public static final int SPRUCE_PRESSURE_PLATE = 521;
public static final int SPRUCE_SAPLING = 522;
public static final int SPRUCE_SIGN = 670;
public static final int SPRUCE_SLAB = 523;
public static final int SPRUCE_STAIRS = 524;
public static final int SPRUCE_TRAPDOOR = 525;
public static final int SPRUCE_WALL_SIGN = 671;
public static final int SPRUCE_WOOD = 526;
public static final int STICKY_PISTON = 527;
public static final int STONE = 528;
public static final int STONE_BRICK_SLAB = 529;
public static final int STONE_BRICK_STAIRS = 530;
public static final int STONE_BRICK_WALL = 672;
public static final int STONE_BRICKS = 531;
public static final int STONE_BUTTON = 532;
public static final int STONE_PRESSURE_PLATE = 533;
public static final int STONE_SLAB = 534;
public static final int STONE_STAIRS = 673;
public static final int STONECUTTER = 674;
public static final int STRIPPED_ACACIA_LOG = 535;
public static final int STRIPPED_ACACIA_WOOD = 536;
public static final int STRIPPED_BIRCH_LOG = 537;
public static final int STRIPPED_BIRCH_WOOD = 538;
public static final int STRIPPED_DARK_OAK_LOG = 539;
public static final int STRIPPED_DARK_OAK_WOOD = 540;
public static final int STRIPPED_JUNGLE_LOG = 541;
public static final int STRIPPED_JUNGLE_WOOD = 542;
public static final int STRIPPED_OAK_LOG = 543;
public static final int STRIPPED_OAK_WOOD = 544;
public static final int STRIPPED_SPRUCE_LOG = 545;
public static final int STRIPPED_SPRUCE_WOOD = 546;
public static final int STRUCTURE_BLOCK = 547;
public static final int STRUCTURE_VOID = 548;
public static final int SUGAR_CANE = 549;
public static final int SUNFLOWER = 550;
public static final int SWEET_BERRY_BUSH = 675;
public static final int TALL_GRASS = 551;
public static final int TALL_SEAGRASS = 552;
public static final int TERRACOTTA = 553;
public static final int TNT = 554;
public static final int TORCH = 555;
public static final int TRAPPED_CHEST = 556;
public static final int TRIPWIRE = 557;
public static final int TRIPWIRE_HOOK = 558;
public static final int TUBE_CORAL = 559;
public static final int TUBE_CORAL_BLOCK = 560;
public static final int TUBE_CORAL_FAN = 561;
public static final int TUBE_CORAL_WALL_FAN = 562;
public static final int TURTLE_EGG = 563;
public static final int VINE = 564;
public static final int WALL_TORCH = 566;
public static final int WATER = 567;
public static final int WET_SPONGE = 568;
public static final int WHEAT = 569;
public static final int WHITE_BANNER = 570;
public static final int WHITE_BED = 571;
public static final int WHITE_CARPET = 572;
public static final int WHITE_CONCRETE = 573;
public static final int WHITE_CONCRETE_POWDER = 574;
public static final int WHITE_GLAZED_TERRACOTTA = 575;
public static final int WHITE_SHULKER_BOX = 576;
public static final int WHITE_STAINED_GLASS = 577;
public static final int WHITE_STAINED_GLASS_PANE = 578;
public static final int WHITE_TERRACOTTA = 579;
public static final int WHITE_TULIP = 580;
public static final int WHITE_WALL_BANNER = 581;
public static final int WHITE_WOOL = 582;
public static final int WITHER_ROSE = 676;
public static final int WITHER_SKELETON_SKULL = 583;
public static final int WITHER_SKELETON_WALL_SKULL = 584;
public static final int YELLOW_BANNER = 585;
public static final int YELLOW_BED = 586;
public static final int YELLOW_CARPET = 587;
public static final int YELLOW_CONCRETE = 588;
public static final int YELLOW_CONCRETE_POWDER = 589;
public static final int YELLOW_GLAZED_TERRACOTTA = 590;
public static final int YELLOW_SHULKER_BOX = 591;
public static final int YELLOW_STAINED_GLASS = 592;
public static final int YELLOW_STAINED_GLASS_PANE = 593;
public static final int YELLOW_TERRACOTTA = 594;
public static final int YELLOW_WALL_BANNER = 595;
public static final int YELLOW_WOOL = 596;
public static final int ZOMBIE_HEAD = 597;
public static final int ZOMBIE_WALL_HEAD = 598;
// Deprecated
public static final int SIGN = OAK_SIGN;
public static final int WALL_SIGN = OAK_WALL_SIGN;
}

View File

@ -434,9 +434,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
return output; return output;
} }
// pkg private for TracedEditSession only, may later become public API private boolean commitRequired() {
boolean commitRequired() { //FAWE start - false for us, returning true if the reorder extent != null for upstream
//FAWE start
return false; return false;
} }
//FAWE end //FAWE end

View File

@ -54,7 +54,7 @@ public abstract class LocalConfiguration {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
public boolean profile = false; public boolean profile = false;
public boolean traceUnflushedSessions = false; public boolean traceUnflushedSessions = true;
public Set<String> disallowedBlocks = new HashSet<>(); public Set<String> disallowedBlocks = new HashSet<>();
protected BlockMask disallowedBlocksMask; protected BlockMask disallowedBlocksMask;
public int defaultChangeLimit = -1; public int defaultChangeLimit = -1;

View File

@ -1192,13 +1192,13 @@ public class LocalSession implements TextureHolder {
/** /**
* Get the brush tool assigned to the item. If there is no tool assigned * Get the brush tool assigned to the item. If there is no tool assigned
* or the tool is not assigned, the slot will be replaced with the * or the tool is not a brush tool, the slot will be replaced with the
* brush tool. * brush tool.
* *
* @param item the item type * @param item the item type
* @return the tool, or {@code null} * @return the tool, or {@code null}
* @throws InvalidToolBindException if the item can't be bound to that item * @throws InvalidToolBindException if the item can't be bound to that item
* @deprecated FAWE binds to the item, not the type - this allows brushes to persist * @deprecated FAWE binds to the item, not the type - this allows brushes to persist, also deprecated in upstream
*/ */
@Deprecated @Deprecated
public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException { public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException {
@ -1232,6 +1232,17 @@ public class LocalSession implements TextureHolder {
} }
//FAWE end //FAWE end
/**
* Get the brush tool assigned to this item.
*
* @param item the item type
* @return the brush tool assigned to the item type
*/
@Nullable
public BrushTool getBrush(ItemType item) {
return getTool(item) instanceof BrushTool tool ? tool : null;
}
//FAWE start - see note of getBrushTool //FAWE start - see note of getBrushTool
/** /**

View File

@ -21,16 +21,22 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.util.ErrorReporting;
import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.ref.Cleaner;
/** /**
* Internal use only. Unused for now, but present in case upstream make it API. * Internal use only. Unused for now, but present in case upstream make it API.
*/ */
class TracedEditSession extends EditSession { class TracedEditSession extends EditSession {
private static final Cleaner cleaner = Cleaner.create();
private final TraceRecord record;
private final Cleaner.Cleanable cleanable;
//FAWE start - does not work with FAWE's ways of doing things... //FAWE start - does not work with FAWE's ways of doing things...
@Deprecated @Deprecated
//FAWE end //FAWE end
@ -45,22 +51,37 @@ class TracedEditSession extends EditSession {
.blockBag(blockBag) .blockBag(blockBag)
.actor(actor) .actor(actor)
.tracing(tracing)); .tracing(tracing));
this.record = new TraceRecord(actor);
this.cleanable = cleaner.register(this, record);
} }
TracedEditSession(EditSessionBuilder builder) { public void close() {
super(builder); try {
super.close();
} finally {
this.record.committed = true;
cleanable.clean();
}
} }
private final Throwable stacktrace = new Throwable("Creation trace."); private static final class TraceRecord implements Runnable {
private final Throwable stacktrace = new Throwable("An EditSession was not closed.");
private final Actor actor;
private volatile boolean committed = false;
private TraceRecord(Actor actor) {
this.actor = actor;
}
@Override @Override
protected void finalize() throws Throwable { public void run() {
super.finalize(); if (!committed) {
WorldEdit.logger.warn("####### EDIT SESSION NOT CLOSED #######");
if (commitRequired()) { WorldEdit.logger.warn("This means that some code did not close their EditSession.");
WorldEdit.logger.warn("####### LEFTOVER BUFFER BLOCKS DETECTED #######");
WorldEdit.logger.warn("This means that some code did not flush their EditSession.");
WorldEdit.logger.warn("Here is a stacktrace from the creation of this EditSession:", stacktrace); WorldEdit.logger.warn("Here is a stacktrace from the creation of this EditSession:", stacktrace);
ErrorReporting.trigger(actor, stacktrace);
}
} }
} }

View File

@ -59,7 +59,6 @@ import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.StringMan; import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.util.image.ImageUtil; import com.fastasyncworldedit.core.util.image.ImageUtil;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -1187,9 +1186,9 @@ public class BrushCommands {
//FAWE start - Suggest different brush material if sand or gravel is used //FAWE start - Suggest different brush material if sand or gravel is used
if (pattern instanceof BlockStateHolder) { if (pattern instanceof BlockStateHolder) {
BlockType type = ((BlockStateHolder) pattern).getBlockType(); BlockType type = ((BlockStateHolder) pattern).getBlockType();
switch (type.getInternalId()) { switch (type.getId()) {
case BlockID.SAND: case "minecraft:sand":
case BlockID.GRAVEL: case "minecraft:gravel":
player.print( player.print(
Caption.of("fawe.worldedit.brush.brush.try.other")); Caption.of("fawe.worldedit.brush.brush.try.other"));
falling = true; falling = true;

View File

@ -113,7 +113,7 @@ public class WorldEditCommands {
//FAWE start //FAWE start
@Command( @Command(
name = "debugpaste", name = "debugpaste",
desc = "Writes a report of latest.log, config.yml, config-legacy.yml, strings.json to https://athion.net/ISPaster/paste" desc = "Writes a report of latest.log, config.yml, worldedit-config.yml, strings.json to https://athion.net/ISPaster/paste"
) )
@CommandPermissions(value = {"worldedit.report", "worldedit.debugpaste"}, queued = false) @CommandPermissions(value = {"worldedit.report", "worldedit.debugpaste"}, queued = false)
public void report(Actor actor) throws WorldEditException { public void report(Actor actor) throws WorldEditException {
@ -121,8 +121,8 @@ public class WorldEditCommands {
try { try {
final File logFile = new File("logs/latest.log"); final File logFile = new File("logs/latest.log");
final File config = new File(Fawe.imp().getDirectory(), "config.yml"); final File config = new File(Fawe.imp().getDirectory(), "config.yml");
final File legacyConfig = new File(Fawe.imp().getDirectory(), "config-legacy.yml"); final File worldeditConfig = new File(Fawe.imp().getDirectory(), "worldedit-config.yml");
dest = IncendoPaster.debugPaste(logFile, Fawe.imp().getDebugInfo(), config, legacyConfig); dest = IncendoPaster.debugPaste(logFile, Fawe.imp().getDebugInfo(), config, worldeditConfig);
} catch (IOException e) { } catch (IOException e) {
actor.printInfo(TextComponent.of(e.getMessage())); actor.printInfo(TextComponent.of(e.getMessage()));
return; return;

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.command.tool; package com.sk89q.worldedit.command.tool;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
@ -56,9 +55,8 @@ public class QueryTool implements BlockTool {
) { ) {
World world = (World) clicked.getExtent(); World world = (World) clicked.getExtent();
EditSession editSession = session.createEditSession(player);
BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
BaseBlock block = editSession.getFullBlock(blockPoint); BaseBlock block = world.getFullBlock(blockPoint);
TextComponent.Builder builder = TextComponent.builder(); TextComponent.Builder builder = TextComponent.builder();
builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE));

View File

@ -120,6 +120,7 @@ import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter; import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter; import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter;
import com.sk89q.worldedit.internal.util.ErrorReporting;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -884,10 +885,9 @@ public final class PlatformCommandManager {
} }
private void handleUnknownException(Actor actor, Throwable t) { private void handleUnknownException(Actor actor, Throwable t) {
actor.print(Caption.of("worldedit.command.error.report"));
actor.print(TextComponent.of(t.getClass().getName() + ": " + t.getMessage()));
//FAWE start - Exchange name //FAWE start - Exchange name
LOGGER.error("An unexpected error while handling a FastAsyncWorldEdit command", t); LOGGER.error("An unexpected error while handling a FastAsyncWorldEdit command", t);
ErrorReporting.trigger(actor, t);
//FAWE end //FAWE end
} }

View File

@ -210,9 +210,9 @@ public class BlockMask extends ABlockMask {
@Override @Override
public boolean replacesAir() { public boolean replacesAir() {
return ordinals[BlockTypes.AIR.getDefaultState().getOrdinal()] return ordinals[1]
|| ordinals[BlockTypes.CAVE_AIR.getDefaultState().getOrdinal()] || ordinals[2]
|| ordinals[BlockTypes.VOID_AIR.getDefaultState().getOrdinal()]; || ordinals[3];
} }
@Override @Override
@ -334,9 +334,9 @@ public class BlockMask extends ABlockMask {
cloned[i] = !cloned[i]; cloned[i] = !cloned[i];
} }
if (replacesAir()) { if (replacesAir()) {
cloned[BlockTypes.AIR.getDefaultState().getOrdinal()] = false; cloned[1] = false;
cloned[BlockTypes.CAVE_AIR.getDefaultState().getOrdinal()] = false; cloned[2] = false;
cloned[BlockTypes.VOID_AIR.getDefaultState().getOrdinal()] = false; cloned[3] = false;
cloned[0] = false; cloned[0] = false;
} }
return new BlockMask(getExtent(), cloned); return new BlockMask(getExtent(), cloned);

View File

@ -44,17 +44,23 @@ public final class Constants {
/** /**
* The DataVersion for Minecraft 1.13 * The DataVersion for Minecraft 1.13
* @deprecated If Fawe drops interaction with 1.13, this method is subject to removal.
*/ */
@Deprecated(forRemoval = true, since = "2.0.0")
public static final int DATA_VERSION_MC_1_13 = 1519; public static final int DATA_VERSION_MC_1_13 = 1519;
/** /**
* The DataVersion for Minecraft 1.13.2 * The DataVersion for Minecraft 1.13.2
* @deprecated If Fawe drops interaction with 1.13, this method is subject to removal.
*/ */
@Deprecated(forRemoval = true, since = "2.0.0")
public static final int DATA_VERSION_MC_1_13_2 = 1631; public static final int DATA_VERSION_MC_1_13_2 = 1631;
/** /**
* The DataVersion for Minecraft 1.14 * The DataVersion for Minecraft 1.14
* @deprecated If Fawe drops interaction with 1.14, this method is subject to removal.
*/ */
@Deprecated(forRemoval = true, since = "2.0.0")
public static final int DATA_VERSION_MC_1_14 = 1952; public static final int DATA_VERSION_MC_1_14 = 1952;
/** /**
@ -72,11 +78,9 @@ public final class Constants {
*/ */
public static final int DATA_VERSION_MC_1_17 = 2724; public static final int DATA_VERSION_MC_1_17 = 2724;
//FAWE start - add data version for 1.18
/** /**
* The DataVersion for Minecraft 1.18 * The DataVersion for Minecraft 1.18
*/ */
public static final int DATA_VERSION_MC_1_18 = 2860; public static final int DATA_VERSION_MC_1_18 = 2860;
//FAWE end
} }

View File

@ -0,0 +1,43 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.util;
import com.fastasyncworldedit.core.configuration.Caption;
import com.google.common.base.Throwables;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
/**
* Simple class for handling error reporting to users.
*/
public class ErrorReporting {
private ErrorReporting() {
}
public static void trigger(Actor actor, Throwable error) {
actor.printError(Caption.of("worldedit.command.error.report"));
actor.print(
TextComponent.builder(error.getClass().getName() + ": " + error.getMessage())
.hoverEvent(HoverEvent.showText(TextComponent.of(Throwables.getStackTraceAsString(error))))
.build()
);
}
}

View File

@ -121,12 +121,12 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType BEDROCK = init(); public static final BlockType BEDROCK = init();
@Nullable @Nullable
public static final BlockType BEE_NEST = init();
@Nullable
public static final BlockType BEEHIVE = init(); public static final BlockType BEEHIVE = init();
@Nullable @Nullable
public static final BlockType BEETROOTS = init(); public static final BlockType BEETROOTS = init();
@Nullable @Nullable
public static final BlockType BEE_NEST = init();
@Nullable
public static final BlockType BELL = init(); public static final BlockType BELL = init();
@Nullable @Nullable
public static final BlockType BIG_DRIPLEAF = init(); public static final BlockType BIG_DRIPLEAF = init();
@ -163,6 +163,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType BIRCH_WOOD = init(); public static final BlockType BIRCH_WOOD = init();
@Nullable @Nullable
public static final BlockType BLACKSTONE = init();
@Nullable
public static final BlockType BLACKSTONE_SLAB = init();
@Nullable
public static final BlockType BLACKSTONE_STAIRS = init();
@Nullable
public static final BlockType BLACKSTONE_WALL = init();
@Nullable
public static final BlockType BLACK_BANNER = init(); public static final BlockType BLACK_BANNER = init();
@Nullable @Nullable
public static final BlockType BLACK_BED = init(); public static final BlockType BLACK_BED = init();
@ -191,14 +199,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType BLACK_WOOL = init(); public static final BlockType BLACK_WOOL = init();
@Nullable @Nullable
public static final BlockType BLACKSTONE = init();
@Nullable
public static final BlockType BLACKSTONE_SLAB = init();
@Nullable
public static final BlockType BLACKSTONE_STAIRS = init();
@Nullable
public static final BlockType BLACKSTONE_WALL = init();
@Nullable
public static final BlockType BLAST_FURNACE = init(); public static final BlockType BLAST_FURNACE = init();
@Nullable @Nullable
public static final BlockType BLUE_BANNER = init(); public static final BlockType BLUE_BANNER = init();
@ -247,14 +247,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType BREWING_STAND = init(); public static final BlockType BREWING_STAND = init();
@Nullable @Nullable
public static final BlockType BRICKS = init();
@Nullable
public static final BlockType BRICK_SLAB = init(); public static final BlockType BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType BRICK_STAIRS = init(); public static final BlockType BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType BRICK_WALL = init(); public static final BlockType BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType BRICKS = init();
@Nullable
public static final BlockType BROWN_BANNER = init(); public static final BlockType BROWN_BANNER = init();
@Nullable @Nullable
public static final BlockType BROWN_BED = init(); public static final BlockType BROWN_BED = init();
@ -389,8 +389,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType COPPER_BLOCK = init(); public static final BlockType COPPER_BLOCK = init();
@Nullable @Nullable
public static final BlockType COPPER_ORE = init();
@Nullable
public static final BlockType CORNFLOWER = init(); public static final BlockType CORNFLOWER = init();
@Nullable @Nullable
public static final BlockType CRACKED_DEEPSLATE_BRICKS = init(); public static final BlockType CRACKED_DEEPSLATE_BRICKS = init();
@ -571,14 +569,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType DEEPSLATE = init(); public static final BlockType DEEPSLATE = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_BRICKS = init();
@Nullable
public static final BlockType DEEPSLATE_BRICK_SLAB = init(); public static final BlockType DEEPSLATE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_BRICK_STAIRS = init(); public static final BlockType DEEPSLATE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_BRICK_WALL = init(); public static final BlockType DEEPSLATE_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_BRICKS = init();
@Nullable
public static final BlockType DEEPSLATE_COAL_ORE = init(); public static final BlockType DEEPSLATE_COAL_ORE = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_COPPER_ORE = init(); public static final BlockType DEEPSLATE_COPPER_ORE = init();
@ -595,14 +593,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType DEEPSLATE_REDSTONE_ORE = init(); public static final BlockType DEEPSLATE_REDSTONE_ORE = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_TILES = init();
@Nullable
public static final BlockType DEEPSLATE_TILE_SLAB = init(); public static final BlockType DEEPSLATE_TILE_SLAB = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_TILE_STAIRS = init(); public static final BlockType DEEPSLATE_TILE_STAIRS = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_TILE_WALL = init(); public static final BlockType DEEPSLATE_TILE_WALL = init();
@Nullable @Nullable
public static final BlockType DEEPSLATE_TILES = init();
@Nullable
public static final BlockType DETECTOR_RAIL = init(); public static final BlockType DETECTOR_RAIL = init();
@Nullable @Nullable
public static final BlockType DIAMOND_BLOCK = init(); public static final BlockType DIAMOND_BLOCK = init();
@ -641,6 +639,8 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType ENCHANTING_TABLE = init(); public static final BlockType ENCHANTING_TABLE = init();
@Nullable @Nullable
public static final BlockType ENDER_CHEST = init();
@Nullable
public static final BlockType END_GATEWAY = init(); public static final BlockType END_GATEWAY = init();
@Nullable @Nullable
public static final BlockType END_PORTAL = init(); public static final BlockType END_PORTAL = init();
@ -651,18 +651,16 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType END_STONE = init(); public static final BlockType END_STONE = init();
@Nullable @Nullable
public static final BlockType END_STONE_BRICKS = init();
@Nullable
public static final BlockType END_STONE_BRICK_SLAB = init(); public static final BlockType END_STONE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType END_STONE_BRICK_STAIRS = init(); public static final BlockType END_STONE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType END_STONE_BRICK_WALL = init(); public static final BlockType END_STONE_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType END_STONE_BRICKS = init();
@Nullable
public static final BlockType EXPOSED_COPPER = init(); public static final BlockType EXPOSED_COPPER = init();
@Nullable @Nullable
public static final BlockType ENDER_CHEST = init();
@Nullable
public static final BlockType EXPOSED_CUT_COPPER = init(); public static final BlockType EXPOSED_CUT_COPPER = init();
@Nullable @Nullable
public static final BlockType EXPOSED_CUT_COPPER_SLAB = init(); public static final BlockType EXPOSED_CUT_COPPER_SLAB = init();
@ -685,12 +683,12 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType FLETCHING_TABLE = init(); public static final BlockType FLETCHING_TABLE = init();
@Nullable @Nullable
public static final BlockType FLOWER_POT = init();
@Nullable
public static final BlockType FLOWERING_AZALEA = init(); public static final BlockType FLOWERING_AZALEA = init();
@Nullable @Nullable
public static final BlockType FLOWERING_AZALEA_LEAVES = init(); public static final BlockType FLOWERING_AZALEA_LEAVES = init();
@Nullable @Nullable
public static final BlockType FLOWER_POT = init();
@Nullable
public static final BlockType FROSTED_ICE = init(); public static final BlockType FROSTED_ICE = init();
@Nullable @Nullable
public static final BlockType FURNACE = init(); public static final BlockType FURNACE = init();
@ -701,10 +699,10 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType GLASS_PANE = init(); public static final BlockType GLASS_PANE = init();
@Nullable @Nullable
public static final BlockType GLOW_LICHEN = init();
@Nullable
public static final BlockType GLOWSTONE = init(); public static final BlockType GLOWSTONE = init();
@Nullable @Nullable
public static final BlockType GLOW_LICHEN = init();
@Nullable
public static final BlockType GOLD_BLOCK = init(); public static final BlockType GOLD_BLOCK = init();
@Nullable @Nullable
public static final BlockType GOLD_ORE = init(); public static final BlockType GOLD_ORE = init();
@ -720,9 +718,6 @@ public final class BlockTypes {
public static final BlockType GRASS = init(); public static final BlockType GRASS = init();
@Nullable @Nullable
public static final BlockType GRASS_BLOCK = init(); public static final BlockType GRASS_BLOCK = init();
@Deprecated
@Nullable
public static final BlockType GRASS_PATH = init();
@Nullable @Nullable
public static final BlockType GRAVEL = init(); public static final BlockType GRAVEL = init();
@Nullable @Nullable
@ -790,10 +785,10 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType HEAVY_WEIGHTED_PRESSURE_PLATE = init(); public static final BlockType HEAVY_WEIGHTED_PRESSURE_PLATE = init();
@Nullable @Nullable
public static final BlockType HONEY_BLOCK = init();
@Nullable
public static final BlockType HONEYCOMB_BLOCK = init(); public static final BlockType HONEYCOMB_BLOCK = init();
@Nullable @Nullable
public static final BlockType HONEY_BLOCK = init();
@Nullable
public static final BlockType HOPPER = init(); public static final BlockType HOPPER = init();
@Nullable @Nullable
public static final BlockType HORN_CORAL = init(); public static final BlockType HORN_CORAL = init();
@ -892,6 +887,8 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType LIGHT = init(); public static final BlockType LIGHT = init();
@Nullable @Nullable
public static final BlockType LIGHTNING_ROD = init();
@Nullable
public static final BlockType LIGHT_BLUE_BANNER = init(); public static final BlockType LIGHT_BLUE_BANNER = init();
@Nullable @Nullable
public static final BlockType LIGHT_BLUE_BED = init(); public static final BlockType LIGHT_BLUE_BED = init();
@ -950,8 +947,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType LIGHT_WEIGHTED_PRESSURE_PLATE = init(); public static final BlockType LIGHT_WEIGHTED_PRESSURE_PLATE = init();
@Nullable @Nullable
public static final BlockType LIGHTNING_ROD = init();
@Nullable
public static final BlockType LILAC = init(); public static final BlockType LILAC = init();
@Nullable @Nullable
public static final BlockType LILY_OF_THE_VALLEY = init(); public static final BlockType LILY_OF_THE_VALLEY = init();
@ -1026,10 +1021,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType MELON_STEM = init(); public static final BlockType MELON_STEM = init();
@Nullable @Nullable
public static final BlockType MOSS_BLOCK = init();
@Nullable
public static final BlockType MOSS_CARPET = init();
@Nullable
public static final BlockType MOSSY_COBBLESTONE = init(); public static final BlockType MOSSY_COBBLESTONE = init();
@Nullable @Nullable
public static final BlockType MOSSY_COBBLESTONE_SLAB = init(); public static final BlockType MOSSY_COBBLESTONE_SLAB = init();
@ -1038,13 +1029,17 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType MOSSY_COBBLESTONE_WALL = init(); public static final BlockType MOSSY_COBBLESTONE_WALL = init();
@Nullable @Nullable
public static final BlockType MOSSY_STONE_BRICKS = init();
@Nullable
public static final BlockType MOSSY_STONE_BRICK_SLAB = init(); public static final BlockType MOSSY_STONE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType MOSSY_STONE_BRICK_STAIRS = init(); public static final BlockType MOSSY_STONE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType MOSSY_STONE_BRICK_WALL = init(); public static final BlockType MOSSY_STONE_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType MOSSY_STONE_BRICKS = init(); public static final BlockType MOSS_BLOCK = init();
@Nullable
public static final BlockType MOSS_CARPET = init();
@Nullable @Nullable
public static final BlockType MOVING_PISTON = init(); public static final BlockType MOVING_PISTON = init();
@Nullable @Nullable
@ -1052,6 +1047,12 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType MYCELIUM = init(); public static final BlockType MYCELIUM = init();
@Nullable @Nullable
public static final BlockType NETHERITE_BLOCK = init();
@Nullable
public static final BlockType NETHERRACK = init();
@Nullable
public static final BlockType NETHER_BRICKS = init();
@Nullable
public static final BlockType NETHER_BRICK_FENCE = init(); public static final BlockType NETHER_BRICK_FENCE = init();
@Nullable @Nullable
public static final BlockType NETHER_BRICK_SLAB = init(); public static final BlockType NETHER_BRICK_SLAB = init();
@ -1060,8 +1061,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType NETHER_BRICK_WALL = init(); public static final BlockType NETHER_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType NETHER_BRICKS = init();
@Nullable
public static final BlockType NETHER_GOLD_ORE = init(); public static final BlockType NETHER_GOLD_ORE = init();
@Nullable @Nullable
public static final BlockType NETHER_PORTAL = init(); public static final BlockType NETHER_PORTAL = init();
@ -1074,10 +1073,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType NETHER_WART_BLOCK = init(); public static final BlockType NETHER_WART_BLOCK = init();
@Nullable @Nullable
public static final BlockType NETHERITE_BLOCK = init();
@Nullable
public static final BlockType NETHERRACK = init();
@Nullable
public static final BlockType NOTE_BLOCK = init(); public static final BlockType NOTE_BLOCK = init();
@Nullable @Nullable
public static final BlockType OAK_BUTTON = init(); public static final BlockType OAK_BUTTON = init();
@ -1212,14 +1207,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE = init(); public static final BlockType POLISHED_BLACKSTONE = init();
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICKS = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_SLAB = init(); public static final BlockType POLISHED_BLACKSTONE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_STAIRS = init(); public static final BlockType POLISHED_BLACKSTONE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICK_WALL = init(); public static final BlockType POLISHED_BLACKSTONE_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE_BRICKS = init();
@Nullable
public static final BlockType POLISHED_BLACKSTONE_BUTTON = init(); public static final BlockType POLISHED_BLACKSTONE_BUTTON = init();
@Nullable @Nullable
public static final BlockType POLISHED_BLACKSTONE_PRESSURE_PLATE = init(); public static final BlockType POLISHED_BLACKSTONE_PRESSURE_PLATE = init();
@ -1257,9 +1252,12 @@ public final class BlockTypes {
public static final BlockType POTTED_ACACIA_SAPLING = init(); public static final BlockType POTTED_ACACIA_SAPLING = init();
@Nullable @Nullable
public static final BlockType POTTED_ALLIUM = init(); public static final BlockType POTTED_ALLIUM = init();
@Deprecated //No longer has "bush"
@Nullable @Nullable
public static final BlockType POTTED_AZALEA_BUSH = init(); public static final BlockType POTTED_AZALEA_BUSH = init();
@Nullable @Nullable
public static final BlockType POTTED_AZALEA = init();
@Nullable
public static final BlockType POTTED_AZURE_BLUET = init(); public static final BlockType POTTED_AZURE_BLUET = init();
@Nullable @Nullable
public static final BlockType POTTED_BAMBOO = init(); public static final BlockType POTTED_BAMBOO = init();
@ -1285,9 +1283,12 @@ public final class BlockTypes {
public static final BlockType POTTED_DEAD_BUSH = init(); public static final BlockType POTTED_DEAD_BUSH = init();
@Nullable @Nullable
public static final BlockType POTTED_FERN = init(); public static final BlockType POTTED_FERN = init();
@Deprecated //No longer has "bush"
@Nullable @Nullable
public static final BlockType POTTED_FLOWERING_AZALEA_BUSH = init(); public static final BlockType POTTED_FLOWERING_AZALEA_BUSH = init();
@Nullable @Nullable
public static final BlockType POTTED_FLOWERING_AZALEA = init();
@Nullable
public static final BlockType POTTED_JUNGLE_SAPLING = init(); public static final BlockType POTTED_JUNGLE_SAPLING = init();
@Nullable @Nullable
public static final BlockType POTTED_LILY_OF_THE_VALLEY = init(); public static final BlockType POTTED_LILY_OF_THE_VALLEY = init();
@ -1324,12 +1325,12 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType PRISMARINE = init(); public static final BlockType PRISMARINE = init();
@Nullable @Nullable
public static final BlockType PRISMARINE_BRICKS = init();
@Nullable
public static final BlockType PRISMARINE_BRICK_SLAB = init(); public static final BlockType PRISMARINE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType PRISMARINE_BRICK_STAIRS = init(); public static final BlockType PRISMARINE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType PRISMARINE_BRICKS = init();
@Nullable
public static final BlockType PRISMARINE_SLAB = init(); public static final BlockType PRISMARINE_SLAB = init();
@Nullable @Nullable
public static final BlockType PRISMARINE_STAIRS = init(); public static final BlockType PRISMARINE_STAIRS = init();
@ -1394,6 +1395,18 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType RAW_IRON_BLOCK = init(); public static final BlockType RAW_IRON_BLOCK = init();
@Nullable @Nullable
public static final BlockType REDSTONE_BLOCK = init();
@Nullable
public static final BlockType REDSTONE_LAMP = init();
@Nullable
public static final BlockType REDSTONE_ORE = init();
@Nullable
public static final BlockType REDSTONE_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WALL_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WIRE = init();
@Nullable
public static final BlockType RED_BANNER = init(); public static final BlockType RED_BANNER = init();
@Nullable @Nullable
public static final BlockType RED_BED = init(); public static final BlockType RED_BED = init();
@ -1414,14 +1427,14 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType RED_MUSHROOM_BLOCK = init(); public static final BlockType RED_MUSHROOM_BLOCK = init();
@Nullable @Nullable
public static final BlockType RED_NETHER_BRICKS = init();
@Nullable
public static final BlockType RED_NETHER_BRICK_SLAB = init(); public static final BlockType RED_NETHER_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType RED_NETHER_BRICK_STAIRS = init(); public static final BlockType RED_NETHER_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType RED_NETHER_BRICK_WALL = init(); public static final BlockType RED_NETHER_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType RED_NETHER_BRICKS = init();
@Nullable
public static final BlockType RED_SAND = init(); public static final BlockType RED_SAND = init();
@Nullable @Nullable
public static final BlockType RED_SANDSTONE = init(); public static final BlockType RED_SANDSTONE = init();
@ -1446,18 +1459,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType RED_WOOL = init(); public static final BlockType RED_WOOL = init();
@Nullable @Nullable
public static final BlockType REDSTONE_BLOCK = init();
@Nullable
public static final BlockType REDSTONE_LAMP = init();
@Nullable
public static final BlockType REDSTONE_ORE = init();
@Nullable
public static final BlockType REDSTONE_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WALL_TORCH = init();
@Nullable
public static final BlockType REDSTONE_WIRE = init();
@Nullable
public static final BlockType REPEATER = init(); public static final BlockType REPEATER = init();
@Nullable @Nullable
public static final BlockType REPEATING_COMMAND_BLOCK = init(); public static final BlockType REPEATING_COMMAND_BLOCK = init();
@ -1482,12 +1483,12 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType SCULK_SENSOR = init(); public static final BlockType SCULK_SENSOR = init();
@Nullable @Nullable
public static final BlockType SEAGRASS = init();
@Nullable
public static final BlockType SEA_LANTERN = init(); public static final BlockType SEA_LANTERN = init();
@Nullable @Nullable
public static final BlockType SEA_PICKLE = init(); public static final BlockType SEA_PICKLE = init();
@Nullable @Nullable
public static final BlockType SEAGRASS = init();
@Nullable
public static final BlockType SHROOMLIGHT = init(); public static final BlockType SHROOMLIGHT = init();
@Nullable @Nullable
public static final BlockType SHULKER_BOX = init(); public static final BlockType SHULKER_BOX = init();
@ -1591,14 +1592,16 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType STONE = init(); public static final BlockType STONE = init();
@Nullable @Nullable
public static final BlockType STONECUTTER = init();
@Nullable
public static final BlockType STONE_BRICKS = init();
@Nullable
public static final BlockType STONE_BRICK_SLAB = init(); public static final BlockType STONE_BRICK_SLAB = init();
@Nullable @Nullable
public static final BlockType STONE_BRICK_STAIRS = init(); public static final BlockType STONE_BRICK_STAIRS = init();
@Nullable @Nullable
public static final BlockType STONE_BRICK_WALL = init(); public static final BlockType STONE_BRICK_WALL = init();
@Nullable @Nullable
public static final BlockType STONE_BRICKS = init();
@Nullable
public static final BlockType STONE_BUTTON = init(); public static final BlockType STONE_BUTTON = init();
@Nullable @Nullable
public static final BlockType STONE_PRESSURE_PLATE = init(); public static final BlockType STONE_PRESSURE_PLATE = init();
@ -1607,8 +1610,6 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType STONE_STAIRS = init(); public static final BlockType STONE_STAIRS = init();
@Nullable @Nullable
public static final BlockType STONECUTTER = init();
@Nullable
public static final BlockType STRIPPED_ACACIA_LOG = init(); public static final BlockType STRIPPED_ACACIA_LOG = init();
@Nullable @Nullable
public static final BlockType STRIPPED_ACACIA_WOOD = init(); public static final BlockType STRIPPED_ACACIA_WOOD = init();
@ -1772,10 +1773,10 @@ public final class BlockTypes {
@Nullable @Nullable
public static final BlockType WEATHERED_CUT_COPPER_SLAB = init(); public static final BlockType WEATHERED_CUT_COPPER_SLAB = init();
@Nullable @Nullable
public static final BlockType WEEPING_VINES = init();
@Nullable
public static final BlockType WEATHERED_CUT_COPPER_STAIRS = init(); public static final BlockType WEATHERED_CUT_COPPER_STAIRS = init();
@Nullable @Nullable
public static final BlockType WEEPING_VINES = init();
@Nullable
public static final BlockType WEEPING_VINES_PLANT = init(); public static final BlockType WEEPING_VINES_PLANT = init();
@Nullable @Nullable
public static final BlockType WET_SPONGE = init(); public static final BlockType WET_SPONGE = init();

View File

@ -2,7 +2,6 @@ package com.sk89q.worldedit.world.block;
import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.fastasyncworldedit.core.registry.state.PropertyKey;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.google.common.primitives.Booleans; import com.google.common.primitives.Booleans;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -14,7 +13,6 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.Registries; import com.sk89q.worldedit.world.registry.Registries;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -218,14 +216,15 @@ public class BlockTypesCache {
: item, item -> item)); : item, item -> item));
int size = blockMap.size() + 1; int size = blockMap.size() + 1;
Field[] idFields = BlockID.class.getDeclaredFields();
for (Field field : idFields) {
size = Math.max(field.getInt(null) + 1, size);
}
BIT_OFFSET = MathMan.log2nlz(size); BIT_OFFSET = MathMan.log2nlz(size);
BIT_MASK = ((1 << BIT_OFFSET) - 1); BIT_MASK = ((1 << BIT_OFFSET) - 1);
values = new BlockType[size]; values = new BlockType[size];
/*Field[] idFields = BlockID.class.getDeclaredFields();
for (Field field : idFields) {
size = Math.max(field.getInt(null) + 1, size);
}
// Register the statically declared ones first // Register the statically declared ones first
for (Field field : idFields) { for (Field field : idFields) {
if (field.getType() == int.class) { if (field.getType() == int.class) {
@ -245,9 +244,30 @@ public class BlockTypesCache {
// Note: Throws IndexOutOfBoundsError if nothing is registered and blocksMap is empty // Note: Throws IndexOutOfBoundsError if nothing is registered and blocksMap is empty
values[internalId] = type; values[internalId] = type;
} }
}*/
// Register "Reserved". Ensure air/reserved and 0/1/2/3
{
int internalId = 0;
for (String id : new String[]{"minecraft:__reserved__", "minecraft:air", "minecraft:cave_air",
"minecraft:void_air"}) {
String defaultState = blockMap.remove(id);
if (defaultState == null) {
defaultState = id;
}
if (values[internalId] != null) {
throw new IllegalStateException(
"Invalid duplicate id for __reserved__! Something has gone very wrong. Are " +
"any plugins shading FAWE?!");
}
BlockType type = register(defaultState, internalId, stateList, tickList);
// Note: Throws IndexOutOfBoundsError if nothing is registered and blocksMap is empty
values[internalId] = type;
internalId++;
}
} }
{ // Register new blocks { // Register real blocks
int internalId = 1; int internalId = 1;
for (Map.Entry<String, String> entry : blockMap.entrySet()) { for (Map.Entry<String, String> entry : blockMap.entrySet()) {
String defaultState = entry.getValue(); String defaultState = entry.getValue();

View File

@ -26,7 +26,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.storage.InvalidFormatException; import com.sk89q.worldedit.world.storage.InvalidFormatException;
/** /**
* The chunk format for Minecraft 1.16 and newer * The chunk format for Minecraft 1.16 and 1.17
*/ */
public class AnvilChunk16 extends AnvilChunk15 { public class AnvilChunk16 extends AnvilChunk15 {

View File

@ -0,0 +1,218 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.chunk;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongArrayTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The chunk format for Minecraft 1.18 and newer
*/
public class AnvilChunk18 implements Chunk {
private final CompoundTag rootTag;
private final Int2ObjectOpenHashMap<BlockState[]> blocks;
private final int rootX;
private final int rootZ;
private Map<BlockVector3, Map<String, Tag>> tileEntities;
/**
* Construct the chunk with a compound tag.
*
* @param tag the tag to read
* @throws DataException on a data error
*/
public AnvilChunk18(CompoundTag tag) throws DataException {
rootTag = tag;
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue();
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "sections", ListTag.class).getValue();
blocks = new Int2ObjectOpenHashMap<>(sections.size());
for (Tag rawSectionTag : sections) {
if (!(rawSectionTag instanceof CompoundTag sectionTag)) {
continue;
}
Object yValue = sectionTag.getValue().get("Y").getValue(); // sometimes a byte, sometimes an int
if (!(yValue instanceof Number)) {
throw new InvalidFormatException("Y is not numeric: " + yValue);
}
int y = ((Number) yValue).intValue();
Tag rawBlockStatesTag = sectionTag.getValue().get("block_states"); // null for sections outside of the world limits
if (rawBlockStatesTag instanceof CompoundTag blockStatesTag) {
// parse palette
List<CompoundTag> paletteEntries = blockStatesTag.getList("palette", CompoundTag.class);
int paletteSize = paletteEntries.size();
if (paletteSize == 0) {
continue;
}
BlockState[] palette = new BlockState[paletteSize];
for (int paletteEntryId = 0; paletteEntryId < paletteSize; paletteEntryId++) {
CompoundTag paletteEntry = paletteEntries.get(paletteEntryId);
BlockType type = BlockTypes.get(paletteEntry.getString("Name"));
if (type == null) {
throw new InvalidFormatException("Invalid block type: " + paletteEntry.getString("Name"));
}
BlockState blockState = type.getDefaultState();
if (paletteEntry.containsKey("Properties")) {
CompoundTag properties = NBTUtils.getChildTag(paletteEntry.getValue(), "Properties", CompoundTag.class);
for (Property<?> property : blockState.getStates().keySet()) {
if (properties.containsKey(property.getName())) {
String value = properties.getString(property.getName());
try {
blockState = getBlockStateWith(blockState, property, value);
} catch (IllegalArgumentException e) {
throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().getId() + ", " + property.getName() + ": " + value);
}
}
}
}
palette[paletteEntryId] = blockState;
}
if (paletteSize == 1) {
// the same block everywhere
blocks.put(y, palette);
continue;
}
// parse block states
long[] blockStatesSerialized = NBTUtils.getChildTag(blockStatesTag.getValue(), "data", LongArrayTag.class).getValue();
BlockState[] chunkSectionBlocks = new BlockState[16 * 16 * 16];
blocks.put(y, chunkSectionBlocks);
readBlockStates(palette, blockStatesSerialized, chunkSectionBlocks);
}
}
}
protected void readBlockStates(BlockState[] palette, long[] blockStatesSerialized, BlockState[] chunkSectionBlocks) throws InvalidFormatException {
PackedIntArrayReader reader = new PackedIntArrayReader(blockStatesSerialized);
for (int blockPos = 0; blockPos < chunkSectionBlocks.length; blockPos++) {
int index = reader.get(blockPos);
if (index >= palette.length) {
throw new InvalidFormatException("Invalid block state table entry: " + index);
}
chunkSectionBlocks[blockPos] = palette[index];
}
}
private <T> BlockState getBlockStateWith(BlockState source, Property<T> property, String value) {
return source.with(property, property.getValueFor(value));
}
/**
* Used to load the tile entities.
*/
private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("block_entities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"block_entities", ListTag.class).getValue();
for (Tag tag : tags) {
if (!(tag instanceof CompoundTag t)) {
throw new InvalidFormatException("CompoundTag expected in block_entities");
}
Map<String, Tag> values = new HashMap<>(t.getValue());
int x = ((IntTag) values.get("x")).getValue();
int y = ((IntTag) values.get("y")).getValue();
int z = ((IntTag) values.get("z")).getValue();
BlockVector3 vec = BlockVector3.at(x, y, z);
tileEntities.put(vec, values);
}
}
/**
* Get the map of tags keyed to strings for a block's tile entity data. May
* return null if there is no tile entity data. Not public yet because
* what this function returns isn't ideal for usage.
*
* @param position the position
* @return the compound tag for that position, which may be null
* @throws DataException thrown if there is a data error
*/
@Nullable
private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException {
if (tileEntities == null) {
populateTileEntities();
}
Map<String, Tag> values = tileEntities.get(position);
if (values == null) {
return null;
}
return new CompoundTag(values);
}
@Override
public BaseBlock getBlock(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
int z = position.getZ() - rootZ * 16;
int section = y >> 4;
int yIndex = y & 0x0F;
BlockState[] sectionBlocks = blocks.get(section);
if (sectionBlocks == null) {
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
BlockState state = sectionBlocks[sectionBlocks.length == 1 ? 0 : ((yIndex << 8) | (z << 4) | x)];
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
return state.toBaseBlock(tileEntity);
}
return state.toBaseBlock();
}
}

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.world.chunk.AnvilChunk13;
import com.sk89q.worldedit.world.chunk.AnvilChunk15; import com.sk89q.worldedit.world.chunk.AnvilChunk15;
import com.sk89q.worldedit.world.chunk.AnvilChunk16; import com.sk89q.worldedit.world.chunk.AnvilChunk16;
import com.sk89q.worldedit.world.chunk.AnvilChunk17; import com.sk89q.worldedit.world.chunk.AnvilChunk17;
import com.sk89q.worldedit.world.chunk.AnvilChunk18;
import com.sk89q.worldedit.world.chunk.Chunk; import com.sk89q.worldedit.world.chunk.Chunk;
import com.sk89q.worldedit.world.chunk.OldChunk; import com.sk89q.worldedit.world.chunk.OldChunk;
@ -72,8 +73,28 @@ public class ChunkStoreHelper {
* @throws DataException if the rootTag is not valid chunk data * @throws DataException if the rootTag is not valid chunk data
*/ */
public static Chunk getChunk(CompoundTag rootTag) throws DataException { public static Chunk getChunk(CompoundTag rootTag) throws DataException {
int dataVersion = rootTag.getInt("DataVersion");
if (dataVersion == 0) {
dataVersion = -1;
}
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if ((dataVersion > 0 || hasLevelSections(rootTag)) && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
rootTag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer.fixUp(DataFixer.FixTypes.CHUNK,
rootTag.asBinaryTag(), dataVersion));
dataVersion = currentDataVersion;
}
}
if (dataVersion >= Constants.DATA_VERSION_MC_1_18) {
return new AnvilChunk18(rootTag);
}
//FAWE start - biome and entity restore //FAWE start - biome and entity restore
return getChunk(rootTag, () -> null); return getChunk(rootTag, () -> null);
//FAWE end
} }
/** /**
@ -113,21 +134,6 @@ public class ChunkStoreHelper {
if (dataVersion == 0) { if (dataVersion == 0) {
dataVersion = -1; dataVersion = -1;
} }
final Platform platform = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING);
final int currentDataVersion = platform.getDataVersion();
if (tag
.getValue()
.containsKey("Sections") && dataVersion < currentDataVersion) { // only fix up MCA format, DFU doesn't support MCR chunks
final DataFixer dataFixer = platform.getDataFixer();
if (dataFixer != null) {
//FAWE start - BinaryTag
tag = (CompoundTag) AdventureNBTConverter.fromAdventure(dataFixer
.fixUp(DataFixer.FixTypes.CHUNK, rootTag.asBinaryTag(), dataVersion)
.get("Level"));
//FAWE end
dataVersion = currentDataVersion;
}
}
//FAWE start - biome and entity restore //FAWE start - biome and entity restore
if (dataVersion >= Constants.DATA_VERSION_MC_1_17) { if (dataVersion >= Constants.DATA_VERSION_MC_1_17) {
return new AnvilChunk17(tag, entitiesTag); return new AnvilChunk17(tag, entitiesTag);
@ -153,6 +159,15 @@ public class ChunkStoreHelper {
return new OldChunk(tag); return new OldChunk(tag);
} }
private static boolean hasLevelSections(CompoundTag rootTag) {
Map<String, Tag> children = rootTag.getValue();
Tag levelTag = children.get("Level");
if (levelTag instanceof CompoundTag) {
return ((CompoundTag) levelTag).getValue().containsKey("Sections");
}
return false;
}
private ChunkStoreHelper() { private ChunkStoreHelper() {
} }

View File

@ -105,7 +105,7 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
endIndex = entryName.lastIndexOf('\\'); endIndex = entryName.lastIndexOf('\\');
} }
folder = entryName.substring(0, endIndex); folder = entryName.substring(0, endIndex);
if (folder.endsWith("poi")) { if (folder.endsWith("poi") || folder.endsWith("entities")) {
continue; continue;
} }
name = folder + "/" + name; name = folder + "/" + name;

View File

@ -101,9 +101,7 @@ public class ZippedMcRegionChunkStore extends McRegionChunkStore {
endIndex = entryName.lastIndexOf('\\'); endIndex = entryName.lastIndexOf('\\');
} }
folder = entryName.substring(0, endIndex); folder = entryName.substring(0, endIndex);
//FAWE start - biome and entity restore
if (folder.endsWith("poi") || folder.endsWith("entities")) { if (folder.endsWith("poi") || folder.endsWith("entities")) {
//FAWE end
continue; continue;
} }
name = folder + "/" + name; name = folder + "/" + name;

View File

@ -238,8 +238,8 @@
"worldedit.error.unknown-block": "Block name '{0}' was not recognized.", "worldedit.error.unknown-block": "Block name '{0}' was not recognized.",
"worldedit.error.disallowed-block": "Block '{0}' not allowed (see WorldEdit configuration).", "worldedit.error.disallowed-block": "Block '{0}' not allowed (see WorldEdit configuration).",
"worldedit.error.max-changes": "Max blocks changed in an operation reached ({0}).", "worldedit.error.max-changes": "Max blocks changed in an operation reached ({0}).",
"worldedit.error.max-brush-radius": "Maximum brush radius (in config-legacy.yml): {0}", "worldedit.error.max-brush-radius": "Maximum brush radius (in worldedit-config.yml): {0}",
"worldedit.error.max-radius": "Maximum radius (in config-legacy.yml): {0}", "worldedit.error.max-radius": "Maximum radius (in worldedit-config.yml): {0}",
"worldedit.error.unknown-direction": "Unknown direction: {0}", "worldedit.error.unknown-direction": "Unknown direction: {0}",
"worldedit.error.empty-clipboard": "Your clipboard is empty. Use //copy first.", "worldedit.error.empty-clipboard": "Your clipboard is empty. Use //copy first.",
"worldedit.error.invalid-filename": "Filename '{0}' invalid: {1}", "worldedit.error.invalid-filename": "Filename '{0}' invalid: {1}",