Separate client and server networking related code

This commit is contained in:
Mrbysco 2024-10-18 19:35:50 +02:00
parent 844efe4260
commit 8fd9afe8d7
23 changed files with 170 additions and 128 deletions

View file

@ -21,7 +21,7 @@ import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
import de.ellpeck.actuallyadditions.mod.items.DrillItem; import de.ellpeck.actuallyadditions.mod.items.DrillItem;
import de.ellpeck.actuallyadditions.mod.items.ItemTag; import de.ellpeck.actuallyadditions.mod.items.ItemTag;
import de.ellpeck.actuallyadditions.mod.items.Sack; 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.sack.SackManager;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
@ -184,7 +184,8 @@ public class CommonEvents {
@SubscribeEvent @SubscribeEvent
public void onLogInEvent(PlayerEvent.PlayerLoggedInEvent event) { public void onLogInEvent(PlayerEvent.PlayerLoggedInEvent event) {
if (!event.getEntity().level().isClientSide && event.getEntity() instanceof ServerPlayer player) { 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() + "."); ActuallyAdditions.LOGGER.info("Sending Player Data to player " + player.getName() + " with UUID " + player.getUUID() + ".");
} }
} }

View file

@ -11,7 +11,7 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui; package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.CrusherContainer; 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.tile.TileEntityCrusher;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@ -62,7 +62,7 @@ public class CrusherScreen extends AAScreen<CrusherContainer> {
protected void actionPerformed(int id) { protected void actionPerformed(int id) {
if (this.isDouble && id == 0) { if (this.isDouble && id == 0) {
PacketHandlerHelper.sendButtonPacket(this.tileGrinder, id); PacketHelperClient.sendButtonPacket(this.tileGrinder, id);
} }
} }

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoffeeMachine; 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.tile.TileEntityCoffeeMachine;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -46,7 +46,7 @@ public class GuiCoffeeMachine extends AAScreen<ContainerCoffeeMachine> {
super.init(); super.init();
this.addRenderableWidget(new Button.Builder(Component.translatable("info.actuallyadditions.gui.ok"), 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()); .bounds(this.leftPos + 60, this.topPos + 11, 58, 20).build());
this.energy = new EnergyDisplay(this.leftPos + 16, this.topPos + 5, this.machine.storage); this.energy = new EnergyDisplay(this.leftPos + 16, this.topPos + 5, this.machine.storage);

View file

@ -11,7 +11,7 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui; package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFireworkBox; 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.tile.TileEntityFireworkBox;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
@ -45,20 +45,20 @@ public class GuiFireworkBox extends AbstractContainerScreen<ContainerFireworkBox
DecimalFormat intFormatter = new DecimalFormat("0"); DecimalFormat intFormatter = new DecimalFormat("0");
int left = this.getGuiLeft() + 2; int left = this.getGuiLeft() + 2;
this.addRenderableWidget(new CustomSlider(left, this.getGuiTop() + 2, Component.literal("Value Play"), 0F, 5F, this.tile.intValuePlay, intFormatter, (slider) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 0))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 1))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 2))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 3))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 4))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 5))); 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() + 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 7))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 8))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 9))); 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) -> PacketHandlerHelper.sendNumberPacket(this.tile, slider.getValue(), 10))); 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 @Override

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFurnaceDouble; 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.tile.TileEntityPoweredFurnace;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@ -54,7 +54,7 @@ public class GuiFurnaceDouble extends AAScreen<ContainerFurnaceDouble> {
public void init() { public void init() {
super.init(); super.init();
this.energy = new EnergyDisplay(this.leftPos + 27, this.topPos + 5, this.tileFurnace.storage); 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(); .bounds(this.getGuiLeft(), this.topPos + 5, 16, 16).build();
buttonAutoSplit.setFGColor(this.tileFurnace.isAutoSplit ? ChatFormatting.DARK_GREEN.getColor() : ChatFormatting.RED.getColor()); buttonAutoSplit.setFGColor(this.tileFurnace.isAutoSplit ? ChatFormatting.DARK_GREEN.getColor() : ChatFormatting.RED.getColor());
this.addRenderableWidget(this.buttonAutoSplit); this.addRenderableWidget(this.buttonAutoSplit);

View file

@ -12,9 +12,9 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerLaserRelayItemWhitelist; 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.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.tile.TileEntityLaserRelayItemAdvanced;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@ -71,14 +71,14 @@ public class GuiLaserRelayItemWhitelist extends AAScreen<ContainerLaserRelayItem
this.buttonSmartWhitelistLeft = this.addRenderableWidget(Button.builder( this.buttonSmartWhitelistLeft = this.addRenderableWidget(Button.builder(
Component.literal("S"), Component.literal("S"),
(button) -> { (button) -> {
PacketHandlerHelper.sendButtonPacket(this.tile, 2); PacketHelperClient.sendButtonPacket(this.tile, 2);
}).bounds(this.leftPos + 3, this.topPos + 79, 16, 16) }).bounds(this.leftPos + 3, this.topPos + 79, 16, 16)
.build()); .build());
this.buttonSmartWhitelistRight = this.addRenderableWidget(Button.builder( this.buttonSmartWhitelistRight = this.addRenderableWidget(Button.builder(
Component.literal("S"), Component.literal("S"),
(button) -> { (button) -> {
PacketHandlerHelper.sendButtonPacket(this.tile, 3); PacketHelperClient.sendButtonPacket(this.tile, 3);
}).bounds(this.leftPos + 157, this.topPos + 79, 16, 16) }).bounds(this.leftPos + 157, this.topPos + 79, 16, 16)
.build()); .build());
} }

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerMiner; 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.tile.TileEntityVerticalDigger;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
@ -40,10 +40,10 @@ public class GuiMiner extends AAScreen<ContainerMiner> {
super.init(); super.init();
this.addRenderableWidget(Button.builder(Component.literal("Mode"), $ -> { 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()); }).bounds(this.leftPos + this.imageWidth / 2 - 51, this.topPos + 75, 50, 20).build());
this.addRenderableWidget(Button.builder(Component.literal("Reset"), $ -> { 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()); }).bounds(this.leftPos + this.imageWidth / 2 + 1, this.topPos + 75, 50, 20).build());
} }
@Override @Override

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerPhantomPlacer; 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.tile.TileEntityPhantomPlacer;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@ -45,7 +45,7 @@ public class GuiPhantomPlacer extends AAScreen<ContainerPhantomPlacer> {
super.init(); super.init();
if (!this.placer.isBreaker) { 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(); .bounds(this.leftPos + 63, this.topPos + 75, 50, 20).build();
this.addRenderableWidget(buttonSide); this.addRenderableWidget(buttonSide);
} }

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerRangedCollector; 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.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityRangedCollector; import de.ellpeck.actuallyadditions.mod.tile.TileEntityRangedCollector;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;

