Skip to content

Commit

Permalink
Fix packet handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyhedral committed Dec 9, 2024
1 parent a18b8e6 commit 862d082
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.client.event.MovementInputUpdateEvent;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.registries.ForgeRegistries;

public class ClientEventHandler {
Expand Down Expand Up @@ -142,7 +143,7 @@ private static void handlePopulateShoppingList() {
sMgr.addItem(player, f.getItemId(), needed);
});

PacketHandler.sendToServer(new AdvancementData(ModAdvancements.Key.POPULATE_LIST));
PacketHandler.send(PacketDistributor.SERVER.noArg(), new AdvancementData(ModAdvancements.Key.POPULATE_LIST));
}

private static void handleToggleShoppingList() {
Expand Down Expand Up @@ -187,7 +188,7 @@ private static void handleAddToQueue() {
CraftingQueueManager.INSTANCE.addProduct(player, res, 1);

// send advancement packet
PacketHandler.sendToServer(new AdvancementData(ModAdvancements.Key.QUEUE_ITEM));
PacketHandler.send(PacketDistributor.SERVER.noArg(), new AdvancementData(ModAdvancements.Key.QUEUE_ITEM));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.List;
Expand Down Expand Up @@ -182,7 +183,7 @@ public void renderToolTip(PoseStack pPoseStack, int pMouseX, int pMouseY) {
this.renderables.clear();

// send advancement packet
PacketHandler.sendToServer(new AdvancementData(ModAdvancements.Key.CLEAR_QUEUE));
PacketHandler.send(PacketDistributor.SERVER.noArg(), new AdvancementData(ModAdvancements.Key.CLEAR_QUEUE));
})
.pos(topX + (width / 2) - 50, topY + height - BUTTON_SIZE - 4)
.size(100, BUTTON_SIZE + 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Constants {

// Network
public static final ResourceLocation CHANNEL_NAME = Util.getResource("channel");
public static final Integer PROTOCOL_VERSION = 1;
public static final String PROTOCOL_VERSION = Integer.toString(1);

// Language
public static final String LOCALE_EN_US = "en_us";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ public static void init() {
registerPacket(new AdvancementPacket(), AdvancementData.class);
}

public static <MSG> void sendToServer(MSG message) {
CraftTracker.HANDLER.send(PacketDistributor.PLAYER.noArg(), message);
public static <MSG> void send(PacketDistributor.PacketTarget target, MSG message) {
CraftTracker.HANDLER.send(target, message);
}

// public static <MSG> void sendToServer(MSG message) {
// CraftTracker.HANDLER.send(PacketDistributor.PLAYER.noArg(), message);
// }

public static <MSG> void sendToPlayer(ServerPlayer player, MSG message) {
CraftTracker.HANDLER.send(PacketDistributor.PLAYER.with(() -> player), message);
}
Expand Down

0 comments on commit 862d082

Please sign in to comment.