|
2 | 2 |
|
3 | 3 | import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices; |
4 | 4 | import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkHolderManager; |
5 | | -import com.destroystokyo.paper.util.maplist.EntityList; |
6 | 5 | import com.fastasyncworldedit.bukkit.adapter.CachedBukkitAdapter; |
7 | 6 | import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore; |
8 | 7 | import com.fastasyncworldedit.bukkit.adapter.NMSAdapter; |
@@ -117,9 +116,7 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { |
117 | 116 |
|
118 | 117 | private static final Logger LOGGER = LogManagerCompat.getLogger(); |
119 | 118 |
|
120 | | - static final boolean POST_CHUNK_REWRITE; |
121 | 119 | private static Method PAPER_CHUNK_GEN_ALL_ENTITIES; |
122 | | - private static Field LEVEL_CHUNK_ENTITIES; |
123 | 120 | private static Field SERVER_LEVEL_ENTITY_MANAGER; |
124 | 121 |
|
125 | 122 | static { |
@@ -189,28 +186,15 @@ public final class PaperweightPlatformAdapter extends NMSAdapter { |
189 | 186 | fieldRemove = BlockEntity.class.getDeclaredField(Refraction.pickName("remove", "p")); |
190 | 187 | fieldRemove.setAccessible(true); |
191 | 188 |
|
192 | | - boolean chunkRewrite; |
193 | 189 | try { |
194 | 190 | Level.class.getDeclaredMethod("moonrise$getEntityLookup"); |
195 | | - chunkRewrite = true; |
196 | 191 | PAPER_CHUNK_GEN_ALL_ENTITIES = ChunkEntitySlices.class.getDeclaredMethod("getAllEntities"); |
197 | 192 | PAPER_CHUNK_GEN_ALL_ENTITIES.setAccessible(true); |
198 | 193 | } catch (NoSuchMethodException ignored) { |
199 | | - chunkRewrite = false; |
200 | | - } |
201 | | - try { |
202 | | - // Paper - Pre-Chunk-Update |
203 | | - LEVEL_CHUNK_ENTITIES = LevelChunk.class.getDeclaredField("entities"); |
204 | | - LEVEL_CHUNK_ENTITIES.setAccessible(true); |
205 | | - } catch (NoSuchFieldException ignored) { |
206 | | - } |
207 | | - try { |
208 | 194 | // Non-Paper |
209 | 195 | SERVER_LEVEL_ENTITY_MANAGER = ServerLevel.class.getDeclaredField(Refraction.pickName("entityManager", "N")); |
210 | 196 | SERVER_LEVEL_ENTITY_MANAGER.setAccessible(true); |
211 | | - } catch (NoSuchFieldException ignored) { |
212 | 197 | } |
213 | | - POST_CHUNK_REWRITE = chunkRewrite; |
214 | 198 | } catch (RuntimeException | Error e) { |
215 | 199 | throw e; |
216 | 200 | } catch (Exception e) { |
@@ -657,32 +641,22 @@ static void removeBeacon(BlockEntity beacon, LevelChunk levelChunk) { |
657 | 641 | } |
658 | 642 |
|
659 | 643 | static List<Entity> getEntities(LevelChunk chunk) { |
660 | | - ExceptionCollector<RuntimeException> collector = new ExceptionCollector<>(); |
661 | 644 | if (PaperLib.isPaper()) { |
662 | | - if (POST_CHUNK_REWRITE) { |
663 | | - try { |
664 | | - //noinspection unchecked |
665 | | - return (List<Entity>) PAPER_CHUNK_GEN_ALL_ENTITIES.invoke(chunk.level.moonrise$getEntityLookup().getChunk(chunk.locX, chunk.locZ)); |
666 | | - } catch (IllegalAccessException | InvocationTargetException e) { |
667 | | - throw new RuntimeException("Failed to lookup entities [POST_CHUNK_REWRITE=true]", e); |
668 | | - } |
669 | | - } |
670 | 645 | try { |
671 | | - EntityList entityList = (EntityList) LEVEL_CHUNK_ENTITIES.get(chunk); |
672 | | - return List.of(entityList.getRawData()); |
673 | | - } catch (IllegalAccessException e) { |
674 | | - collector.add(new RuntimeException("Failed to lookup entities [POST_CHUNK_REWRITE=false]", e)); |
675 | | - // fall through |
| 646 | + //noinspection unchecked |
| 647 | + return (List<Entity>) PAPER_CHUNK_GEN_ALL_ENTITIES.invoke(chunk.level |
| 648 | + .moonrise$getEntityLookup() |
| 649 | + .getChunk(chunk.locX, chunk.locZ)); |
| 650 | + } catch (IllegalAccessException | InvocationTargetException e) { |
| 651 | + throw new RuntimeException("Failed to lookup entities [PAPER=true]", e); |
676 | 652 | } |
677 | 653 | } |
678 | 654 | try { |
679 | 655 | //noinspection unchecked |
680 | 656 | return ((PersistentEntitySectionManager<Entity>) (SERVER_LEVEL_ENTITY_MANAGER.get(chunk.level))).getEntities(chunk.getPos()); |
681 | 657 | } catch (IllegalAccessException e) { |
682 | | - collector.add(new RuntimeException("Failed to lookup entities [PAPER=false]", e)); |
| 658 | + throw new RuntimeException("Failed to lookup entities [PAPER=false]", e); |
683 | 659 | } |
684 | | - collector.throwIfPresent(); |
685 | | - return List.of(); |
686 | 660 | } |
687 | 661 |
|
688 | 662 | record FakeIdMapBlock(int size) implements IdMap<net.minecraft.world.level.block.state.BlockState> { |
|
0 commit comments