From ddb7ef24896d2daafd8418c2b527f50a3d64a204 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:20:54 -0800 Subject: [PATCH] Override Mohist's crappy explosion handling --- README.md | 7 ++++- gradle.properties | 2 +- .../io/wdsj/hybridfix/HybridFixPlugin.java | 1 + .../io/wdsj/hybridfix/config/Settings.java | 4 +++ .../mohist/ExplosionDetonateEventMixin.java | 30 +++++++++++++++++++ .../mohist/ExplosionStartEventMixin.java | 30 +++++++++++++++++++ .../bridge/permission/EntityPermMixin.java | 2 +- .../mixin/fix/capability/PlayerListMixin.java | 1 + .../capability/mohist/PlayerListMixin.java | 4 +++ .../mixins.bridge.explosion.mohist.json | 12 ++++++++ 10 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionDetonateEventMixin.java create mode 100644 src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionStartEventMixin.java create mode 100644 src/main/resources/mixins.bridge.explosion.mohist.json diff --git a/README.md b/README.md index a669763..6c5d443 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,9 @@ Provide bugfixes for Forge+Bukkit server environments. ### Mods -- Simple Difficulty(And any other similar mods) thirst is not getting reset on player respawn[(Luohuayu/CatServer#536)](https://github.com/Luohuayu/CatServer/issues/536)[(MohistMC/Mohist#2905)](https://github.com/MohistMC/Mohist/issues/2905) +- Simple Difficulty, ToughAsNails(And any other similar mods) thirst is not getting reset on player respawn[(Luohuayu/CatServer#536)](https://github.com/Luohuayu/CatServer/issues/536)[(MohistMC/Mohist#2905)](https://github.com/MohistMC/Mohist/issues/2905) + +## Implemented Features + +- Auto override Mohist's crappy built-in explosion handling with our own method. +- Bridge Forge permission processing to Bukkit. diff --git a/gradle.properties b/gradle.properties index dc27c6b..4437ae7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -101,7 +101,7 @@ mixin_booter_version = 9.1 # You should change package root once they are generated generate_mixins_json = true # Delimit configs with spaces. Should only put configs name instead of full file name -mixin_configs = fix.capability bridge.explosion bridge.permission fix.capability.mohist +mixin_configs = fix.capability bridge.explosion bridge.explosion.mohist bridge.permission fix.capability.mohist # A refmap is a json that denotes mapping conversions, this json is generated automatically, with the name `mixins.mod_id.refmap.json` # Use the property `mixin_refmap` if you want it to use a different name, only one name is accepted mixin_refmap = mixins.${mod_id}.refmap.json diff --git a/src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java b/src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java index 4334397..dc60de4 100644 --- a/src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java +++ b/src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java @@ -23,6 +23,7 @@ public class HybridFixPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { put("mixins.fix.capability.json", () -> Settings.fixCapabilityReset); put("mixins.fix.capability.mohist.json" , () -> Settings.fixCapabilityReset && Utils.isClassLoaded("com.mohistmc.MohistMC")); put("mixins.bridge.explosion.json", () -> Settings.passExplosionEventToBukkit); + put("mixins.bridge.explosion.mohist.json", () -> Settings.passExplosionEventToBukkit && Settings.overrideMohistExplosionHandling && Utils.isClassLoaded("com.mohistmc.MohistMC")); put("mixins.bridge.permission.json", () -> Settings.bridgeForgePermissionsToBukkit); } }); diff --git a/src/main/java/io/wdsj/hybridfix/config/Settings.java b/src/main/java/io/wdsj/hybridfix/config/Settings.java index d5c92d0..064fad4 100644 --- a/src/main/java/io/wdsj/hybridfix/config/Settings.java +++ b/src/main/java/io/wdsj/hybridfix/config/Settings.java @@ -15,6 +15,10 @@ public class Settings { @Config.RequiresMcRestart public static boolean passExplosionEventToBukkit = !Utils.isClassLoaded("com.mohistmc.MohistMC"); // Default enable if not Mohist (Honestly Mohist's explosion handling is shit) + @Config.Comment("Override Mohist's crappy explosion handling with HybridFix's.") + @Config.RequiresMcRestart + public static boolean overrideMohistExplosionHandling = Utils.isClassLoaded("com.mohistmc.MohistMC"); + @Config.Comment("Bridge Forge permissions to Bukkit.") @Config.RequiresMcRestart public static boolean bridgeForgePermissionsToBukkit = !Utils.isClassLoaded("com.mohistmc.MohistMC"); diff --git a/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionDetonateEventMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionDetonateEventMixin.java new file mode 100644 index 0000000..c8e88a6 --- /dev/null +++ b/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionDetonateEventMixin.java @@ -0,0 +1,30 @@ +package io.wdsj.hybridfix.mixin.bridge.explosion.mohist; + +import net.minecraft.world.Explosion; +import net.minecraft.world.World; +import net.minecraftforge.event.world.ExplosionEvent; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ExplosionEvent.Detonate.class) +public abstract class ExplosionDetonateEventMixin extends ExplosionEvent { + public ExplosionDetonateEventMixin(World world, Explosion explosion) { + super(world, explosion); + } + + + @Redirect( + method = "", + at = @At( + value = "INVOKE", + target = "Lorg/bukkit/plugin/PluginManager;callEvent(Lorg/bukkit/event/Event;)V" + ), + remap = false + ) + public void swallowEvent(PluginManager instance, Event event) { + // no-op + } +} diff --git a/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionStartEventMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionStartEventMixin.java new file mode 100644 index 0000000..167d589 --- /dev/null +++ b/src/main/java/io/wdsj/hybridfix/mixin/bridge/explosion/mohist/ExplosionStartEventMixin.java @@ -0,0 +1,30 @@ +package io.wdsj.hybridfix.mixin.bridge.explosion.mohist; + +import net.minecraft.world.Explosion; +import net.minecraft.world.World; +import net.minecraftforge.event.world.ExplosionEvent; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ExplosionEvent.Start.class) +public abstract class ExplosionStartEventMixin extends ExplosionEvent { + public ExplosionStartEventMixin(World world, Explosion explosion) { + super(world, explosion); + } + + + @Redirect( + method = "", + at = @At( + value = "INVOKE", + target = "Lorg/bukkit/plugin/PluginManager;callEvent(Lorg/bukkit/event/Event;)V" + ), + remap = false + ) + public void swallowEvent(PluginManager instance, Event event) { + // no-op + } +} diff --git a/src/main/java/io/wdsj/hybridfix/mixin/bridge/permission/EntityPermMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/bridge/permission/EntityPermMixin.java index 00a546c..491435d 100644 --- a/src/main/java/io/wdsj/hybridfix/mixin/bridge/permission/EntityPermMixin.java +++ b/src/main/java/io/wdsj/hybridfix/mixin/bridge/permission/EntityPermMixin.java @@ -5,5 +5,5 @@ import org.spongepowered.asm.mixin.Mixin; @Mixin(Entity.class) -public abstract class EntityPermMixin implements IEntityPermissionGetter { +public abstract class EntityPermMixin implements IEntityPermissionGetter { // Method impl is provided by hybrids } diff --git a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java index c582594..e5bdfc7 100644 --- a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java +++ b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/PlayerListMixin.java @@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +// Common injection logic for most hybrid server implementations, except Mohist @Mixin(PlayerList.class) public abstract class PlayerListMixin { @Inject( diff --git a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java index 85d302e..d421336 100644 --- a/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java +++ b/src/main/java/io/wdsj/hybridfix/mixin/fix/capability/mohist/PlayerListMixin.java @@ -9,6 +9,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +/* + * Mohist inlines method body into recreatePlayerEntity from CraftBukkit moveToWorld, causes common mixin won't work + * now we need to handle this manually. + */ @Mixin(PlayerList.class) public abstract class PlayerListMixin { diff --git a/src/main/resources/mixins.bridge.explosion.mohist.json b/src/main/resources/mixins.bridge.explosion.mohist.json new file mode 100644 index 0000000..f1b9479 --- /dev/null +++ b/src/main/resources/mixins.bridge.explosion.mohist.json @@ -0,0 +1,12 @@ +{ + "package": "io.wdsj.hybridfix.mixin.bridge.explosion.mohist", + "required": true, + "refmap": "${mixin_refmap}", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "ExplosionStartEventMixin", + "ExplosionDetonateEventMixin" + ] +} \ No newline at end of file