From 1964ce97ba0121d4346d8134fb7395285193137c Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Sun, 16 Jan 2022 18:37:55 +0200 Subject: Add test for WItemSlot filters --- .../io/github/cottonmc/test/TestDescription.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 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 70c50d4..69be1f4 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/TestDescription.java @@ -1,17 +1,22 @@ 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 io.github.cottonmc.cotton.gui.widget.icon.TextureIcon; - import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; +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.WButton; +import io.github.cottonmc.cotton.gui.widget.WGridPanel; +import io.github.cottonmc.cotton.gui.widget.WItemSlot; +import io.github.cottonmc.cotton.gui.widget.WLabel; +import io.github.cottonmc.cotton.gui.widget.WTextField; +import io.github.cottonmc.cotton.gui.widget.icon.TextureIcon; + 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"); @@ -51,6 +56,14 @@ public class TestDescription extends SyncedGuiDescription { this.getRootPanel().validate(this); + getRootPanel().streamChildren() + .forEach(child -> { + if (child instanceof WItemSlot wis) { + // Prevent apples from entering the item slots + wis.setFilter(stack -> !stack.isOf(Items.APPLE)); + } + }); + ScreenNetworking.of(this, NetworkSide.SERVER).receive(TEST_MESSAGE, buf -> { System.out.println("Received on the server!"); }); -- cgit