From b990fb863f0877199bb2a965de5020bdcb76dbf4 Mon Sep 17 00:00:00 2001 From: Mgazul Date: Mon, 25 Nov 2024 01:22:11 +0800 Subject: [PATCH] Some Update --- .../mohistmc/banner/config/BannerConfig.java | 4 ++++ .../mixin/server/level/MixinServerLevel.java | 15 +++++++++++--- .../lighting/MixinSkyLightSectionStorage.java | 20 +++++++++++++++++++ .../level/spawner/MixinNaturalSpawner.java | 1 + .../v1_20_R1/entity/CraftPlayer.java | 5 +++++ .../main/resources/banner.server.mixins.json | 3 ++- 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/lighting/MixinSkyLightSectionStorage.java diff --git a/modules/banner-api/src/main/java/com/mohistmc/banner/config/BannerConfig.java b/modules/banner-api/src/main/java/com/mohistmc/banner/config/BannerConfig.java index ba7de9d4b..8642575cb 100644 --- a/modules/banner-api/src/main/java/com/mohistmc/banner/config/BannerConfig.java +++ b/modules/banner-api/src/main/java/com/mohistmc/banner/config/BannerConfig.java @@ -141,7 +141,9 @@ private static double getDouble(String path, double def) public static double WatchDogTimeOut; public static String Watchdogtimetodo; public static boolean spawnForChunk; + public static boolean spawnForNatural; public static boolean NoRaining; + public static boolean SkyLight15; public static boolean networkmanager_debug; public static List networkmanager_intercept; @@ -164,6 +166,7 @@ private static void banner() { server_thread = getInt("threadpriority.server_thread", 8); nospawnEntity = getList("entity.nospawn", Collections.emptyList()); spawnForChunk = getBoolean("entity.spawnForChunk", true); + spawnForNatural = getBoolean("entity.spawnForNatural", true); clear_item = getBoolean("entity.clear.item.enable", false); clear_item__whitelist = getList("entity.clear.item.whitelist", Collections.emptyList()); clear_item__msg = getString("entity.clear.item.msg", "[Server] Cleaned up %size% drops"); @@ -178,5 +181,6 @@ private static void banner() { networkmanager_debug = getBoolean("networkmanager.debug", false); networkmanager_intercept = getList("networkmanager.intercept", Collections.emptyList()); Watchdogtimetodo = getString("Watchdogtimetodo", "restart"); + SkyLight15 = getBoolean("SkyLight15", false); } } diff --git a/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java index 5e797dbf3..f0fb399c9 100644 --- a/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java +++ b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/server/level/MixinServerLevel.java @@ -375,12 +375,21 @@ public int sendParticles(T type, double posX, double return this.sendParticles(type, posX, posY, posZ, particleCount, xOffset, yOffset, zOffset, speed); } - @Inject(method = "addEntity", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;addNewEntity(Lnet/minecraft/world/level/entity/EntityAccess;)Z")) - private void banner$addEntityEvent(Entity entityIn, CallbackInfoReturnable cir) { + @Inject(method = "addEntity", cancellable = true, at = @At(value = "HEAD")) + private void banner$canAddEntity(Entity entityIn, CallbackInfoReturnable cir) { CreatureSpawnEvent.SpawnReason reason = banner$reason.get() == null ? CreatureSpawnEvent.SpawnReason.DEFAULT : banner$reason.get(); - if (!BannerConfig.spawnForChunk && (reason.equals(SpawnReason.NATURAL) || reason.equals(SpawnReason.CHUNK_GEN))) { + if (!BannerConfig.spawnForChunk && reason.equals(SpawnReason.CHUNK_GEN)) { + cir.setReturnValue(false); + } + + if (!BannerConfig.spawnForNatural && reason.equals(SpawnReason.NATURAL)) { cir.setReturnValue(false); } + } + + @Inject(method = "addEntity", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;addNewEntity(Lnet/minecraft/world/level/entity/EntityAccess;)Z")) + private void banner$addEntityEvent(Entity entityIn, CallbackInfoReturnable cir) { + CreatureSpawnEvent.SpawnReason reason = banner$reason.get() == null ? CreatureSpawnEvent.SpawnReason.DEFAULT : banner$reason.get(); banner$reason.set(null); if (DistValidate.isValid((LevelAccessor) this) && !CraftEventFactory.doEntityAddEventCalling((ServerLevel) (Object) this, entityIn, reason)) { cir.setReturnValue(false); diff --git a/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/lighting/MixinSkyLightSectionStorage.java b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/lighting/MixinSkyLightSectionStorage.java new file mode 100644 index 000000000..169a1e918 --- /dev/null +++ b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/lighting/MixinSkyLightSectionStorage.java @@ -0,0 +1,20 @@ +package com.mohistmc.banner.mixin.world.level.lighting; + +import net.minecraft.world.level.lighting.SkyLightSectionStorage; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SkyLightSectionStorage.class) +public class MixinSkyLightSectionStorage { + + /** + * @author Mgazul + * @reason Mandatory 15 + */ + @Inject(method = "getLightValue(JZ)I", cancellable = true, at = @At(value = "HEAD")) + protected void getLightValue(long packedPos, boolean updateAll, CallbackInfoReturnable cir) { + cir.setReturnValue(15); + } +} diff --git a/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/spawner/MixinNaturalSpawner.java b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/spawner/MixinNaturalSpawner.java index 9185076d6..2be0b8df9 100644 --- a/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/spawner/MixinNaturalSpawner.java +++ b/modules/banner-server/src/main/java/com/mohistmc/banner/mixin/world/level/spawner/MixinNaturalSpawner.java @@ -135,6 +135,7 @@ public static void spawnForChunk(ServerLevel worldserver, LevelChunk chunk, Natu */ @Overwrite public static void spawnCategoryForPosition(MobCategory category, ServerLevel level, ChunkAccess chunk, BlockPos pos, NaturalSpawner.SpawnPredicate filter, NaturalSpawner.AfterSpawnCallback callback) { + if (!BannerConfig.spawnForNatural) return; StructureManager structuremanager = level.structureManager(); ChunkGenerator chunkgenerator = level.getChunkSource().getGenerator(); int i = pos.getY(); diff --git a/modules/banner-server/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftPlayer.java b/modules/banner-server/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftPlayer.java index 0689259cf..a0a834502 100644 --- a/modules/banner-server/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftPlayer.java +++ b/modules/banner-server/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftPlayer.java @@ -908,6 +908,11 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau Preconditions.checkArgument(location.getWorld() != null, "location.world"); location.checkFinite(); + // TODO Fix chunk loading + if (!location.getChunk().isLoaded()) { + location.getChunk().load(); + } + ServerPlayer entity = getHandle(); if (getHealth() == 0 || entity.isRemoved()) { diff --git a/modules/banner-server/src/main/resources/banner.server.mixins.json b/modules/banner-server/src/main/resources/banner.server.mixins.json index 13fa109ae..18cc23111 100644 --- a/modules/banner-server/src/main/resources/banner.server.mixins.json +++ b/modules/banner-server/src/main/resources/banner.server.mixins.json @@ -546,6 +546,7 @@ "world.level.storage.loot.functions.MixinLootingEnchantFunction", "world.level.storage.loot.parameters.LootParametersMixin", "world.level.storage.loot.predicates.MixinExplosionCondition", - "world.level.storage.loot.predicates.MixinRandomChanceWithLootingCondition" + "world.level.storage.loot.predicates.MixinRandomChanceWithLootingCondition", + "world.level.lighting.MixinSkyLightSectionStorage" ] }