aboutsummaryrefslogtreecommitdiff
path: root/GuiTest/src
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-12-17 20:08:01 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-12-17 20:08:01 +0200
commit788176dcaa49ced35e9f441a820410bcd4f09cfe (patch)
tree5525f6eb32436802515063a699dc0dccc46aa70d /GuiTest/src
parent66d11270b27d1fb53458c96879d3d3ca37dfeccf (diff)
downloadLibGui-788176dcaa49ced35e9f441a820410bcd4f09cfe.tar.gz
LibGui-788176dcaa49ced35e9f441a820410bcd4f09cfe.tar.bz2
LibGui-788176dcaa49ced35e9f441a820410bcd4f09cfe.zip
Add screen networking API, update to 1.16.43.3.0
Diffstat (limited to 'GuiTest/src')
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java20
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!");
+ });
}
}