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 22, 2023
2 parents ed30e5b + 6dfa7d1 commit 217231e
Show file tree
Hide file tree
Showing 26 changed files with 351 additions and 176 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/label-merge-conflicts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Label conflicting PRs"
on:
push:
pull_request_target:
types: [ synchronize ]
pull_request:
types: [ synchronize ]

permissions:
pull-requests: write

jobs:
main:
if: github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Label conflicting PRs
uses: eps1lon/actions-label-merge-conflict@v2.1.0
with:
dirtyLabel: "unresolved-merge-conflict"
repoToken: "${{ secrets.GITHUB_TOKEN }}"
commentOnDirty: "Please take a moment and address the merge conflicts of your pull request. Thanks!"
continueOnMissingPermissions: true
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/CommonJavaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean
options.encoding = "UTF-8"
links(
"https://jd.advntr.dev/api/latest/",
"https://logging.apache.org/log4j/2.x/log4j-api/apidocs/",
"https://logging.apache.org/log4j/2.x/javadoc/log4j-api/",
"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/default-impl/0.5.7/",
"https://jd.papermc.io/paper/1.20/",
"https://intellectualsites.github.io/fastasyncworldedit-javadocs/worldedit-core/"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -93,21 +95,24 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
.getInstance()
.getBukkitImplAdapter());
private final ReadWriteLock sectionLock = new ReentrantReadWriteLock();
private final ReentrantLock callLock = new ReentrantLock();
private final ServerLevel serverLevel;
private final int chunkX;
private final int chunkZ;
private final int minHeight;
private final int maxHeight;
private final int minSectionPosition;
private final int maxSectionPosition;
private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>();
private final Object sendLock = new Object();
private LevelChunkSection[] sections;
private LevelChunk levelChunk;
private DataLayer[] blockLight;
private DataLayer[] skyLight;
private boolean createCopy = false;
private PaperweightGetBlocks_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
private int copyKey = 0;

public PaperweightGetBlocks(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
Expand Down Expand Up @@ -142,13 +147,27 @@ public boolean isCreateCopy() {
}

@Override
public void setCreateCopy(boolean createCopy) {
public int setCreateCopy(boolean createCopy) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
}
this.createCopy = createCopy;
return ++this.copyKey;
}

@Override
public IChunkGet getCopy(final int key) {
return copies.remove(key);
}

@Override
public IChunkGet getCopy() {
return copy;
public void lockCall() {
this.callLock.lock();
}

@Override
public void unlockCall() {
this.callLock.unlock();
}

@Override
Expand Down Expand Up @@ -444,8 +463,17 @@ public LevelChunk ensureLoaded(ServerLevel nmsWorld, int chunkX, int chunkZ) {
@Override
@SuppressWarnings("rawtypes")
public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finalizer) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
}
forceLoadSections = false;
copy = createCopy ? new PaperweightGetBlocks_Copy(getChunk()) : null;
PaperweightGetBlocks_Copy copy = createCopy ? new PaperweightGetBlocks_Copy(levelChunk) : null;
if (createCopy) {
if (copies.containsKey(copyKey)) {
throw new IllegalStateException("Copy key already used.");
}
copies.put(copyKey, copy);
}
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
Expand Down Expand Up @@ -882,18 +910,18 @@ private char[] loadPrivately(int layer) {
if (super.sections[layer] != null) {
synchronized (super.sectionLocks[layer]) {
if (super.sections[layer].isFull() && super.blocks[layer] != null) {
char[] blocks = new char[4096];
System.arraycopy(super.blocks[layer], 0, blocks, 0, 4096);
return blocks;
return super.blocks[layer];
}
}
}
return PaperweightGetBlocks.this.update(layer, null, true);
}

@Override
public synchronized void send(int mask, boolean lighting) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting);
public void send(int mask, boolean lighting) {
synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting);
}
}

