Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import brachy.modularui.drawable.text.Spacer;
import brachy.modularui.utils.Alignment;

import net.minecraft.network.chat.FormattedText;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.network.chat.Component;

import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
Expand All @@ -31,7 +30,7 @@ default T reset() {
* @param c component to add
* @return this
*/
default T add(FormattedText c) {
default T add(Component c) {
getRichText().add(c);
return getThis();
}
Expand Down Expand Up @@ -61,7 +60,7 @@ default T addDrawable(IDrawable drawable) {
return getThis();
}

default T addLine(FormattedText formattedText) {
default T addLine(Component formattedText) {
getRichText().add(formattedText).newLine();
return getThis();
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/brachy/modularui/api/drawable/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import brachy.modularui.utils.Alignment;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -31,9 +32,9 @@ public interface Text extends IDrawable, IJsonSerializable<Text> {

TextRenderer renderer = new TextRenderer();

Component EMPTY = str("");
Component LINE_FEED = str("\n");
Component SPACE = str(" ");
Component EMPTY = CommonComponents.EMPTY;
Component LINE_FEED = CommonComponents.NEW_LINE;
Component SPACE = CommonComponents.SPACE;

// Formatting for convenience
ChatFormatting BLACK = ChatFormatting.BLACK;
Expand Down Expand Up @@ -116,11 +117,11 @@ static ModularComponent comp(@NotNull Component... keys) {
if (keys.length == 0) {
return ModularComponent.empty();
}
MutableComponent main = ModularComponent.empty();
ModularComponent main = ModularComponent.empty();
for (Component key : keys) {
main.append(key);
}
return main.asModular();
return main;
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.lwjgl.opengl.GL11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -514,6 +515,23 @@ public boolean isBEREnabled() {
return true;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof BaseSchemaRenderer that)) return false;

return schema.equals(that.schema) && renderLevel.equals(that.renderLevel) && camera.equals(that.camera) &&
Arrays.equals(viewport, that.viewport);
}

@Override
public int hashCode() {
int result = schema.hashCode();
result = 31 * result + renderLevel.hashCode();
result = 31 * result + camera.hashCode();
result = 31 * result + Arrays.hashCode(viewport);
return result;
}

protected enum CompileStatus {
DISABLED,
COMPILING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ public class AbstractContainerScreenMixin implements IClickableContainerScreen {
protected Slot hoveredSlot;

@Unique
private Slot gtceu$clickedSlot;
private Slot modularui$clickedSlot;

/**
* Mixin into ModularUI screen wrapper to return the true hovered slot.
* The method is private and only the mouse pos is ever passed to this method.
* That's why we can just return the current hovered slot.
*/
@Inject(method = "findSlot", at = @At("HEAD"), cancellable = true)
public void getSlot(double mouseX, double mouseY, CallbackInfoReturnable<Slot> cir) {
if (this.gtceu$clickedSlot != null) {
cir.setReturnValue(this.gtceu$clickedSlot);
public void modularui$getSlot(double mouseX, double mouseY, CallbackInfoReturnable<Slot> cir) {
if (this.modularui$clickedSlot != null) {
cir.setReturnValue(this.modularui$clickedSlot);
} else if (IMuiScreen.class.isAssignableFrom(this.getClass())) {
cir.setReturnValue(this.hoveredSlot);
}
}

@Override
public void gtceu$setClickedSlot(Slot slot) {
this.gtceu$clickedSlot = slot;
public void modularui$setClickedSlot(Slot slot) {
this.modularui$clickedSlot = slot;
}

@Override
public Slot gtceu$getClickedSlot() {
return gtceu$clickedSlot;
public Slot modularui$getClickedSlot() {
return modularui$clickedSlot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public class MinecraftMixin {

@Inject(method = "runTick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Timer;advanceTime(J)I", shift = At.Shift.AFTER))
public void timer(CallbackInfo ci) {
public void modularui$updateTimer(CallbackInfo ci) {
int ticks = ClientProxy.getTimer60Fps().advanceTime(Util.getMillis());
for (int j = 0; j < Math.min(20, ticks); ++j) {
ClientScreenHandler.onFrameUpdate();
}
}

@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;removed()V"))
public void setScreen(Screen guiScreen, CallbackInfo ci) {
public void modularui$trackRealScreenClose(Screen guiScreen, CallbackInfo ci) {
if (guiScreen == null) {
// the ScreenEvent.Closing is also closed when the screen is transitioning to another screen,
// but we only want to know when the next screen null is, so that all screens close.
// but we only want to know when the next screen is null, so that all screens close.
ClientScreenHandler.onCloseScreens(this.screen);
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/brachy/modularui/drawable/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@ public Circle copyOrImmutable() {
.setColor(this.colorInner, this.colorOuter)
.setSegments(this.segments);
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof Circle circle)) return false;

return colorInner == circle.colorInner && colorOuter == circle.colorOuter && segments == circle.segments;
}

@Override
public int hashCode() {
int result = colorInner;
result = 31 * result + colorOuter;
result = 31 * result + segments;
return result;
}
}
12 changes: 12 additions & 0 deletions src/main/java/brachy/modularui/drawable/DelegateDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ public Widget<?> asWidget() {
public Icon asIcon() {
return this.drawable.asIcon();
}

@Override
public boolean equals(Object o) {
if (!(o instanceof DelegateDrawable that)) return false;

return drawable.equals(that.drawable);
}

@Override
public int hashCode() {
return drawable.hashCode();
}
}
12 changes: 12 additions & 0 deletions src/main/java/brachy/modularui/drawable/DelegateIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ protected void setDelegate(IIcon icon) {
this.icon = icon;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof DelegateIcon that)) return false;

return icon.equals(that.icon);
}

@Override
public int hashCode() {
return icon.hashCode();
}

@Override
public String toString() {
return getClass().getSimpleName() + "(" + this.icon + ")";
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/brachy/modularui/drawable/DrawableStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.gson.JsonParseException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -85,4 +86,16 @@ public boolean saveToJson(JsonObject json) {
json.add("drawables", jsonArray);
return true;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof DrawableStack that)) return false;

return Arrays.equals(drawables, that.drawables);
}

@Override
public int hashCode() {
return Arrays.hashCode(drawables);
}
}
17 changes: 17 additions & 0 deletions src/main/java/brachy/modularui/drawable/FlowDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,21 @@ public FlowDrawable removeAll() {
this.icons.clear();
return this;
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof FlowDrawable that)) return false;

return axis == that.axis && icons.equals(that.icons) &&
mainAxisAlignment == that.mainAxisAlignment && crossAxisAlignment == that.crossAxisAlignment;
}

@Override
public int hashCode() {
int result = axis.hashCode();
result = 31 * result + icons.hashCode();
result = 31 * result + mainAxisAlignment.hashCode();
result = 31 * result + crossAxisAlignment.hashCode();
return result;
}
}
12 changes: 12 additions & 0 deletions src/main/java/brachy/modularui/drawable/FluidDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ public FluidDrawable setFluid(FluidStack fluid) {
this.fluid = fluid;
return this;
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof FluidDrawable that)) return false;

return fluid.isFluidEqual(that.fluid);
}

@Override
public int hashCode() {
return fluid.hashCode();
}
}
18 changes: 18 additions & 0 deletions src/main/java/brachy/modularui/drawable/HoverableIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class HoverableIcon extends DelegateIcon implements IHoverable, ITooltip<HoverableIcon> {

private final Area area = new Area();
Expand Down Expand Up @@ -43,4 +45,20 @@ public HoverableIcon tooltip(RichTooltip tooltip) {
this.tooltip = tooltip;
return this;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof HoverableIcon that)) return false;
if (!super.equals(o)) return false;

return area.equals(that.area) && Objects.equals(tooltip, that.tooltip);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + area.hashCode();
result = 31 * result + Objects.hashCode(tooltip);
return result;
}
}
12 changes: 12 additions & 0 deletions src/main/java/brachy/modularui/drawable/HueBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
previous = current;
}
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof HueBar hueBar)) return false;

