From 48f4dcad0207016b225b0ade428146bbfc6fb11f Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 23 Feb 2025 01:18:17 +0300 Subject: [PATCH] add some patches --- build-data/divinemc.at | 2 + .../0015-Optimize-entity-stupid-brain.patch | 28 +++++++ .../features/0032-Configurable-MC-67.patch | 18 ++++ ...able-saving-of-snowball-and-firework.patch | 44 ++++++++++ .../0034-Catch-update-suppressors.patch | 83 +++++++++++++++++++ .../0009-Add-chunk-worker-algorithm.patch | 11 ++- ...10-Configurable-thread-pool-priority.patch | 18 ++++ .../org/bxteam/divinemc/DivineConfig.java | 13 +-- .../bxteam/divinemc/DivineWorldConfig.java | 12 ++- .../exception/UpdateSuppressorException.java | 31 +++++++ 10 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 divinemc-server/minecraft-patches/features/0032-Configurable-MC-67.patch create mode 100644 divinemc-server/minecraft-patches/features/0033-Option-to-disable-saving-of-snowball-and-firework.patch create mode 100644 divinemc-server/minecraft-patches/features/0034-Catch-update-suppressors.patch create mode 100644 divinemc-server/paper-patches/features/0010-Configurable-thread-pool-priority.patch create mode 100644 divinemc-server/src/main/java/org/bxteam/divinemc/util/exception/UpdateSuppressorException.java diff --git a/build-data/divinemc.at b/build-data/divinemc.at index a8ffb2d..73ecc0d 100644 --- a/build-data/divinemc.at +++ b/build-data/divinemc.at @@ -8,6 +8,8 @@ private-f net.minecraft.world.level.levelgen.RandomState router private-f net.minecraft.world.level.levelgen.RandomState sampler public net.minecraft.util.Mth SIN public net.minecraft.world.entity.ai.Brain sensors +public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities lineOfSightTest +public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities nearbyEntities public net.minecraft.world.entity.ai.sensing.Sensor scanRate public net.minecraft.world.entity.ai.sensing.Sensor timeToTick public net.minecraft.world.level.ServerExplosion damageSource diff --git a/divinemc-server/minecraft-patches/features/0015-Optimize-entity-stupid-brain.patch b/divinemc-server/minecraft-patches/features/0015-Optimize-entity-stupid-brain.patch index ddf9734..580e1cd 100644 --- a/divinemc-server/minecraft-patches/features/0015-Optimize-entity-stupid-brain.patch +++ b/divinemc-server/minecraft-patches/features/0015-Optimize-entity-stupid-brain.patch @@ -374,6 +374,34 @@ index ec90ea4e66c6c38d7ad41805a16c63e006e44be4..0204fe68c97d152a7c3201620b6709a8 private boolean isAcceptableLandingPosition(ServerLevel level, E entity, BlockPos pos) { BlockPos blockPos = entity.blockPosition(); +diff --git a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java +index 24d1928445b5571e040a2b12d5c82e77a880d9bd..dac0a23aebf2dea1972c07d5c82079da7c9837ac 100644 +--- a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java ++++ b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java +@@ -21,9 +21,22 @@ public class VillagerBabiesSensor extends Sensor { + entity.getBrain().setMemory(MemoryModuleType.VISIBLE_VILLAGER_BABIES, this.getNearestVillagerBabies(entity)); + } + ++ // DivineMC start - Optimize baby villager sensor + private List getNearestVillagerBabies(LivingEntity livingEntity) { +- return ImmutableList.copyOf(this.getVisibleEntities(livingEntity).findAll(this::isVillagerBaby)); ++ NearestVisibleLivingEntities visibleEntities = this.getVisibleEntities(livingEntity); ++ ImmutableList.Builder babies = ImmutableList.builder(); ++ ++ for (LivingEntity target : visibleEntities.nearbyEntities) { ++ if (target.getType() == EntityType.VILLAGER ++ && target.isBaby() ++ && visibleEntities.lineOfSightTest.test(target)) { ++ babies.add(target); ++ } ++ } ++ ++ return babies.build(); + } ++ // DivineMC end - Optimize baby villager sensor + + private boolean isVillagerBaby(LivingEntity livingEntity) { + return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby(); diff --git a/net/minecraft/world/entity/animal/goat/Goat.java b/net/minecraft/world/entity/animal/goat/Goat.java index 6f106f10466440f8e65e04511f67d48f082d703f..15728d4fbe7a12c7a3b94a9ef88e7141b1225fa3 100644 --- a/net/minecraft/world/entity/animal/goat/Goat.java diff --git a/divinemc-server/minecraft-patches/features/0032-Configurable-MC-67.patch b/divinemc-server/minecraft-patches/features/0032-Configurable-MC-67.patch new file mode 100644 index 0000000..c2cd60f --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0032-Configurable-MC-67.patch @@ -0,0 +1,18 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Sun, 23 Feb 2025 01:03:59 +0300 +Subject: [PATCH] Configurable MC-67 + + +diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java +index 356a1bfc610214912f58c4126cdd5694ffecfcb8..55bde2487078d0c7dcb3a367d070838770fc0f4e 100644 +--- a/net/minecraft/world/entity/Entity.java ++++ b/net/minecraft/world/entity/Entity.java +@@ -4020,6 +4020,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + } + + public boolean canTeleport(Level fromLevel, Level toLevel) { ++ if (!fromLevel.divineConfig.allowEntityPortalWithPassenger && (this.isPassenger() || this.isVehicle())) return false; // DivineMC - Allow entity teleport with passenger + if (!this.isAlive() || !this.valid) return false; // Paper - Fix item duplication and teleport issues + if (fromLevel.dimension() == Level.END && toLevel.dimension() == Level.OVERWORLD) { + for (Entity entity : this.getPassengers()) { diff --git a/divinemc-server/minecraft-patches/features/0033-Option-to-disable-saving-of-snowball-and-firework.patch b/divinemc-server/minecraft-patches/features/0033-Option-to-disable-saving-of-snowball-and-firework.patch new file mode 100644 index 0000000..8e0bd33 --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0033-Option-to-disable-saving-of-snowball-and-firework.patch @@ -0,0 +1,44 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Sun, 23 Feb 2025 01:04:29 +0300 +Subject: [PATCH] Option to disable saving of snowball and firework + + +diff --git a/net/minecraft/world/entity/projectile/FireworkRocketEntity.java b/net/minecraft/world/entity/projectile/FireworkRocketEntity.java +index 774ca9e0b56fd175ae246051de762d0c4256ca58..3a380d038ef1231624a646c38b60a4344694e321 100644 +--- a/net/minecraft/world/entity/projectile/FireworkRocketEntity.java ++++ b/net/minecraft/world/entity/projectile/FireworkRocketEntity.java +@@ -364,4 +364,14 @@ public class FireworkRocketEntity extends Projectile implements ItemSupplier { + double d1 = entity.position().z - this.position().z; + return DoubleDoubleImmutablePair.of(d, d1); + } ++ ++ // DivineMC start - Option to disable saving firework ++ @Override ++ public boolean shouldBeSaved() { ++ if (this.level().divineConfig.disableFireworkSaving) { ++ return false; ++ } ++ return super.shouldBeSaved(); ++ } ++ // DivineMC end - Option to disable saving firework + } +diff --git a/net/minecraft/world/entity/projectile/Snowball.java b/net/minecraft/world/entity/projectile/Snowball.java +index cad1f8cb68ef9615587e651a3120f68a3c32add0..18298f3ba544e07110ea8d5b15ae753f7e3de65a 100644 +--- a/net/minecraft/world/entity/projectile/Snowball.java ++++ b/net/minecraft/world/entity/projectile/Snowball.java +@@ -100,4 +100,14 @@ public class Snowball extends ThrowableItemProjectile { + this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause + } + } ++ ++ // DivineMC start - Option to disable snowball saving ++ @Override ++ public boolean shouldBeSaved() { ++ if (this.level().divineConfig.disableSnowballSaving) { ++ return false; ++ } ++ return super.shouldBeSaved(); ++ } ++ // DivineMC end - Option to disable snowball saving + } diff --git a/divinemc-server/minecraft-patches/features/0034-Catch-update-suppressors.patch b/divinemc-server/minecraft-patches/features/0034-Catch-update-suppressors.patch new file mode 100644 index 0000000..a09bfdb --- /dev/null +++ b/divinemc-server/minecraft-patches/features/0034-Catch-update-suppressors.patch @@ -0,0 +1,83 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> +Date: Sun, 23 Feb 2025 01:14:54 +0300 +Subject: [PATCH] Catch update suppressors + + +diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java +index 4535858701b2bb232b9d2feb2af6551526232ddc..aa4dd7517e8be167aef1eaf7aa907e3ce7cc0e62 100644 +--- a/net/minecraft/network/protocol/PacketUtils.java ++++ b/net/minecraft/network/protocol/PacketUtils.java +@@ -27,6 +27,10 @@ public class PacketUtils { + if (processor.shouldHandleMessage(packet)) { + try { + packet.handle(processor); ++ // DivineMC start - Catch update suppressors ++ } catch (org.bxteam.divinemc.util.exception.UpdateSuppressorException e) { ++ LOGGER.info(e.getMessage()); ++ // DivineMC end - Catch update suppressors + } catch (Exception var4) { + if (var4 instanceof ReportedException reportedException && reportedException.getCause() instanceof OutOfMemoryError) { + throw makeReportedException(var4, packet, processor); +diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java +index b7815831ff1a2fa9aa52e96f1a50a5aa6823ff8a..85f81c83aff81133289a03f12a059729b7d2e00e 100644 +--- a/net/minecraft/server/MinecraftServer.java ++++ b/net/minecraft/server/MinecraftServer.java +@@ -1789,6 +1789,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop +Date: Sun, 23 Feb 2025 00:43:23 +0300 +Subject: [PATCH] Configurable thread pool priority + + +diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java +index 27447481c6e6b526cda032aff54a5c87256c217d..87d22532c680b7c6d3244a13e91fccbcc1a7e004 100644 +--- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java ++++ b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java +@@ -28,6 +28,7 @@ public final class MoonriseCommon { + LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable); + } + }); ++ thread.setPriority(DivineConfig.threadPoolPriority); // DivineMC - Configurable thread pool priority + } + } + ); diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java index 8a032ea..ed6fe4a 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java @@ -2,8 +2,6 @@ package org.bxteam.divinemc; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.configuration.ConfigurationSection; @@ -23,7 +21,7 @@ import java.util.logging.Level; @SuppressWarnings("unused") @NullMarked -public final class DivineConfig { +public final class DivineConfig { // TODO: Remake config system private DivineConfig() { throw new IllegalStateException("Utility class"); } @@ -194,6 +192,7 @@ public final class DivineConfig { public static long chunkDataCacheLimit = 32678L; public static int maxViewDistance = 32; public static ChunkSystemAlgorithms chunkWorkerAlgorithm = ChunkSystemAlgorithms.C2ME; + public static int threadPoolPriority = Thread.NORM_PRIORITY + 1; public static boolean enableSecureSeed = false; public static boolean enableDensityFunctionCompiler = false; public static boolean enableStructureLayoutOptimizer = true; @@ -203,9 +202,7 @@ public final class DivineConfig { nativeAccelerationEnabled = getBoolean(config, "settings.chunk-generation.native-acceleration-enabled", nativeAccelerationEnabled); allowAVX512 = getBoolean(config, "settings.chunk-generation.allow-avx512", allowAVX512, - "Enables AVX512 support for natives-math optimizations", - "", - "Read more about AVX512: https://en.wikipedia.org/wiki/AVX-512"); + "Enables AVX512 support for natives-math optimizations"); isaTargetLevelOverride = getInt(config, "settings.chunk-generation.isa-target-level-override", isaTargetLevelOverride, "Overrides the ISA target located by the native loader, which allows forcing AVX512 (must be a value between 6-9 for AVX512 support).", "Value must be between 1-9, and -1 to disable override"); @@ -222,6 +219,8 @@ public final class DivineConfig { chunkWorkerAlgorithm = ChunkSystemAlgorithms.valueOf(getString(config, "settings.chunk-generation.chunk-worker-algorithm", chunkWorkerAlgorithm.name(), "Modifies what algorithm the chunk system will use to define thread counts. values: MOONRISE, C2ME, C2ME_AGGRESSIVE")); + threadPoolPriority = getInt(config, "settings.chunk-generation.thread-pool-priority", threadPoolPriority, + "Sets the priority of the thread pool used for chunk generation"); enableSecureSeed = getBoolean(config, "settings.misc.enable-secure-seed", enableSecureSeed, "This feature is based on Secure Seed mod by Earthcomputer.", @@ -258,6 +257,7 @@ public final class DivineConfig { public static boolean clumpOrbs = true; public static boolean ignoreMovedTooQuicklyWhenLagging = true; public static boolean alwaysAllowWeirdMovement = true; + public static boolean updateSuppressionCrashFix = true; private static void miscSettings() { skipUselessSecondaryPoiSensor = getBoolean(config, "settings.misc.skip-useless-secondary-poi-sensor", skipUselessSecondaryPoiSensor); @@ -267,6 +267,7 @@ public final class DivineConfig { "Improves general gameplay experience of the player when the server is lagging, as they won't get lagged back (message 'moved too quickly')"); alwaysAllowWeirdMovement = getBoolean(config, "settings.misc.always-allow-weird-movement", alwaysAllowWeirdMovement, "Means ignoring messages like 'moved too quickly' and 'moved wrongly'"); + updateSuppressionCrashFix = getBoolean(config, "settings.misc.update-suppression-crash-fix", updateSuppressionCrashFix); } public static boolean enableFasterTntOptimization = true; diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineWorldConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineWorldConfig.java index 2ef9680..fc4b847 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineWorldConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineWorldConfig.java @@ -10,6 +10,7 @@ import java.util.Map; import static org.bxteam.divinemc.DivineConfig.log; +@SuppressWarnings("unused") @NullMarked public final class DivineWorldConfig { private final YamlConfiguration config; @@ -74,9 +75,18 @@ public final class DivineWorldConfig { } public boolean snowballCanKnockback = true; + public boolean disableSnowballSaving = false; public boolean eggCanKnockback = true; - private void setSnowballAndEggKnockback() { + public boolean disableFireworkSaving = false; + private void projectilesSettings() { snowballCanKnockback = getBoolean("gameplay-mechanics.projectiles.snowball.knockback", snowballCanKnockback); + disableSnowballSaving = getBoolean("gameplay-mechanics.projectiles.snowball.disable-saving", disableSnowballSaving); eggCanKnockback = getBoolean("gameplay-mechanics.projectiles.egg.knockback", eggCanKnockback); + disableFireworkSaving = getBoolean("gameplay-mechanics.projectiles.firework.disable-saving", disableFireworkSaving); + } + + public boolean allowEntityPortalWithPassenger = true; + private void unsupportedFeatures() { + allowEntityPortalWithPassenger = getBoolean("unsupported-features.allow-entity-portal-with-passenger", allowEntityPortalWithPassenger); } } diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/util/exception/UpdateSuppressorException.java b/divinemc-server/src/main/java/org/bxteam/divinemc/util/exception/UpdateSuppressorException.java new file mode 100644 index 0000000..6033394 --- /dev/null +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/util/exception/UpdateSuppressorException.java @@ -0,0 +1,31 @@ +package org.bxteam.divinemc.util.exception; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; + +public class UpdateSuppressorException extends RuntimeException { + private final BlockPos pos; + private final Block source; + + public UpdateSuppressorException(BlockPos pos, Block source) { + super("Update suppression"); + this.pos = pos; + this.source = source; + } + + public BlockPos getPos() { + return pos; + } + + public Block getSource() { + return source; + } + + public String getMessage() { + if (pos != null) { + return "An update suppression processed, form [%s] to [x:%d,y:%d,z:%d]".formatted(source.getName(), pos.getX(), pos.getY(), pos.getZ()); + } else { + return "An update suppression processed, form [%s]".formatted(source.getName()); + } + } +}