/**
Expand Down Expand Up @@ -997,9 +1025,7 @@ private char ordinal(net.minecraft.world.level.block.state.BlockState ibd, Paper

public LevelChunkSection[] getSections(boolean force) {
force &= forceLoadSections;
sectionLock.readLock().lock();
LevelChunkSection[] tmp = sections;
sectionLock.readLock().unlock();
if (tmp == null || force) {
try {
sectionLock.writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.world.level.chunk.LevelChunk;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -108,7 +109,8 @@ public boolean isCreateCopy() {
}

@Override
public void setCreateCopy(boolean createCopy) {
public int setCreateCopy(boolean createCopy) {
return -1;
}

@Override
Expand Down Expand Up @@ -215,6 +217,10 @@ public boolean hasSection(int layer) {
@Override
public char[] load(int layer) {
layer -= getMinSectionPosition();
if (blocks[layer] == null) {
blocks[layer] = new char[4096];
Arrays.fill(blocks[layer], (char) BlockTypesCache.ReservedIDs.AIR);
}
return blocks[layer];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -94,6 +96,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
.getInstance()
.getBukkitImplAdapter());
private final ReadWriteLock sectionLock = new ReentrantReadWriteLock();
private final ReentrantLock callLock = new ReentrantLock();
private final ServerLevel serverLevel;
private final int chunkX;
private final int chunkZ;
Expand All @@ -103,14 +106,16 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private final int maxSectionPosition;
private final Registry<Biome> biomeRegistry;
private final IdMap<Holder<Biome>> biomeHolderIdMap;
private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>();
private final Object sendLock = new Object();
private LevelChunkSection[] sections;
private LevelChunk levelChunk;
private DataLayer[] blockLight;
private DataLayer[] skyLight;
private boolean createCopy = false;
private PaperweightGetBlocks_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
private int copyKey = 0;

public PaperweightGetBlocks(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
Expand Down Expand Up @@ -147,13 +152,27 @@ public boolean isCreateCopy() {
}

@Override
public void setCreateCopy(boolean createCopy) {
public int setCreateCopy(boolean createCopy) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
}
this.createCopy = createCopy;
return ++this.copyKey;
}

@Override
public IChunkGet getCopy(final int key) {
return copies.remove(key);
}

@Override
public IChunkGet getCopy() {
return copy;
public void lockCall() {
this.callLock.lock();
}

@Override
public void unlockCall() {
this.callLock.unlock();
}

@Override
Expand Down Expand Up @@ -433,8 +452,17 @@ public LevelChunk ensureLoaded(ServerLevel nmsWorld, int chunkX, int chunkZ) {
@Override
@SuppressWarnings("rawtypes")
public synchronized <T extends Future<T>> T call(IChunkSet set, Runnable finalizer) {
if (!callLock.isHeldByCurrentThread()) {
throw new IllegalStateException("Attempted to call chunk GET but chunk was not call-locked.");
}
forceLoadSections = false;
copy = createCopy ? new PaperweightGetBlocks_Copy(getChunk()) : null;
PaperweightGetBlocks_Copy copy = createCopy ? new PaperweightGetBlocks_Copy(levelChunk) : null;
if (createCopy) {
if (copies.containsKey(copyKey)) {
throw new IllegalStateException("Copy key already used.");
}
copies.put(copyKey, copy);
}
try {
ServerLevel nmsWorld = serverLevel;
LevelChunk nmsChunk = ensureLoaded(nmsWorld, chunkX, chunkZ);
Expand Down Expand Up @@ -928,18 +956,18 @@ private char[] loadPrivately(int layer) {
if (super.sections[layer] != null) {
synchronized (super.sectionLocks[layer]) {
if (super.sections[layer].isFull() && super.blocks[layer] != null) {
char[] blocks = new char[4096];
System.arraycopy(super.blocks[layer], 0, blocks, 0, 4096);
return blocks;
return super.blocks[layer];
}
}
}
return PaperweightGetBlocks.this.update(layer, null, true);
}

@Override
public synchronized void send(int mask, boolean lighting) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting);
public void send(int mask, boolean lighting) {
synchronized (sendLock) {
PaperweightPlatformAdapter.sendChunk(serverLevel, chunkX, chunkZ, lighting);
}
}

/**
Expand Down Expand Up @@ -1050,9 +1078,7 @@ private char ordinal(BlockState ibd, PaperweightFaweAdapter adapter) {

public LevelChunkSection[] getSections(boolean force) {
force &= forceLoadSections;
sectionLock.readLock().lock();
LevelChunkSection[] tmp = sections;
sectionLock.readLock().unlock();
if (tmp == null || force) {
try {
sectionLock.writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
Expand All @@ -24,6 +23,7 @@
import net.minecraft.world.level.chunk.PalettedContainer;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -110,7 +110,8 @@ public boolean isCreateCopy() {
}

@Override
public void setCreateCopy(boolean createCopy) {
public int setCreateCopy(boolean createCopy) {
return -1;
}

@Override
Expand Down Expand Up @@ -206,6 +207,10 @@ public boolean hasSection(int layer) {
@Override
public char[] load(int layer) {
layer -= getMinSectionPosition();
if (blocks[layer] == null) {
blocks[layer] = new char[4096];
Arrays.fill(blocks[layer], (char) BlockTypesCache.ReservedIDs.AIR);
}
return blocks[layer];
}

Expand Down
Loading

0 comments on commit 217231e

Please sign in to comment.