View file

@ -13,7 +13,7 @@
// //
//import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; //import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
//import de.ellpeck.actuallyadditions.mod.inventory.ContainerSmileyCloud; //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.network.PacketHandler;
//import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; //import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
//import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud; //import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud;

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerXPSolidifier; 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.tile.TileEntityXPSolidifier;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
@ -39,39 +39,39 @@ public class GuiXPSolidifier extends AAScreen<ContainerXPSolidifier> {
super.init(); super.init();
Button buttonOne = this.addRenderableWidget(Button.builder(Component.literal("1"), btn -> { 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); this.solidifier.onButtonPressed(0, minecraft.player);
}).bounds(this.leftPos + 62, this.topPos + 44, 16, 16).build()); }).bounds(this.leftPos + 62, this.topPos + 44, 16, 16).build());
Button buttonFive = this.addRenderableWidget(Button.builder(Component.literal("5"), btn -> { 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); this.solidifier.onButtonPressed(1, minecraft.player);
}).bounds(this.leftPos + 80, this.topPos + 44, 16, 16).build()); }).bounds(this.leftPos + 80, this.topPos + 44, 16, 16).build());
Button buttonTen = this.addRenderableWidget(Button.builder(Component.literal("10"), btn -> { 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); this.solidifier.onButtonPressed(2, minecraft.player);
}).bounds(this.leftPos + 99, this.topPos + 44, 16, 16).build()); }).bounds(this.leftPos + 99, this.topPos + 44, 16, 16).build());
Button buttonTwenty = this.addRenderableWidget(Button.builder(Component.literal("20"), btn -> { 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); this.solidifier.onButtonPressed(3, minecraft.player);
}).bounds(this.leftPos + 62, this.topPos + 61, 16, 16).build()); }).bounds(this.leftPos + 62, this.topPos + 61, 16, 16).build());
Button buttonThirty = this.addRenderableWidget(Button.builder(Component.literal("30"), btn -> { 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); this.solidifier.onButtonPressed(4, minecraft.player);
}).bounds(this.leftPos + 80, this.topPos + 61, 16, 16).build()); }).bounds(this.leftPos + 80, this.topPos + 61, 16, 16).build());
Button buttonForty = this.addRenderableWidget(Button.builder(Component.literal("40"), btn -> { 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); this.solidifier.onButtonPressed(5, minecraft.player);
}).bounds(this.leftPos + 99, this.topPos + 61, 16, 16).build()); }).bounds(this.leftPos + 99, this.topPos + 61, 16, 16).build());
Button buttonFifty = this.addRenderableWidget(Button.builder(Component.literal("50"), btn -> { 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); this.solidifier.onButtonPressed(6, minecraft.player);
}).bounds(this.leftPos + 62, this.topPos + 78, 16, 16).build()); }).bounds(this.leftPos + 62, this.topPos + 78, 16, 16).build());
Button buttonSixtyFour = this.addRenderableWidget(Button.builder(Component.literal("64"), btn -> { 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); this.solidifier.onButtonPressed(7, minecraft.player);
}).bounds(this.leftPos + 80, this.topPos + 78, 16, 16).build()); }).bounds(this.leftPos + 80, this.topPos + 78, 16, 16).build());
Button buttonAll = this.addRenderableWidget(Button.builder(Component.literal("All"), btn -> { 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); this.solidifier.onButtonPressed(8, minecraft.player);
}).bounds(this.leftPos + 99, this.topPos + 78, 16, 16).build()); }).bounds(this.leftPos + 99, this.topPos + 78, 16, 16).build());
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.actuallyadditions.mod.inventory.gui; package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ItemTagContainer; 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 de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.SackContainer; 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.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;

