generated from JamCoreModding/template-mod
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7be2adc
commit 78d0d36
Showing
11 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
- (feat) config options with long names will now render in the screen as scrolling strings. | ||
- (chore) various code cleanups | ||
- (chore) use parchment mappings | ||
- Add `ClientPlayLifecycleEvents`. |
36 changes: 36 additions & 0 deletions
36
...on/src/main/java/io/github/jamalam360/jamlib/events/client/ClientPlayLifecycleEvents.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,36 @@ | ||
package io.github.jamalam360.jamlib.events.client; | ||
|
||
import com.mojang.authlib.minecraft.client.MinecraftClient; | ||
import dev.architectury.event.Event; | ||
import dev.architectury.event.EventFactory; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
/** | ||
* Events for client-side player lifecycle events. | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public class ClientPlayLifecycleEvents { | ||
/** | ||
* Called when the local player has joined a logical server. | ||
*/ | ||
public static final Event<Join> JOIN = EventFactory.createLoop(Join.class); | ||
/** | ||
* Called when the local player leaves a logical server. | ||
*/ | ||
public static final Event<Leave> DISCONNECT = EventFactory.createLoop(Leave.class); | ||
|
||
@Environment(EnvType.CLIENT) | ||
@FunctionalInterface | ||
public interface Join { | ||
void onJoin(Minecraft client); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
@FunctionalInterface | ||
public interface Leave { | ||
void onLeave(Minecraft client); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/io/github/jamalam360/jamlib/mixin/event/ClientPacketListenerMixin.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 io.github.jamalam360.jamlib.mixin.event; | ||
|
||
import io.github.jamalam360.jamlib.events.client.ClientPlayLifecycleEvents; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientPacketListener; | ||
import net.minecraft.network.protocol.game.ClientboundLoginPacket; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ClientPacketListener.class) | ||
@Environment(EnvType.CLIENT) | ||
public class ClientPacketListenerMixin { | ||
/** | ||
* Injection point taken from Fabric API - <a href="https://github.com/FabricMC/fabric/blob/1.21.2/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/mixin/networking/client/ClientPlayNetworkHandlerMixin.java#L54">...</a> | ||
*/ | ||
@Inject( | ||
method = "handleLogin", | ||
at = @At("RETURN") | ||
) | ||
private void jamlib$joinServer(ClientboundLoginPacket packet, CallbackInfo ci) { | ||
ClientPlayLifecycleEvents.JOIN.invoker().onJoin(Minecraft.getInstance()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
common/src/main/java/io/github/jamalam360/jamlib/mixin/event/ConnectionMixin.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,35 @@ | ||
package io.github.jamalam360.jamlib.mixin.event; | ||
|
||
import io.github.jamalam360.jamlib.events.client.ClientPlayLifecycleEvents; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.Connection; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Connection.class) | ||
@Environment(EnvType.CLIENT) | ||
public class ConnectionMixin { | ||
@Inject( | ||
method = "channelInactive", | ||
at = @At("HEAD") | ||
) | ||
private void jamlib$callDisconnectEvent(ChannelHandlerContext channelHandlerContext, CallbackInfo ci) { | ||
ClientPlayLifecycleEvents.DISCONNECT.invoker().onLeave(Minecraft.getInstance()); | ||
} | ||
|
||
@Inject( | ||
method = "handleDisconnection", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/network/PacketListener;onDisconnect(Lnet/minecraft/network/DisconnectionDetails;)V" | ||
) | ||
) | ||
private void jamlib$callDisconnectEvent(CallbackInfo ci) { | ||
ClientPlayLifecycleEvents.DISCONNECT.invoker().onLeave(Minecraft.getInstance()); | ||
} | ||
} |
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,17 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "io.github.jamalam360.jamlib.mixin", | ||
"compatibilityLevel": "JAVA_17", | ||
"mixins": [ | ||
], | ||
"client": [ | ||
"event.ClientPacketListenerMixin", | ||
"event.ConnectionMixin" | ||
], | ||
"server": [ | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
] | ||
}, | ||
"mixins": [ | ||
"jamlib.mixins.json" | ||
], | ||
"depends": { | ||
"fabric": ">=${fabric_api_version}", | ||
|
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
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
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
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
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