Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mod.mixin): impl ClientPermissionsChangedEvent
- Loading branch information
1 parent
a6332c7
commit 03ee734
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/org/auioc/mcmod/arnicalib/mod/client/event/AHClientEventFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.auioc.mcmod.arnicalib.mod.client.event; | ||
|
||
import org.auioc.mcmod.arnicalib.game.event.client.ClientPermissionsChangedEvent; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class AHClientEventFactory { | ||
|
||
private static final IEventBus BUS = MinecraftForge.EVENT_BUS; | ||
|
||
public static void onPermissionChanged(LocalPlayer player, int oldLevel, int newLevel) { | ||
BUS.post(new ClientPermissionsChangedEvent(player, oldLevel, newLevel)); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/auioc/mcmod/arnicalib/mod/mixin/client/MixinLocalPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.auioc.mcmod.arnicalib.mod.mixin.client; | ||
|
||
import org.auioc.mcmod.arnicalib.mod.client.event.AHClientEventFactory; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import net.minecraft.client.player.LocalPlayer; | ||
|
||
@Mixin(value = LocalPlayer.class) | ||
public class MixinLocalPlayer { | ||
|
||
@Shadow | ||
private int permissionLevel; | ||
|
||
@Inject( | ||
method = "Lnet/minecraft/client/player/LocalPlayer;setPermissionLevel(I)V", | ||
at = @At(value = "HEAD"), | ||
require = 1, | ||
allow = 1 | ||
) | ||
private void setPermissionLevel(int p_108649_, CallbackInfo ci) { | ||
AHClientEventFactory.onPermissionChanged(((LocalPlayer) (Object) this), this.permissionLevel, p_108649_); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters