diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-12-17 18:38:14 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-12-17 18:38:14 +0200 |
commit | a608419e38cf02362df4cfb77a3587108f76bfc6 (patch) | |
tree | 04f75070a2da4f04c362fc20eb559aea3f1b4fd0 /GuiTest/src/main/java/io | |
parent | f880c0d5ac35be17703581fa0dc847e0de053424 (diff) | |
download | LibGui-a608419e38cf02362df4cfb77a3587108f76bfc6.tar.gz LibGui-a608419e38cf02362df4cfb77a3587108f76bfc6.tar.bz2 LibGui-a608419e38cf02362df4cfb77a3587108f76bfc6.zip |
Add screen networking API
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!"); + }); } } |