diff options
Diffstat (limited to 'GuiTest/src/main/java/io')
-rw-r--r-- | GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java b/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java index b3e0c80..e0602be 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java @@ -1,14 +1,19 @@ package io.github.cottonmc.test; import io.github.cottonmc.cotton.gui.SyncedGuiDescription; +import io.github.cottonmc.cotton.gui.networking.NetworkSide; +import io.github.cottonmc.cotton.gui.networking.ScreenNetworking; import io.github.cottonmc.cotton.gui.widget.*; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.text.LiteralText; +import net.minecraft.util.Identifier; public class TestDescription extends SyncedGuiDescription { - + private static final Identifier TEST_MESSAGE = new Identifier("libgui", "test"); + private static final Identifier UNREGISTERED_ON_SERVER = new Identifier("libgui", "unregistered_on_server"); + public TestDescription(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) { super(type, syncId, playerInventory, getBlockInventory(context, GuiBlockEntity.INVENTORY_SIZE), null); @@ -16,7 +21,14 @@ public class TestDescription extends SyncedGuiDescription { root.add(WItemSlot.of(blockInventory, 0, 4, 1), 0, 1); - root.add(new WButton(new LiteralText("Button A")), 0, 3, 4, 1); + WButton buttonA = new WButton(new LiteralText("Button A")); + + buttonA.setOnClick(() -> { + ScreenNetworking.of(this, NetworkSide.CLIENT).send(TEST_MESSAGE, buf -> {}); + ScreenNetworking.of(this, NetworkSide.CLIENT).send(UNREGISTERED_ON_SERVER, buf -> {}); + }); + + root.add(buttonA, 0, 3, 4, 1); root.add(new WButton(new LiteralText("Button B")), 5, 3, 4, 1); root.add(new WButton(new LiteralText("Button C")), 0, 5, 4, 1); root.add(new WButton(new LiteralText("Button D")), 5, 5, 4, 1); @@ -29,5 +41,9 @@ public class TestDescription extends SyncedGuiDescription { System.out.println(root.toString()); this.getRootPanel().validate(this); + + ScreenNetworking.of(this, NetworkSide.SERVER).receive(TEST_MESSAGE, buf -> { + System.out.println("Received on the server!"); + }); } } |