From 8fd9afe8d7507328fb29a930cea5c910d8321e58 Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Fri, 18 Oct 2024 19:35:50 +0200 Subject: [PATCH] Separate client and server networking related code --- .../mod/event/CommonEvents.java | 5 +- .../mod/inventory/gui/CrusherScreen.java | 4 +- .../mod/inventory/gui/GuiCoffeeMachine.java | 4 +- .../mod/inventory/gui/GuiFireworkBox.java | 26 +++---- .../mod/inventory/gui/GuiFurnaceDouble.java | 4 +- .../gui/GuiLaserRelayItemWhitelist.java | 8 +- .../mod/inventory/gui/GuiMiner.java | 6 +- .../mod/inventory/gui/GuiPhantomPlacer.java | 4 +- .../mod/inventory/gui/GuiRangedCollector.java | 2 +- .../mod/inventory/gui/GuiSmileyCloud.java | 2 +- .../mod/inventory/gui/GuiXPSolidifier.java | 20 ++--- .../mod/inventory/gui/ItemTagScreen.java | 2 +- .../mod/inventory/gui/SackGui.java | 2 +- .../mod/inventory/gui/VoidSackGui.java | 2 +- .../mod/items/ItemWingsOfTheBats.java | 4 +- .../mod/network/PacketHandler.java | 40 +++++----- .../mod/network/PacketHandlerClient.java | 39 ---------- ...lerHelper.java => PacketHelperClient.java} | 74 ++++++++++++++----- .../mod/network/PacketHelperServer.java | 38 ++++++++++ .../{ => packet}/PacketClientToServer.java | 4 +- .../{ => packet}/PacketServerToClient.java | 4 +- .../mod/tile/TileEntityItemInterface.java | 2 +- .../actuallyadditions/mod/util/AssetUtil.java | 2 +- 23 files changed, 170 insertions(+), 128 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerClient.java rename src/main/java/de/ellpeck/actuallyadditions/mod/network/{PacketHandlerHelper.java => PacketHelperClient.java} (54%) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperServer.java rename src/main/java/de/ellpeck/actuallyadditions/mod/network/{ => packet}/PacketClientToServer.java (93%) rename src/main/java/de/ellpeck/actuallyadditions/mod/network/{ => packet}/PacketServerToClient.java (93%) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index 20386f4dc..b85688d6e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -21,7 +21,7 @@ import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.DrillItem; import de.ellpeck.actuallyadditions.mod.items.ItemTag; import de.ellpeck.actuallyadditions.mod.items.Sack; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperServer; import de.ellpeck.actuallyadditions.mod.sack.SackManager; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; @@ -184,7 +184,8 @@ public class CommonEvents { @SubscribeEvent public void onLogInEvent(PlayerEvent.PlayerLoggedInEvent event) { if (!event.getEntity().level().isClientSide && event.getEntity() instanceof ServerPlayer player) { - PacketHandlerHelper.syncPlayerData(player, true); + ActuallyAdditions.LOGGER.info("Player " + player.getName() + " with UUID " + player.getUUID() + " logged in."); + PacketHelperServer.syncPlayerData(player, true); ActuallyAdditions.LOGGER.info("Sending Player Data to player " + player.getName() + " with UUID " + player.getUUID() + "."); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java index 4ea96618b..8071e187c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/CrusherScreen.java @@ -11,7 +11,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.CrusherContainer; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCrusher; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; @@ -62,7 +62,7 @@ public class CrusherScreen extends AAScreen { protected void actionPerformed(int id) { if (this.isDouble && id == 0) { - PacketHandlerHelper.sendButtonPacket(this.tileGrinder, id); + PacketHelperClient.sendButtonPacket(this.tileGrinder, id); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java index 76e7092cf..333d70038 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoffeeMachine; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoffeeMachine; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.Minecraft; @@ -46,7 +46,7 @@ public class GuiCoffeeMachine extends AAScreen { super.init(); this.addRenderableWidget(new Button.Builder(Component.translatable("info.actuallyadditions.gui.ok"), - (b) -> PacketHandlerHelper.sendButtonPacket(this.machine, 0)) + (b) -> PacketHelperClient.sendButtonPacket(this.machine, 0)) .bounds(this.leftPos + 60, this.topPos + 11, 58, 20).build()); this.energy = new EnergyDisplay(this.leftPos + 16, this.topPos + 5, this.machine.storage); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java index 089c138a5..427e72317 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFireworkBox.java @@ -11,7 +11,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFireworkBox; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityFireworkBox; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.gui.GuiGraphics; @@ -45,20 +45,20 @@ public class GuiFireworkBox extends AbstractContainerScreen PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 0))); - this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 23, Component.literal("Average Charge Amount"), 1F, 4F, this.tile.chargeAmount, intFormatter, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 1))); - this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 44, Component.literal("Average Flight Time"), 1F, 3F, this.tile.flightTime, intFormatter, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 2))); - this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 65, Component.literal("Effect Chance"), 0F, 1F, this.tile.trailOrFlickerChance, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 3))); - this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 86, Component.literal("Flicker/Trail Ratio"), 0F, 1F, this.tile.flickerChance, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 4))); - this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 107, Component.literal("Color Amount"), 1, 6, this.tile.colorAmount, intFormatter, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 5))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 2, Component.literal("Value Play"), 0F, 5F, this.tile.intValuePlay, intFormatter, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 0))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 23, Component.literal("Average Charge Amount"), 1F, 4F, this.tile.chargeAmount, intFormatter, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 1))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 44, Component.literal("Average Flight Time"), 1F, 3F, this.tile.flightTime, intFormatter, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 2))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 65, Component.literal("Effect Chance"), 0F, 1F, this.tile.trailOrFlickerChance, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 3))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 86, Component.literal("Flicker/Trail Ratio"), 0F, 1F, this.tile.flickerChance, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 4))); + this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 107, Component.literal("Color Amount"), 1, 6, this.tile.colorAmount, intFormatter, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 5))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 2, Component.literal("Small Ball"), 0F, 1F, this.tile.typeChance0, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 6))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 23, Component.literal("Large Ball"), 0F, 1F, this.tile.typeChance1, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 7))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 44, Component.literal("Star Shape"), 0F, 1F, this.tile.typeChance2, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 8))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 65, Component.literal("Creeper Shape"), 0F, 1F, this.tile.typeChance3, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 9))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 86, Component.literal("Burst"), 0F, 1F, this.tile.typeChance4, null, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 10))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 2, Component.literal("Small Ball"), 0F, 1F, this.tile.typeChance0, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 6))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 23, Component.literal("Large Ball"), 0F, 1F, this.tile.typeChance1, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 7))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 44, Component.literal("Star Shape"), 0F, 1F, this.tile.typeChance2, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 8))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 65, Component.literal("Creeper Shape"), 0F, 1F, this.tile.typeChance3, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 9))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 86, Component.literal("Burst"), 0F, 1F, this.tile.typeChance4, null, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 10))); - this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 107, Component.literal("Area of Effect"), 0, 4, this.tile.areaOfEffect, intFormatter, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 11))); + this.addRenderableWidget(new CustomSlider(left + 150, this.getGuiTop() + 107, Component.literal("Area of Effect"), 0, 4, this.tile.areaOfEffect, intFormatter, (slider) -> PacketHelperClient.sendNumberPacket(this.tile, slider.getValue(), 11))); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java index a8d6538c2..ef4343bc5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFurnaceDouble.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFurnaceDouble; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPoweredFurnace; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; @@ -54,7 +54,7 @@ public class GuiFurnaceDouble extends AAScreen { public void init() { super.init(); this.energy = new EnergyDisplay(this.leftPos + 27, this.topPos + 5, this.tileFurnace.storage); - this.buttonAutoSplit = Button.builder(Component.literal("S"), (button) -> PacketHandlerHelper.sendButtonPacket(this.tileFurnace, 0)) + this.buttonAutoSplit = Button.builder(Component.literal("S"), (button) -> PacketHelperClient.sendButtonPacket(this.tileFurnace, 0)) .bounds(this.getGuiLeft(), this.topPos + 5, 16, 16).build(); buttonAutoSplit.setFGColor(this.tileFurnace.isAutoSplit ? ChatFormatting.DARK_GREEN.getColor() : ChatFormatting.RED.getColor()); this.addRenderableWidget(this.buttonAutoSplit); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java index 72ffcad39..19d73b25e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java @@ -12,9 +12,9 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerLaserRelayItemWhitelist; -import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemAdvanced; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; @@ -71,14 +71,14 @@ public class GuiLaserRelayItemWhitelist extends AAScreen { - PacketHandlerHelper.sendButtonPacket(this.tile, 2); + PacketHelperClient.sendButtonPacket(this.tile, 2); }).bounds(this.leftPos + 3, this.topPos + 79, 16, 16) .build()); this.buttonSmartWhitelistRight = this.addRenderableWidget(Button.builder( Component.literal("S"), (button) -> { - PacketHandlerHelper.sendButtonPacket(this.tile, 3); + PacketHelperClient.sendButtonPacket(this.tile, 3); }).bounds(this.leftPos + 157, this.topPos + 79, 16, 16) .build()); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java index 5d876876a..a077eebbd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerMiner; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityVerticalDigger; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.gui.GuiGraphics; @@ -40,10 +40,10 @@ public class GuiMiner extends AAScreen { super.init(); this.addRenderableWidget(Button.builder(Component.literal("Mode"), $ -> { - PacketHandlerHelper.sendButtonPacket(this.miner, 0); + PacketHelperClient.sendButtonPacket(this.miner, 0); }).bounds(this.leftPos + this.imageWidth / 2 - 51, this.topPos + 75, 50, 20).build()); this.addRenderableWidget(Button.builder(Component.literal("Reset"), $ -> { - PacketHandlerHelper.sendButtonPacket(this.miner, 1); + PacketHelperClient.sendButtonPacket(this.miner, 1); }).bounds(this.leftPos + this.imageWidth / 2 + 1, this.topPos + 75, 50, 20).build()); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java index 8ae412812..92afa5d23 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerPhantomPlacer; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomPlacer; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; @@ -45,7 +45,7 @@ public class GuiPhantomPlacer extends AAScreen { super.init(); if (!this.placer.isBreaker) { - buttonSide = Button.builder(Component.literal(this.getSide()), (button) -> PacketHandlerHelper.sendButtonPacket(this.placer, 0)) + buttonSide = Button.builder(Component.literal(this.getSide()), (button) -> PacketHelperClient.sendButtonPacket(this.placer, 0)) .bounds(this.leftPos + 63, this.topPos + 75, 50, 20).build(); this.addRenderableWidget(buttonSide); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java index 51a6ed2f1..fd3d693ca 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerRangedCollector; -import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.tile.TileEntityRangedCollector; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java index 4ac85d3d2..055c973f4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiSmileyCloud.java @@ -13,7 +13,7 @@ // //import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; //import de.ellpeck.actuallyadditions.mod.inventory.ContainerSmileyCloud; -//import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +//import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; //import de.ellpeck.actuallyadditions.mod.network.PacketHandler; //import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; //import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java index e025bee0d..746b77d5c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.ContainerXPSolidifier; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityXPSolidifier; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.gui.GuiGraphics; @@ -39,39 +39,39 @@ public class GuiXPSolidifier extends AAScreen { super.init(); Button buttonOne = this.addRenderableWidget(Button.builder(Component.literal("1"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 0); + PacketHelperClient.sendButtonPacket(this.solidifier, 0); this.solidifier.onButtonPressed(0, minecraft.player); }).bounds(this.leftPos + 62, this.topPos + 44, 16, 16).build()); Button buttonFive = this.addRenderableWidget(Button.builder(Component.literal("5"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 1); + PacketHelperClient.sendButtonPacket(this.solidifier, 1); this.solidifier.onButtonPressed(1, minecraft.player); }).bounds(this.leftPos + 80, this.topPos + 44, 16, 16).build()); Button buttonTen = this.addRenderableWidget(Button.builder(Component.literal("10"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 2); + PacketHelperClient.sendButtonPacket(this.solidifier, 2); this.solidifier.onButtonPressed(2, minecraft.player); }).bounds(this.leftPos + 99, this.topPos + 44, 16, 16).build()); Button buttonTwenty = this.addRenderableWidget(Button.builder(Component.literal("20"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 3); + PacketHelperClient.sendButtonPacket(this.solidifier, 3); this.solidifier.onButtonPressed(3, minecraft.player); }).bounds(this.leftPos + 62, this.topPos + 61, 16, 16).build()); Button buttonThirty = this.addRenderableWidget(Button.builder(Component.literal("30"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 4); + PacketHelperClient.sendButtonPacket(this.solidifier, 4); this.solidifier.onButtonPressed(4, minecraft.player); }).bounds(this.leftPos + 80, this.topPos + 61, 16, 16).build()); Button buttonForty = this.addRenderableWidget(Button.builder(Component.literal("40"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 5); + PacketHelperClient.sendButtonPacket(this.solidifier, 5); this.solidifier.onButtonPressed(5, minecraft.player); }).bounds(this.leftPos + 99, this.topPos + 61, 16, 16).build()); Button buttonFifty = this.addRenderableWidget(Button.builder(Component.literal("50"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 6); + PacketHelperClient.sendButtonPacket(this.solidifier, 6); this.solidifier.onButtonPressed(6, minecraft.player); }).bounds(this.leftPos + 62, this.topPos + 78, 16, 16).build()); Button buttonSixtyFour = this.addRenderableWidget(Button.builder(Component.literal("64"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 7); + PacketHelperClient.sendButtonPacket(this.solidifier, 7); this.solidifier.onButtonPressed(7, minecraft.player); }).bounds(this.leftPos + 80, this.topPos + 78, 16, 16).build()); Button buttonAll = this.addRenderableWidget(Button.builder(Component.literal("All"), btn -> { - PacketHandlerHelper.sendButtonPacket(this.solidifier, 8); + PacketHelperClient.sendButtonPacket(this.solidifier, 8); this.solidifier.onButtonPressed(8, minecraft.player); }).bounds(this.leftPos + 99, this.topPos + 78, 16, 16).build()); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/ItemTagScreen.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/ItemTagScreen.java index 024c8838f..82d00175c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/ItemTagScreen.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/ItemTagScreen.java @@ -1,7 +1,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ItemTagContainer; -import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java index 9f0910918..81fe76093 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.SackContainer; -import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java index 70192a74e..54c091f57 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java @@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import com.mojang.blaze3d.systems.RenderSystem; import de.ellpeck.actuallyadditions.mod.inventory.VoidSackContainer; -import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.ChatFormatting; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java index 47dcd99cf..cfbdf47b9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java @@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; -import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; +import de.ellpeck.actuallyadditions.mod.network.PacketHelperServer; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -178,7 +178,7 @@ public class ItemWingsOfTheBats extends ItemBase { } if (shouldSend) { - PacketHandlerHelper.syncPlayerData(player, false); + PacketHelperServer.syncPlayerData(player, false); data.shouldDisableBatWings = false; //was set only temporarily to send it } } else { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 4c2553be3..2cfd89167 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -16,10 +16,12 @@ import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IStringReactor; -import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketServerToClient; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.PacketFlow; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; @@ -27,7 +29,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; -import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.handling.IPayloadContext; import net.neoforged.neoforge.network.registration.PayloadRegistrar; @@ -41,27 +42,33 @@ public final class PacketHandler { public static final IDataHandler LASER_HANDLER = new IDataHandler() { @Override public void handleData(CompoundTag compound, IPayloadContext context) { - AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), compound.getInt("Color"), compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha")); + ActuallyAdditions.LOGGER.info("Received laser update"); + if(context.flow() == PacketFlow.CLIENTBOUND) { + PacketHelperClient.handleLaser(compound, context); + } } }; public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() { @Override public void handleData(CompoundTag compound, IPayloadContext context) { - if (FMLEnvironment.dist.isClient()) { - PacketHandlerClient.handleTileUpdate(compound, context); + ActuallyAdditions.LOGGER.info("Received tile entity update"); + if(context.flow() == PacketFlow.CLIENTBOUND) { + PacketHelperClient.handleTileUpdate(compound, context); } } }; public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() { @Override public void handleData(CompoundTag compound, IPayloadContext context) { - if (FMLEnvironment.dist.isClient()) { - PacketHandlerClient.handleLaserParticle(compound, context); + ActuallyAdditions.LOGGER.info("Received laser particle update"); + if(context.flow() == PacketFlow.CLIENTBOUND) { + PacketHelperClient.handleLaserParticle(compound, context); } } }; public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> { if (context.player() != null) { + ActuallyAdditions.LOGGER.info("Received button press"); Player player = context.player(); Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); @@ -76,6 +83,7 @@ public final class PacketHandler { }; public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = (compound, context) -> { if (context.player() != null) { + ActuallyAdditions.LOGGER.info("Received button press"); Player player = context.player(); Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); Entity entity = level.getEntity(compound.getInt("PlayerID")); @@ -89,6 +97,7 @@ public final class PacketHandler { }; public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = (compound, context) -> { if (context.player() != null) { + ActuallyAdditions.LOGGER.info("Received number update"); Player player = context.player(); Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); @@ -100,6 +109,7 @@ public final class PacketHandler { }; public static final IDataHandler GUI_STRING_TO_TILE_HANDLER = (compound, context) -> { if (context.player() != null) { + ActuallyAdditions.LOGGER.info("Received string update"); Player player = context.player(); Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); BlockEntity tile = level.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); @@ -111,24 +121,16 @@ public final class PacketHandler { }; public static final IDataHandler SYNC_PLAYER_DATA = new IDataHandler() { @Override - public void handleData(CompoundTag compound, IPayloadContext context) { - CompoundTag dataTag = compound.getCompound("Data"); - Player player = context.player(); //ActuallyAdditions.PROXY.getCurrentPlayer(); - - if (player != null) { - PlayerData.getDataFromPlayer(player).readFromNBT(dataTag, false); - - if (compound.getBoolean("Log")) { - ActuallyAdditions.LOGGER.info("Receiving (new or changed) Player Data for player " + player.getName() + "."); - } - } else { - ActuallyAdditions.LOGGER.error("Tried to receive Player Data for the current player, but he doesn't seem to be present!"); + ActuallyAdditions.LOGGER.info("Received player data"); + if(context.flow() == PacketFlow.CLIENTBOUND) { + PacketHelperClient.handlePlayerUpdate(compound, context); } } }; public static final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> { if (context.player() != null) { + ActuallyAdditions.LOGGER.info("Received player data Server"); Level level = context.player().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("World")))); Player player = level.getServer().getPlayerList().getPlayer(compound.getUUID("UUID")); if (player != null) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerClient.java deleted file mode 100644 index 4a2a932d7..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerClient.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.ellpeck.actuallyadditions.mod.network; - -import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; -import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.neoforged.neoforge.network.handling.IPayloadContext; - -public final class PacketHandlerClient { - public static void handleTileUpdate(CompoundTag compound, IPayloadContext context) { - Level world = Minecraft.getInstance().level; - if (world != null) { - BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); - if (tile instanceof TileEntityBase tileBase) { - tileBase.readSyncableNBT(compound.getCompound("Data"), world.registryAccess(), TileEntityBase.NBTType.SYNC); - } - } - } - - public static void handleLaserParticle(CompoundTag compound, IPayloadContext context) { - Minecraft mc = Minecraft.getInstance(); - ItemStack stack = ItemStack.parseOptional(context.player().registryAccess(), compound); - - double inX = compound.getDouble("InX") + 0.5; - double inY = compound.getDouble("InY") + 0.78; - double inZ = compound.getDouble("InZ") + 0.5; - - double outX = compound.getDouble("OutX") + 0.5; - double outY = compound.getDouble("OutY") + 0.525; - double outZ = compound.getDouble("OutZ") + 0.5; - - mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, inX, inY, inZ), - outX, outY, outZ, 0, 0.025, 0); - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java similarity index 54% rename from src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java rename to src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java index 9d0e3e5bb..a6c4d31df 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperClient.java @@ -1,5 +1,5 @@ /* - * This file ("PacketHandlerHelper.java") is part of the Actually Additions mod for Minecraft. + * This file ("PacketHelperClient.java") is part of the Actually Additions mod for Minecraft. * It is created and owned by Ellpeck and distributed * under the Actually Additions License to be found at * http://ellpeck.de/actaddlicense @@ -12,19 +12,69 @@ package de.ellpeck.actuallyadditions.mod.network; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.neoforge.network.PacketDistributor; +import net.neoforged.neoforge.network.handling.IPayloadContext; -public final class PacketHandlerHelper { +public final class PacketHelperClient { + public static void handleLaser(CompoundTag compound, IPayloadContext context) { + AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), compound.getInt("Color"), compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha")); + } + + public static void handleTileUpdate(CompoundTag compound, IPayloadContext context) { + Level world = Minecraft.getInstance().level; + if (world != null) { + BlockEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z"))); + if (tile instanceof TileEntityBase tileBase) { + tileBase.readSyncableNBT(compound.getCompound("Data"), world.registryAccess(), TileEntityBase.NBTType.SYNC); + } + } + } + + public static void handleLaserParticle(CompoundTag compound, IPayloadContext context) { + Minecraft mc = Minecraft.getInstance(); + ItemStack stack = ItemStack.parseOptional(context.player().registryAccess(), compound); + + double inX = compound.getDouble("InX") + 0.5; + double inY = compound.getDouble("InY") + 0.78; + double inZ = compound.getDouble("InZ") + 0.5; + + double outX = compound.getDouble("OutX") + 0.5; + double outY = compound.getDouble("OutY") + 0.525; + double outZ = compound.getDouble("OutZ") + 0.5; + + mc.level.addParticle(ParticleLaserItem.Factory.createData(stack, inX, inY, inZ), + outX, outY, outZ, 0, 0.025, 0); + } + + public static void handlePlayerUpdate(CompoundTag compound, IPayloadContext context) { + CompoundTag dataTag = compound.getCompound("Data"); + Player player = context.player(); //ActuallyAdditions.PROXY.getCurrentPlayer(); + + if (player != null) { + PlayerData.getDataFromPlayer(player).readFromNBT(dataTag, false); + + if (compound.getBoolean("Log")) { + ActuallyAdditions.LOGGER.info("Receiving (new or changed) Player Data for player " + player.getName() + "."); + } + } else { + ActuallyAdditions.LOGGER.error("Tried to receive Player Data for the current player, but he doesn't seem to be present!"); + } + } - public static void sendButtonPacket(BlockEntity tile, int buttonId) { CompoundTag compound = new CompoundTag(); BlockPos pos = tile.getBlockPos(); @@ -37,20 +87,6 @@ public final class PacketHandlerHelper { PacketDistributor.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); } - public static void syncPlayerData(Player player, boolean log) { - CompoundTag compound = new CompoundTag(); - compound.putBoolean("Log", log); - - CompoundTag data = new CompoundTag(); - PlayerData.getDataFromPlayer(player).writeToNBT(data, false); - compound.put("Data", data); - - if (player instanceof ServerPlayer) { - ((ServerPlayer) player).connection.send(new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA)); - } - } - - public static void sendPlayerDataToServer(boolean log, int type) { CompoundTag compound = new CompoundTag(); compound.putBoolean("Log", log); @@ -86,7 +122,7 @@ public final class PacketHandlerHelper { } } - + public static void sendNumberPacket(BlockEntity tile, double number, int id) { CompoundTag compound = new CompoundTag(); compound.putInt("X", tile.getBlockPos().getX()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperServer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperServer.java new file mode 100644 index 000000000..97952b426 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHelperServer.java @@ -0,0 +1,38 @@ +/* + * This file ("PacketHandlerHelper.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.network; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.data.PlayerData; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketServerToClient; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; + +/** + * A helper class for sending packets from the server to the client. + */ +public final class PacketHelperServer { + + public static void syncPlayerData(Player player, boolean log) { + CompoundTag compound = new CompoundTag(); + compound.putBoolean("Log", log); + + CompoundTag data = new CompoundTag(); + PlayerData.getDataFromPlayer(player).writeToNBT(data, false); + compound.put("Data", data); + ActuallyAdditions.LOGGER.info("Sending data {}", data); + + if (player instanceof ServerPlayer serverPlayer) { + serverPlayer.connection.send(new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA)); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketClientToServer.java similarity index 93% rename from src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java rename to src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketClientToServer.java index e9c391391..48ac430e2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketClientToServer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketClientToServer.java @@ -8,9 +8,11 @@ * © 2015-2017 Ellpeck */ -package de.ellpeck.actuallyadditions.mod.network; +package de.ellpeck.actuallyadditions.mod.network.packet; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.network.IDataHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketServerToClient.java similarity index 93% rename from src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java rename to src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketServerToClient.java index 583a39fbb..e4245432a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketServerToClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/PacketServerToClient.java @@ -8,9 +8,11 @@ * © 2015-2017 Ellpeck */ -package de.ellpeck.actuallyadditions.mod.network; +package de.ellpeck.actuallyadditions.mod.network.packet; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.network.IDataHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java index b98862eaa..aab270930 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterface.java @@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; -import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index 91b70ae72..67bd26d9b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -17,7 +17,7 @@ import com.mojang.math.Axis; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; -import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; +import de.ellpeck.actuallyadditions.mod.network.packet.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft;