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 @@ -19,10 +19,11 @@
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -79,27 +80,32 @@ protected void apply(@NotNull Map<ResourceLocation, JsonElement> jsons, @NotNull
BOX_CACHE.clear();
}

public static boolean onBlockHighlight(Vec3 cameraPos, Entity cameraEntity, PoseStack stack, BlockPos blockPos, BlockState state, VertexConsumer consumer, int color) {
public static @Nullable HighlightRenderState extractState(Level level, BlockPos pos, BlockState state) {
if (state.getBlock() instanceof Highlightable highlightable) {
var highlight = highlightable.getHighlight(cameraEntity.level(), blockPos, state);
var highlight = highlightable.getHighlight(level, pos, state);
if (highlight != null) {
highlight.render(consumer, stack, cameraPos, state.getOffset(blockPos), blockPos);
return true;
return new HighlightRenderState.Dynamic(highlight, state.getOffset(pos));
}
}
if (STATE_CACHE.containsKey(state)) {
Vec3 offset = state.getOffset(blockPos);
return new HighlightRenderState.Cached(STATE_CACHE.get(state), state.getOffset(pos));
}
return null;
}

public static boolean onBlockHighlight(Vec3 cameraPos, PoseStack stack, BlockPos pos, HighlightRenderState state, VertexConsumer consumer, int color) {
if (state instanceof HighlightRenderState.Dynamic(var highlight, var offset)) {
highlight.render(consumer, stack, cameraPos, offset, pos);
return true;
} else if (state instanceof HighlightRenderState.Cached(var lines, var offset) && lines.length % 9 == 0) {
stack.pushPose();
float x = (float) (blockPos.getX() - cameraPos.x());
float y = (float) (blockPos.getY() - cameraPos.y());
float z = (float) (blockPos.getZ() - cameraPos.z());
float x = (float) (pos.getX() - cameraPos.x());
float y = (float) (pos.getY() - cameraPos.y());
float z = (float) (pos.getZ() - cameraPos.z());
x += (float) offset.x();
y += (float) offset.y();
z += (float) offset.z();

float[] lines = STATE_CACHE.get(state);
if (lines.length % 9 != 0) return false;

for (int i = 0; i < lines.length; i += 9) {
HighlightLine.render(
stack, consumer,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.teamresourceful.resourcefullib.client.highlights;

import com.teamresourceful.resourcefullib.client.highlights.base.Highlight;
import net.minecraft.world.phys.Vec3;

public sealed interface HighlightRenderState {

Vec3 offset();

record Dynamic(Highlight highlight, Vec3 offset) implements HighlightRenderState {}
record Cached(float[] data, Vec3 offset) implements HighlightRenderState {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.teamresourceful.resourcefullib.client.screens;

import com.teamresourceful.resourcefullib.client.utils.CursorUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
Expand All @@ -10,40 +9,15 @@

public abstract class AbstractContainerCursorScreen<T extends AbstractContainerMenu> extends AbstractContainerScreen<T> implements CursorScreen {

private Cursor cursor = Cursor.DEFAULT;

public AbstractContainerCursorScreen(T abstractContainerMenu, Inventory inventory, Component component) {
super(abstractContainerMenu, inventory, component);
}

@Override
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) {
setCursor(Cursor.DEFAULT);
super.render(graphics, mouseX, mouseY, f);
setCursor(children(), mouseX, mouseY);

switch (cursor) {
case DEFAULT -> CursorUtils.setDefault();
case POINTER -> CursorUtils.setPointing();
case DISABLED -> CursorUtils.setDisabled();
case TEXT -> CursorUtils.setText();
case CROSSHAIR -> CursorUtils.setCrosshair();
case RESIZE_EW -> CursorUtils.setResizeEastWest();
case RESIZE_NS -> CursorUtils.setResizeNorthSouth();
case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest();
case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast();
case RESIZE_ALL -> CursorUtils.setResizeAll();
if (this.getRectangle().containsPoint(mouseX, mouseY)) {
applyCursor(graphics, children(), mouseX, mouseY);
}
}

@Override
public void removed() {
super.removed();
CursorUtils.setDefault();
}

@Override
public void setCursor(Cursor cursor) {
this.cursor = cursor;
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
package com.teamresourceful.resourcefullib.client.screens;

import com.teamresourceful.resourcefullib.client.utils.CursorUtils;
import com.teamresourceful.resourcefullib.client.utils.ScreenUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;

public abstract class BaseCursorScreen extends Screen implements CursorScreen {

private Cursor cursor = Cursor.DEFAULT;

protected BaseCursorScreen(Component component) {
super(component);
}

@Override
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) {
boolean wihinBounds = ScreenUtils.inBounds(this.getRectangle(), mouseX, mouseY);
if (!wihinBounds) {
actuallyRender(graphics, mouseX, mouseY, f);
} else {
setCursor(Cursor.DEFAULT);
actuallyRender(graphics, mouseX, mouseY, f);
setCursor(children(), mouseX, mouseY);

switch (cursor) {
case DEFAULT -> CursorUtils.setDefault();
case POINTER -> CursorUtils.setPointing();
case DISABLED -> CursorUtils.setDisabled();
case TEXT -> CursorUtils.setText();
case CROSSHAIR -> CursorUtils.setCrosshair();
case RESIZE_EW -> CursorUtils.setResizeEastWest();
case RESIZE_NS -> CursorUtils.setResizeNorthSouth();
case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest();
case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast();
case RESIZE_ALL -> CursorUtils.setResizeAll();
}
super.render(graphics, mouseX, mouseY, f);
if (this.getRectangle().containsPoint(mouseX, mouseY)) {
applyCursor(graphics, children(), mouseX, mouseY);
}
}

public void actuallyRender(@NotNull GuiGraphics graphics, int i, int j, float f) {
super.render(graphics, i, j, f);
}

@Override
public void removed() {
super.removed();
CursorUtils.setDefault();
}

@Override
public void setCursor(Cursor cursor) {
this.cursor = cursor;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.teamresourceful.resourcefullib.client.screens;

import com.mojang.blaze3d.platform.cursor.CursorType;
import com.mojang.blaze3d.platform.cursor.CursorTypes;
import com.teamresourceful.resourcefullib.client.components.CursorWidget;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.MultiLineEditBox;
Expand All @@ -10,36 +13,34 @@

public interface CursorScreen {

void setCursor(Cursor cursor);


default void setCursor(List<? extends GuiEventListener> listeners, double mouseX, double mouseY) {
default void applyCursor(GuiGraphics graphics, List<? extends GuiEventListener> listeners, double mouseX, double mouseY) {
for (GuiEventListener child : listeners) {
boolean hovered = child.isMouseOver(mouseX, mouseY);
if (child instanceof CursorWidget widget && hovered) {
setCursor(widget.getCursor());
break;
} else if (child instanceof AbstractWidget widget && hovered && widget.visible) {
if (widget.active) {
setCursor(widget instanceof EditBox || widget instanceof MultiLineEditBox ? Cursor.TEXT : Cursor.POINTER);
} else {
setCursor(Cursor.DISABLED);
}
if (child instanceof CursorWidget widget && child.isMouseOver(mouseX, mouseY)) {
widget.getCursor().apply(graphics);
break;
}
}
}

enum Cursor {
DEFAULT,
POINTER,
DISABLED,
TEXT,
CROSSHAIR,
RESIZE_EW,
RESIZE_NS,
RESIZE_NWSE,
RESIZE_NESW,
RESIZE_ALL
DEFAULT(CursorType.DEFAULT),
POINTER(CursorTypes.POINTING_HAND),
DISABLED(CursorTypes.NOT_ALLOWED),
TEXT(CursorTypes.IBEAM),
CROSSHAIR(CursorTypes.CROSSHAIR),
RESIZE_EW(CursorTypes.RESIZE_EW),
RESIZE_NS(CursorTypes.RESIZE_NS),
RESIZE_ALL(CursorTypes.RESIZE_ALL),
;

private final CursorType type;

Cursor(CursorType type) {
this.type = type;
}

public void apply(GuiGraphics graphics) {
graphics.requestCursor(this.type);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ private static long mean(long[] values) {

private static String getPing(Minecraft mc) {
var logger = mc.getDebugOverlay().getPingLogger();
if (logger.size() == 0) {
return "N/A";
}

long min = Long.MAX_VALUE;
long max = Long.MIN_VALUE;
long sum = 0L;

for (int i = 0; i < logger.capacity(); i++) {
for (int i = 0; i < logger.size(); i++) {
long sample = logger.get(i);
min = Math.min(min, sample);
max = Math.max(max, sample);
sum += sample;
}

return "%.2f avg ms / %d min ms / %d max ms".formatted(
sum / (double) logger.capacity(),
sum / (double) logger.size(),
min,
max
);
Expand Down

This file was deleted.

Loading
Loading