-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.20.4 networking work, I still need to work on a bit, I don't unders…
…tand every change yet This commit mainly exists because I need to switch machines and for a 1.20.1 merge
- Loading branch information
Showing
9 changed files
with
87 additions
and
43 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
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
src/main/java/de/srendi/advancedperipherals/client/ClientNetworking.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 de.srendi.advancedperipherals.client; | ||
|
||
import dan200.computercraft.shared.network.NetworkMessage; | ||
import dan200.computercraft.shared.network.server.ServerNetworkContext; | ||
import de.srendi.advancedperipherals.network.base.IPacket; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientPacketListener; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.PacketListener; | ||
import net.minecraft.network.protocol.Packet; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class ClientNetworking { | ||
private ClientNetworking() { | ||
} | ||
|
||
public static void sendToServer(IPacket<?> message) { | ||
ClientPacketListener connection = Minecraft.getInstance().getConnection(); | ||
if (connection != null) { | ||
connection.send(new Packet<>() { | ||
@Override | ||
public void write(@NotNull FriendlyByteBuf pBuffer) { | ||
message.encode(pBuffer); | ||
} | ||
|
||
@Override | ||
public void handle(@NotNull PacketListener pHandler) { | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/de/srendi/advancedperipherals/client/KeyBindings.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
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
15 changes: 5 additions & 10 deletions
15
src/main/java/de/srendi/advancedperipherals/network/base/IPacket.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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
package de.srendi.advancedperipherals.network.base; | ||
|
||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.neoforged.network.NetworkEvent; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.neoforged.neoforge.network.handling.IPayloadContext; | ||
import net.neoforged.neoforge.network.handling.IPayloadHandler; | ||
|
||
import java.util.function.Supplier; | ||
public interface IPacket<T extends IPacket<?> & CustomPacketPayload> extends IPayloadHandler<T> { | ||
|
||
public interface IPacket { | ||
|
||
static <MSG extends IPacket> void handle(MSG message, Supplier<NetworkEvent.Context> context) { | ||
NetworkEvent.Context ctx = context.get(); | ||
ctx.enqueueWork(() -> message.handle(ctx)); | ||
ctx.setPacketHandled(true); | ||
static <MSG extends IPacket<?>> void handlePacket(MSG message) { | ||
} | ||
|
||
void handle(NetworkEvent.Context context); | ||
|
||
void encode(FriendlyByteBuf buffer); | ||
|
||
} |
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