From df7465a59f260f80840107759bc40e66a3a7f107 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 9 Mar 2025 16:20:58 +0700 Subject: [PATCH] Wither skeleton sword and helmet server config --- .../ru/dbotthepony/mc/otm/config/ServerConfig.kt | 8 ++++++++ .../ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt | 11 +++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt index 78c37014b..64766db67 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ServerConfig.kt @@ -76,4 +76,12 @@ object ServerConfig : AbstractConfig("misc") { builder.pop() } } + + val WITHER_SKELETON_HELMET_CHANCE: Double by builder + .comment("Chance of Wither Skeleton spawning with Netherite Helmet AND Withered Steel sword") + .defineInRange("WITHER_SKELETON_HELMET_CHANCE", 0.1, 0.0, 1.0) + + val WITHER_SKELETON_SWORD_CHANCE: Double by builder + .comment("Chance of Wither Skeleton spawning with Withered Steel sword") + .defineInRange("WITHER_SKELETON_HELMET_CHANCE", 0.24, 0.0, 1.0) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt index d1faa29ae..d7d1bb5d4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/entity/SpawnModifiers.kt @@ -6,6 +6,7 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items import net.neoforged.bus.api.SubscribeEvent import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent +import ru.dbotthepony.mc.otm.config.ServerConfig import ru.dbotthepony.mc.otm.core.otmRandom import ru.dbotthepony.mc.otm.registry.game.MItems @@ -16,15 +17,17 @@ object WitheredSkeletonSpawnHandler { val entity = event.entity if (entity is WitherSkeleton) { - val giveHelmet = event.level.otmRandom.nextFloat() < 0.1f - val giveSword = event.level.otmRandom.nextFloat() < 0.24f + val giveHelmet = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_HELMET_CHANCE + val giveSword = event.level.otmRandom.nextFloat() < ServerConfig.WITHER_SKELETON_SWORD_CHANCE if (giveHelmet) { - entity.setItemSlot(EquipmentSlot.HEAD, ItemStack(Items.NETHERITE_HELMET)) + if (!entity.hasItemInSlot(EquipmentSlot.HEAD)) + entity.setItemSlot(EquipmentSlot.HEAD, ItemStack(Items.NETHERITE_HELMET)) } if (giveSword || giveHelmet) { - entity.setItemSlot(EquipmentSlot.MAINHAND, ItemStack(MItems.WITHERED_STEEL_SWORD)) + if (!entity.hasItemInSlot(EquipmentSlot.MAINHAND) || entity.getItemBySlot(EquipmentSlot.MAINHAND).item == Items.STONE_SWORD) + entity.setItemSlot(EquipmentSlot.MAINHAND, ItemStack(MItems.WITHERED_STEEL_SWORD)) } } }