View file

@ -12,7 +12,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.actuallyadditions.mod.inventory.VoidSackContainer; 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.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;

View file

@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; 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 de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -178,7 +178,7 @@ public class ItemWingsOfTheBats extends ItemBase {
} }
if (shouldSend) { if (shouldSend) {
PacketHandlerHelper.syncPlayerData(player, false); PacketHelperServer.syncPlayerData(player, false);
data.shouldDisableBatWings = false; //was set only temporarily to send it data.shouldDisableBatWings = false; //was set only temporarily to send it
} }
} else { } else {

View file

@ -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.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor; import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.IStringReactor; 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.BlockPos;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; 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.inventory.AbstractContainerMenu;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; 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.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.handling.IPayloadContext; import net.neoforged.neoforge.network.handling.IPayloadContext;
import net.neoforged.neoforge.network.registration.PayloadRegistrar; import net.neoforged.neoforge.network.registration.PayloadRegistrar;
@ -41,27 +42,33 @@ public final class PacketHandler {
public static final IDataHandler LASER_HANDLER = new IDataHandler() { public static final IDataHandler LASER_HANDLER = new IDataHandler() {
@Override @Override
public void handleData(CompoundTag compound, IPayloadContext context) { 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() { public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() {
@Override @Override
public void handleData(CompoundTag compound, IPayloadContext context) { public void handleData(CompoundTag compound, IPayloadContext context) {
if (FMLEnvironment.dist.isClient()) { ActuallyAdditions.LOGGER.info("Received tile entity update");
PacketHandlerClient.handleTileUpdate(compound, context); if(context.flow() == PacketFlow.CLIENTBOUND) {
PacketHelperClient.handleTileUpdate(compound, context);
} }
} }
}; };
public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() { public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() {
@Override @Override
public void handleData(CompoundTag compound, IPayloadContext context) { public void handleData(CompoundTag compound, IPayloadContext context) {
if (FMLEnvironment.dist.isClient()) { ActuallyAdditions.LOGGER.info("Received laser particle update");
PacketHandlerClient.handleLaserParticle(compound, context); if(context.flow() == PacketFlow.CLIENTBOUND) {
PacketHelperClient.handleLaserParticle(compound, context);
} }
} }
}; };
public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> { public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> {
if (context.player() != null) { if (context.player() != null) {
ActuallyAdditions.LOGGER.info("Received button press");
Player player = context.player(); Player player = context.player();
Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); 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"))); 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) -> { public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = (compound, context) -> {
if (context.player() != null) { if (context.player() != null) {
ActuallyAdditions.LOGGER.info("Received button press");
Player player = context.player(); Player player = context.player();
Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID"))));
Entity entity = level.getEntity(compound.getInt("PlayerID")); 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) -> { public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = (compound, context) -> {
if (context.player() != null) { if (context.player() != null) {
ActuallyAdditions.LOGGER.info("Received number update");
Player player = context.player(); Player player = context.player();
Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); 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"))); 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) -> { public static final IDataHandler GUI_STRING_TO_TILE_HANDLER = (compound, context) -> {
if (context.player() != null) { if (context.player() != null) {
ActuallyAdditions.LOGGER.info("Received string update");
Player player = context.player(); Player player = context.player();
Level level = player.getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("WorldID")))); 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"))); 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() { public static final IDataHandler SYNC_PLAYER_DATA = new IDataHandler() {
@Override @Override
public void handleData(CompoundTag compound, IPayloadContext context) { public void handleData(CompoundTag compound, IPayloadContext context) {
CompoundTag dataTag = compound.getCompound("Data"); ActuallyAdditions.LOGGER.info("Received player data");
Player player = context.player(); //ActuallyAdditions.PROXY.getCurrentPlayer(); if(context.flow() == PacketFlow.CLIENTBOUND) {
PacketHelperClient.handlePlayerUpdate(compound, context);
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 final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> { public static final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> {
if (context.player() != null) { 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")))); Level level = context.player().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(compound.getString("World"))));
Player player = level.getServer().getPlayerList().getPlayer(compound.getUUID("UUID")); Player player = level.getServer().getPlayerList().getPlayer(compound.getUUID("UUID"));
if (player != null) { if (player != null) {

View file

@ -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);
}
}

View file

@ -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 * It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at * under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense * 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.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; 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;
import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave; 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.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player; 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.minecraft.world.level.block.entity.BlockEntity;
import net.neoforged.neoforge.network.PacketDistributor; 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) { public static void sendButtonPacket(BlockEntity tile, int buttonId) {
CompoundTag compound = new CompoundTag(); CompoundTag compound = new CompoundTag();
BlockPos pos = tile.getBlockPos(); BlockPos pos = tile.getBlockPos();
@ -37,20 +87,6 @@ public final class PacketHandlerHelper {
PacketDistributor.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); 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) { public static void sendPlayerDataToServer(boolean log, int type) {
CompoundTag compound = new CompoundTag(); CompoundTag compound = new CompoundTag();
compound.putBoolean("Log", log); compound.putBoolean("Log", log);
@ -86,7 +122,7 @@ public final class PacketHandlerHelper {
} }
} }
public static void sendNumberPacket(BlockEntity tile, double number, int id) { public static void sendNumberPacket(BlockEntity tile, double number, int id) {
CompoundTag compound = new CompoundTag(); CompoundTag compound = new CompoundTag();
compound.putInt("X", tile.getBlockPos().getX()); compound.putInt("X", tile.getBlockPos().getX());

View file

@ -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));
}
}
}

View file

@ -8,9 +8,11 @@
* © 2015-2017 Ellpeck * © 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.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.IDataHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.codec.StreamCodec;

View file

@ -8,9 +8,11 @@
* © 2015-2017 Ellpeck * © 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.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.network.IDataHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.codec.StreamCodec;

View file

@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler; 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.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper; import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;

View file

@ -17,7 +17,7 @@ import com.mojang.math.Axis;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderTypes;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler; 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 de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;