Skip to content

Commit

Permalink
Made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Jan 21, 2024
1 parent 785f905 commit 2b3db37
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 171 deletions.
32 changes: 16 additions & 16 deletions src/main/java/codechicken/lib/colour/Colour.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codechicken/lib/gui/modular/ModularGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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() {
Expand All @@ -225,32 +225,8 @@ public GuiButton getOkButton() {

/**
* If cancel button is disabled, ok button will automatically resize.
* */
*/
public GuiButton getCancelButton() {
return cancelButton;
}
}
























}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
19 changes: 2 additions & 17 deletions src/main/java/codechicken/lib/gui/modular/elements/GuiElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,7 @@
* This is then used to properly layer elements and child elements when they are rendered.
* <tr>- 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)
* <tr>- 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.
* <tr>- Reduce the amount of ambiguity when building GUIs. (Whether I succeeded here is up for debate xD)
* <tr>- Cut out a lot of random bloat that was never used in v2.
* <p>
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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() + "{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
46 changes: 20 additions & 26 deletions src/main/java/codechicken/lib/gui/modular/lib/ScissorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T> screenAccess);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Created by brandon3055 on 09/09/2023
*/
public class DataSync<T> {

public static final int PKT_SEND_CHANGES = 255;
private final ModularGuiContainerMenu containerMenu;
private final AbstractDataStore<T> dataStore;
private final Supplier<T> valueGetter;
Expand All @@ -25,7 +25,7 @@ public DataSync(ModularGuiContainerMenu containerMenu, AbstractDataStore<T> data
}

public T get() {
return dataStore.getValue();
return dataStore.get();
}

/**
Expand All @@ -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);
});
Expand Down
Loading

0 comments on commit 2b3db37

Please sign in to comment.