forked from Noxcrew/noxesium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completely redo how plugin messages are used, switch to fabric packets
- Loading branch information
Showing
14 changed files
with
576 additions
and
107 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
33 changes: 33 additions & 0 deletions
33
api/src/main/java/com/noxcrew/noxesium/api/util/ByteUtil.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,33 @@ | ||
package com.noxcrew.noxesium.api.util; | ||
|
||
/** | ||
* Provides utilities for storing additional details in a single byte value. | ||
*/ | ||
public class ByteUtil { | ||
|
||
/** | ||
* Returns whether the flag at index in command is enabled. | ||
* | ||
* @param command A byte that contains multiple boolean values. | ||
* @param index The index in the byte to read out. | ||
*/ | ||
public static boolean hasFlag(byte command, int index) { | ||
return (command & (1 << index)) != 0; | ||
} | ||
|
||
/** | ||
* Returns an edited version of the command to have the value at | ||
* the given index set to value. | ||
* | ||
* @param command A byte that contains multiple boolean values. | ||
* @param index The index in the byte to write to. | ||
* @param value The new value to store in the byte. | ||
*/ | ||
public static byte setFlag(byte command, int index, boolean value) { | ||
if (value) { | ||
return (byte) (command | (1 << index)); | ||
} else { | ||
return (byte) (command & ~(1 << index)); | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPacket.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,25 @@ | ||
package com.noxcrew.noxesium.network; | ||
|
||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
|
||
/** | ||
* The basis for a fabric packet as used by Noxesium, these always contain | ||
* a version varint which allows different versions of the mod to communicate. | ||
*/ | ||
public abstract class NoxesiumPacket implements FabricPacket { | ||
|
||
/** The version of this packet. */ | ||
public final int version; | ||
|
||
/** | ||
* Creates a new Noxesium packet with the given version. | ||
* | ||
* @param version The version of this packet, this is always | ||
* the first varint of any Noxesium packet and | ||
* allows the contents of packets to change | ||
* over time without much issue. | ||
*/ | ||
public NoxesiumPacket(int version) { | ||
this.version = version; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPacketHandler.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,21 @@ | ||
package com.noxcrew.noxesium.network; | ||
|
||
import com.noxcrew.noxesium.network.clientbound.ClientboundNoxesiumPacket; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.FabricPacket; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.minecraft.client.player.LocalPlayer; | ||
|
||
/** | ||
* A simple packet handler used by Noxesium which defers the result of the packet | ||
* to the packet instance itself. | ||
*/ | ||
public class NoxesiumPacketHandler implements ClientPlayNetworking.PlayPacketHandler<FabricPacket> { | ||
|
||
@Override | ||
public void receive(FabricPacket packet, LocalPlayer player, PacketSender responseSender) { | ||
if (packet instanceof ClientboundNoxesiumPacket clientboundNoxesiumPacket) { | ||
clientboundNoxesiumPacket.receive(player, responseSender); | ||
} | ||
} | ||
} |
Oops, something went wrong.