diff --git a/src/main/java/codechicken/lib/colour/Colour.java b/src/main/java/codechicken/lib/colour/Colour.java index fa94af40..61b22b05 100644 --- a/src/main/java/codechicken/lib/colour/Colour.java +++ b/src/main/java/codechicken/lib/colour/Colour.java @@ -134,75 +134,75 @@ public Colour set(float[] floats) { return set(floats[0], floats[1], floats[2], floats[3]); } - public Colour r(float r) { + public Colour rF(float r) { this.r = (byte) (255F * r); return this; } - public Colour g(float g) { + public Colour gF(float g) { this.g = (byte) (255F * g); return this; } - public Colour b(float b) { + public Colour bF(float b) { this.b = (byte) (255F * b); return this; } - public Colour a(float a) { + public Colour aF(float a) { this.a = (byte) (255F * a); return this; } - public Colour r(int r) { + public Colour rF(int r) { this.r = (byte) r; return this; } - public Colour g(int g) { + public Colour gF(int g) { this.g = (byte) g; return this; } - public Colour b(int b) { + public Colour bF(int b) { this.b = (byte) b; return this; } - public Colour a(int a) { + public Colour aF(int a) { this.a = (byte) a; return this; } - public float r() { + public float rF() { return r / 255F; } - public float g() { + public float gF() { return g / 255F; } - public float b() { + public float bF() { return b / 255F; } - public float a() { + public float aF() { return a / 255F; } - public float rI() { + public int r() { return r & 0xFF; } - public float gI() { + public int g() { return g & 0xFF; } - public float bI() { + public int b() { return b & 0xFF; } - public float aI() { + public int a() { return a & 0xFF; } diff --git a/src/main/java/codechicken/lib/gui/modular/ModularGui.java b/src/main/java/codechicken/lib/gui/modular/ModularGui.java index 6fcb4e6f..b0a9d527 100644 --- a/src/main/java/codechicken/lib/gui/modular/ModularGui.java +++ b/src/main/java/codechicken/lib/gui/modular/ModularGui.java @@ -9,6 +9,7 @@ import net.covers1624.quack.collection.FastStream; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.network.chat.Component; @@ -204,7 +205,7 @@ public boolean vanillaSlotRendering() { /** * Create a new {@link GuiRender} for the current render call. * - * @param buffers BufferSource can be retried from {@link net.minecraft.client.gui.GuiGraphics} + * @param buffers BufferSource can be retried from {@link GuiGraphics} * @return A new {@link GuiRender} for the current render call. */ public GuiRender createRender(MultiBufferSource.BufferSource buffers) { diff --git a/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java b/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java index a770f997..0063b6a6 100644 --- a/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java +++ b/src/main/java/codechicken/lib/gui/modular/ModularGuiContainer.java @@ -141,13 +141,12 @@ protected void containerTick() { } @Override - public void onClose() { - super.onClose(); + public void removed() { + super.removed(); modularGui.onGuiClose(); } //=== Input Pass-though ===// - //TODO, We probably dont need to call super for most of these, If anyone tries adding vanilla components to these guis its probably going to break. @Override public void mouseMoved(double mouseX, double mouseY) { diff --git a/src/main/java/codechicken/lib/gui/modular/ModularGuiScreen.java b/src/main/java/codechicken/lib/gui/modular/ModularGuiScreen.java index 100f876e..10fd1060 100644 --- a/src/main/java/codechicken/lib/gui/modular/ModularGuiScreen.java +++ b/src/main/java/codechicken/lib/gui/modular/ModularGuiScreen.java @@ -78,13 +78,11 @@ public void tick() { } @Override - public void onClose() { - super.onClose(); + public void removed() { modularGui.onGuiClose(); } //=== Input Pass-though ===// - //TODO, We probably dont need to call super for most of these, If anyone tries adding vanilla components to these guis its probably going to break. @Override public void mouseMoved(double mouseX, double mouseY) { diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java index 96f1a117..c4550bae 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiColourPicker.java @@ -65,7 +65,7 @@ public static GuiColourPicker create(GuiParent guiParent, ColourState colourS slider = makeSlider(background, 0xFFFFFFFF, picker.sliderStateAlpha()) .constrain(TOP, relative(slider.get(BOTTOM), 1)); } else { - colourState.set(colourState.getColour().a(0)); + colourState.set(colourState.getColour().aF(0)); } ColourPreview preview = new ColourPreview(background, () -> hasAlpha ? colourState.get() : (colourState.get() | 0xFF000000)) @@ -200,19 +200,19 @@ public ColourState getState() { } public SliderState sliderStateAlpha() { - return SliderState.forSlider(() -> (double) colourState.getColour().a(), e -> colourState.set(colourState.getColour().a(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); + return SliderState.forSlider(() -> (double) colourState.getColour().aF(), e -> colourState.set(colourState.getColour().aF(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); } public SliderState sliderStateRed() { - return SliderState.forSlider(() -> (double) colourState.getColour().r(), e -> colourState.set(colourState.getColour().r(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); + return SliderState.forSlider(() -> (double) colourState.getColour().rF(), e -> colourState.set(colourState.getColour().rF(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); } public SliderState sliderStateGreen() { - return SliderState.forSlider(() -> (double) colourState.getColour().g(), e -> colourState.set(colourState.getColour().g(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); + return SliderState.forSlider(() -> (double) colourState.getColour().gF(), e -> colourState.set(colourState.getColour().gF(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); } public SliderState sliderStateBlue() { - return SliderState.forSlider(() -> (double) colourState.getColour().b(), e -> colourState.set(colourState.getColour().b(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); + return SliderState.forSlider(() -> (double) colourState.getColour().bF(), e -> colourState.set(colourState.getColour().bF(e.floatValue())), () -> -1D / (Screen.hasShiftDown() ? 16 : 64)); } public TextState getTextState() { @@ -225,32 +225,8 @@ public GuiButton getOkButton() { /** * If cancel button is disabled, ok button will automatically resize. - * */ + */ public GuiButton getCancelButton() { return cancelButton; } -} - - - - - - - - - - - - - - - - - - - - - - - - +} \ No newline at end of file diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java index fb174d15..a3195c62 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiDVD.java @@ -93,7 +93,5 @@ public void render(GuiRender render, double mouseX, double mouseY, float partial velocity.y = velocity.y > 0 ? MathHelper.clip(velocity.y, 0.4, 0.6) : MathHelper.clip(velocity.y, -0.4, -0.6); velocity.normalize(); } - -// if (bounces == 2) } } diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiElement.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiElement.java index 5f5d6db8..8942e51f 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiElement.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiElement.java @@ -11,6 +11,7 @@ import net.covers1624.quack.util.SneakyUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,7 +34,7 @@ * This is then used to properly layer elements and child elements when they are rendered. * - Switch everything over to the new RenderType system. (This is mostly handled behind the scenes. You don't need to mess with it when creating a GUI) * - Consolidate all the various rendering helper methods into one convenient utility class. - * The new {@link net.minecraft.client.gui.GuiGraphics} system showed me a good way to implement this. + * The new {@link GuiGraphics} system showed me a good way to implement this. * - Reduce the amount of ambiguity when building GUIs. (Whether I succeeded here is up for debate xD) * - Cut out a lot of random bloat that was never used in v2. *

@@ -229,14 +230,6 @@ public boolean blockMouseEvents() { return isMouseOver() && isOpaque(); } - /** - * @return True if the cursor is within the bounds of this element. - */ - @Deprecated(forRemoval = true) //use #isMouseOver() - public boolean isMouseOver(double mouseX, double mouseY) { - return isMouseOver;//GuiRender.isInRect(xMin(), yMin(), xSize(), ySize(), mouseX, mouseY) && !blockMouseOver(this, mouseX, mouseY); - } - /** * @return True if the cursor is within the bounds of this element, and there is no opaque element above this one obstructing the cursor. */ @@ -265,14 +258,6 @@ public int hoverTime() { return hoverTime; } - /** - * Note, Due to this using hoverTime, there may be a 1 tick delay in the updating of this value. - */ - @Deprecated(forRemoval = true) //use #isMouseOver() - public boolean hovered() { - return hoverTime > 0; - } - @Override public String toString() { return getClass().getSimpleName() + "{" + diff --git a/src/main/java/codechicken/lib/gui/modular/lib/GuiProvider.java b/src/main/java/codechicken/lib/gui/modular/lib/GuiProvider.java index fe7c8fa2..32dbcbb5 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/GuiProvider.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/GuiProvider.java @@ -2,10 +2,11 @@ import codechicken.lib.gui.modular.ModularGui; import codechicken.lib.gui.modular.elements.GuiElement; +import codechicken.lib.gui.modular.lib.container.ContainerGuiProvider; /** * This interface is used to build modular gui Screens. - * For modular gui container screens use {@link codechicken.lib.gui.modular.lib.container.ContainerGuiProvider} + * For modular gui container screens use {@link ContainerGuiProvider} * * Created by brandon3055 on 19/08/2023 */ diff --git a/src/main/java/codechicken/lib/gui/modular/lib/ScissorHandler.java b/src/main/java/codechicken/lib/gui/modular/lib/ScissorHandler.java index e84e17f2..06952dec 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/ScissorHandler.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/ScissorHandler.java @@ -30,7 +30,7 @@ public void pushGuiScissor(double x, double y, double width, double height) { public void pushScissor(int x, int y, int width, int height) { int xMax = x + width; int yMax = y + height; - stack.addLast(new ScissorState(x, y, xMax, yMax, stack.peekLast()).apply()); + stack.addLast(ScissorState.createState(x, y, xMax, yMax, stack.peekLast()).apply()); } public void popScissor() { @@ -46,36 +46,30 @@ public void popScissor() { } } - private static class ScissorState { - private int x; - private int y; - private int xMax; - private int yMax; + private record ScissorState(int x, int y, int xMax, int yMax) { - private ScissorState(int x, int y, int xMax, int yMax, ScissorState prevState) { + private ScissorState apply() { + RenderSystem.enableScissor(x, y, xMax - x, yMax - y); + return this; + } + + private static ScissorState createState(int newX, int newY, int newXMax, int newYMax, ScissorState prevState) { if (prevState != null) { - this.x = Math.max(prevState.x, x); - this.y = Math.max(prevState.y, y); - this.xMax = Math.min(prevState.xMax, xMax); - this.yMax = Math.min(prevState.yMax, yMax); + int x = Math.max(prevState.x, newX); + int y = Math.max(prevState.y, newY); + int xMax = Math.min(prevState.xMax, newXMax); + int yMax = Math.min(prevState.yMax, newYMax); Minecraft mc = Minecraft.getInstance(); - if (this.x < 0) this.x = 0; - if (this.y < 0) this.y = 0; - if (this.xMax > mc.getWindow().getScreenWidth()) this.xMax = mc.getWindow().getScreenWidth(); - if (this.yMax > mc.getWindow().getScreenHeight()) this.yMax = mc.getWindow().getScreenHeight(); - if (this.xMax < this.x) this.xMax = this.x; - if (this.yMax < this.y) this.yMax = this.y; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (xMax > mc.getWindow().getScreenWidth()) xMax = mc.getWindow().getScreenWidth(); + if (yMax > mc.getWindow().getScreenHeight()) yMax = mc.getWindow().getScreenHeight(); + if (xMax < x) xMax = x; + if (yMax < y) yMax = y; + return new ScissorState(x, y, xMax, yMax); } else { - this.x = x; - this.y = y; - this.xMax = xMax; - this.yMax = yMax; + return new ScissorState(newX, newY, newXMax, newYMax); } } - - private ScissorState apply() { - RenderSystem.enableScissor(x, y, xMax - x, yMax - y); - return this; - } } } diff --git a/src/main/java/codechicken/lib/gui/modular/lib/container/ContainerGuiProvider.java b/src/main/java/codechicken/lib/gui/modular/lib/container/ContainerGuiProvider.java index b8c105cc..92282ee8 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/container/ContainerGuiProvider.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/container/ContainerGuiProvider.java @@ -1,6 +1,7 @@ package codechicken.lib.gui.modular.lib.container; import codechicken.lib.gui.modular.ModularGui; +import codechicken.lib.gui.modular.ModularGuiContainer; import codechicken.lib.gui.modular.lib.GuiProvider; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -26,7 +27,7 @@ public final void buildGui(ModularGui gui) { * The given menu accessor should always be the parent screen unless your using some custom modular gui implementation. * * @param gui The modular gui instance. - * @param screenAccess The screen access (This will be a gui class that extends {@link codechicken.lib.gui.modular.ModularGuiContainer} + * @param screenAccess The screen access (This will be a gui class that extends {@link ModularGuiContainer} */ public abstract void buildGui(ModularGui gui, ContainerScreenAccess screenAccess); } diff --git a/src/main/java/codechicken/lib/gui/modular/lib/container/DataSync.java b/src/main/java/codechicken/lib/gui/modular/lib/container/DataSync.java index 7355bdce..4b0cb9ec 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/container/DataSync.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/container/DataSync.java @@ -12,7 +12,7 @@ * Created by brandon3055 on 09/09/2023 */ public class DataSync { - + public static final int PKT_SEND_CHANGES = 255; private final ModularGuiContainerMenu containerMenu; private final AbstractDataStore dataStore; private final Supplier valueGetter; @@ -25,7 +25,7 @@ public DataSync(ModularGuiContainerMenu containerMenu, AbstractDataStore data } public T get() { - return dataStore.getValue(); + return dataStore.get(); } /** @@ -35,8 +35,8 @@ public void detectAndSend() { if (dataStore.isSameValue(valueGetter.get())) { return; } - dataStore.setValue(valueGetter.get()); - containerMenu.sendPacketToClient(255, buf -> { + dataStore.set(valueGetter.get()); + containerMenu.sendPacketToClient(PKT_SEND_CHANGES, buf -> { buf.writeByte((byte) containerMenu.dataSyncs.indexOf(this)); dataStore.toBytes(buf); }); diff --git a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Position.java b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Position.java index c6187fbb..df430507 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Position.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Position.java @@ -34,31 +34,11 @@ static Position create(Supplier getX, Supplier getY) { * Creates a new position, bound to the specified parent's position. * */ static Position create(GuiParent parent) { - return new Bound(parent); + return new Dynamic(parent::xMin, parent::yMin); } record Immutable(@Override double x, @Override double y) implements Position { } - record Bound(GuiParent parent) implements Position { - @Override - public double x() { - return parent.xMin(); - } - - @Override - public double y() { - return parent.yMin(); - } - - @Override - public String toString() { - return "Bound{" + - "x=" + x() + - ", y=" + y() + - '}'; - } - } - record Dynamic(Supplier getX, Supplier getY) implements Position { @Override public double x() { diff --git a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java index bce94d75..0fb6328f 100644 --- a/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java +++ b/src/main/java/codechicken/lib/gui/modular/lib/geometry/Rectangle.java @@ -154,7 +154,7 @@ static Rectangle create(double x, double y, double width, double height) { * Returns a new rectangle bound to the specified parent's geometry. */ static Rectangle create(GuiParent parent) { - return new Bound(Position.create(parent), parent); + return new Dynamic(Position.create(parent), parent::xSize, parent::ySize); } static Rectangle create(Position position, Supplier getWidth, Supplier getHeight) { @@ -194,35 +194,6 @@ public String toString() { } } - /** - * Should not be created directly - */ - record Bound(Position position, GuiParent parent) implements Rectangle { - @Override - public Position pos() { - return position; - } - - @Override - public double width() { - return parent.xSize(); - } - - @Override - public double height() { - return parent.ySize(); - } - - @Override - public String toString() { - return "Bound{" + - "pos=" + pos() + - ", width=" + width() + - ", height=" + height() + - '}'; - } - } - record Dynamic(Position position, Supplier getWidth, Supplier getHeight) implements Rectangle { @Override public Position pos() { diff --git a/src/main/java/codechicken/lib/internal/ClientInit.java b/src/main/java/codechicken/lib/internal/ClientInit.java index e3414e88..1e1eb056 100644 --- a/src/main/java/codechicken/lib/internal/ClientInit.java +++ b/src/main/java/codechicken/lib/internal/ClientInit.java @@ -10,6 +10,9 @@ import codechicken.lib.render.CCRenderEventHandler; import codechicken.lib.render.block.BlockRenderingRegistry; import net.covers1624.quack.util.CrashLock; +import net.minecraft.client.Minecraft; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraftforge.client.event.ClientPlayerNetworkEvent; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; @@ -81,6 +84,6 @@ private static void onRegisterGeometryLoaders(ModelEvent.RegisterGeometryLoaders public static void onResourceReload(RegisterClientReloadListenersEvent event) { event.registerReloadListener(CCGuiTextures.getAtlasHolder()); - CursorHelper.onResourceReload(); + event.registerReloadListener((ResourceManagerReloadListener) e -> CursorHelper.onResourceReload()); } } diff --git a/src/main/java/codechicken/lib/internal/network/CCLNetwork.java b/src/main/java/codechicken/lib/internal/network/CCLNetwork.java index 5fbd194b..5655ef14 100644 --- a/src/main/java/codechicken/lib/internal/network/CCLNetwork.java +++ b/src/main/java/codechicken/lib/internal/network/CCLNetwork.java @@ -15,10 +15,10 @@ public class CCLNetwork { //Client handled. public static final int C_ADD_LANDING_EFFECTS = 1; public static final int C_OPEN_CONTAINER = 10; - public static final int C_GUI_SYNC = 11; + public static final int C_GUI_SYNC = 20; //Server handled. - public static final int S_GUI_SYNC = 1; + public static final int S_GUI_SYNC = 20; //Login handled. public static final int L_CONFIG_SYNC = 1; diff --git a/src/main/java/codechicken/lib/inventory/container/data/AbstractDataStore.java b/src/main/java/codechicken/lib/inventory/container/data/AbstractDataStore.java index 6120027d..759b2db8 100644 --- a/src/main/java/codechicken/lib/inventory/container/data/AbstractDataStore.java +++ b/src/main/java/codechicken/lib/inventory/container/data/AbstractDataStore.java @@ -3,7 +3,6 @@ import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; import net.minecraft.nbt.Tag; -import net.minecraft.network.FriendlyByteBuf; import java.util.Objects; @@ -20,11 +19,11 @@ public AbstractDataStore(T defaultValue) { this.value = defaultValue; } - public T getValue() { + public T get() { return value; } - public void setValue(T value) { + public void set(T value) { this.value = value; markDirty(); } diff --git a/src/main/java/codechicken/lib/inventory/container/data/FluidData.java b/src/main/java/codechicken/lib/inventory/container/data/FluidData.java index 62288a63..5a5bf64c 100644 --- a/src/main/java/codechicken/lib/inventory/container/data/FluidData.java +++ b/src/main/java/codechicken/lib/inventory/container/data/FluidData.java @@ -21,7 +21,7 @@ public FluidData(FluidStack defaultValue) { } @Override - public void setValue(FluidStack value) { + public void set(FluidStack value) { this.value = value.copy(); markDirty(); } diff --git a/src/main/java/codechicken/lib/inventory/container/modular/ModularSlot.java b/src/main/java/codechicken/lib/inventory/container/modular/ModularSlot.java index 92d86333..bfa02872 100644 --- a/src/main/java/codechicken/lib/inventory/container/modular/ModularSlot.java +++ b/src/main/java/codechicken/lib/inventory/container/modular/ModularSlot.java @@ -20,8 +20,7 @@ public class ModularSlot extends Slot { private Predicate validator = stack -> true; private Function stackLimit = stack -> Integer.MAX_VALUE; private BiPredicate canRemove = (player, stack) -> true; - private BiConsumer onSet = (oldStack, newStack) -> { - }; + private BiConsumer onSet = (oldStack, newStack) -> {}; public ModularSlot(Container container, int index) { this(container, index, 0, 0); diff --git a/src/main/java/codechicken/lib/render/CCRenderEventHandler.java b/src/main/java/codechicken/lib/render/CCRenderEventHandler.java index de22f22b..1f25a147 100644 --- a/src/main/java/codechicken/lib/render/CCRenderEventHandler.java +++ b/src/main/java/codechicken/lib/render/CCRenderEventHandler.java @@ -53,10 +53,4 @@ public void onBlockHighlight(RenderHighlightEvent.Block event) { RenderUtils.bufferShapeHitBox(mat, event.getMultiBufferSource(), event.getCamera(), voxelHit.shape); } } - - @OnlyIn (Dist.CLIENT) - @SubscribeEvent (priority = EventPriority.LOW) - public void screenOpenEvent(ScreenEvent.Opening event) { - CursorHelper.resetCursor(); - } }