-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Common-Networking by Mysticdrew
Various other changes and fixes
- Loading branch information
1 parent
2c06ce5
commit 0c2ed5b
Showing
22 changed files
with
147 additions
and
131 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
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,17 +1,25 @@ | ||
package com.girafi.ping; | ||
|
||
import com.girafi.ping.network.packet.ClientSendPing; | ||
import com.girafi.ping.network.packet.ServerBroadcastPing; | ||
import com.girafi.ping.util.TempConfig; | ||
import commonnetwork.api.Network; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class PingCommon { | ||
private static TempConfig config; | ||
|
||
public static void setConfigFolder (Path configPath) { | ||
public static void loadCommon(Path configPath) { | ||
config = TempConfig.load(configPath.resolve(Constants.MOD_ID + ".json").toFile()); | ||
|
||
|
||
Network.registerPacket(ClientSendPing.CHANNEL, ClientSendPing.class, ClientSendPing::encode, ClientSendPing::decode, ClientSendPing::handle) | ||
.registerPacket(ServerBroadcastPing.CHANNEL, ServerBroadcastPing.class, ServerBroadcastPing::encode, ServerBroadcastPing::decode, ServerBroadcastPing::handle); | ||
} | ||
|
||
public static TempConfig config() { | ||
return config; | ||
} | ||
|
||
} |
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
32 changes: 26 additions & 6 deletions
32
common/src/main/java/com/girafi/ping/network/packet/ClientSendPing.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,27 +1,47 @@ | ||
package com.girafi.ping.network.packet; | ||
|
||
import com.girafi.ping.Constants; | ||
import com.girafi.ping.data.PingWrapper; | ||
import commonnetwork.api.Dispatcher; | ||
import commonnetwork.networking.data.PacketContext; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
/** | ||
* Sent from the Client, handled on the Server | ||
*/ | ||
public class ClientSendPing { | ||
private final PingWrapper ping; | ||
public static final ResourceLocation CHANNEL = new ResourceLocation(Constants.MOD_ID, "client_send_ping"); | ||
private PingWrapper ping; | ||
|
||
public ClientSendPing() {} | ||
|
||
public ClientSendPing(PingWrapper ping) { | ||
this.ping = ping; | ||
} | ||
|
||
public PingWrapper getPing() { | ||
return ping; | ||
} | ||
|
||
public static void encode(ClientSendPing pingPacket, FriendlyByteBuf buf) { | ||
pingPacket.ping.writeToBuffer(buf); | ||
} | ||
|
||
public static ClientSendPing receive(FriendlyByteBuf buf) { | ||
public static ClientSendPing decode(FriendlyByteBuf buf) { | ||
return new ClientSendPing(PingWrapper.readFromBuffer(buf)); | ||
} | ||
|
||
public PingWrapper getPing() { | ||
return ping; | ||
} | ||
|
||
public static void handle(PacketContext<ClientSendPing> ctx) { | ||
ServerPlayer playerMP = ctx.sender(); | ||
if (playerMP != null) { | ||
for (Player player : playerMP.level().players()) { | ||
if (player instanceof ServerPlayer) { | ||
Dispatcher.sendToServer(new ServerBroadcastPing(ctx.message().getPing())); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
4 changes: 0 additions & 4 deletions
4
...java/com/girafi/ping/util/PingSounds.java → ...java/com/girafi/ping/util/PingSounds.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
4 changes: 1 addition & 3 deletions
4
...rc/main/java/com/girafi/ping/Waddles.java → ...c/src/main/java/com/girafi/ping/Ping.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
Oops, something went wrong.