From 2d3007515bcef7ceeaac1ea231714aade7b5cd2b Mon Sep 17 00:00:00 2001 From: blockingHD Date: Sun, 7 Apr 2024 20:30:01 +0100 Subject: [PATCH 01/51] Add getRelevantPlayers method to OnDatapackSyncEvent (#766) Closes #733 --- .../neoforge/common/NeoForgeEventHandler.java | 3 +-- .../neoforge/event/OnDatapackSyncEvent.java | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeEventHandler.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeEventHandler.java index 93154652138..6ed7d5bd565 100644 --- a/src/main/java/net/neoforged/neoforge/common/NeoForgeEventHandler.java +++ b/src/main/java/net/neoforged/neoforge/common/NeoForgeEventHandler.java @@ -109,12 +109,11 @@ public void tagsUpdated(TagsUpdatedEvent event) { @SubscribeEvent public void onDpSync(final OnDatapackSyncEvent event) { - final List players = event.getPlayer() == null ? event.getPlayerList().getPlayers() : List.of(event.getPlayer()); RegistryManager.getDataMaps().forEach((registry, values) -> { final var regOpt = event.getPlayerList().getServer().overworld().registryAccess() .registry(registry); if (regOpt.isEmpty()) return; - players.forEach(player -> { + event.getRelevantPlayers().forEach(player -> { if (!player.connection.isConnected(RegistryDataMapSyncPayload.ID)) { return; } diff --git a/src/main/java/net/neoforged/neoforge/event/OnDatapackSyncEvent.java b/src/main/java/net/neoforged/neoforge/event/OnDatapackSyncEvent.java index 0208996307f..b7bdadb24ad 100644 --- a/src/main/java/net/neoforged/neoforge/event/OnDatapackSyncEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/OnDatapackSyncEvent.java @@ -5,6 +5,7 @@ package net.neoforged.neoforge.event; +import java.util.stream.Stream; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.players.PlayerList; import net.neoforged.bus.api.Event; @@ -26,15 +27,27 @@ public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player) } /** - * @return The server's player list to get a view of all players. + * Gets the server's player list, containing all players, when the event fires. + * + * @return The server's player list. */ public PlayerList getPlayerList() { return this.playerList; } /** - * @return The player to sync datapacks to. Null when syncing for all players, - * such as when the reload command runs. + * Creates a stream of players that need to receive data during this event, which is the specified player (if present) or all players. + * + * @return A stream of players to sync data to. + */ + public Stream getRelevantPlayers() { + return this.player == null ? this.playerList.getPlayers().stream() : Stream.of(this.player); + } + + /** + * Gets the player that is joining the server, or null when syncing for all players, such as when the reload command runs. + * + * @return The player to sync datapacks to. Null when syncing for all players. */ @Nullable public ServerPlayer getPlayer() { From 9f0d3d489e3746bfe5664ca989f309c261b90c89 Mon Sep 17 00:00:00 2001 From: shartte Date: Sun, 7 Apr 2024 21:34:43 +0200 Subject: [PATCH 02/51] Fixes ModMismatchEvent crash (#784) --- .../neoforged/neoforge/event/ModMismatchEvent.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java b/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java index ec5c03519d5..049d7d6632a 100644 --- a/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java @@ -83,18 +83,16 @@ public LevelStorageSource.LevelDirectory getLevelDirectory() { */ @Nullable public ArtifactVersion getPreviousVersion(String modId) { - if (this.versionDifferences.containsKey(modId)) - return this.versionDifferences.get(modId).oldVersion(); + var versionDifference = this.versionDifferences.get(modId); - return null; + return versionDifference != null ? versionDifference.oldVersion() : null; } @Nullable - public ArtifactVersion getCurrentVersion(String modid) { - if (this.versionDifferences.containsKey(modid)) - return this.versionDifferences.get(modid).newVersion(); + public ArtifactVersion getCurrentVersion(String modId) { + var versionDifference = this.versionDifferences.get(modId); - return null; + return versionDifference != null ? versionDifference.newVersion() : null; } /** @@ -137,6 +135,7 @@ public boolean anyResolved() { public Stream getResolved() { return resolved.keySet().stream() + .filter(versionDifferences::containsKey) .map(modid -> new MismatchResolutionResult(modid, versionDifferences.get(modid), resolved.get(modid))) .sorted(Comparator.comparing(MismatchResolutionResult::modid)); } From 21d61cd2403f4ec664af563410816aaff6d759fb Mon Sep 17 00:00:00 2001 From: Dennis C Date: Wed, 10 Apr 2024 19:17:06 +0200 Subject: [PATCH 03/51] [1.20.4] Improve detection of dynamic block light sources during light updates in chunk generation and loading (#765) --- .../world/level/chunk/ChunkAccess.java.patch | 20 ++++++++-------- .../level/chunk/ImposterProtoChunk.java.patch | 11 ++++++--- .../common/extensions/IBlockExtension.java | 24 +++++++++++++++---- .../extensions/IBlockStateExtension.java | 12 ++++++++++ .../debug/block/BlockPropertyTests.java | 5 ++++ 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/patches/net/minecraft/world/level/chunk/ChunkAccess.java.patch b/patches/net/minecraft/world/level/chunk/ChunkAccess.java.patch index 58545111275..a7067f01d20 100644 --- a/patches/net/minecraft/world/level/chunk/ChunkAccess.java.patch +++ b/patches/net/minecraft/world/level/chunk/ChunkAccess.java.patch @@ -9,35 +9,35 @@ public static final int NO_FILLED_SECTION = -1; private static final Logger LOGGER = LogUtils.getLogger(); private static final LongSet EMPTY_REFERENCE_SET = new LongOpenHashSet(); -@@ -308,23 +_,28 @@ +@@ -308,10 +_,19 @@ @Override public final void findBlockLightSources(BiConsumer p_285269_) { - this.findBlocks(p_284897_ -> p_284897_.getLightEmission() != 0, p_285269_); -+ this.findBlocks((p_284897_, pos) -> p_284897_.getLightEmission(this, pos) != 0, p_285269_); ++ this.findBlocks(p_284897_ -> p_284897_.hasDynamicLightEmission() || p_284897_.getLightEmission(net.minecraft.world.level.EmptyBlockGetter.INSTANCE, BlockPos.ZERO) != 0, (p_284897_, pos) -> p_284897_.getLightEmission(this, pos) != 0, p_285269_); } public void findBlocks(Predicate p_285343_, BiConsumer p_285030_) { -+ findBlocks((state, pos) -> p_285343_.test(state), p_285030_); ++ findBlocks(p_285343_, (state, pos) -> p_285343_.test(state), p_285030_); + } + ++ @Deprecated(forRemoval = true) + public void findBlocks(java.util.function.BiPredicate p_285343_, BiConsumer p_285030_) { ++ findBlocks(state -> p_285343_.test(state, BlockPos.ZERO), p_285343_, p_285030_); ++ } ++ ++ public void findBlocks(Predicate p_285343_, java.util.function.BiPredicate fineFilter, BiConsumer p_285030_) { BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); for(int i = this.getMinSection(); i < this.getMaxSection(); ++i) { - LevelChunkSection levelchunksection = this.getSection(this.getSectionIndexFromSectionY(i)); -- if (levelchunksection.maybeHas(p_285343_)) { -+ if (levelchunksection.maybeHas((state) -> p_285343_.test(state, BlockPos.ZERO))) { - BlockPos blockpos = SectionPos.of(this.chunkPos, i).origin(); - - for(int j = 0; j < 16; ++j) { +@@ -323,8 +_,9 @@ for(int k = 0; k < 16; ++k) { for(int l = 0; l < 16; ++l) { BlockState blockstate = levelchunksection.getBlockState(l, j, k); - if (p_285343_.test(blockstate)) { - p_285030_.accept(blockpos$mutableblockpos.setWithOffset(blockpos, l, j, k), blockstate); + blockpos$mutableblockpos.setWithOffset(blockpos, l, j, k); -+ if (p_285343_.test(blockstate, blockpos$mutableblockpos.immutable())) { ++ if (fineFilter.test(blockstate, blockpos$mutableblockpos)) { + p_285030_.accept(blockpos$mutableblockpos, blockstate); } } diff --git a/patches/net/minecraft/world/level/chunk/ImposterProtoChunk.java.patch b/patches/net/minecraft/world/level/chunk/ImposterProtoChunk.java.patch index 080e6c208fc..e02c237651e 100644 --- a/patches/net/minecraft/world/level/chunk/ImposterProtoChunk.java.patch +++ b/patches/net/minecraft/world/level/chunk/ImposterProtoChunk.java.patch @@ -1,11 +1,16 @@ --- a/net/minecraft/world/level/chunk/ImposterProtoChunk.java +++ b/net/minecraft/world/level/chunk/ImposterProtoChunk.java -@@ -217,6 +_,10 @@ +@@ -217,6 +_,15 @@ } @Override -+ public void findBlocks(java.util.function.BiPredicate p_285343_, BiConsumer p_285030_) { -+ this.wrapped.findBlocks(p_285343_, p_285030_); ++ public void findBlocks(java.util.function.BiPredicate p_285465_, BiConsumer p_285030_) { ++ this.wrapped.findBlocks(p_285465_, p_285030_); ++ } ++ ++ @Override ++ public void findBlocks(Predicate p_285465_, java.util.function.BiPredicate fineFilter, BiConsumer p_285030_) { ++ this.wrapped.findBlocks(p_285465_, fineFilter, p_285030_); + } + public TickContainerAccess getBlockTicks() { diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java index 7d5e6d5843d..dbce3e51889 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java @@ -32,6 +32,7 @@ import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; @@ -104,19 +105,32 @@ default float getFriction(BlockState state, LevelReader level, BlockPos pos, @Nu return self().getFriction(); } + /** + * Whether this block has dynamic light emission which is not solely based on the {@link BlockState} and instead + * uses the {@link BlockPos}, the {@link AuxiliaryLightManager} or another external data source to determine its + * light value in {@link #getLightEmission(BlockState, BlockGetter, BlockPos)} + * + * @param state the block state being checked + * @return true if this block cannot determine its light emission solely based on the block state, false otherwise + */ + default boolean hasDynamicLightEmission(BlockState state) { + return false; + } + /** * Get a light value for this block, taking into account the given state and coordinates, normal ranges are between 0 and 15 * * @param state The state of this block - * @param level The level this block is in - * @param pos The position of this block in the level, will be {@link BlockPos#ZERO} when the chunk being loaded or - * generated calls this to check whether it contains any light sources + * @param level The level this block is in, may be {@link EmptyBlockGetter#INSTANCE}, see implementation notes + * @param pos The position of this block in the level, may be {@link BlockPos#ZERO}, see implementation notes * @return The light value * @implNote