13
0
geforkt von Mirrors/Paper

Begin fixing issues

See diff in the update text file
Dieser Commit ist enthalten in:
Spottedleaf 2024-10-24 08:18:20 -07:00
Ursprung c4d6fdcff0
Commit 77baea3bf9
9 geänderte Dateien mit 2540 neuen und 2481 gelöschten Zeilen

Datei anzeigen

@ -13,12 +13,7 @@ add notes to moonrise patch:
todo:
- double check that the misc changes commit on dev/1.21.2 moonrise is applied
- implement platformhooks
- delete old block state table patch
- in StateHolder, implement getNullableValue from blockstate_propertyaccess
- ChunkEntitySlices getChunkEntities(), callEntitiesLoadEvent(), callEntitiesUnloadEvent()
- in ChunkEntitySlices, implement modifySavedEntities() by copying from old
- in ChunkEntitySlices, implement unload() Entity.setRemoved()
- change PersistentEntitySectionManager addEntity chunk system call to have event=true
- implement PlayerChunkUnloadEvent in PlatformHooks#onChunkUnWatch
- make sure chunk pos is passed in PlatformHooks#postLoadProtoChunk
- implement chunk_system.ChunkMapMixin diff from reference
@ -32,11 +27,10 @@ todo:
- implement chunk_system.ServerLevelMixin diff from reference
- implement chunk_tick_iteration
- implement collisions.ServerExplosionMixin diff from reference
- implement modifyEntityTrackingRange with org.spigotmc.TrackingRange.getEntityTrackingRange
- implement random_ticking.BiomeMixin diff from reference
- implement starlight.LevelLightEngineMixin diff from reference
- implement starlight.ThreadedLevelLightEngineMixin diff from reference
- implement starlight.ChunkSerializerMixin diff from reference
- implement starlight.SerializableChunkData$SectionData diff from reference
- implement starlight.SerializableChunkDataMixin diff from reference
- unfuck the chtunk system config diff
- chunk system: move get entity lookup reroute into the folia scheduler api patch

Datei anzeigen

