From 4171bf341b013d6340e9d3736e23dca6eeb44cd1 Mon Sep 17 00:00:00 2001 From: whatsy Date: Wed, 14 Oct 2026 15:02:54 -0400 Subject: [PATCH 1/5] Add config option to allow using healing machines as a respawn point --- .../mod/common/mixin/ServerPlayerMixin.java | 50 +++++++++++++++++++ .../mod/common/block/HealingMachineBlock.kt | 17 ++++--- .../mod/common/config/CobblemonConfig.kt | 3 ++ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java b/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java index d967bd1ea0..eea43af09f 100644 --- a/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java +++ b/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java @@ -15,6 +15,7 @@ import com.cobblemon.mod.common.api.riding.RidingStyle; import com.cobblemon.mod.common.api.spawning.spawner.PlayerSpawner; import com.cobblemon.mod.common.api.spawning.spawner.PlayerSpawnerFactory; import com.cobblemon.mod.common.api.stats.CobblemonStats; +import com.cobblemon.mod.common.block.HealingMachineBlock; import com.cobblemon.mod.common.duck.ServerLevelDuck; import com.cobblemon.mod.common.entity.pokemon.PokemonEntity; import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules; @@ -22,16 +23,20 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayer.class) @@ -142,4 +147,49 @@ public abstract class ServerPlayerMixin implements PlayerSpawnerAccessor { ((ServerLevelDuck) this.serverLevel()).cobblemon$getLevelResourceLocation() ); } + + @ModifyVariable(method = "findRespawnAndUseSpawnBlock", at = @At("HEAD"), ordinal = 0) + private static boolean cobblemon$forceRespawnAtHealingMachine( + boolean forced, + @Local(argsOnly = true) ServerLevel level, + @Local(argsOnly = true) BlockPos pos + ) { + return forced || cobblemon$isHealingMachineRespawn(level, pos); + } + + @ModifyExpressionValue( + method = "findRespawnAndUseSpawnBlock", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/state/BlockState;getBlock()Lnet/minecraft/world/level/block/Block;", + ordinal = 0 + ) + ) + private static Block cobblemon$useAnchorHandlingForHealingMachine( + Block block, + @Local(argsOnly = true) ServerLevel level, + @Local(argsOnly = true) BlockPos pos + ) { + return cobblemon$isHealingMachineRespawn(level, pos) ? Blocks.RESPAWN_ANCHOR : block; + } + + @ModifyExpressionValue( + method = "findRespawnAndUseSpawnBlock", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/RespawnAnchorBlock;canSetSpawn(Lnet/minecraft/world/level/Level;)Z" + ) + ) + private static boolean cobblemon$allowHealingMachineDimension( + boolean canSetAnchorSpawn, + @Local(argsOnly = true) ServerLevel level, + @Local(argsOnly = true) BlockPos pos + ) { + return canSetAnchorSpawn || cobblemon$isHealingMachineRespawn(level, pos); + } + + @Unique + private static boolean cobblemon$isHealingMachineRespawn(ServerLevel level, BlockPos pos) { + return level.getBlockState(pos).getBlock() instanceof HealingMachineBlock; + } } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt index fa2ea45f6c..415c6aa72e 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt @@ -32,12 +32,7 @@ import net.minecraft.world.item.TooltipFlag import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level -import net.minecraft.world.level.block.BaseEntityBlock -import net.minecraft.world.level.block.Block -import net.minecraft.world.level.block.HorizontalDirectionalBlock -import net.minecraft.world.level.block.Mirror -import net.minecraft.world.level.block.RenderShape -import net.minecraft.world.level.block.Rotation +import net.minecraft.world.level.block.* import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.entity.BlockEntityTicker import net.minecraft.world.level.block.entity.BlockEntityType @@ -158,7 +153,14 @@ class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { } val party = serverPlayerEntity.party() val pc = serverPlayerEntity.pc() - val healPC = player.level().gameRules.getBoolean(CobblemonGameRules.HEALERS_HEAL_PC); + val healPC = player.level().gameRules.getBoolean(CobblemonGameRules.HEALERS_HEAL_PC) + + // Do spawnpoint stuff + if (Cobblemon.config.healingMachineRespawn) { + if (!player.isCreative) { + player.setRespawnPosition(world.dimension(), blockPos, player.yRot, false, true) + } + } if (party.none() && (!healPC || pc.none())) { player.sendSystemMessage(lang("healingmachine.nopokemon").red(), true) @@ -183,6 +185,7 @@ class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { player.sendSystemMessage(lang("healingmachine.notenoughcharge", "${((neededCharge/party.count())*100f).toInt()}%").red(), true) } party.forEach { it.tryRecallWithAnimation() } + return InteractionResult.CONSUME } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt index 42577590e6..0ecd0f32cc 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt @@ -407,6 +407,9 @@ class CobblemonConfig { @CobblemonConfigField(Category.World, lang = "type_gem_tick_chance", SERVER) var typeGemTickChance = 1.0f + @CobblemonConfigField(Category.Healing, lang = "healing_machine_respawn", SERVER) + var healingMachineRespawn = true // TODO: set this to false before merge + fun clone(): CobblemonConfig { val newConfig = CobblemonConfig() CobblemonConfig::class.memberProperties.forEach { property -> From edb3f906f82af85b5f580ada4e801592041c059e Mon Sep 17 00:00:00 2001 From: Gertimoshka <25247769-gertimoshka@users.noreply.gitlab.com> Date: Wed, 14 Oct 2026 21:48:14 +0200 Subject: [PATCH 2/5] Simpler Mixin --- .../mod/common/mixin/ServerPlayerMixin.java | 59 +++++-------------- .../mod/common/block/HealingMachineBlock.kt | 18 ++++-- .../resources/cobblemon-common.accesswidener | 4 +- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java b/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java index eea43af09f..1aa6184912 100644 --- a/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java +++ b/common/src/main/java/com/cobblemon/mod/common/mixin/ServerPlayerMixin.java @@ -28,16 +28,19 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Optional; @Mixin(ServerPlayer.class) public abstract class ServerPlayerMixin implements PlayerSpawnerAccessor { @@ -148,48 +151,16 @@ public abstract class ServerPlayerMixin implements PlayerSpawnerAccessor { ); } - @ModifyVariable(method = "findRespawnAndUseSpawnBlock", at = @At("HEAD"), ordinal = 0) - private static boolean cobblemon$forceRespawnAtHealingMachine( - boolean forced, - @Local(argsOnly = true) ServerLevel level, - @Local(argsOnly = true) BlockPos pos - ) { - return forced || cobblemon$isHealingMachineRespawn(level, pos); - } - - @ModifyExpressionValue( - method = "findRespawnAndUseSpawnBlock", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;getBlock()Lnet/minecraft/world/level/block/Block;", - ordinal = 0 - ) + @Inject( + method = "findRespawnAndUseSpawnBlock(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;FZZ)Ljava/util/Optional;", + at = @At(value = "HEAD"), + cancellable = true ) - private static Block cobblemon$useAnchorHandlingForHealingMachine( - Block block, - @Local(argsOnly = true) ServerLevel level, - @Local(argsOnly = true) BlockPos pos - ) { - return cobblemon$isHealingMachineRespawn(level, pos) ? Blocks.RESPAWN_ANCHOR : block; - } - - @ModifyExpressionValue( - method = "findRespawnAndUseSpawnBlock", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/block/RespawnAnchorBlock;canSetSpawn(Lnet/minecraft/world/level/Level;)Z" - ) - ) - private static boolean cobblemon$allowHealingMachineDimension( - boolean canSetAnchorSpawn, - @Local(argsOnly = true) ServerLevel level, - @Local(argsOnly = true) BlockPos pos - ) { - return canSetAnchorSpawn || cobblemon$isHealingMachineRespawn(level, pos); - } - - @Unique - private static boolean cobblemon$isHealingMachineRespawn(ServerLevel level, BlockPos pos) { - return level.getBlockState(pos).getBlock() instanceof HealingMachineBlock; + private static void cobblemon$useHealthStationAsRespawn(ServerLevel level, BlockPos pos, float angle, boolean forced, boolean keepInventory, CallbackInfoReturnable> cir) { + BlockState state = level.getBlockState(pos); + Block block = state.getBlock(); + if (block instanceof HealingMachineBlock && HealingMachineBlock.Companion.canSetSpawn(level)) { + cir.setReturnValue(HealingMachineBlock.Companion.findStandUpPosition(EntityType.PLAYER, level, pos).map((vec3) -> ServerPlayer.RespawnPosAngle.of(vec3, pos))); + } } } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt index 415c6aa72e..2b3dd5800b 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt @@ -24,6 +24,7 @@ import net.minecraft.network.chat.Component import net.minecraft.server.level.ServerPlayer import net.minecraft.util.RandomSource import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.EntityType import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.player.Player import net.minecraft.world.item.Item @@ -31,6 +32,7 @@ import net.minecraft.world.item.ItemStack import net.minecraft.world.item.TooltipFlag import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter +import net.minecraft.world.level.CollisionGetter import net.minecraft.world.level.Level import net.minecraft.world.level.block.* import net.minecraft.world.level.block.entity.BlockEntity @@ -43,9 +45,11 @@ import net.minecraft.world.level.block.state.properties.IntegerProperty import net.minecraft.world.level.block.state.properties.Property import net.minecraft.world.level.pathfinder.PathComputationType import net.minecraft.world.phys.BlockHitResult +import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.Shapes import net.minecraft.world.phys.shapes.VoxelShape +import java.util.Optional @Suppress("DEPRECATED", "OVERRIDE_DEPRECATION") class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { @@ -74,6 +78,14 @@ class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { const val MAX_CHARGE_LEVEL = 5 val CHARGE_LEVEL: IntegerProperty = IntegerProperty.create("charge", 0, MAX_CHARGE_LEVEL + 1) val NATURAL: BooleanProperty = BooleanProperty.create("natural") + + fun canSetSpawn(level: Level): Boolean { + return Cobblemon.config.healingMachineRespawn + } + + fun findStandUpPosition(entityType: EntityType<*>, level: CollisionGetter, pos: BlockPos): Optional { + return RespawnAnchorBlock.findStandUpPosition(entityType, level, pos) // Exists if we ever want to make something more custom, but anchor block logic should suffice + } } init { @@ -156,10 +168,8 @@ class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { val healPC = player.level().gameRules.getBoolean(CobblemonGameRules.HEALERS_HEAL_PC) // Do spawnpoint stuff - if (Cobblemon.config.healingMachineRespawn) { - if (!player.isCreative) { - player.setRespawnPosition(world.dimension(), blockPos, player.yRot, false, true) - } + if (canSetSpawn(world)) { + player.setRespawnPosition(world.dimension(), blockPos, player.yRot, false, true) } if (party.none() && (!healPC || pc.none())) { diff --git a/common/src/main/resources/cobblemon-common.accesswidener b/common/src/main/resources/cobblemon-common.accesswidener index 8be5773f85..2bdc984b56 100644 --- a/common/src/main/resources/cobblemon-common.accesswidener +++ b/common/src/main/resources/cobblemon-common.accesswidener @@ -157,4 +157,6 @@ transitive-accessible method net/minecraft/client/model/HumanoidModel setupAttac transitive-accessible method net/minecraft/client/model/HumanoidModel poseRightArm (Lnet/minecraft/world/entity/LivingEntity;)V transitive-accessible method net/minecraft/client/model/HumanoidModel poseLeftArm (Lnet/minecraft/world/entity/LivingEntity;)V -transitive-accessible method net/minecraft/world/level/block/BaseEntityBlock createTickerHelper (Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityTicker;)Lnet/minecraft/world/level/block/entity/BlockEntityTicker; \ No newline at end of file +transitive-accessible method net/minecraft/world/level/block/BaseEntityBlock createTickerHelper (Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityType;Lnet/minecraft/world/level/block/entity/BlockEntityTicker;)Lnet/minecraft/world/level/block/entity/BlockEntityTicker; + +transitive-accessible class net/minecraft/server/level/ServerPlayer$RespawnPosAngle \ No newline at end of file From bacc482bf0637a99a9d7e006f62fc8aa74622fc5 Mon Sep 17 00:00:00 2001 From: whatsy Date: Wed, 14 Oct 2026 16:25:16 -0400 Subject: [PATCH 3/5] finishing touches --- CHANGELOG.md | 1 + .../com/cobblemon/mod/common/block/HealingMachineBlock.kt | 2 +- .../kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt | 3 --- .../cobblemon/mod/common/world/gamerules/CobblemonGameRules.kt | 2 ++ 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1003484a94..31bcb6b31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [1.8.3 (MONTH xth, 2026)](#1-8-3) ### Additions +- Added the `healersSetSpawn` gamerule. When enabled, using a healing machine will set your spawnpoint. ### Pokémon Added #### Generation 4 diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt index 2b3dd5800b..6c7bd0da1d 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/HealingMachineBlock.kt @@ -80,7 +80,7 @@ class HealingMachineBlock(settings: Properties) : BaseEntityBlock(settings) { val NATURAL: BooleanProperty = BooleanProperty.create("natural") fun canSetSpawn(level: Level): Boolean { - return Cobblemon.config.healingMachineRespawn + return level.gameRules.getBoolean(CobblemonGameRules.HEALER_SET_SPAWN) } fun findStandUpPosition(entityType: EntityType<*>, level: CollisionGetter, pos: BlockPos): Optional { diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt index 0ecd0f32cc..42577590e6 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt @@ -407,9 +407,6 @@ class CobblemonConfig { @CobblemonConfigField(Category.World, lang = "type_gem_tick_chance", SERVER) var typeGemTickChance = 1.0f - @CobblemonConfigField(Category.Healing, lang = "healing_machine_respawn", SERVER) - var healingMachineRespawn = true // TODO: set this to false before merge - fun clone(): CobblemonConfig { val newConfig = CobblemonConfig() CobblemonConfig::class.memberProperties.forEach { property -> diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/world/gamerules/CobblemonGameRules.kt b/common/src/main/kotlin/com/cobblemon/mod/common/world/gamerules/CobblemonGameRules.kt index f3781c695a..8799e025eb 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/world/gamerules/CobblemonGameRules.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/world/gamerules/CobblemonGameRules.kt @@ -26,5 +26,7 @@ object CobblemonGameRules { val SHINY_STARTERS: GameRules.Key = Cobblemon.implementation.registerGameRule("doShinyStarters", GameRules.Category.MISC, BooleanRuleInvoker.`cobblemon$create`(false)) @JvmField val HEALERS_HEAL_PC: GameRules.Key = Cobblemon.implementation.registerGameRule("healersHealPC", GameRules.Category.MISC, BooleanRuleInvoker.`cobblemon$create`(false)) + @JvmField + val HEALER_SET_SPAWN: GameRules.Key = Cobblemon.implementation.registerGameRule("healersSetSpawn", GameRules.Category.MISC, BooleanRuleInvoker.`cobblemon$create`(false)) } \ No newline at end of file From 5210121b3d76dd550f2326574089452cfc68a68c Mon Sep 17 00:00:00 2001 From: whatsy Date: Tue, 27 Oct 2026 23:36:23 -0400 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31bcb6b31d..41c4b6c5b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## [1.8.3 (MONTH xth, 2026)](#1-8-3) +## [1.8.5 (MONTH xth, 2026)](#1-8-5) ### Additions - Added the `healersSetSpawn` gamerule. When enabled, using a healing machine will set your spawnpoint. From e48e492392d62524675831160e74163b7767b3a5 Mon Sep 17 00:00:00 2001 From: whatsy Date: Tue, 27 Oct 2026 23:45:20 -0400 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d3ff9c05a..4827110154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,5 @@ # Changelog ## [1.8.5 (MONTH xth, 2026)](#1-8-5) -## [1.8.x (MONTH xth, 2026)](#1-8-x) ### Additions - Added the `healersSetSpawn` gamerule. When enabled, using a healing machine will set your spawnpoint.