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
18 changes: 9 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Done to increase the memory available to Gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true
org.gradle.warning.mode=all

Expand All @@ -11,7 +11,7 @@ maven.group = com.thecsdev

# Mod properties
mod.id = tcdcommons
mod.version = 5.5.6
mod.version = 5.6.0-beta.1
mod.name = TCDCommons API
mod.description = TheCSDev's personal Minecraft modding library.
mod.author = TheCSDev
Expand All @@ -22,23 +22,23 @@ mod.link.sources = https://thecsdev.com/fwd/tcdcommons-sources/
mod.link.issues = https://thecsdev.com/fwd/tcdcommons-issues/

# 'pack.mcmeta' properties
pack.format = 88
pack.format = 97.1

# Minecraft properties
minecraft.version = 26.2
minecraft.version = 26.3

# Fabric properties
fabric.loader_version = 0.19.2
fabric.api_version = 0.152.1+26.2
fabric.loader_version = 0.19.5
fabric.api_version = 0.160.5+26.3

# fabric.mod.json properties
fabric.json.entrypoints.main = com.thecsdev.commonmc.fabric.TCDCommonsFabric
fabric.json.entrypoints.client = com.thecsdev.commonmc.fabric.TCDCommonsFabric
fabric.json.entrypoints.server = com.thecsdev.commonmc.fabric.TCDCommonsFabric

fabric.json.depends.java = >=25
fabric.json.depends.minecraft = ~26.2
fabric.json.depends.fabricloader = >=0.18.5
fabric.json.depends.minecraft = >=26.3- <26.4
fabric.json.depends.fabricloader = >=0.19.5
fabric.json.depends.fabric-api = *

# Neo-Forge properties
Expand All @@ -47,4 +47,4 @@ neoforge.version = 26.2.0.1-beta
# neoforge.mods.toml properties
net.toml.loaderVersion = [4,)
neo.toml.dependencies.neoforge = [26.2.0.1-beta,)
neo.toml.dependencies.minecraft = [26.2, 26.3)
neo.toml.dependencies.minecraft = [26.3-, 26.4)
30 changes: 0 additions & 30 deletions src/main/java/com/thecsdev/common/math/TMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,6 @@ public final class TMath
// ==================================================
private TMath() {}
// ==================================================
/**
* Clamps a {@code int} value to the given {@code min/max} range.
* @param value the value to clamp
* @param min The minimum value.
* @param max The maximum value.
* @return {@code min} if {@code value < min}, {@code max} if {@code value > max}, otherwise {@code value}.
*/
@Deprecated(forRemoval = true)
public static final int clampi(int value, int min, int max) { return Math.max(min, Math.min(max, value)); }

/**
* Clamps a {@code float} value to the given {@code min/max} range.
* @param value the value to clamp
* @param min The minimum value.
* @param max The maximum value.
* @return {@code min} if {@code value < min}, {@code max} if {@code value > max}, otherwise {@code value}.
*/
@Deprecated(forRemoval = true)
public static final float clampf(float value, float min, float max) { return Math.max(min, Math.min(max, value)); }