return axis == hueBar.axis;
}

@Override
public int hashCode() {
return axis.hashCode();
}
}
19 changes: 19 additions & 0 deletions src/main/java/brachy/modularui/drawable/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@ public boolean saveToJson(JsonObject json) {
return true;
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof Icon icon)) return false;

return width == icon.width && height == icon.height && Float.compare(aspectRatio, icon.aspectRatio) == 0 &&
drawable.equals(icon.drawable) && alignment.equals(icon.alignment) && margin.equals(icon.margin);
}

@Override
public int hashCode() {
int result = drawable.hashCode();
result = 31 * result + width;
result = 31 * result + height;
result = 31 * result + Float.hashCode(aspectRatio);
result = 31 * result + alignment.hashCode();
result = 31 * result + margin.hashCode();
return result;
}

@Override
public String toString() {
return getClass().getSimpleName() + "(" + this.drawable.getClass().getSimpleName() + ")";
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/brachy/modularui/drawable/IngredientDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import lombok.Setter;
import lombok.experimental.Tolerate;

import java.util.Arrays;

public class IngredientDrawable implements IDrawable, IJsonSerializable<IngredientDrawable> {

@Getter
Expand Down Expand Up @@ -58,4 +60,18 @@ public IngredientDrawable cycleTime(int cycleTime) {
public void setItems(Ingredient ingredient) {
setItems(ingredient.getItems());
}

@Override
public final boolean equals(Object o) {
if (!(o instanceof IngredientDrawable that)) return false;

return cycleTime == that.cycleTime && Arrays.equals(items, that.items);
}

@Override
public int hashCode() {
int result = Arrays.hashCode(items);
result = 31 * result + cycleTime;
return result;
}
}
Loading