Skip to content

Commit 89e6aaf

Browse files
committed
add for 1.21.11
1 parent 363f234 commit 89e6aaf

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/PaperweightFaweAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ public BaseBlock getFullBlock(final Location location) {
324324
SideEffect.HISTORY,
325325
SideEffect.HEIGHTMAPS,
326326
SideEffect.LIGHTING,
327-
SideEffect.NEIGHBORS
327+
SideEffect.NEIGHBORS,
328+
SideEffect.ENTITY_EVENTS
328329
);
329330

330331
@Override

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/PaperweightGetBlocks.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,34 @@ protected <T extends Future<T>> T internalCall(
667667
entity.load(input);
668668
entity.absSnapTo(x, y, z, yaw, pitch);
669669
entity.setUUID(NbtUtils.uuid(nativeTag));
670+
Runnable onError = () -> LOGGER.warn(
671+
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
672+
id,
673+
nmsWorld.getWorld().getName(),
674+
x,
675+
y,
676+
z
677+
);
678+
if (!set.getSideEffectSet().shouldApply(SideEffect.ENTITY_EVENTS)) {
679+
entity.spawnReason = CreatureSpawnEvent.SpawnReason.CUSTOM;
680+
entity.generation = false;
681+
if (PaperLib.isPaper()) {
682+
if (!nmsWorld.moonrise$getEntityLookup().addNewEntity(entity, false)) {
683+
onError.run();
684+
}
685+
continue;
686+
}
687+
// Not paper
688+
try {
689+
PaperweightPlatformAdapter.getEntitySectionManager(nmsWorld).addNewEntity(entity);
690+
continue;
691+
} catch (IllegalAccessException e) {
692+
// Fallback
693+
LOGGER.warn("Error bypassing entity events on spawn on Spigot", e);
694+
}
695+
}
670696
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
671-
LOGGER.warn(
672-
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
673-
id,
674-
nmsWorld.getWorld().getName(),
675-
x,
676-
y,
677-
z
678-
);
697+
onError.run();
679698
// Unsuccessful create should not be saved to history
680699
iterator.remove();
681700
}

worldedit-bukkit/adapters/adapter-1_21_11/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_11/PaperweightPlatformAdapter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,18 @@ static List<Entity> getEntities(LevelChunk chunk) {
624624
}
625625
try {
626626
//noinspection unchecked
627-
return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos());
627+
return getEntitySectionManager(chunk.level).getEntities(chunk.getPos());
628628
} catch (IllegalAccessException e) {
629629
throw new RuntimeException("Failed to lookup entities [PAPER=false]", e);
630630
}
631631
}
632632

633+
/**
634+
* Spigot only
635+
*/
636+
static PersistentEntitySectionManager<Entity> getEntitySectionManager(ServerLevel level) throws IllegalAccessException {
637+
//noinspection unchecked
638+
return (PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(level));
639+
}
640+
633641
}

0 commit comments

Comments
 (0)