/**
* Clamps a {@code double} value to the given {@code min/max} range.
* @param value the value to clamp
* @param min The minimum value.
* @param max The maximum value.
* @return {@code min} if {@code value < min}, {@code max} if {@code value > max}, otherwise {@code value}.
*/
@Deprecated(forRemoval = true)
public static final double clampd(double value, double min, double max) { return Math.max(min, Math.min(max, value)); }
// --------------------------------------------------
/**
* Clamps a {@code float} value to the range [0.0f, 1.0f].
* @param value the value to clamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static com.thecsdev.commonmc.api.client.gui.util.TInputContext.InputType.MOUSE_PRESS;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
import static org.lwjgl.sdl.SDLScancode.SDL_SCANCODE_ESCAPE;

/**
* A {@link TContextMenu} is a specialized {@link TElement} that represents a context menu
Expand All @@ -63,10 +63,10 @@ public TContextMenu()
focusableProperty().set(true, TContextMenu.class);
//in order to have child context menus be visible, we need not clip descendants
clipsDescendantsProperty().set(false, TContextMenu.class);
clipsDescendantsProperty().addFilter(__ -> false, TContextMenu.class);
clipsDescendantsProperty().addFilter(_ -> false, TContextMenu.class);

//handle being assigned to a new screen
screenProperty().addChangeListener((p, o, n) -> {
screenProperty().addChangeListener((_, _, n) -> {
//ignore removals from screens (aka screen becoming null)
if(n == null) return;
//remove other dropdown elements "branches". there cannot be more than one
Expand All @@ -82,7 +82,7 @@ public TContextMenu()
});

//ensure the parent is always a screen or another context menu
parentProperty().addChangeListener((p, o, n) -> {
parentProperty().addChangeListener((_, _, n) -> {
if(n == null) return;
if(!(n instanceof TScreen) && !(n instanceof TContextMenu)) {
n.remove(this); //restore to stable state - caution: re-invokes this change listener
Expand All @@ -93,13 +93,13 @@ public TContextMenu()
//tracking the root context menu element (this has to be placed last)
this.rootContextMenu.setReadOnly(true, TContextMenu.class);
this.rootContextMenu.setOwner(PropertyAccessor.class, TContextMenu.class);
this.rootContextMenu.addChangeListener((p, o, n) -> {
this.rootContextMenu.addChangeListener((_, _, n) -> {
//propagate the new root context menu to all child context menus
for(final var child : this)
if(child instanceof TContextMenu childMenu)
setRootCtxMenuValue(childMenu, n);
});
parentProperty().addChangeListener((p, o, n) -> {
parentProperty().addChangeListener((_, _, _) -> {
//find the root context menu and set it
@NotNull TContextMenu root = this;
@Nullable TElement next = this;
Expand Down Expand Up @@ -139,7 +139,7 @@ public TContextMenu()
//close this dropdown if a key press happens without focus
//to this dropdown or one of its (grand/)children
case KEY_PRESS: {
if(!isFocusAncestor() || context.getKeyCode() == GLFW_KEY_ESCAPE)
if(!isFocusAncestor() || context.getScanCode() == SDL_SCANCODE_ESCAPE)
return remove();
else break;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ public final Builder addButton(
btn.setBounds(0, 0, this.client.font.width(text) + (TButtonWidget.LBL_PAD_X * 2), 15);
btn.eClicked.addListener(onClick); //on-click goes first, as is may rely on btn#getClient()
btn.eClicked.addListener( //then remove, which also clears the screen/client property value
__ -> btn.getParentMenu().rootContextMenuProperty().get().remove());
_ -> btn.getParentMenu().rootContextMenuProperty().get().remove());
this.entries.add(btn);
return this;
}
Expand All @@ -319,7 +319,7 @@ public final Builder addContextMenu(
btn.getLabel().setText(text);
btn.getLabel().textAlignmentProperty().set(CompassDirection.WEST, Builder.class);
btn.setBounds(0, 0, this.client.font.width(text) + (TButtonWidget.LBL_PAD_X * 2), 15);
btn.eClicked.addListener(__ -> {
btn.eClicked.addListener(_ -> {
//add the context menu
final var menu = Objects.requireNonNull(menuBuilder.apply(btn), "Context menu Supplier returned 'null'");
btn.getParentMenu().add(menu);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.thecsdev.commonmc.api.client.gui.misc;

import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
import com.thecsdev.common.properties.IntegerProperty;
import com.thecsdev.common.properties.NotNullProperty;
import com.thecsdev.common.util.annotations.Virtual;
import com.thecsdev.commonmc.api.client.gui.TElement;
import com.thecsdev.commonmc.api.client.gui.render.TGuiGraphics;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static net.minecraft.client.renderer.RenderPipelines.GUI_TEXTURED;
import static net.minecraft.client.renderer.texture.TextureManager.INTENTIONAL_MISSING_TEXTURE;

/**
* A {@link TElement} whose sole purpose is to render a sprite/texture.
Expand All @@ -25,7 +25,7 @@
// TTextureElement IMPLEMENTATION
// ================================================== ==================================================
private final NotNullProperty<RenderPipeline> renderPipeline = new NotNullProperty<>(GUI_TEXTURED);
private final NotNullProperty<Identifier> texture = new NotNullProperty<>(INTENTIONAL_MISSING_TEXTURE);
private final NotNullProperty<Identifier> texture = new NotNullProperty<>(MissingTextureAtlasSprite.getLocation());
private final NotNullProperty<Mode> mode = new NotNullProperty<>(Mode.TEXTURE);
private final IntegerProperty color = new IntegerProperty(0xFFFFFFFF);
// ==================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;

import static org.lwjgl.sdl.SDLMouse.SDL_BUTTON_LEFT;
import static org.lwjgl.sdl.SDLMouse.SDL_BUTTON_MIDDLE;
import static org.lwjgl.sdl.SDLScancode.*;

/**
* A panel element primarily featuring functionality like scrolling.
Expand All @@ -38,7 +41,7 @@ public TPanelElement()

//clamp01 the scroll amount
this.scrollAmount.addFilter(Point2d::clamp01, TPanelElement.class);
this.scrollAmount.addChangeListener((p, o, n) -> {
this.scrollAmount.addChangeListener((_, _, _) -> {
final var ccb = getContentBounds();
final var ncb = computeContentBoundsFromScrollAmount();
moveChildren(ncb.x - ccb.x, ncb.y - ccb.y);
Expand Down Expand Up @@ -84,7 +87,7 @@ public TPanelElement()
switch(context.getInputType())
{
//mouse press should result in focus, so we return true here
case MOUSE_PRESS: return (context.getMouseButton() == 0 || context.getMouseButton() == 2) && isFocusable();
case MOUSE_PRESS: return (context.getMouseButton() == SDL_BUTTON_LEFT || context.getMouseButton() == SDL_BUTTON_MIDDLE) && isFocusable();
//mouse scroll should result in scrolling
case MOUSE_SCROLL: {
final int ss = this.scrollSensitivity.getI();
Expand Down Expand Up @@ -117,11 +120,11 @@ public TPanelElement()
final int s = this.scrollSensitivity.getI();
int dX = 0, dY = 0;
//noinspection DataFlowIssue
switch(context.getKeyCode()) {
case GLFW.GLFW_KEY_UP: dY += s; break;
case GLFW.GLFW_KEY_DOWN: dY -= s; break;
case GLFW.GLFW_KEY_LEFT: dX += s; break;
case GLFW.GLFW_KEY_RIGHT: dX -= s; break;
switch(context.getScanCode()) {
case SDL_SCANCODE_UP: dY += s; break;
case SDL_SCANCODE_DOWN: dY -= s; break;
case SDL_SCANCODE_LEFT: dX += s; break;
case SDL_SCANCODE_RIGHT: dX -= s; break;
default: break;
}
if(dX != 0 || dY != 0) { scroll(dX, dY); return true; }
Expand All @@ -141,8 +144,7 @@ public TPanelElement()
*/
private final Bounds2i computeContentBoundsFromScrollAmount()
{
//Point2d - constructor: new Point2d(double x, double y) - fields: .x .y (doubles)
//Bounds2i fields: .x .y .width .height .endX .endY (integers)
//prerequisites
final Bounds2i bb = getBounds(); //current rectangle of this element (viewport)
final Bounds2i cbb = getContentBounds(); //current rectangle encapsulating all children bounding boxes
final Point2d sa = this.scrollAmount.get();
Expand Down Expand Up @@ -183,11 +185,10 @@ private final Bounds2i computeContentBoundsFromScrollAmount()
*/
private final Point2d computeScrollAmountFromContentBounds()
{
//Point2d - constructor: new Point2d(double x, double y) - fields: .x .y (doubles)
//Bounds2i fields: .x .y .width .height .endX .endY (integers)
//prerequisites
final Bounds2i bb = getBounds(); //rectangle of this element (viewport)
final Bounds2i cbb = getContentBounds(); //rectangle encapsulating all children bounding boxes
final int sp = this.scrollPadding.getI(); // NEW: Scroll Padding
final int sp = this.scrollPadding.getI(); //scroll padding

// 1. Calculate the effective maximum scrollable distance (delta)
// The scrollable range is reduced by 2 * sp.
Expand All @@ -201,21 +202,8 @@ private final Point2d computeScrollAmountFromContentBounds()
final double offsetX = (bb.x + sp) - cbb.x;
final double offsetY = (bb.y + sp) - cbb.y;

double scrollAmountX;
if (maxScrollX > 0) {
// sa = Offset / MaxScroll.
scrollAmountX = offsetX / maxScrollX;
} else {
// Content fits or is smaller than viewport, so scroll is 0.
scrollAmountX = 0.0;
}

double scrollAmountY;
if (maxScrollY > 0) {
scrollAmountY = offsetY / maxScrollY;
} else {
scrollAmountY = 0.0;
}
double scrollAmountX = (maxScrollX > 0) ? (offsetX / maxScrollX) : 0.0;
double scrollAmountY = (maxScrollY > 0) ? (offsetY / maxScrollY) : 0.0;

// The scroll amount should be between 0 and 1.
// We ensure this using Math.min/max, just in case of floating point inaccuracies or external manipulation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.lwjgl.sdl.SDLMouse.SDL_BUTTON_LEFT;

/**
* {@link TElement} implementation that has the visual appearance to that of a "window",
* featuring a title-bar that has a title label and control buttons like [X].
Expand Down Expand Up @@ -140,11 +142,11 @@ public TWindowElement()
return switch(context.getInputType())
{
//LMB mouse press returns true, so drag input can be handled
case MOUSE_PRESS -> context.getMouseButton() == 0;
case MOUSE_PRESS -> context.getMouseButton() == SDL_BUTTON_LEFT;
//mouse release stops the drag, so clear the drag values
case MOUSE_RELEASE -> {
//FIXME - Releasing another button causes this to yield false. This is an issue in the input system.
if(context.getMouseButton() != 0) yield false;
if(context.getMouseButton() != SDL_BUTTON_LEFT) yield false;
this.dragDeltaX = this.dragDeltaY = 0;
TGuiUtils.keepElementWithinBounds(this, getParent().getBounds());
yield true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.thecsdev.commonmc.api.client.gui.render;

import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.platform.cursor.CursorType;
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
import com.thecsdev.common.util.annotations.Virtual;
import com.thecsdev.commonmc.api.client.gui.TElement;
import com.thecsdev.commonmc.api.client.gui.screen.TScreen;
Expand All @@ -15,7 +15,7 @@
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.render.GuiRenderer;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
import net.minecraft.data.AtlasIds;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -159,7 +159,7 @@ protected TGuiGraphics(GuiGraphicsExtractor drawContext, int mouseX, int mouseY,
* @param color The sprite's ARGB color.
*/
public @Virtual void drawMissingNo(int x, int y, int width, int height, int color) {
drawGuiSprite(TextureManager.INTENTIONAL_MISSING_TEXTURE, x, y, width, height, color);
drawGuiSprite(MissingTextureAtlasSprite.getLocation(), x, y, width, height, color);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thecsdev.commonmc.api.client.gui.render;

import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
import com.thecsdev.commonmc.resource.TSprites;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Objects;
import java.util.function.Predicate;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.sdl.SDLScancode.*;

/**
* Same as {@link TScreen}, but with some extra features such as arrow-key
Expand Down Expand Up @@ -42,11 +42,11 @@ public TScreenPlus() {}
if(context.getInputType() == TInputContext.InputType.KEY_PRESS)
{
//obtain the direction based on the pressed key-code
final CompassDirection direction = switch(context.getKeyCode()) {
case GLFW_KEY_UP -> CompassDirection.NORTH;
case GLFW_KEY_DOWN -> CompassDirection.SOUTH;
case GLFW_KEY_LEFT -> CompassDirection.WEST;
case GLFW_KEY_RIGHT -> CompassDirection.EAST;
final CompassDirection direction = switch(context.getScanCode()) {
case SDL_SCANCODE_UP -> CompassDirection.NORTH;
case SDL_SCANCODE_DOWN -> CompassDirection.SOUTH;
case SDL_SCANCODE_LEFT -> CompassDirection.WEST;
case SDL_SCANCODE_RIGHT -> CompassDirection.EAST;
case null, default -> null;
};
if(direction == null) return false;
Expand Down Expand Up @@ -144,8 +144,8 @@ public TScreenPlus() {}
//multiplying the cross-axis by a weight (e.g., 4) makes the cursor strongly
//prefer jumping in a straight line rather than making wild diagonal jumps.
long distSq = switch(direction) {
case NORTH, SOUTH -> (dX * dX * 4) + (dY * dY); // Penalize X variance
case EAST, WEST -> (dX * dX) + (dY * dY * 4); // Penalize Y variance
case NORTH, SOUTH -> (dX * dX * 4) + (dY * dY); //penalize X variance
case EAST, WEST -> (dX * dX) + (dY * dY * 4); //penalize Y variance
default -> (dX * dX) + (dY * dY);
};

Expand Down
Loading
Loading