Skip to content

Commit

Permalink
Merge branch 'main' into feat/improved-entity-operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 authored Oct 14, 2023
2 parents d987643 + 470c75d commit 2a45fcd
Show file tree
Hide file tree
Showing 33 changed files with 222 additions and 73 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ logger.lifecycle("""
*******************************************
""")

var rootVersion by extra("2.8.1")
var rootVersion by extra("2.8.2")
var snapshot by extra("SNAPSHOT")
var revision: String by extra("")
var buildNumber by extra("")
Expand Down
5 changes: 3 additions & 2 deletions buildSrc/src/main/kotlin/LibsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ fun Project.applyLibrariesConfiguration() {

scm {
url.set("https://github.com/IntellectualSites/FastAsyncWorldEdit")
connection.set("scm:https://[email protected]/IntellectualSites/FastAsyncWorldEdit.git")
developerConnection.set("scm:git://github.com/IntellectualSites/FastAsyncWorldEdit.git")
connection.set("scm:git:https://github.com/IntellectualSites/FastAsyncWorldEdit.git")
developerConnection.set("scm:git:[email protected]:IntellectualSites/FastAsyncWorldEdit.git")
tag.set("${project.version}")
}

issueManagement {
Expand Down
8 changes: 6 additions & 2 deletions buildSrc/src/main/kotlin/PlatformConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,27 @@ fun Project.applyPlatformAndCoreConfiguration() {
name.set("Alexander Brandes")
email.set("contact(at)notmyfault.dev")
organization.set("IntellectualSites")
organizationUrl.set("https://github.com/IntellectualSites")
}
developer {
id.set("SirYwell")
name.set("Hannes Greule")
organization.set("IntellectualSites")
organizationUrl.set("https://github.com/IntellectualSites")
}
developer {
id.set("dordsor21")
name.set("dordsor21")
organization.set("IntellectualSites")
organizationUrl.set("https://github.com/IntellectualSites")
}
}

scm {
url.set("https://github.com/IntellectualSites/FastAsyncWorldEdit")
connection.set("scm:https://[email protected]/IntellectualSites/FastAsyncWorldEdit.git")
developerConnection.set("scm:git://github.com/IntellectualSites/FastAsyncWorldEdit.git")
connection.set("scm:git:https://github.com/IntellectualSites/FastAsyncWorldEdit.git")
developerConnection.set("scm:git:[email protected]:IntellectualSites/FastAsyncWorldEdit.git")
tag.set("${project.version}")
}

issueManagement{
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mapmanager = "1.8.0-SNAPSHOT"
griefprevention = "16.18.1"
griefdefender = "2.1.0-SNAPSHOT"
residence = "4.5._13.1"
towny = "0.99.5.20"
towny = "0.99.6.0"
plotsquared = "7.0.0"

# Third party
Expand All @@ -23,9 +23,9 @@ sparsebitset = "1.3"
parallelgzip = "1.0.5"
adventure = "4.14.0"
adventure-bukkit = "4.3.1"
checkerqual = "3.38.0"
checkerqual = "3.39.0"
truezip = "6.8.4"
auto-value = "1.10.2"
auto-value = "1.10.4"
findbugs = "3.0.2"
rhino-runtime = "1.7.14"
zstd-jni = "1.4.8-1" # Not latest as it can be difficult to obtain latest ZSTD libs
Expand All @@ -46,7 +46,7 @@ text = "3.0.4"
piston = "0.5.7"

# Tests
mockito = "5.5.0"
mockito = "5.6.0"

# Gradle plugins
pluginyml = "0.6.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.PaperweightFaweAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_17_R1_2.PaperweightPlatformAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent;
Expand Down Expand Up @@ -288,7 +289,9 @@ private static void readTagIntoEntity(net.minecraft.nbt.CompoundTag tag, Entity
* @param tag the tag
*/
private static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag tag) {
entity.save(tag);
//FAWE start - avoid villager async catcher
PaperweightPlatformAdapter.readEntityIntoTag(entity, tag);
//FAWE end
}

private static Block getBlockFromType(BlockType blockType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ private static String getEntityId(Entity entity) {
return resourceLocation == null ? null : resourceLocation.toString();
}

private static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag compoundTag) {
entity.save(compoundTag);
}

@Override
public BukkitImplAdapter<net.minecraft.nbt.Tag> getParent() {
return parent;
Expand Down Expand Up @@ -367,7 +363,7 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
PaperweightPlatformAdapter.readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public boolean contains(Object get) {
public Iterator<CompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
input.save(tag);
PaperweightPlatformAdapter.readEntityIntoTag(input, tag);
return (CompoundTag) adapter.toNative(tag);
}).collect(Collectors.toList());
return result.iterator();
Expand Down Expand Up @@ -445,7 +445,7 @@ public LevelChunk ensureLoaded(ServerLevel nmsWorld, int chunkX, int chunkZ) {
@SuppressWarnings("rawtypes")
public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finalizer) {
forceLoadSections = false;
copy = createCopy ? new PaperweightGetBlocks_Copy(levelChunk) : null;
copy = createCopy ? new PaperweightGetBlocks_Copy(getChunk()) : null;
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public CompoundTag getTile(int x, int y, int z) {
protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag);
PaperweightPlatformAdapter.readEntityIntoTag(entity, compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import net.minecraft.util.BitStorage;
import net.minecraft.util.Unit;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome;
Expand Down Expand Up @@ -90,6 +92,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final Field fieldGameEventDispatcherSections;
private static final MethodHandle methodremoveBlockEntityTicker;

private static final Field fieldOffers;
private static final MerchantOffers OFFERS = new MerchantOffers();

private static final Field fieldRemove;

private static final Logger LOGGER = LogManagerCompat.getLogger();
Expand Down Expand Up @@ -145,6 +150,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {

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

fieldOffers = AbstractVillager.class.getDeclaredField(Refraction.pickName("offers", "bU"));
fieldOffers.setAccessible(true);
} catch (RuntimeException e) {
throw e;
} catch (Throwable rethrow) {
Expand Down Expand Up @@ -492,4 +500,27 @@ static List<Entity> getEntities(LevelChunk chunk) {
return chunk.level.entityManager.getEntities(chunk.getPos());
}

public static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag compoundTag) {
boolean isVillager = entity instanceof AbstractVillager && !Fawe.isMainThread();
boolean unset = false;
if (isVillager) {
try {
if (fieldOffers.get(entity) != null) {
fieldOffers.set(entity, OFFERS);
unset = true;
}
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to set offers field to villager to avoid async catcher.", e);
}
}
entity.save(compoundTag);
if (unset) {
try {
fieldOffers.set(entity, null);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to set offers field to null again on villager.", e);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.PaperweightPlatformAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent;
Expand Down Expand Up @@ -270,7 +271,9 @@ private static Entity createEntityFromId(String id, net.minecraft.world.level.Le
* @param tag the tag
*/
private static void readTagIntoEntity(net.minecraft.nbt.CompoundTag tag, Entity entity) {
entity.load(tag);
//FAWE start - avoid villager async catcher
PaperweightPlatformAdapter.readEntityIntoTag(entity, tag);
//FAWE end
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ private static String getEntityId(Entity entity) {
return resourceLocation == null ? null : resourceLocation.toString();
}

private static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag compoundTag) {
entity.save(compoundTag);
}

@Override
public BukkitImplAdapter<net.minecraft.nbt.Tag> getParent() {
return parent;
Expand Down Expand Up @@ -360,7 +356,7 @@ public BaseEntity getEntity(org.bukkit.entity.Entity entity) {
EntityType type = com.sk89q.worldedit.world.entity.EntityTypes.get(id);
Supplier<CompoundBinaryTag> saveTag = () -> {
final net.minecraft.nbt.CompoundTag minecraftTag = new net.minecraft.nbt.CompoundTag();
readEntityIntoTag(mcEntity, minecraftTag);
PaperweightPlatformAdapter.readEntityIntoTag(mcEntity, minecraftTag);
//add Id for AbstractChangeSet to work
final CompoundBinaryTag tag = (CompoundBinaryTag) toNativeBinary(minecraftTag);
final Map<String, BinaryTag> tags = NbtUtils.getCompoundBinaryTagValues(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public boolean contains(Object get) {
public Iterator<CompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
input.save(tag);
PaperweightPlatformAdapter.readEntityIntoTag(input, tag);
return (CompoundTag) adapter.toNative(tag);
}).collect(Collectors.toList());
return result.iterator();
Expand Down Expand Up @@ -434,7 +434,7 @@ public LevelChunk ensureLoaded(ServerLevel nmsWorld, int chunkX, int chunkZ) {
@SuppressWarnings("rawtypes")
public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finalizer) {
forceLoadSections = false;
copy = createCopy ? new PaperweightGetBlocks_Copy(levelChunk) : null;
copy = createCopy ? new PaperweightGetBlocks_Copy(getChunk()) : null;
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CompoundTag getTile(int x, int y, int z) {
protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag);
PaperweightPlatformAdapter.readEntityIntoTag(entity, compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import net.minecraft.util.Unit;
import net.minecraft.util.ZeroBitStorage;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.biome.Biome;
Expand Down Expand Up @@ -98,6 +100,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {
private static final MethodHandle methodRemoveGameEventListener;
private static final MethodHandle methodremoveTickingBlockEntity;

private static final Field fieldOffers;
private static final MerchantOffers OFFERS = new MerchantOffers();

private static final Field fieldRemove;

private static final Logger LOGGER = LogManagerCompat.getLogger();
Expand Down Expand Up @@ -158,6 +163,9 @@ public final class PaperweightPlatformAdapter extends NMSAdapter {

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

fieldOffers = AbstractVillager.class.getDeclaredField(Refraction.pickName("offers", "bW"));
fieldOffers.setAccessible(true);
} catch (RuntimeException e) {
throw e;
} catch (Throwable rethrow) {
Expand Down Expand Up @@ -571,7 +579,6 @@ public static BiomeType adapt(Holder<Biome> biome, LevelAccessor levelAccessor)
return BiomeTypes.get(biome.unwrapKey().orElseThrow().location().toString());
}

@SuppressWarnings("unchecked")
static void removeBeacon(BlockEntity beacon, LevelChunk levelChunk) {
try {
// Do the method ourselves to avoid trying to reflect generic method parameters
Expand All @@ -595,6 +602,29 @@ static List<Entity> getEntities(LevelChunk chunk) {
return chunk.level.entityManager.getEntities(chunk.getPos());
}

public static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag compoundTag) {
boolean isVillager = entity instanceof AbstractVillager && !Fawe.isMainThread();
boolean unset = false;
if (isVillager) {
try {
if (fieldOffers.get(entity) != null) {
fieldOffers.set(entity, OFFERS);
unset = true;
}
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to set offers field to villager to avoid async catcher.", e);
}
}
entity.save(compoundTag);
if (unset) {
try {
fieldOffers.set(entity, null);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to set offers field to null again on villager.", e);
}
}
}

record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_19_R3.PaperweightPlatformAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extension.platform.Watchdog;
import com.sk89q.worldedit.extent.Extent;
Expand Down Expand Up @@ -276,7 +277,9 @@ private static void readTagIntoEntity(net.minecraft.nbt.CompoundTag tag, Entity
* @param tag the tag
*/
private static void readEntityIntoTag(Entity entity, net.minecraft.nbt.CompoundTag tag) {
entity.save(tag);
//FAWE start - avoid villager async catcher
PaperweightPlatformAdapter.readEntityIntoTag(entity, tag);
//FAWE end
}

private static Block getBlockFromType(BlockType blockType) {
Expand Down
Loading

0 comments on commit 2a45fcd

Please sign in to comment.