Skip to content

Commit

Permalink
Override Mohist's crappy explosion handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Dec 28, 2024
1 parent 0434787 commit ddb7ef2
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wdsj/hybridfix/HybridFixPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/wdsj/hybridfix/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "<init>",
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
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<init>",
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/mixins.bridge.explosion.mohist.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit ddb7ef2

Please sign in to comment.