-
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
0cecfbb
commit a89b063
Showing
15 changed files
with
578 additions
and
96 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,19 +1,42 @@ | ||
package kasuga.lib.core.network; | ||
|
||
import kasuga.lib.core.annos.Inner; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraftforge.network.NetworkDirection; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
/** | ||
* This packet should be sent by logical client and received by logical server. | ||
* It is used for your custom packets that transmit custom data from client to server. | ||
* To register one of this, see {@link kasuga.lib.registrations.common.ChannelReg} | ||
*/ | ||
public abstract class C2SPacket extends Packet { | ||
public C2SPacket() {super();} | ||
public C2SPacket(FriendlyByteBuf buf) {} | ||
|
||
/** | ||
* This function is the deserializer of your packet. | ||
* See {@link Packet} for more constructor info. | ||
* @param buf data bytes you got from the network. | ||
*/ | ||
public C2SPacket(FriendlyByteBuf buf) {super(buf);} | ||
|
||
@Inner | ||
public boolean onReach(NetworkEvent.Context context) { | ||
context.enqueueWork(() -> handle(context)); | ||
return true; | ||
} | ||
|
||
/** | ||
* The handler of your packet. After this packet has been received by | ||
* logical server, we would handle this packet in this method. | ||
* @param context some server info, such level, player and so on. | ||
*/ | ||
public abstract void handle(NetworkEvent.Context context); | ||
|
||
/** | ||
* The encoder of your packet. You must put all your data into this | ||
* byte buffer in order to transmit them. | ||
* @param buf the data container buffer, push your data into it. | ||
*/ | ||
abstract public void encode(FriendlyByteBuf buf); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
package kasuga.lib.core.network; | ||
|
||
import kasuga.lib.core.annos.Inner; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
/** | ||
* This packet should be sent by logical server and received by logical client. | ||
* It is used for your custom packets that transmit custom data from server to client. | ||
* To register one of this, see {@link kasuga.lib.registrations.common.ChannelReg} | ||
*/ | ||
public abstract class S2CPacket extends Packet { | ||
|
||
public S2CPacket() {super();} | ||
/** | ||
* The decoder constructor of your packet. Take all your data out from the byte buffer here. | ||
* @param buf the received byte buffer. | ||
*/ | ||
public S2CPacket(FriendlyByteBuf buf) {super(buf);} | ||
@Override | ||
@Inner | ||
public boolean onReach(NetworkEvent.Context context) { | ||
context.enqueueWork(() -> handle(Minecraft.getInstance())); | ||
return true; | ||
} | ||
|
||
/** | ||
* The handler of your packet, the packet would be handled here. | ||
* @param minecraft Your minecraft client. | ||
*/ | ||
public abstract void handle(Minecraft minecraft); | ||
|
||
/** | ||
* Push your data into the byte buffer here. | ||
* @param buf the data container buffer, push your data into it. | ||
*/ | ||
public abstract void encode(FriendlyByteBuf buf); | ||
} |
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
Oops, something went wrong.