diff options
57 files changed, 1080 insertions, 1058 deletions
diff --git a/GuiTest/build.gradle b/GuiTest/build.gradle index c1423b2..5ae2c60 100644 --- a/GuiTest/build.gradle +++ b/GuiTest/build.gradle @@ -32,8 +32,6 @@ dependencies { modApi "net.fabricmc:fabric-loader:${rootProject.loader_version}" modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" - compileOnly ("com.google.code.findbugs:jsr305:3.0.2") { transitive = false } - implementation project(':') } diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java index 69a0640..96ac123 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlock.java @@ -8,7 +8,6 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; import net.minecraft.world.World; public class GuiBlock extends BlockWithEntity { @@ -24,8 +23,8 @@ public class GuiBlock extends BlockWithEntity { } @Override - public BlockEntity createBlockEntity(BlockView var1) { - return new GuiBlockEntity(); + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new GuiBlockEntity(pos, state); } @Override diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java index 6a9f741..ddbbe0a 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/GuiBlockEntity.java @@ -1,5 +1,6 @@ package io.github.cottonmc.test; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -10,16 +11,17 @@ import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.BlockPos; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class GuiBlockEntity extends BlockEntity implements ImplementedInventory, NamedScreenHandlerFactory { static final int INVENTORY_SIZE = 8; DefaultedList<ItemStack> items = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); - public GuiBlockEntity() { - super(LibGuiTest.GUI_BLOCKENTITY_TYPE); + public GuiBlockEntity(BlockPos pos, BlockState state) { + super(LibGuiTest.GUI_BLOCKENTITY_TYPE, pos, state); } @Override diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java index 8b567b7..17bfdaa 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/LibGuiTest.java @@ -6,6 +6,7 @@ import java.nio.file.Path; import java.util.Optional; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; @@ -35,7 +36,7 @@ public class LibGuiTest implements ModInitializer { Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK); GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC)); Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM); - GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null); + GUI_BLOCKENTITY_TYPE = FabricBlockEntityTypeBuilder.create(GuiBlockEntity::new, GUI_BLOCK).build(null); Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE); GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> { diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java index 65efe75..22a1bb8 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/LibGuiTestClient.java @@ -16,7 +16,7 @@ public class LibGuiTestClient implements ClientModInitializer { (desc, inventory, title) -> new CottonInventoryScreen<>(desc, inventory.player, title) ); - CottonHud.INSTANCE.add(new WHudTest(), 10, -20, 10, 10); + CottonHud.add(new WHudTest(), 10, -20, 10, 10); } } diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java index 85ad3cd..de8a06a 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java @@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.widget.TooltipBuilder; import io.github.cottonmc.cotton.gui.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WLabel; import io.github.cottonmc.cotton.gui.widget.WSlider; +import io.github.cottonmc.cotton.gui.widget.WSprite; import io.github.cottonmc.cotton.gui.widget.WTextField; import io.github.cottonmc.cotton.gui.widget.WTiledSprite; import io.github.cottonmc.cotton.gui.widget.WWidget; @@ -19,12 +20,6 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; public class TestClientGui extends LightweightGuiDescription { - - @Environment(EnvType.CLIENT) - public static final BackgroundPainter PANEL = (x, y, panel)->{ - ScreenDrawing.drawBeveledPanel(x-1, y-1, panel.getWidth()+2, panel.getHeight()+2); - }; - //private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png"); //private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png"); @@ -36,10 +31,13 @@ public class TestClientGui extends LightweightGuiDescription { WGridPanel root = new WGridPanel(22); this.setRootPanel(root); WLabel title = new WLabel(new LiteralText("Client Test Gui"), WLabel.DEFAULT_TEXT_COLOR) { + private final WWidget tooltipWidget = new WSprite(new Identifier("minecraft", "textures/block/cobblestone.png")); + @Environment(EnvType.CLIENT) @Override public void addTooltip(TooltipBuilder tooltip) { tooltip.add(new LiteralText("Radical!")); + tooltip.add(tooltipWidget); } }; WTiledSprite wood = new WTiledSprite( @@ -146,7 +144,7 @@ public class TestClientGui extends LightweightGuiDescription { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(x, y, this.getWidth(), this.getHeight(), color); + ScreenDrawing.coloredRect(matrices, x, y, this.getWidth(), this.getHeight(), color); } } } diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java index 2cc1e4b..41d566d 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java @@ -16,7 +16,7 @@ public class WHudTest extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(x, y, width, height, 0xFF_00FF00); + ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF_00FF00); } @Override diff --git a/gradle.properties b/gradle.properties index 3761a8e..13efc74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.16.5 - yarn_mappings=1.16.5+build.3 - loader_version=0.11.1 + minecraft_version=20w51a + yarn_mappings=20w51a+build.2 + loader_version=0.10.8 # Mod Properties - mod_version = 3.3.3 + mod_version = 4.0.0-beta.1 maven_group = io.github.cottonmc archives_base_name = LibGui # Dependencies - fabric_version=0.30.0+1.16 + fabric_version=0.28.3+1.17 jankson_version=3.0.1+j1.2.0 - modmenu_version=1.14.15 + modmenu_version=2.0.0-beta.1+build.2 diff --git a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java index ce0dd4b..fae723e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/SyncedGuiDescription.java @@ -26,7 +26,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LibGuiClient; +import io.github.cottonmc.cotton.gui.client.LibGui; import io.github.cottonmc.cotton.gui.networking.NetworkSide; import io.github.cottonmc.cotton.gui.widget.WGridPanel; import io.github.cottonmc.cotton.gui.widget.WLabel; @@ -80,7 +80,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio } public int getTitleColor() { - return (world.isClient && LibGuiClient.config.darkMode) ? darkTitleColor : titleColor; + return (world.isClient && LibGui.isDarkMode()) ? darkTitleColor : titleColor; } public SyncedGuiDescription setRootPanel(WPanel panel) { @@ -164,7 +164,7 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio /** WILL MODIFY toInsert! Returns true if anything was inserted. */ private boolean insertIntoExisting(ItemStack toInsert, Slot slot, PlayerEntity player) { ItemStack curSlotStack = slot.getStack(); - if (!curSlotStack.isEmpty() && canStacksCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) { + if (!curSlotStack.isEmpty() && ItemStack.canCombine(toInsert, curSlotStack) && slot.canInsert(toInsert)) { int combinedAmount = curSlotStack.getCount() + toInsert.getCount(); int maxAmount = Math.min(toInsert.getMaxCount(), slot.getMaxItemCount()); if (combinedAmount <= maxAmount) { @@ -299,52 +299,6 @@ public class SyncedGuiDescription extends ScreenHandler implements GuiDescriptio } @Nullable - public WWidget doMouseUp(int x, int y, int state) { - if (rootPanel!=null) return rootPanel.onMouseUp(x, y, state); - return null; - } - - @Nullable - public WWidget doMouseDown(int x, int y, int button) { - if (rootPanel!=null) return rootPanel.onMouseDown(x, y, button); - return null; - } - - public void doMouseDrag(int x, int y, int button, double deltaX, double deltaY) { - if (rootPanel!=null) rootPanel.onMouseDrag(x, y, button, deltaX, deltaY); - } - - public void doClick(int x, int y, int button) { - if (focus!=null) { - int wx = focus.getAbsoluteX(); - int wy = focus.getAbsoluteY(); - - if (x>=wx && x<wx+focus.getWidth() && y>=wy && y<wy+focus.getHeight()) { - //Do nothing, focus will get the click soon - } else { - //Invalidate the component first - WWidget lastFocus = focus; - focus = null; - lastFocus.onFocusLost(); - } - } - - //if (rootPanel!=null) rootPanel.onClick(x, y, button); - } - - public void doCharType(char ch) { - if (focus!=null) focus.onCharTyped(ch); - } - - //public void doKeyPress(int key) { - // if (focus!=null) focus.onKeyPressed(key); - //} - - //public void doKeyRelease(int key) { - // if (focus!=null) focus.onKeyReleased(key); - //} - - @Nullable @Override public PropertyDelegate getPropertyDelegate() { return propertyDelegate; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index f00bf80..13ca534 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -1,5 +1,6 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.widget.WItemSlot; @@ -13,11 +14,12 @@ import io.github.cottonmc.cotton.gui.widget.WWidget; public interface BackgroundPainter { /** * Paint the specified panel to the screen. + * @param matrices The rendering matrix stack * @param left The absolute position of the left of the panel, in gui-screen coordinates * @param top The absolute position of the top of the panel, in gui-screen coordinates * @param panel The panel being painted */ - public void paintBackground(int left, int top, WWidget panel); + public void paintBackground(MatrixStack matrices, int left, int top, WWidget panel); /** * The {@code VANILLA} background painter draws a vanilla-like gui panel using {@linkplain NinePatch nine-patch textures}. @@ -40,9 +42,9 @@ public interface BackgroundPainter { /** * The {@code SLOT} background painter draws item slots or slot-like widgets. */ - public static BackgroundPainter SLOT = (left, top, panel) -> { + public static BackgroundPainter SLOT = (matrices, left, top, panel) -> { if (!(panel instanceof WItemSlot)) { - ScreenDrawing.drawBeveledPanel(left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); + ScreenDrawing.drawBeveledPanel(matrices, left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); } else { WItemSlot slot = (WItemSlot)panel; for(int x = 0; x < slot.getWidth()/18; ++x) { @@ -53,26 +55,26 @@ public interface BackgroundPainter { //this will cause a slightly discolored bottom border on vanilla backgrounds but it's necessary for color support, it shouldn't be *too* visible unless you're looking for it int hi = 0xB8FFFFFF; if (slot.isBigSlot()) { - ScreenDrawing.drawBeveledPanel((x * 18) + left - 4, (y * 18) + top - 4, 26, 26, + ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left - 4, (y * 18) + top - 4, 26, 26, lo, bg, hi); if (slot.getFocusedSlot() == index) { int sx = (x * 18) + left - 4; int sy = (y * 18) + top - 4; - ScreenDrawing.coloredRect(sx, sy, 26, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 26 - 1, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 1, sy + 26 - 1, 26 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy, 26, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 26 - 1, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 1, sy + 26 - 1, 26 - 1, 1, 0xFF_FFFFA0); } } else { - ScreenDrawing.drawBeveledPanel((x * 18) + left, (y * 18) + top, 16+2, 16+2, + ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left, (y * 18) + top, 16+2, 16+2, lo, bg, hi); if (slot.getFocusedSlot() == index) { int sx = (x * 18) + left; int sy = (y * 18) + top; - ScreenDrawing.coloredRect(sx, sy, 18, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 18 - 1, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 1, sy + 18 - 1, 18 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy, 18, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 18 - 1, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 1, sy + 18 - 1, 18 - 1, 1, 0xFF_FFFFA0); } } } @@ -85,11 +87,11 @@ public interface BackgroundPainter { * * @param panelColor the panel background color * @return a colorful gui panel painter - * @see ScreenDrawing#drawGuiPanel(int, int, int, int, int) + * @see ScreenDrawing#drawGuiPanel(MatrixStack, int, int, int, int, int) */ public static BackgroundPainter createColorful(int panelColor) { - return (left, top, panel) -> { - ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); + return (matrices, left, top, panel) -> { + ScreenDrawing.drawGuiPanel(matrices, left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); }; } @@ -101,11 +103,11 @@ public interface BackgroundPainter { * @return a colorful gui panel painter */ public static BackgroundPainter createColorful(int panelColor, float contrast) { - return (left, top, panel) -> { + return (matrices, left, top, panel) -> { int shadowColor = ScreenDrawing.multiplyColor(panelColor, 1.0f - contrast); int hilightColor = ScreenDrawing.multiplyColor(panelColor, 1.0f + contrast); - ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, shadowColor, panelColor, hilightColor, 0xFF000000); + ScreenDrawing.drawGuiPanel(matrices, left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, shadowColor, panelColor, hilightColor, 0xFF000000); }; } @@ -146,9 +148,9 @@ public interface BackgroundPainter { * @since 1.5.0 */ |