@ -12,10 +12,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@
+package ca.spottedleaf.moonrise.common;
+
+import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder;
+import com.mojang.datafixers.DataFixer;
+import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ChunkHolder;
+import net.minecraft.server.level.GenerationChunkHolder;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
@ -56,7 +56,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ public boolean allowAsyncTicketUpdates();
+
+ public void onChunkHolderTicketChange(final ServerLevel world, final NewChunkHolder holder, final int oldLevel, final int newLevel);
+ public void onChunkHolderTicketChange(final ServerLevel world, final ChunkHolder holder, final int oldLevel, final int newLevel);
+
+ public void chunkUnloadFromWorld(final LevelChunk chunk);
+
@ -694,11 +694,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
-import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor;
+import ca.spottedleaf.concurrentutil.util.Priority;
+import ca.spottedleaf.moonrise.common.PlatformHooks;
import ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel;
import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkSystemLevelChunk;
import ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader;
import com.mojang.logging.LogUtils;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.FullChunkStatus;
@@ -0,0 +0,0 @@ public final class ChunkSystem {
private static final Logger LOGGER = LogUtils.getLogger();
}
public static void scheduleChunkTask(final ServerLevel level, final int chunkX, final int chunkZ, final Runnable run) {
- scheduleChunkTask(level, chunkX, chunkZ, run, PrioritisedExecutor.Priority.NORMAL);
@ -707,27 +707,47 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- public static void scheduleChunkTask(final ServerLevel level, final int chunkX, final int chunkZ, final Runnable run, final PrioritisedExecutor.Priority priority) {
+ public static void scheduleChunkTask(final ServerLevel level, final int chunkX, final int chunkZ, final Runnable run, final Priority priority) {
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleChunkTask(chunkX, chunkZ, run, priority);
level.chunkSource.mainThreadProcessor.execute(run);
}
public static void scheduleChunkLoad(final ServerLevel level, final int chunkX, final int chunkZ, final boolean gen,
- final ChunkStatus toStatus, final boolean addTicket, final PrioritisedExecutor.Priority priority,
+ final ChunkStatus toStatus, final boolean addTicket, final Priority priority,
final Consumer<ChunkAccess> onComplete) {
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleChunkLoad(chunkX, chunkZ, gen, toStatus, addTicket, priority, onComplete);
}
if (gen) {
scheduleChunkLoad(level, chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
@@ -0,0 +0,0 @@ public final class ChunkSystem {
private static long chunkLoadCounter = 0L;
public static void scheduleChunkLoad(final ServerLevel level, final int chunkX, final int chunkZ, final ChunkStatus toStatus,
- final boolean addTicket, final PrioritisedExecutor.Priority priority, final Consumer<ChunkAccess> onComplete) {
+ final boolean addTicket, final Priority priority, final Consumer<ChunkAccess> onComplete) {
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleChunkLoad(chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
if (!org.bukkit.Bukkit.isPrimaryThread()) {
scheduleChunkTask(level, chunkX, chunkZ, () -> {
scheduleChunkLoad(level, chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
@@ -0,0 +0,0 @@ public final class ChunkSystem {
}
loadCallback.accept(result.orElse(null));
}, (final Runnable r) -> {
- scheduleChunkTask(level, chunkX, chunkZ, r, PrioritisedExecutor.Priority.HIGHEST);
+ scheduleChunkTask(level, chunkX, chunkZ, r, Priority.HIGHEST);
});
}
public static void scheduleTickingState(final ServerLevel level, final int chunkX, final int chunkZ,
final FullChunkStatus toStatus, final boolean addTicket,
- final PrioritisedExecutor.Priority priority, final Consumer<LevelChunk> onComplete) {
+ final Priority priority, final Consumer<LevelChunk> onComplete) {
((ChunkSystemServerLevel)level).moonrise$getChunkTaskScheduler().scheduleTickingState(chunkX, chunkZ, toStatus, addTicket, priority, onComplete);
// This method goes unused until the chunk system rewrite
if (toStatus == FullChunkStatus.INACCESSIBLE) {
throw new IllegalArgumentException("Cannot wait for INACCESSIBLE status");
@@ -0,0 +0,0 @@ public final class ChunkSystem {
}
loadCallback.accept(result.orElse(null));
}, (final Runnable r) -> {
- scheduleChunkTask(level, chunkX, chunkZ, r, PrioritisedExecutor.Priority.HIGHEST);
+ scheduleChunkTask(level, chunkX, chunkZ, r, Priority.HIGHEST);
});
}
@@ -0,0 +0,0 @@ public final class ChunkSystem {
@ -1002,6 +1022,211 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
public static int getMaxLightSection(final LevelHeightAccessor world) {
diff --git a/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java b/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
@@ -0,0 +0,0 @@
+package ca.spottedleaf.moonrise.paper;
+
+import ca.spottedleaf.moonrise.common.PlatformHooks;
+import com.mojang.datafixers.DataFixer;
+import net.minecraft.core.BlockPos;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ChunkHolder;
+import net.minecraft.server.level.GenerationChunkHolder;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.util.datafix.DataFixTypes;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.level.BlockGetter;
+import net.minecraft.world.level.ChunkPos;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.chunk.ChunkAccess;
+import net.minecraft.world.level.chunk.LevelChunk;
+import net.minecraft.world.level.chunk.ProtoChunk;
+import net.minecraft.world.level.chunk.storage.SerializableChunkData;
+import net.minecraft.world.level.entity.EntityTypeTest;
+import net.minecraft.world.phys.AABB;
+import java.util.List;
+import java.util.function.Predicate;
+
+public final class PaperHooks implements PlatformHooks {
+
+ @Override
+ public String getBrand() {
+ return "Paper";
+ }
+
+ @Override
+ public int getLightEmission(final BlockState blockState, final BlockGetter world, final BlockPos pos) {
+ return blockState.getLightEmission();
+ }
+
+ @Override
+ public Predicate<BlockState> maybeHasLightEmission() {
+ return (final BlockState state) -> {
+ return state.getLightEmission() != 0;
+ };
+ }
+
+ @Override
+ public boolean hasCurrentlyLoadingChunk() {
+ return false;
+ }
+
+ @Override
+ public LevelChunk getCurrentlyLoadingChunk(final GenerationChunkHolder holder) {
+ return null;
+ }
+
+ @Override
+ public void setCurrentlyLoading(final GenerationChunkHolder holder, final LevelChunk levelChunk) {
+
+ }
+
+ @Override
+ public void chunkFullStatusComplete(final LevelChunk newChunk, final ProtoChunk original) {
+
+ }
+
+ @Override
+ public boolean allowAsyncTicketUpdates() {
+ return true;
+ }
+
+ @Override
+ public void onChunkHolderTicketChange(final ServerLevel world, final ChunkHolder holder, final int oldLevel, final int newLevel) {
+
+ }
+
+ @Override
+ public void chunkUnloadFromWorld(final LevelChunk chunk) {
+
+ }
+
+ @Override
+ public void chunkSyncSave(final ServerLevel world, final ChunkAccess chunk, final SerializableChunkData data) {
+
+ }
+
+ @Override
+ public void onChunkWatch(final ServerLevel world, final LevelChunk chunk, final ServerPlayer player) {
+
+ }
+
+ @Override
+ public void onChunkUnWatch(final ServerLevel world, final ChunkPos chunk, final ServerPlayer player) {
+
+ }
+
+ @Override
+ public void addToGetEntities(final Level world, final Entity entity, final AABB boundingBox, final Predicate<? super Entity> predicate, final List<Entity> into) {
+
+ }
+
+ @Override
+ public <T extends Entity> void addToGetEntities(final Level world, final EntityTypeTest<Entity, T> entityTypeTest, final AABB boundingBox, final Predicate<? super T> predicate, final List<? super T> into, final int maxCount) {
+
+ }
+
+ @Override
+ public void entityMove(final Entity entity, final long oldSection, final long newSection) {
+
+ }
+
+ @Override
+ public boolean screenEntity(final ServerLevel world, final Entity entity, final boolean fromDisk, final boolean event) {
+ return true;
+ }
+
+ @Override
+ public boolean configFixMC224294() {
+ return true;
+ }
+
+ @Override
+ public boolean configAutoConfigSendDistance() {
+
+ }
+
+ @Override
+ public double configPlayerMaxLoadRate() {
+
+ }
+
+ @Override
+ public double configPlayerMaxGenRate() {
+
+ }
+
+ @Override
+ public double configPlayerMaxSendRate() {
+
+ }
+
+ @Override
+ public int configPlayerMaxConcurrentLoads() {
+
+ }
+
+ @Override
+ public int configPlayerMaxConcurrentGens() {
+
+ }
+
+ @Override
+ public long configAutoSaveInterval() {
+
+ }
+
+ @Override
+ public int configMaxAutoSavePerTick() {
+
+ }
+
+ @Override
+ public boolean configFixMC159283() {
+ return true;
+ }
+
+ @Override
+ public boolean forceNoSave(final ChunkAccess chunk) {
+ return chunk instanceof LevelChunk levelChunk && levelChunk.mustNotSave;
+ }
+
+ @Override
+ public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion) {
+ return type.update(dataFixer, nbt, fromVersion, toVersion);
+ }
+
+ @Override
+ public boolean hasMainChunkLoadHook() {
+ return false;
+ }
+
+ @Override
+ public void mainChunkLoad(final ChunkAccess chunk, final SerializableChunkData chunkData) {
+
+ }
+
+ @Override
+ public List<Entity> modifySavedEntities(final ServerLevel world, final int chunkX, final int chunkZ, final List<Entity> entities) {
+ return entities;
+ }
+
+ @Override
+ public void unloadEntity(final Entity entity) {
+ entity.setRemoved(Entity.RemovalReason.UNLOADED_TO_CHUNK, org.bukkit.event.entity.EntityRemoveEvent.Cause.UNLOAD);
+ }
+
+ @Override
+ public int modifyEntityTrackingRange(final Entity entity, final int currentRange) {
+ return org.spigotmc.TrackingRange.getEntityTrackingRange(entity, currentRange);
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
@ -1029,3 +1254,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
// Paper end - chunk system hooks
if (!this.addEntityUuid(entity)) {
diff --git a/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks b/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/resources/META-INF/services/ca.spottedleaf.moonrise.common.PlatformHooks
@@ -0,0 +1 @@
+ca.spottedleaf.moonrise.paper.PaperHooks

Datei anzeigen

@ -0,0 +1,117 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 23 Oct 2024 22:13:41 -0700
Subject: [PATCH] fixup! MC Utils
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/PlatformHooks.java
@@ -0,0 +0,0 @@
package ca.spottedleaf.moonrise.common;
+import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixer;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
@@ -0,0 +0,0 @@ import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.GenerationChunkHolder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
-import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
@@ -0,0 +0,0 @@ public interface PlatformHooks {
// support for CB chunk mustNotSave
public boolean forceNoSave(final ChunkAccess chunk);
- public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt,
+ public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt,
final int fromVersion, final int toVersion);
public boolean hasMainChunkLoadHook();
@@ -0,0 +0,0 @@ public interface PlatformHooks {
public void unloadEntity(final Entity entity);
+ public void postLoadProtoChunk(final ServerLevel world, final ProtoChunk chunk);
+
public int modifyEntityTrackingRange(final Entity entity, final int currentRange);
public static final class Holder {
diff --git a/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java b/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
+++ b/src/main/java/ca/spottedleaf/moonrise/paper/PaperHooks.java
@@ -0,0 +0,0 @@
package ca.spottedleaf.moonrise.paper;
import ca.spottedleaf.moonrise.common.PlatformHooks;
+import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFixer;
+import com.mojang.serialization.Dynamic;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtOps;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.GenerationChunkHolder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
-import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
@@ -0,0 +0,0 @@ public final class PaperHooks implements PlatformHooks {
}
@Override
- public CompoundTag convertNBT(final DataFixTypes type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion) {
- return type.update(dataFixer, nbt, fromVersion, toVersion);
+ public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt,
+ final int fromVersion, final int toVersion) {
+ return (CompoundTag)dataFixer.update(
+ type, new Dynamic<>(NbtOps.INSTANCE, nbt), fromVersion, toVersion
+ ).getValue();
}
@Override
@@ -0,0 +0,0 @@ public final class PaperHooks implements PlatformHooks {
entity.setRemoved(Entity.RemovalReason.UNLOADED_TO_CHUNK, org.bukkit.event.entity.EntityRemoveEvent.Cause.UNLOAD);
}
+ @Override
+ public void postLoadProtoChunk(final ServerLevel world, final ProtoChunk chunk) {
+ net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk(world, chunk.getEntities());
+ }
+
@Override
public int modifyEntityTrackingRange(final Entity entity, final int currentRange) {
return org.spigotmc.TrackingRange.getEntityTrackingRange(entity, currentRange);
diff --git a/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java b/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
+++ b/src/main/java/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
@@ -0,0 +0,0 @@ public class ChunkStatusTasks {
}, context.mainThreadExecutor());
}
- private static void postLoadProtoChunk(ServerLevel world, List<CompoundTag> entities) {
+ public static void postLoadProtoChunk(ServerLevel world, List<CompoundTag> entities) { // Paper - public
if (!entities.isEmpty()) {
// CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
world.addWorldGenChunkEntities(EntityType.loadEntitiesRecursive(entities, world, EntitySpawnReason.LOAD).filter((entity) -> {
diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
@@ -0,0 +0,0 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
// I don't want to know why this is a generic type.
Entity entityCasted = (Entity)entity;
boolean wasRemoved = entityCasted.isRemoved();
- boolean screened = ca.spottedleaf.moonrise.common.util.ChunkSystem.screenEntity((net.minecraft.server.level.ServerLevel)entityCasted.level(), entityCasted, existing, false);
+ boolean screened = ca.spottedleaf.moonrise.common.util.ChunkSystem.screenEntity((net.minecraft.server.level.ServerLevel)entityCasted.level(), entityCasted, existing, true);
if ((!wasRemoved && entityCasted.isRemoved()) || !screened) {
// removed by callback
return false;

Datei anzeigen

@ -1,345 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 21 Oct 2024 12:52:44 -0700
Subject: [PATCH] Revert "Custom table implementation for blockstate state
lookups"
This reverts commit 14a7e6521ba0ce6dc8ebf98a1ccce59a5ec6a194.
TODO Replace via deleting the patch
diff --git a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
deleted file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
+++ /dev/null
@@ -0,0 +0,0 @@
-package io.papermc.paper.util.table;
-
-import com.google.common.collect.Table;
-import net.minecraft.world.level.block.state.StateHolder;
-import net.minecraft.world.level.block.state.properties.Property;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-public final class ZeroCollidingReferenceStateTable {
-
- // upper 32 bits: starting index
- // lower 32 bits: bitset for contained ids
- protected final long[] this_index_table;
- protected final Comparable<?>[] this_table;
- protected final StateHolder<?, ?> this_state;
-
- protected long[] index_table;
- protected StateHolder<?, ?>[][] value_table;
-
- public ZeroCollidingReferenceStateTable(final StateHolder<?, ?> state, final Map<Property<?>, Comparable<?>> this_map) {
- this.this_state = state;
- this.this_index_table = this.create_table(this_map.keySet());
-
- int max_id = -1;
- for (final Property<?> property : this_map.keySet()) {
- final int id = lookup_vindex(property, this.this_index_table);
- if (id > max_id) {
- max_id = id;
- }
- }
-
- this.this_table = new Comparable[max_id + 1];
- for (final Map.Entry<Property<?>, Comparable<?>> entry : this_map.entrySet()) {
- this.this_table[lookup_vindex(entry.getKey(), this.this_index_table)] = entry.getValue();
- }
- }
-
- public void loadInTable(final Table<Property<?>, Comparable<?>, StateHolder<?, ?>> table,
- final Map<Property<?>, Comparable<?>> this_map) {
- final Set<Property<?>> combined = new HashSet<>(table.rowKeySet());
- combined.addAll(this_map.keySet());
-
- this.index_table = this.create_table(combined);
-
- int max_id = -1;
- for (final Property<?> property : combined) {
- final int id = lookup_vindex(property, this.index_table);
- if (id > max_id) {
- max_id = id;
- }
- }
-
- this.value_table = new StateHolder[max_id + 1][];
-
- final Map<Property<?>, Map<Comparable<?>, StateHolder<?, ?>>> map = table.rowMap();
- for (final Property<?> property : map.keySet()) {
- final Map<Comparable<?>, StateHolder<?, ?>> propertyMap = map.get(property);
-
- final int id = lookup_vindex(property, this.index_table);
- final StateHolder<?, ?>[] states = this.value_table[id] = new StateHolder[property.getPossibleValues().size()];
-
- for (final Map.Entry<Comparable<?>, StateHolder<?, ?>> entry : propertyMap.entrySet()) {
- if (entry.getValue() == null) {
- // TODO what
- continue;
- }
-
- states[((Property)property).getIdFor(entry.getKey())] = entry.getValue();
- }
- }
-
-
- for (final Map.Entry<Property<?>, Comparable<?>> entry : this_map.entrySet()) {
- final Property<?> property = entry.getKey();
- final int index = lookup_vindex(property, this.index_table);
-
- if (this.value_table[index] == null) {
- this.value_table[index] = new StateHolder[property.getPossibleValues().size()];
- }
-
- this.value_table[index][((Property)property).getIdFor(entry.getValue())] = this.this_state;
- }
- }
-
-
- protected long[] create_table(final Collection<Property<?>> collection) {
- int max_id = -1;
- for (final Property<?> property : collection) {
- final int id = property.getId();
- if (id > max_id) {
- max_id = id;
- }
- }
-
- final long[] ret = new long[((max_id + 1) + 31) >>> 5]; // ceil((max_id + 1) / 32)
-
- for (final Property<?> property : collection) {
- final int id = property.getId();
-
- ret[id >>> 5] |= (1L << (id & 31));
- }
-
- int total = 0;
- for (int i = 1, len = ret.length; i < len; ++i) {
- ret[i] |= (long)(total += Long.bitCount(ret[i - 1] & 0xFFFFFFFFL)) << 32;
- }
-
- return ret;
- }
-
- public Comparable<?> get(final Property<?> state) {
- final Comparable<?>[] table = this.this_table;
- final int index = lookup_vindex(state, this.this_index_table);
-
- if (index < 0 || index >= table.length) {
- return null;
- }
- return table[index];
- }
-
- public StateHolder<?, ?> get(final Property<?> property, final Comparable<?> with) {
- final int withId = ((Property)property).getIdFor(with);
- if (withId < 0) {
- return null;
- }
-
- final int index = lookup_vindex(property, this.index_table);
- final StateHolder<?, ?>[][] table = this.value_table;
- if (index < 0 || index >= table.length) {
- return null;
- }
-
- final StateHolder<?, ?>[] values = table[index];
-
- if (withId >= values.length) {
- return null;
- }
-
- return values[withId];
- }
-
- protected static int lookup_vindex(final Property<?> property, final long[] index_table) {
- final int id = property.getId();
- final long bitset_mask = (1L << (id & 31));
- final long lower_mask = bitset_mask - 1;
- final int index = id >>> 5;
- if (index >= index_table.length) {
- return -1;
- }
- final long index_value = index_table[index];
- final long contains_check = ((index_value & bitset_mask) - 1) >> (Long.SIZE - 1); // -1L if doesn't contain
-
- // index = total bits set in lower table values (upper 32 bits of index_value) plus total bits set in lower indices below id
- // contains_check is 0 if the bitset had id set, else it's -1: so index is unaffected if contains_check == 0,
- // otherwise it comes out as -1.
- return (int)(((index_value >>> 32) + Long.bitCount(index_value & lower_mask)) | contains_check);
- }
-}
diff --git a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
+++ b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
private final Reference2ObjectArrayMap<Property<?>, Comparable<?>> values;
private Table<Property<?>, Comparable<?>, S> neighbours;
protected final MapCodec<S> propertiesCodec;
- protected final io.papermc.paper.util.table.ZeroCollidingReferenceStateTable optimisedTable; // Paper - optimise state lookup
protected StateHolder(O owner, Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap, MapCodec<S> codec) {
this.owner = owner;
this.values = propertyMap;
this.propertiesCodec = codec;
- this.optimisedTable = new io.papermc.paper.util.table.ZeroCollidingReferenceStateTable(this, propertyMap); // Paper - optimise state lookup
}
public <T extends Comparable<T>> S cycle(Property<T> property) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
public <T extends Comparable<T>> boolean hasProperty(Property<T> property) {
- return this.optimisedTable.get(property) != null; // Paper - optimise state lookup
+ return this.values.containsKey(property);
}
public <T extends Comparable<T>> T getValue(Property<T> property) {
- Comparable<?> comparable = this.optimisedTable.get(property); // Paper - optimise state lookup
+ Comparable<?> comparable = this.values.get(property);
if (comparable == null) {
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + this.owner);
} else {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
public <T extends Comparable<T>> Optional<T> getOptionalValue(Property<T> property) {
- Comparable<?> comparable = this.optimisedTable.get(property); // Paper - optimise state lookup
+ Comparable<?> comparable = this.values.get(property);
return comparable == null ? Optional.empty() : Optional.of(property.getValueClass().cast(comparable));
}
public <T extends Comparable<T>, V extends T> S setValue(Property<T> property, V value) {
- // Paper start - optimise state lookup
- final S ret = (S)this.optimisedTable.get(property, value);
- if (ret == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
+ Comparable<?> comparable = this.values.get(property);
+ if (comparable == null) {
+ throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + this.owner);
+ } else if (comparable.equals(value)) {
+ return (S)this;
+ } else {
+ S object = this.neighbours.get(property, value);
+ if (object == null) {
+ throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
+ } else {
+ return object;
+ }
}
- return ret;
- // Paper end - optimise state lookup
}
public <T extends Comparable<T>, V extends T> S trySetValue(Property<T> property, V value) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
}
- this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table)); this.optimisedTable.loadInTable((Table)this.neighbours, this.values); // Paper - optimise state lookup
+ this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table));
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
@@ -0,0 +0,0 @@ import java.util.Optional;
public class BooleanProperty extends Property<Boolean> {
private final ImmutableSet<Boolean> values = ImmutableSet.of(true, false);
- // Paper start - optimise iblockdata state lookup
- @Override
- public final int getIdFor(final Boolean value) {
- return value.booleanValue() ? 1 : 0;
- }
- // Paper end - optimise iblockdata state lookup
-
protected BooleanProperty(String name) {
super(name, Boolean.class);
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
@@ -0,0 +0,0 @@ public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Prope
private final ImmutableSet<T> values;
private final Map<String, T> names = Maps.newHashMap();
- // Paper start - optimise iblockdata state lookup
- private int[] idLookupTable;
-
- @Override
- public final int getIdFor(final T value) {
- return this.idLookupTable[value.ordinal()];
- }
- // Paper end - optimise iblockdata state lookup
-
protected EnumProperty(String name, Class<T> type, Collection<T> values) {
super(name, type);
this.values = ImmutableSet.copyOf(values);
@@ -0,0 +0,0 @@ public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Prope
this.names.put(string, enum_);
}
- // Paper start - optimise BlockState lookup
- int id = 0;
- this.idLookupTable = new int[type.getEnumConstants().length];
- java.util.Arrays.fill(this.idLookupTable, -1);
- for (final T value : this.getPossibleValues()) {
- this.idLookupTable[value.ordinal()] = id++;
- }
- // Paper end - optimise BlockState lookup
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
@@ -0,0 +0,0 @@ public class IntegerProperty extends Property<Integer> {
public final int min;
public final int max;
- // Paper start - optimise iblockdata state lookup
- @Override
- public final int getIdFor(final Integer value) {
- final int val = value.intValue();
- final int ret = val - this.min;
-
- return ret | ((this.max - ret) >> 31);
- }
- // Paper end - optimise iblockdata state lookup
-
protected IntegerProperty(String name, int min, int max) {
super(name, Integer.class);
if (min < 0) {
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/Property.java b/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
@@ -0,0 +0,0 @@ public abstract class Property<T extends Comparable<T>> {
);
private final Codec<Property.Value<T>> valueCodec = this.codec.xmap(this::value, Property.Value::value);
- // Paper start - optimise iblockdata state lookup
- private static final java.util.concurrent.atomic.AtomicInteger ID_GENERATOR = new java.util.concurrent.atomic.AtomicInteger();
- private final int id = ID_GENERATOR.getAndIncrement();
-
- public final int getId() {
- return this.id;
- }
-
- public abstract int getIdFor(final T value);
- // Paper end - optimise state lookup
-
protected Property(String name, Class<T> type) {
this.clazz = type;
this.name = name;

Datei anzeigen

@ -371,27 +371,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
import net.minecraft.SharedConstants;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel;
-import net.minecraft.util.datafix.DataFixTypes;
+import net.minecraft.util.datafix.fixes.References;
public final class ChunkSystemConverters {
@@ -0,0 +0,0 @@ public final class ChunkSystemConverters {
public static CompoundTag convertPoiCompoundTag(final CompoundTag data, final ServerLevel world) {
final int dataVersion = getDataVersion(data, DEFAULT_POI_DATA_VERSION);
- // Paper start - dataconverter
- return ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(
- ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.POI_CHUNK, data, dataVersion, getCurrentVersion()
- );
- // Paper end - dataconverter
+ return PlatformHooks.get().convertNBT(DataFixTypes.POI_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
- return DataFixTypes.POI_CHUNK.update(world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
+ return PlatformHooks.get().convertNBT(References.POI_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
}
public static CompoundTag convertEntityChunkCompoundTag(final CompoundTag data, final ServerLevel world) {
final int dataVersion = getDataVersion(data, DEFAULT_ENTITY_CHUNK_DATA_VERSION);
- // Paper start - dataconverter
- return ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(
- ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ENTITY_CHUNK, data, dataVersion, getCurrentVersion()
- );
- // Paper end - dataconverter
+ return PlatformHooks.get().convertNBT(DataFixTypes.ENTITY_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
- return DataFixTypes.ENTITY_CHUNK.update(world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
+ return PlatformHooks.get().convertNBT(References.ENTITY_CHUNK, world.getServer().getFixerUpper(), data, dataVersion, getCurrentVersion());
}
private ChunkSystemConverters() {}
@ -3902,18 +3900,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
final ListTag entitiesTag = new ListTag();
- final java.util.Map<net.minecraft.world.entity.EntityType<?>, Integer> savedEntityCounts = new java.util.HashMap<>(); // Paper - Entity load/save limit per chunk
- for (final Entity entity : entities) {
- // Paper start - Entity load/save limit per chunk
- final EntityType<?> entityType = entity.getType();
- final int saveLimit = world.paperConfig().chunks.entityPerChunkSaveLimit.getOrDefault(entityType, -1);
- if (saveLimit > -1) {
- if (savedEntityCounts.getOrDefault(entityType, 0) >= saveLimit) {
- continue;
- }
- savedEntityCounts.merge(entityType, 1, Integer::sum);
- }
- // Paper end - Entity load/save limit per chunk
+ for (final Entity entity : PlatformHooks.get().modifySavedEntities(world, chunkPos.x, chunkPos.z, entities)) {
CompoundTag compoundTag = new CompoundTag();
if (entity.save(compoundTag)) {
@ -3964,9 +3951,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- }
- // Paper end
-
private List<Entity> getAllEntities() {
- private List<Entity> getAllEntities() {
+ public List<Entity> getAllEntities() {
final int len = this.entities.size();
if (len == 0) {
return new ArrayList<>();
@@ -0,0 +0,0 @@ public final class ChunkEntitySlices {
return false;
}
@ -4426,13 +4415,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.player.connection.send(this.updateClientChunkRadius(sendViewDistance));
this.player.connection.send(this.updateClientSimulationDistance(tickViewDistance));
@@ -0,0 +0,0 @@ public final class RegionizedPlayerChunkLoader {
// now all tickets should be removed, which is all of our external state
}
- // For external checks
- public it.unimi.dsi.fastutil.longs.LongOpenHashSet getSentChunksRaw() {
+
+ public LongOpenHashSet getSentChunksRaw() {
return this.sentChunks;
+ return this.sentChunks;
+ }
}
}
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
@ -6210,7 +6199,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
final ProtoChunk protoChunk = (ProtoChunk)this.fromChunk;
chunk = new LevelChunk(this.world, protoChunk, (final LevelChunk unused) -> {
- ChunkStatusTasks.postLoadProtoChunk(world, protoChunk.getEntities(), protoChunk.getPos()); // Paper - pass chunk pos
+ ChunkStatusTasks.postLoadProtoChunk(world, protoChunk.getEntities());
+ PlatformHooks.get().postLoadProtoChunk(world, protoChunk);
});
this.chunkHolder.replaceProtoChunk(new ImposterProtoChunk(chunk, false));
}
@ -10001,8 +9990,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/core/MappedRegistry.java
+++ b/src/main/java/net/minecraft/core/MappedRegistry.java
@@ -0,0 +0,0 @@ public class MappedRegistry<T> implements WritableRegistry<T> {
};
private final Object tagAdditionLock = new Object();
return this.getTags();
}
+ // Paper start - fluid method optimisations
+ private void injectFluidRegister(
@ -10027,15 +10016,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ this.injectFluidRegister(key, value); // Paper - fluid method optimisations
return reference;
}
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Spigot end
// Paper end - Improved watchdog support; move final shutdown items here
- ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.deinit(); // Paper - rewrite chunk system
+ // Paper start - rewrite chunk system
+ LOGGER.info("Waiting for I/O tasks to complete...");
@ -10045,22 +10034,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ ca.spottedleaf.moonrise.common.util.MoonriseCommon.haltExecutors();
+ }
+ // Paper end - rewrite chunk system
// Paper start - move final shutdown items here
Util.shutdownExecutors();
try {
}
public String getLocalIp() {
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
@@ -0,0 +0,0 @@ public class ChunkHolder extends GenerationChunkHolder implements ca.spottedleaf
if (ichunkaccess != null) {
ichunkaccess.setUnsaved(true);
return false;
} else {
ichunkaccess.markUnsaved();
- LevelChunk chunk = this.getChunkToSend(); // Paper - rewrite chunk system
+ LevelChunk chunk = this.playersSentChunkTo.size() == 0 ? null : this.getChunkToSend(); // Paper - rewrite chunk system
if (chunk != null) {
int j = this.lightEngine.getMinLightSection();
if (chunk == null) {
return false;
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
@ -10224,7 +10213,7 @@ diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/mai
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
// Paper start - optimise random ticking
@ -10240,7 +10229,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
final ChunkPos cpos = chunk.getPos();
final int offsetX = cpos.x << 4;
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
final int offsetY = (sectionIndex + minSection) << 4;
final LevelChunkSection section = sections[sectionIndex];
final net.minecraft.world.level.chunk.PalettedContainer<net.minecraft.world.level.block.state.BlockState> states = section.states;
@ -10289,7 +10278,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
}
}
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// Paper end - optimise random ticking
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
@ -10297,8 +10286,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
ChunkPos chunkcoordintpair = chunk.getPos();
boolean flag = this.isRaining();
int j = chunkcoordintpair.getMinBlockX();
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
ProfilerFiller gameprofilerfiller = this.getProfiler();
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("thunder");
- if (!this.paperConfig().environment.disableThunder && flag && this.isThundering() && this.spigotConfig.thunderChance > 0 && this.random.nextInt(this.spigotConfig.thunderChance) == 0) { // Spigot // Paper - Option to disable thunder
@ -10306,7 +10295,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
BlockPos blockposition = this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15));
if (this.isRainingAt(blockposition)) {
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
if (!this.paperConfig().environment.disableIceAndSnow) { // Paper - Option to disable ice and snow
for (int l = 0; l < randomTickSpeed; ++l) {
@ -10935,11 +10924,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ if (collisionShape.isEmpty()) {
+ continue;
+ }
+
+ final AABB toCollide = boundingBox.move(-(double)blockX, -(double)blockY, -(double)blockZ);
- if (ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.voxelShapeIntersectNoEmpty(collisionShape, toCollide)) {
- return true;
+ final AABB toCollide = boundingBox.move(-(double)blockX, -(double)blockY, -(double)blockZ);
+
+ final AABB singleAABB = ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)collisionShape).moonrise$getSingleAABBRepresentation();
+ if (singleAABB != null) {
+ if (ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.voxelShapeIntersect(singleAABB, toCollide)) {
@ -10982,32 +10971,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- Vec3 vec3d = Vec3.ZERO;
- int k1 = 0;
- BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+ }
-
- for (int l1 = i; l1 < j; ++l1) {
- for (int i2 = k; i2 < l; ++i2) {
- for (int j2 = i1; j2 < j1; ++j2) {
- blockposition_mutableblockposition.set(l1, i2, j2);
- FluidState fluid = this.level().getFluidState(blockposition_mutableblockposition);
+ final AABB boundingBox = this.getBoundingBox().deflate(1.0E-3);
-
- if (fluid.is(tag)) {
- double d2 = (double) ((float) i2 + fluid.getHeight(this.level(), blockposition_mutableblockposition));
+ final Level world = this.level;
+ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(world);
-
- if (d2 >= axisalignedbb.minY) {
- flag1 = true;
- d1 = Math.max(d2 - axisalignedbb.minY, d1);
- if (flag) {
- Vec3 vec3d1 = fluid.getFlow(this.level(), blockposition_mutableblockposition);
+ final int minBlockX = Mth.floor(boundingBox.minX);
+ final int minBlockY = Math.max((minSection << 4), Mth.floor(boundingBox.minY));
+ final int minBlockZ = Mth.floor(boundingBox.minZ);
-
- if (d1 < 0.4D) {
- vec3d1 = vec3d1.scale(d1);
- }
+ }
+
+ final AABB boundingBox = this.getBoundingBox().deflate(1.0E-3);
+
+ final Level world = this.level;
+ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(world);
+
+ final int minBlockX = Mth.floor(boundingBox.minX);
+ final int minBlockY = Math.max((minSection << 4), Mth.floor(boundingBox.minY));
+ final int minBlockZ = Mth.floor(boundingBox.minZ);
+
+ // note: bounds are exclusive in Vanilla, so we subtract 1 - our loop expects bounds to be inclusive
+ final int maxBlockX = Mth.ceil(boundingBox.maxX) - 1;
+ final int maxBlockY = Math.min((ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(world) << 4) | 15, Mth.ceil(boundingBox.maxY) - 1);
@ -11015,9 +11008,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ final boolean isPushable = this.isPushedByFluid();
+ final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
- vec3d = vec3d.add(vec3d1);
- ++k1;
+
+ Vec3 pushVector = Vec3.ZERO;
+ double totalPushes = 0.0;
+ double maxHeightDiff = 0.0;
@ -11037,7 +11028,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
+ for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
+ final net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunkSource.getChunk(currChunkX, currChunkZ, net.minecraft.world.level.chunk.status.ChunkStatus.FULL, false).getSections();
+
- vec3d = vec3d.add(vec3d1);
- ++k1;
+ // bound y
+ for (int currChunkY = minChunkY; currChunkY <= maxChunkY; ++currChunkY) {
+ final int sectionIdx = currChunkY - minSection;
@ -11066,10 +11059,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ if (fluidState.isEmpty() || !fluidState.is(fluid)) {
+ continue;
}
- // CraftBukkit start - store last lava contact location
- if (tag == FluidTags.LAVA) {
- this.lastLavaContact = blockposition_mutableblockposition.immutable();
+ }
+
+ mutablePos.set(currX | (currChunkX << 4), currY | (currChunkY << 4), currZ | (currChunkZ << 4));
+
@ -11085,7 +11075,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ if (!isPushable) {
+ continue;
+ }
}
- // CraftBukkit start - store last lava contact location
- if (tag == FluidTags.LAVA) {
- this.lastLavaContact = blockposition_mutableblockposition.immutable();
+
+ ++totalPushes;
+
@ -11154,7 +11147,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.world, chunkX, chunkZ, "Accessing poi chunk off-main");
@ -11164,7 +11157,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return ret == null ? Optional.empty() : ret.getSectionForVanilla(chunkY);
}
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
public final void moonrise$onUnload(final long coordinate) { // Paper - rewrite chunk system
final int chunkX = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkX(coordinate);
final int chunkZ = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkZ(coordinate);
@ -11180,7 +11173,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.updateDistanceTracking(sectionPos);
}
}
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
public final void moonrise$loadInPoiChunk(final ca.spottedleaf.moonrise.patches.chunk_system.level.poi.PoiChunk poiChunk) {
final int chunkX = poiChunk.chunkX;
final int chunkZ = poiChunk.chunkZ;
@ -11194,35 +11187,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
final PoiSection section = poiChunk.getSection(sectionY);
if (section != null && !((ca.spottedleaf.moonrise.patches.chunk_system.level.poi.ChunkSystemPoiSection)section).moonrise$isEmpty()) {
this.onSectionLoad(SectionPos.asLong(chunkX, sectionY, chunkZ));
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
@Override
public final net.minecraft.nbt.CompoundTag moonrise$read(final int chunkX, final int chunkZ) throws java.io.IOException {
- if (!ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.isRegionFileThread()) {
- return ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.loadData(
- this.world, chunkX, chunkZ, ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.RegionFileType.POI_DATA,
- ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.getIOBlockingPriorityForCurrentThread()
- );
- }
- return this.moonrise$getRegionStorage().read(new ChunkPos(chunkX, chunkZ));
+ return ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.loadData(
+ this.world, chunkX, chunkZ, ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionFileType.POI_DATA,
+ ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.getIOBlockingPriorityForCurrentThread()
+ );
}
@Override
public final void moonrise$write(final int chunkX, final int chunkZ, final net.minecraft.nbt.CompoundTag data) throws java.io.IOException {
- if (!ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.isRegionFileThread()) {
- ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.scheduleSave(this.world, chunkX, chunkZ, data, ca.spottedleaf.moonrise.patches.chunk_system.io.RegionFileIOThread.RegionFileType.POI_DATA);
- return;
- }
- this.moonrise$getRegionStorage().write(new ChunkPos(chunkX, chunkZ), data);
+ ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.scheduleSave(this.world, chunkX, chunkZ, data, ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionFileType.POI_DATA);
}
// Paper end - rewrite chunk system
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection> implements ca.spotted
@@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage<PoiSection, PoiSection.Packed> im
}
public int sectionsToVillage(SectionPos pos) {
@ -11240,7 +11205,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
@@ -0,0 +0,0 @@ public class PoiSection implements ca.spottedleaf.moonrise.patches.chunk_system.
}
private boolean isValid;
// Paper start - rewrite chunk system
- private final Optional<PoiSection> noAllocOptional = Optional.of((PoiSection)(Object)this);;
@ -11387,12 +11352,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- lastChunk = (LevelChunk)chunkSource.getChunk(newChunkX, newChunkZ, ChunkStatus.FULL, false);
- }
+ final ChunkSource chunkSource = this.getChunkSource();
+
- if (lastChunk == null) {
+ for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
+ for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
+ final ChunkAccess chunk = chunkSource.getChunk(currChunkX, currChunkZ, ChunkStatus.FULL, false);
- if (lastChunk == null) {
+
+ if (chunk == null) {
continue;
}
@ -11615,7 +11580,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Paper end - optimise random ticking
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, java.util.concurrent.Executor executor) { // Paper - create paper world config & Anti-Xray
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator) { // Paper - create paper world config
+ // Paper start - getblock optimisations - cache world height/sections
+ final DimensionType dimType = holder.value();
+ this.minY = dimType.minY();
@ -11628,6 +11593,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
this.generator = gen;
@@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
if (slices == null) {
return new org.bukkit.entity.Entity[0];
}
- return slices.getChunkEntities();
+
+ List<org.bukkit.entity.Entity> ret = new java.util.ArrayList<>();
+ for (Entity entity : slices.getAllEntities()) {
+ org.bukkit.entity.Entity bukkit = entity.getBukkitEntity();
+ if (bukkit != null && bukkit.isValid()) {
+ ret.add(bukkit);
+ }
+ }
+
+ return ret.toArray(new org.bukkit.entity.Entity[0]);
}
// Paper end - rewrite chunk system
diff --git a/src/main/java/net/minecraft/world/level/biome/BiomeManager.java b/src/main/java/net/minecraft/world/level/biome/BiomeManager.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/biome/BiomeManager.java
@ -11647,7 +11630,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -0,0 +0,0 @@ public abstract class BlockBehaviour implements FeatureElement {
private boolean isRandomlyTicking;
private int lightBlock;
// Paper start - rewrite chunk system
- private int opacityIfCached;
@ -11719,7 +11702,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
protected BlockStateBase(Block block, Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
@@ -0,0 +0,0 @@ public abstract class BlockBehaviour implements FeatureElement {
this.legacySolid = this.calculateSolid();
this.lightBlock = ((Block) this.owner).getLightBlock(this.asState());
// Paper start - rewrite chunk system
this.isConditionallyFullOpaque = this.canOcclude & this.useShapeForLightOcclusion;
- this.opacityIfCached = this.cache == null || this.isConditionallyFullOpaque ? -1 : this.cache.lightBlock;
@ -11791,7 +11774,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
protected final O owner;
- private final Reference2ObjectArrayMap<Property<?>, Comparable<?>> values;
+ private Reference2ObjectArrayMap<Property<?>, Comparable<?>> values; // Paper - optimise blockstate property access - remove final
private Table<Property<?>, Comparable<?>, S> neighbours;
private Map<Property<?>, S[]> neighbours;
protected final MapCodec<S> propertiesCodec;
+ // Paper start - optimise blockstate property access
@ -11845,21 +11828,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public <T extends Comparable<T>> Optional<T> getOptionalValue(Property<T> property) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
@Nullable
public <T extends Comparable<T>> T getNullableValue(Property<T> property) {
- Comparable<?> comparable = this.values.get(property);
- return comparable == null ? null : property.getValueClass().cast(comparable);
+ return property == null ? null : this.optimisedTable.get(this.tableIndex, property); // Paper - optimise blockstate property access
}
public <T extends Comparable<T>, V extends T> S setValue(Property<T> property, V value) {
- Comparable<?> comparable = this.values.get(property);
- if (comparable == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + this.owner);
- } else if (comparable.equals(value)) {
- return (S)this;
- } else {
- S object = this.neighbours.get(property, value);
- if (object == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
- } else {
- return object;
- }
- return this.setValueInternal(property, value, comparable);
+ // Paper start - optimise blockstate property access
+ final S ret = this.optimisedTable.set(this.tableIndex, property, value);
+ if (ret != null) {
@ -11871,19 +11853,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public <T extends Comparable<T>, V extends T> S trySetValue(Property<T> property, V value) {
- Comparable<?> comparable = this.values.get(property);
- if (comparable != null && !comparable.equals(value)) {
- S object = this.neighbours.get(property, value);
- if (object == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
- } else {
- return object;
- }
- } else {
- return (S)this;
- return (S)(comparable == null ? this : this.setValueInternal(property, value, comparable));
+ // Paper start - optimise blockstate property access
+ if (property == null) {
+ return (S)(StateHolder<O, S>)(Object)this;
}
+ }
+ final S ret = this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
+ if (ret != null) {
+ return ret;
@ -11892,33 +11866,44 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - optimise blockstate property access
}
private <T extends Comparable<T>, V extends T> S setValueInternal(Property<T> property, V newValue, Comparable<?> oldValue) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
public void populateNeighbours(Map<Map<Property<?>, Comparable<?>>, S> states) {
- if (this.neighbours != null) {
- throw new IllegalStateException();
- } else {
- Map<Property<?>, S[]> map = new Reference2ObjectArrayMap<>(this.values.size());
+ // Paper start - optimise blockstate property access
+ final Map<Map<Property<?>, Comparable<?>>, S> map = states;
+ if (true) {
+ if (this.optimisedTable.isLoaded()) {
+ return;
+ }
+ this.optimisedTable.loadInTable(map);
+
- for (Entry<Property<?>, Comparable<?>> entry : this.values.entrySet()) {
- Property<?> property = entry.getKey();
- map.put(property, property.getPossibleValues().stream().map(value -> states.get(this.makeNeighbourValues(property, value))).toArray());
- }
+ // de-duplicate the tables
+ for (final Map.Entry<Map<Property<?>, Comparable<?>>, S> entry : map.entrySet()) {
+ final S value = entry.getValue();
+ ((StateHolder<O, S>)value).optimisedTable = this.optimisedTable;
+ }
+
- this.neighbours = map;
+ // remove values arrays
+ for (final Map.Entry<Map<Property<?>, Comparable<?>>, S> entry : map.entrySet()) {
+ final S value = entry.getValue();
+ ((StateHolder<O, S>)value).values = null;
+ }
}
+
+ return;
+ }
+ // Paper end - optimise blockstate property access
if (this.neighbours != null) {
throw new IllegalStateException();
} else {
+ // Paper end optimise blockstate property access
}
private Map<Property<?>, Comparable<?>> makeNeighbourValues(Property<?> property, Comparable<?> value) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
@ -11936,13 +11921,15 @@ diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/Bool
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
@@ -0,0 +0,0 @@ import com.google.common.collect.ImmutableSet;
import java.util.Collection;
@@ -0,0 +0,0 @@ package net.minecraft.world.level.block.state.properties;
import java.util.List;
import java.util.Optional;
-public class BooleanProperty extends Property<Boolean> {
+public class BooleanProperty extends Property<Boolean> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<Boolean> { // Paper - optimise blockstate property access
private final ImmutableSet<Boolean> values = ImmutableSet.of(true, false);
-public final class BooleanProperty extends Property<Boolean> {
+public final class BooleanProperty extends Property<Boolean> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<Boolean> { // Paper - optimise blockstate property access
private static final List<Boolean> VALUES = List.of(true, false);
private static final int TRUE_INDEX = 0;
private static final int FALSE_INDEX = 1;
+ // Paper start - optimise blockstate property access
+ private static final Boolean[] BY_ID = new Boolean[]{ Boolean.FALSE, Boolean.TRUE };
@ -11953,7 +11940,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - optimise blockstate property access
+
protected BooleanProperty(String name) {
private BooleanProperty(String name) {
super(name, Boolean.class);
+ this.moonrise$setById(BY_ID); // Paper - optimise blockstate property access
}
@ -11967,10 +11954,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
import java.util.stream.Collectors;
import net.minecraft.util.StringRepresentable;
-public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Property<T> {
+public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Property<T> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<T> { // Paper - optimise blockstate property access
private final ImmutableSet<T> values;
private final Map<String, T> names = Maps.newHashMap();
-public final class EnumProperty<T extends Enum<T> & StringRepresentable> extends Property<T> {
+public final class EnumProperty<T extends Enum<T> & StringRepresentable> extends Property<T> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<T> { // Paper - optimise blockstate property access
private final List<T> values;
private final Map<String, T> names;
private final int[] ordinalToIndex;
+ // Paper start - optimise blockstate property access
+ private int[] idLookupTable;
@ -11982,7 +11970,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ private void init() {
+ final Collection<T> values = this.getPossibleValues();
+ final java.util.Collection<T> values = this.getPossibleValues();
+ final Class<T> clazz = this.getValueClass();
+
+ int id = 0;
@ -12000,12 +11988,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - optimise blockstate property access
+
protected EnumProperty(String name, Class<T> type, Collection<T> values) {
private EnumProperty(String name, Class<T> type, List<T> values) {
super(name, type);
this.values = ImmutableSet.copyOf(values);
@@ -0,0 +0,0 @@ public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Prope
if (values.isEmpty()) {
@@ -0,0 +0,0 @@ public final class EnumProperty<T extends Enum<T> & StringRepresentable> extends
this.names.put(string, enum_);
this.names = builder.buildOrThrow();
}
+ this.init(); // Paper - optimise blockstate property access
}
@ -12015,13 +12003,13 @@ diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/Inte
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
@@ -0,0 +0,0 @@ import java.util.Collection;
@@ -0,0 +0,0 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;
-public class IntegerProperty extends Property<Integer> {
+public class IntegerProperty extends Property<Integer> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<Integer> { // Paper - optimise blockstate property access
private final ImmutableSet<Integer> values;
-public final class IntegerProperty extends Property<Integer> {
+public final class IntegerProperty extends Property<Integer> implements ca.spottedleaf.moonrise.patches.blockstate_propertyaccess.PropertyAccess<Integer> { // Paper - optimise blockstate property access
private final IntImmutableList values;
public final int min;
public final int max;
@ -12047,12 +12035,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - optimise blockstate property access
+
protected IntegerProperty(String name, int min, int max) {
private IntegerProperty(String name, int min, int max) {
super(name, Integer.class);
if (min < 0) {
@@ -0,0 +0,0 @@ public class IntegerProperty extends Property<Integer> {
this.values = ImmutableSet.copyOf(set);
@@ -0,0 +0,0 @@ public final class IntegerProperty extends Property<Integer> {
this.max = max;
this.values = IntImmutableList.toList(IntStream.range(min, max + 1));
}
+ this.init(); // Paper - optimise blockstate property access
}
@ -12148,12 +12136,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
static final Logger LOGGER = LogUtils.getLogger();
private static final TickingBlockEntity NULL_TICKER = new TickingBlockEntity() {
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
*/
org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(bukkitChunk, this.needsDecoration));
- ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(this.locX, this.locZ).getEntityChunk().callEntitiesLoadEvent(); // Paper - rewrite chunk system
+ org.bukkit.craftbukkit.event.CraftEventFactory.callEntitiesLoadEvent(this.level, this.chunkPos, ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(this.locX, this.locZ).getEntityChunk().getAllEntities()); // Paper - rewrite chunk system
if (this.needsDecoration) {
try (co.aikar.timings.Timing ignored = this.level.timings.chunkLoadPopulate.startTiming()) { // Paper
@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
public void unloadCallback() {
if (!this.loadedTicketLevel) { LOGGER.error("Double calling chunk unload!", new Throwable()); } // Paper
org.bukkit.Server server = this.level.getCraftServer();
- ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(this.locX, this.locZ).getEntityChunk().callEntitiesUnloadEvent(); // Paper - rewrite chunk system
+ org.bukkit.craftbukkit.event.CraftEventFactory.callEntitiesUnloadEvent(this.level, this.chunkPos, ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(this.locX, this.locZ).getEntityChunk().getAllEntities()); // Paper - rewrite chunk system
org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(bukkitChunk, true); // Paper - rewrite chunk system - force save to true so that mustNotSave is correctly set below
server.getPluginManager().callEvent(unloadEvent);
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -0,0 +0,0 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
private PalettedContainer<Holder<Biome>> biomes;
private PalettedContainer<Holder<Biome>> biomes; // CraftBukkit - read/write
// Paper start - block counting
- private static final it.unimi.dsi.fastutil.ints.IntArrayList FULL_LIST = new it.unimi.dsi.fastutil.ints.IntArrayList(16*16*16);
@ -12384,7 +12390,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
// this.threadingDetector.checkAndUnlock(); // Paper - disable this
);
}
+ // Paper start - optimise palette reads
@ -12414,25 +12420,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end - optimise palette reads
+
// Paper start - Anti-Xray - Add preset values
@Deprecated @io.papermc.paper.annotation.DoNotUse public static <T> Codec<PalettedContainer<T>> codecRW(IdMap<T> idList, Codec<T> entryCodec, PalettedContainer.Strategy paletteProvider, T defaultValue) { return PalettedContainer.codecRW(idList, entryCodec, paletteProvider, defaultValue, null); }
public static <T> Codec<PalettedContainer<T>> codecRW(IdMap<T> idList, Codec<T> entryCodec, PalettedContainer.Strategy paletteProvider, T defaultValue, T @org.jetbrains.annotations.Nullable [] presetValues) {
public PalettedContainer(
IdMap<T> idList,
PalettedContainer.Strategy paletteProvider,
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
}
}
// Paper end
this.registry = idList;
this.strategy = paletteProvider;
this.data = new PalettedContainer.Data<>(dataProvider, storage, dataProvider.factory().create(dataProvider.bits(), idList, this, paletteEntries));
+ this.updateData(this.data); // Paper - optimise palette reads
}
// Paper start - Anti-Xray - Add preset values
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
private PalettedContainer(IdMap<T> idList, PalettedContainer.Strategy paletteProvider, PalettedContainer.Data<T> data) {
this.registry = idList;
this.strategy = paletteProvider;
this.data = data;
+ this.updateData(this.data); // Paper - optimise palette reads
}
// Paper start - Anti-Xray - Add preset values
private PalettedContainer(PalettedContainer<T> container) {
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
this.registry = idList;
this.data = this.createOrReuseData(null, 0);
@ -12446,9 +12451,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
data2.copyFrom(data.palette, data.storage);
this.data = data2;
+ this.updateData(this.data); // Paper - optimise palette reads
this.addPresetValues();
return object == null ? -1 : data2.palette.idFor(object);
// Paper end
return data2.palette.idFor(object);
}
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
}
@ -12483,9 +12488,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
buf.readLongArray(data.storage.getRaw());
this.data = data;
+ this.updateData(this.data); // Paper - optimise palette reads
this.addPresetValues(); // Paper - Anti-Xray - Add preset values (inefficient, but this isn't used by the server)
} finally {
this.release();
}
@@ -0,0 +0,0 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
void accept(T object, int count);
}
@ -12590,7 +12595,7 @@ diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.ja
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -0,0 +0,0 @@ import net.minecraft.nbt.NbtIo; // Paper
@@ -0,0 +0,0 @@ import net.minecraft.util.profiling.jfr.JvmProfiler;
import net.minecraft.world.level.ChunkPos;
import org.slf4j.Logger;
@ -12600,12 +12605,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private static final Logger LOGGER = LogUtils.getLogger();
private static final int SECTOR_BYTES = 4096;
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
private final IntBuffer timestamps;
@VisibleForTesting
protected final RegionBitmap usedSectors;
+ // Paper start - rewrite chunk system
+ @Override
+ public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(final CompoundTag data, final ChunkPos pos) throws IOException {
+ public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(final net.minecraft.nbt.CompoundTag data, final ChunkPos pos) throws IOException {
+ final RegionFile.ChunkBuffer buffer = ((RegionFile)(Object)this).new ChunkBuffer(pos);
+ ((ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemChunkBuffer)buffer).moonrise$setWriteOnClose(false);
+
@ -12617,9 +12622,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ );
+ }
+ // Paper end - rewrite chunk system
// Paper start - Attempt to recalculate regionfile header if it is corrupt
private static long roundToSectors(long bytes) {
long sectors = bytes >>> 12; // 4096 = 2^12
+
public RegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException {
this(storageKey, directory, path, RegionFileVersion.getSelected(), dsync);
}
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
@Nullable
@ -12638,9 +12644,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (!Files.isRegularFile(path, new LinkOption[0])) {
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
}
// Paper end
public static final int MAX_CHUNK_SIZE = 500 * 1024 * 1024; // Paper - don't write garbage data to disk if writing serialization fails
- private class ChunkBuffer extends ByteArrayOutputStream {
+ private class ChunkBuffer extends ByteArrayOutputStream implements ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemChunkBuffer { // Paper - rewrite chunk system
@ -12788,10 +12794,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
// Paper end - rewrite chunk system
// Paper start - recalculate region file headers
private final boolean isChunkData;
protected RegionFileStorage(RegionStorageInfo storageKey, Path directory, boolean dsync) { // Paper - protected
@@ -0,0 +0,0 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
this.isChunkData = isChunkDataFolder(this.folder); // Paper - recalculate region file headers
this.info = storageKey;
}
+ // Paper start - rewrite chunk system
@ -12860,8 +12866,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
}
- private boolean canPassThroughWall(Direction face, BlockGetter world, BlockPos pos, BlockState state, BlockPos fromPos, BlockState fromState) {
- Object2ByteLinkedOpenHashMap object2bytelinkedopenhashmap;
- private static boolean canPassThroughWall(Direction face, BlockGetter world, BlockPos pos, BlockState state, BlockPos fromPos, BlockState fromState) {
- VoxelShape voxelshape = fromState.getCollisionShape(world, fromPos);
+ // Paper start - fluid method optimisations
+ private static boolean canPassThroughWall(final Direction direction, final BlockGetter level,
+ final BlockPos fromPos, final BlockState fromState,
@ -12871,56 +12877,71 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return true;
+ }
- if (voxelshape == Shapes.block()) {
+ if (((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)fromState).moonrise$occludesFullBlock() | ((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)toState).moonrise$occludesFullBlock()) {
+ // don't even try to cache simple cases
return false;
- } else {
- VoxelShape voxelshape1 = state.getCollisionShape(world, pos);
-
- if (voxelshape1 == Shapes.block()) {
- return false;
- } else if (voxelshape1 == Shapes.empty() && voxelshape == Shapes.empty()) {
- return true;
- } else {
- Object2ByteLinkedOpenHashMap object2bytelinkedopenhashmap;
-
- if (!state.getBlock().hasDynamicShape() && !fromState.getBlock().hasDynamicShape()) {
- object2bytelinkedopenhashmap = (Object2ByteLinkedOpenHashMap) FlowingFluid.OCCLUSION_CACHE.get();
- } else {
- object2bytelinkedopenhashmap = null;
+ if (((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)fromState).moonrise$occludesFullBlock() | ((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)toState).moonrise$occludesFullBlock()) {
+ // don't even try to cache simple cases
+ return false;
}
- }
+ }
- Block.BlockStatePairKey block_a;
- FlowingFluid.BlockStatePairKey fluidtypeflowing_a;
+ final ca.spottedleaf.moonrise.patches.collisions.util.FluidOcclusionCacheKey[] cache = ((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)fromState).moonrise$hasCache() & ((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)toState).moonrise$hasCache() ?
+ COLLISION_OCCLUSION_CACHE.get() : null;
- if (object2bytelinkedopenhashmap != null) {
- block_a = new Block.BlockStatePairKey(state, fromState, face);
- byte b0 = object2bytelinkedopenhashmap.getAndMoveToFirst(block_a);
- fluidtypeflowing_a = new FlowingFluid.BlockStatePairKey(state, fromState, face);
- byte b0 = object2bytelinkedopenhashmap.getAndMoveToFirst(fluidtypeflowing_a);
+ final int keyIndex
+ = (((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)fromState).moonrise$uniqueId1() ^ ((ca.spottedleaf.moonrise.patches.collisions.block.CollisionBlockState)toState).moonrise$uniqueId2() ^ ((ca.spottedleaf.moonrise.patches.collisions.util.CollisionDirection)(Object)direction).moonrise$uniqueId())
+ & (COLLISION_OCCLUSION_CACHE_SIZE - 1);
- if (b0 != 127) {
- return b0 != 0;
- }
- } else {
- fluidtypeflowing_a = null;
- }
-
- boolean flag = !Shapes.mergedFaceOccludes(voxelshape1, voxelshape, face);
+ if (cache != null) {
+ final ca.spottedleaf.moonrise.patches.collisions.util.FluidOcclusionCacheKey cached = cache[keyIndex];
+ if (cached != null && cached.first() == fromState && cached.second() == toState && cached.direction() == direction) {
+ return cached.result();
}
- } else {
- block_a = null;
}
- VoxelShape voxelshape = state.getCollisionShape(world, pos);
- VoxelShape voxelshape1 = fromState.getCollisionShape(world, fromPos);
- boolean flag = !Shapes.mergedFaceOccludes(voxelshape, voxelshape1, face);
+ final VoxelShape shape1 = fromState.getCollisionShape(level, fromPos);
+ final VoxelShape shape2 = toState.getCollisionShape(level, toPos);
+ }
+ }
- if (object2bytelinkedopenhashmap != null) {
- if (object2bytelinkedopenhashmap.size() == 200) {
- object2bytelinkedopenhashmap.removeLastByte();
- }
+ final VoxelShape shape1 = fromState.getCollisionShape(level, fromPos);
+ final VoxelShape shape2 = toState.getCollisionShape(level, toPos);
- object2bytelinkedopenhashmap.putAndMoveToFirst(fluidtypeflowing_a, (byte) (flag ? 1 : 0));
- }
+ final boolean result = !Shapes.mergedFaceOccludes(shape1, shape2, direction);
- object2bytelinkedopenhashmap.putAndMoveToFirst(block_a, (byte) (flag ? 1 : 0));
- return flag;
- }
+ if (cache != null) {
+ // we can afford to replace in-use keys more often due to the excessive caching the collision patch does in mergedFaceOccludes
+ cache[keyIndex] = new ca.spottedleaf.moonrise.patches.collisions.util.FluidOcclusionCacheKey(fromState, toState, direction, result);
}
- return flag;
+
+ return result;
}
+ // Paper end - fluid method optimisations
@ -12951,7 +12972,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end - fluid method optimisations
}
protected abstract boolean canConvertToSource(Level world);
protected abstract boolean canConvertToSource(ServerLevel world);
diff --git a/src/main/java/net/minecraft/world/level/material/FluidState.java b/src/main/java/net/minecraft/world/level/material/FluidState.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/material/FluidState.java
@ -13024,7 +13045,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return this.isRandomlyTicking; // Paper - fluid method optimisations
}
public void randomTick(Level world, BlockPos pos, RandomSource random) {
public void randomTick(ServerLevel world, BlockPos pos, RandomSource random) {
@@ -0,0 +0,0 @@ public final class FluidState extends StateHolder<Fluid, FluidState> {
}
@ -13072,30 +13093,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper end - optimise collisions
}
@@ -0,0 +0,0 @@ public final class Shapes {
}
public static VoxelShape getFaceShape(VoxelShape shape, Direction direction) {
- return ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)shape).moonrise$getFaceShapeClamped(direction); // Paper - optimise collisions
+ if (shape == block()) {
+ return block();
+ } else {
+ Direction.Axis axis = direction.getAxis();
+ boolean bl;
+ int i;
+ if (direction.getAxisDirection() == Direction.AxisDirection.POSITIVE) {
+ bl = DoubleMath.fuzzyEquals(shape.max(axis), 1.0, 1.0E-7);
+ i = shape.shape.getSize(axis) - 1;
+ } else {
+ bl = DoubleMath.fuzzyEquals(shape.min(axis), 0.0, 1.0E-7);
+ i = 0;
+ }
+
+ return (VoxelShape)(!bl ? empty() : new SliceShape(shape, axis, i));
+ }
}
// Paper start - optimise collisions
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
@ -13315,18 +13312,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return AABB.clip(((VoxelShape)(Object)this).toAabbs(), from, to, offset);
@@ -0,0 +0,0 @@ public abstract class VoxelShape implements ca.spottedleaf.moonrise.patches.coll
}
}
private VoxelShape calculateFace(Direction direction) {
- Direction.Axis axis = direction.getAxis();
- DoubleList doubleList = this.getCoords(axis);
- if (doubleList.size() == 2
- && DoubleMath.fuzzyEquals(doubleList.getDouble(0), 0.0, 1.0E-7)
- && DoubleMath.fuzzyEquals(doubleList.getDouble(1), 1.0, 1.0E-7)) {
- private VoxelShape calculateFace(Direction facing) {
- Direction.Axis axis = facing.getAxis();
- if (this.isCubeLikeAlong(axis)) {
- return this;
- } else {
- Direction.AxisDirection axisDirection = direction.getAxisDirection();
- Direction.AxisDirection axisDirection = facing.getAxisDirection();
- int i = this.findIndex(axis, axisDirection == Direction.AxisDirection.POSITIVE ? 0.9999999 : 1.0E-7);
- return new SliceShape(this, axis, i);
- SliceShape sliceShape = new SliceShape(this, axis, i);
- if (sliceShape.isEmpty()) {
- return Shapes.empty();
- } else {
- return (VoxelShape)(sliceShape.isCubeLike() ? Shapes.block() : sliceShape);
+ private VoxelShape calculateFace(Direction direction) {
+ // Paper start - optimise collisions
+ final Direction.Axis axis = direction.getAxis();
+ switch (axis) {
@ -13341,9 +13341,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ default: {
+ throw new IllegalStateException("Unknown axis: " + axis);
+ }
}
}
+ // Paper end - optimise collisions
}
// Paper start - optimise collisions
protected boolean isCubeLike() {

Datei anzeigen

@ -0,0 +1,87 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 24 Oct 2024 08:11:12 -0700
Subject: [PATCH] fixup! Paper config files
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
@@ -0,0 +0,0 @@ public class GlobalConfiguration extends ConfigurationPart {
public static GlobalConfiguration get() {
return instance;
}
+
+ public ChunkLoadingBasic chunkLoadingBasic;
+
+ public class ChunkLoadingBasic extends ConfigurationPart {
+ @Comment("The maximum rate in chunks per second that the server will send to any individual player. Set to -1 to disable this limit.")
+ public double playerMaxChunkSendRate = 75.0;
+
+ @Comment(
+ "The maximum rate at which chunks will load for any individual player. " +
+ "Note that this setting also affects chunk generations, since a chunk load is always first issued to test if a" +
+ "chunk is already generated. Set to -1 to disable this limit."
+ )
+ public double playerMaxChunkLoadRate = 100.0;
+
+ @Comment("The maximum rate at which chunks will generate for any individual player. Set to -1 to disable this limit.")
+ public double playerMaxChunkGenerateRate = -1.0;
+ }
+
+ public ChunkLoadingAdvanced chunkLoadingAdvanced;
+
+ public class ChunkLoadingAdvanced extends ConfigurationPart {
+ @Comment(
+ "Set to true if the server will match the chunk send radius that clients have configured" +
+ "in their view distance settings if the client is less-than the server's send distance."
+ )
+ public boolean autoConfigSendDistance = true;
+
+ @Comment(
+ "Specifies the maximum amount of concurrent chunk loads that an individual player can have." +
+ "Set to 0 to let the server configure it automatically per player, or set it to -1 to disable the limit."
+ )
+ public int playerMaxConcurrentChunkLoads = 0;
+
+ @Comment(
+ "Specifies the maximum amount of concurrent chunk generations that an individual player can have." +
+ "Set to 0 to let the server configure it automatically per player, or set it to -1 to disable the limit."
+ )
+ public int playerMaxConcurrentChunkGenerates = 0;
+ }
static void set(GlobalConfiguration instance) {
GlobalConfiguration.instance = instance;
}
@@ -0,0 +0,0 @@ public class GlobalConfiguration extends ConfigurationPart {
public int incomingPacketThreshold = 300;
}
- public ChunkLoading chunkLoading;
-
- public class ChunkLoading extends ConfigurationPart {
- public int minLoadRadius = 2;
- public int maxConcurrentSends = 2;
- public boolean autoconfigSendDistance = true;
- public double targetPlayerChunkSendRate = 100.0;
- public double globalMaxChunkSendRate = -1.0;
- public boolean enableFrustumPriority = false;
- public double globalMaxChunkLoadRate = -1.0;
- public double playerMaxConcurrentLoads = 20.0;
- public double globalMaxConcurrentLoads = 500.0;
- public double playerMaxChunkLoadRate = -1.0;
- }
-
public UnsupportedSettings unsupportedSettings;
public class UnsupportedSettings extends ConfigurationPart {
@@ -0,0 +0,0 @@ public class GlobalConfiguration extends ConfigurationPart {
@PostProcess
private void postProcess() {
- //io.papermc.paper.chunk.system.scheduling.ChunkTaskScheduler.init(this);
+ ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler.init(this);
}
}

Datei anzeigen

@ -1,343 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 11 Mar 2021 20:05:44 -0800
Subject: [PATCH] Custom table implementation for blockstate state lookups
Testing some redstone intensive machines showed to bring about a 10%
improvement.
diff --git a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
@@ -0,0 +0,0 @@
+package io.papermc.paper.util.table;
+
+import com.google.common.collect.Table;
+import net.minecraft.world.level.block.state.StateHolder;
+import net.minecraft.world.level.block.state.properties.Property;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public final class ZeroCollidingReferenceStateTable {
+
+ // upper 32 bits: starting index
+ // lower 32 bits: bitset for contained ids
+ protected final long[] this_index_table;
+ protected final Comparable<?>[] this_table;
+ protected final StateHolder<?, ?> this_state;
+
+ protected long[] index_table;
+ protected StateHolder<?, ?>[][] value_table;
+
+ public ZeroCollidingReferenceStateTable(final StateHolder<?, ?> state, final Map<Property<?>, Comparable<?>> this_map) {
+ this.this_state = state;
+ this.this_index_table = this.create_table(this_map.keySet());
+
+ int max_id = -1;
+ for (final Property<?> property : this_map.keySet()) {
+ final int id = lookup_vindex(property, this.this_index_table);
+ if (id > max_id) {
+ max_id = id;
+ }
+ }
+
+ this.this_table = new Comparable[max_id + 1];
+ for (final Map.Entry<Property<?>, Comparable<?>> entry : this_map.entrySet()) {
+ this.this_table[lookup_vindex(entry.getKey(), this.this_index_table)] = entry.getValue();
+ }
+ }
+
+ public void loadInTable(final Table<Property<?>, Comparable<?>, StateHolder<?, ?>> table,
+ final Map<Property<?>, Comparable<?>> this_map) {
+ final Set<Property<?>> combined = new HashSet<>(table.rowKeySet());
+ combined.addAll(this_map.keySet());
+
+ this.index_table = this.create_table(combined);
+
+ int max_id = -1;
+ for (final Property<?> property : combined) {
+ final int id = lookup_vindex(property, this.index_table);
+ if (id > max_id) {
+ max_id = id;
+ }
+ }
+
+ this.value_table = new StateHolder[max_id + 1][];
+
+ final Map<Property<?>, Map<Comparable<?>, StateHolder<?, ?>>> map = table.rowMap();
+ for (final Property<?> property : map.keySet()) {
+ final Map<Comparable<?>, StateHolder<?, ?>> propertyMap = map.get(property);
+
+ final int id = lookup_vindex(property, this.index_table);
+ final StateHolder<?, ?>[] states = this.value_table[id] = new StateHolder[property.getPossibleValues().size()];
+
+ for (final Map.Entry<Comparable<?>, StateHolder<?, ?>> entry : propertyMap.entrySet()) {
+ if (entry.getValue() == null) {
+ // TODO what
+ continue;
+ }
+
+ states[((Property)property).getIdFor(entry.getKey())] = entry.getValue();
+ }
+ }
+
+
+ for (final Map.Entry<Property<?>, Comparable<?>> entry : this_map.entrySet()) {
+ final Property<?> property = entry.getKey();
+ final int index = lookup_vindex(property, this.index_table);
+
+ if (this.value_table[index] == null) {
+ this.value_table[index] = new StateHolder[property.getPossibleValues().size()];
+ }
+
+ this.value_table[index][((Property)property).getIdFor(entry.getValue())] = this.this_state;
+ }
+ }
+
+
+ protected long[] create_table(final Collection<Property<?>> collection) {
+ int max_id = -1;
+ for (final Property<?> property : collection) {
+ final int id = property.getId();
+ if (id > max_id) {
+ max_id = id;
+ }
+ }
+
+ final long[] ret = new long[((max_id + 1) + 31) >>> 5]; // ceil((max_id + 1) / 32)
+
+ for (final Property<?> property : collection) {
+ final int id = property.getId();
+
+ ret[id >>> 5] |= (1L << (id & 31));
+ }
+
+ int total = 0;
+ for (int i = 1, len = ret.length; i < len; ++i) {
+ ret[i] |= (long)(total += Long.bitCount(ret[i - 1] & 0xFFFFFFFFL)) << 32;
+ }
+
+ return ret;
+ }
+
+ public Comparable<?> get(final Property<?> state) {
+ final Comparable<?>[] table = this.this_table;
+ final int index = lookup_vindex(state, this.this_index_table);
+
+ if (index < 0 || index >= table.length) {
+ return null;
+ }
+ return table[index];
+ }
+
+ public StateHolder<?, ?> get(final Property<?> property, final Comparable<?> with) {
+ final int withId = ((Property)property).getIdFor(with);
+ if (withId < 0) {
+ return null;
+ }
+
+ final int index = lookup_vindex(property, this.index_table);
+ final StateHolder<?, ?>[][] table = this.value_table;
+ if (index < 0 || index >= table.length) {
+ return null;
+ }
+
+ final StateHolder<?, ?>[] values = table[index];
+
+ if (withId >= values.length) {
+ return null;
+ }
+
+ return values[withId];
+ }
+
+ protected static int lookup_vindex(final Property<?> property, final long[] index_table) {
+ final int id = property.getId();
+ final long bitset_mask = (1L << (id & 31));
+ final long lower_mask = bitset_mask - 1;
+ final int index = id >>> 5;
+ if (index >= index_table.length) {
+ return -1;
+ }
+ final long index_value = index_table[index];
+ final long contains_check = ((index_value & bitset_mask) - 1) >> (Long.SIZE - 1); // -1L if doesn't contain
+
+ // index = total bits set in lower table values (upper 32 bits of index_value) plus total bits set in lower indices below id
+ // contains_check is 0 if the bitset had id set, else it's -1: so index is unaffected if contains_check == 0,
+ // otherwise it comes out as -1.
+ return (int)(((index_value >>> 32) + Long.bitCount(index_value & lower_mask)) | contains_check);
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
+++ b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
private final Reference2ObjectArrayMap<Property<?>, Comparable<?>> values;
private Table<Property<?>, Comparable<?>, S> neighbours;
protected final MapCodec<S> propertiesCodec;
+ protected final io.papermc.paper.util.table.ZeroCollidingReferenceStateTable optimisedTable; // Paper - optimise state lookup
protected StateHolder(O owner, Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap, MapCodec<S> codec) {
this.owner = owner;
this.values = propertyMap;
this.propertiesCodec = codec;
+ this.optimisedTable = new io.papermc.paper.util.table.ZeroCollidingReferenceStateTable(this, propertyMap); // Paper - optimise state lookup
}
public <T extends Comparable<T>> S cycle(Property<T> property) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
public <T extends Comparable<T>> boolean hasProperty(Property<T> property) {
- return this.values.containsKey(property);
+ return this.optimisedTable.get(property) != null; // Paper - optimise state lookup
}
public <T extends Comparable<T>> T getValue(Property<T> property) {
- Comparable<?> comparable = this.values.get(property);
+ Comparable<?> comparable = this.optimisedTable.get(property); // Paper - optimise state lookup
if (comparable == null) {
throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + this.owner);
} else {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
public <T extends Comparable<T>> Optional<T> getOptionalValue(Property<T> property) {
- Comparable<?> comparable = this.values.get(property);
+ Comparable<?> comparable = this.optimisedTable.get(property); // Paper - optimise state lookup
return comparable == null ? Optional.empty() : Optional.of(property.getValueClass().cast(comparable));
}
public <T extends Comparable<T>, V extends T> S setValue(Property<T> property, V value) {
- Comparable<?> comparable = this.values.get(property);
- if (comparable == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " as it does not exist in " + this.owner);
- } else if (comparable.equals(value)) {
- return (S)this;
- } else {
- S object = this.neighbours.get(property, value);
- if (object == null) {
- throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
- } else {
- return object;
- }
+ // Paper start - optimise state lookup
+ final S ret = (S)this.optimisedTable.get(property, value);
+ if (ret == null) {
+ throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
}
+ return ret;
+ // Paper end - optimise state lookup
}
public <T extends Comparable<T>, V extends T> S trySetValue(Property<T> property, V value) {
@@ -0,0 +0,0 @@ public abstract class StateHolder<O, S> {
}
}
- this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table));
+ this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table)); this.optimisedTable.loadInTable((Table)this.neighbours, this.values); // Paper - optimise state lookup
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/BooleanProperty.java
@@ -0,0 +0,0 @@ import java.util.Optional;
public class BooleanProperty extends Property<Boolean> {
private final ImmutableSet<Boolean> values = ImmutableSet.of(true, false);
+ // Paper start - optimise iblockdata state lookup
+ @Override
+ public final int getIdFor(final Boolean value) {
+ return value.booleanValue() ? 1 : 0;
+ }
+ // Paper end - optimise iblockdata state lookup
+
protected BooleanProperty(String name) {
super(name, Boolean.class);
}
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/EnumProperty.java
@@ -0,0 +0,0 @@ public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Prope
private final ImmutableSet<T> values;
private final Map<String, T> names = Maps.newHashMap();
+ // Paper start - optimise iblockdata state lookup
+ private int[] idLookupTable;
+
+ @Override
+ public final int getIdFor(final T value) {
+ return this.idLookupTable[value.ordinal()];
+ }
+ // Paper end - optimise iblockdata state lookup
+
protected EnumProperty(String name, Class<T> type, Collection<T> values) {
super(name, type);
this.values = ImmutableSet.copyOf(values);
@@ -0,0 +0,0 @@ public class EnumProperty<T extends Enum<T> & StringRepresentable> extends Prope
this.names.put(string, enum_);
}
+ // Paper start - optimise BlockState lookup
+ int id = 0;
+ this.idLookupTable = new int[type.getEnumConstants().length];
+ java.util.Arrays.fill(this.idLookupTable, -1);
+ for (final T value : this.getPossibleValues()) {
+ this.idLookupTable[value.ordinal()] = id++;
+ }
+ // Paper end - optimise BlockState lookup
}
@Override
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java b/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/IntegerProperty.java
@@ -0,0 +0,0 @@ public class IntegerProperty extends Property<Integer> {
public final int min;
public final int max;
+ // Paper start - optimise iblockdata state lookup
+ @Override
+ public final int getIdFor(final Integer value) {
+ final int val = value.intValue();
+ final int ret = val - this.min;
+
+ return ret | ((this.max - ret) >> 31);
+ }
+ // Paper end - optimise iblockdata state lookup
+
protected IntegerProperty(String name, int min, int max) {
super(name, Integer.class);
if (min < 0) {
diff --git a/src/main/java/net/minecraft/world/level/block/state/properties/Property.java b/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
+++ b/src/main/java/net/minecraft/world/level/block/state/properties/Property.java
@@ -0,0 +0,0 @@ public abstract class Property<T extends Comparable<T>> {
);
private final Codec<Property.Value<T>> valueCodec = this.codec.xmap(this::value, Property.Value::value);
+ // Paper start - optimise iblockdata state lookup
+ private static final java.util.concurrent.atomic.AtomicInteger ID_GENERATOR = new java.util.concurrent.atomic.AtomicInteger();
+ private final int id = ID_GENERATOR.getAndIncrement();
+
+ public final int getId() {
+ return this.id;
+ }
+
+ public abstract int getIdFor(final T value);
+ // Paper end - optimise state lookup
+
protected Property(String name, Class<T> type) {
this.clazz = type;
this.name = name;