Skip to content
Closed
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
11 changes: 7 additions & 4 deletions src/main/java/nofrills/features/dungeons/CroesusSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ private static void highlightLoot(ItemStack stack, Slot slot) {
if (color == null) return;
SlotOptions.setBackground(slot, color);
if (floorLabel.value()) {
String prefix = name.startsWith("Master Mode") ? "M" : "F";
String floorLine = Utils.getLoreLines(stack).getFirst();
int floor = Utils.parseRoman(floorLine.substring(floorLine.lastIndexOf(" ") + 1));
SlotOptions.setCount(slot, prefix + floor);
List<String> loreLines = Utils.getLoreLines(stack);
if (!loreLines.isEmpty()) {
String prefix = name.startsWith("Master Mode") ? "M" : "F";
String floorLine = loreLines.getFirst();
int floor = Utils.parseRoman(floorLine.substring(floorLine.lastIndexOf(" ") + 1));
SlotOptions.setCount(slot, prefix + floor);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private static boolean isEquipButton(Slot slot, int target) {
ItemStack stack = slot.getItem();
Item item = stack.getItem();
String name = Utils.toPlain(stack.getHoverName());
if (!stack.isEmpty() && target != -1 && name.startsWith(Utils.format("Slot {}:", target))) {
String prefix = Utils.format("Slot {}:", target);
if (!stack.isEmpty() && target != -1 && (name.equals(prefix) || name.startsWith(prefix + " "))) {
if (noUnequip.value() && item.equals(Items.LIME_DYE)) {
return false;
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/nofrills/features/kuudra/VesuviusSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ private static void highlightLoot(ItemStack stack, Slot slot) {
if (color == null) return;
SlotOptions.setBackground(slot, color);
if (tierLabel.value()) {
String tierLine = Utils.getLoreLines(stack).getFirst();
SlotOptions.setCount(slot, switch (tierLine) {
case "Hot Tier" -> "T2";
case "Burning Tier" -> "T3";
case "Fiery Tier" -> "T4";
case "Infernal Tier" -> "T5";
default -> "T1";
});
List<String> loreLines = Utils.getLoreLines(stack);
if (!loreLines.isEmpty()) {
String tierLine = loreLines.getFirst();
SlotOptions.setCount(slot, switch (tierLine) {
case "Hot Tier" -> "T2";
case "Burning Tier" -> "T3";
case "Fiery Tier" -> "T4";
case "Infernal Tier" -> "T5";
default -> "T1";
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nofrills/features/misc/NoDamageSplash.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class NoDamageSplash {

public static final SettingEnum<HideMode> mode = new SettingEnum<>(HideMode.Always, HideMode.class, "mode", instance);

private static final Pattern pattern = Pattern.compile("[0-9]*");
private static final Pattern pattern = Pattern.compile("[0-9]+");

private static boolean isActive() {
if (instance.isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void updateSpeedSlot(ChestMenu handler) {

)));
SlotOptions.setSpoofed(handler.getSlot(speedSlot1Id), SlotOptions.stackWithName(
SlotOptions.stackWithCount(stack, changeSpeed),
SlotOptions.stackWithCount(stack, Math.max(1, changeSpeed)),
Component.literal("Speed").withStyle(style -> style.withItalic(false).withColor(ChatFormatting.YELLOW))
));
}
Expand Down Expand Up @@ -151,7 +151,7 @@ private static void updateColorSlot(ChestMenu handler) {
stack = Items.WHITE_WOOL.getDefaultInstance();
}
SlotOptions.setSpoofed(handler.getSlot(colorSlot1Id), SlotOptions.stackWithName(
SlotOptions.stackWithCount(stack, Math.abs(colorTarget1)),
SlotOptions.stackWithCount(stack, Math.max(1, Math.abs(colorTarget1))),
Component.literal("Color").withStyle(style -> style.withItalic(false).withColor(ChatFormatting.YELLOW))
));
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/nofrills/hud/elements/DungeonMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,16 @@ public void onMapUpdate(ClientboundMapItemDataPacket packet) {
packet.colorPatch().ifPresent(data -> {
byte[] colors = data.mapColors();
NativeImage nativeImage = mapTexture.getPixels();
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 128; j++) {
int k = j + i * 128;
nativeImage.setPixel(j, i, MapColor.getColorFromPackedId(colors[k]));
int startX = data.startX();
int startY = data.startY();
int width = data.width();
int height = data.height();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int k = j + i * width;
if (k < colors.length && startX + j < 128 && startY + i < 128) {
nativeImage.setPixel(startX + j, startY + i, MapColor.getColorFromPackedId(colors[k]));
}
}
}
mapTexture.upload();
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/nofrills/misc/CurveSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ public void addPos(Vec3 pos) {
this.activeTicks = this.activeDuration;
this.clearTicks = this.clearDuration;
if (this.particleList.size() > 3) {
this.solvedPos = solve();
Vec3 solution = solve();
if (solution != null) {
this.solvedPos = solution;
}
}
}

public double getLastDist(Vec3 pos) {
return !this.particleList.isEmpty() ? this.particleList.getLast().distanceTo(pos) : this.startPos.distanceTo(pos);
return !this.particleList.isEmpty() ? this.particleList.getLast().distanceTo(pos) : (this.startPos != null ? this.startPos.distanceTo(pos) : 0.0);
}

public Optional<Vec3> getSolvedPos() {
Expand All @@ -104,6 +107,7 @@ private double calculateT(double[] vec) {

private Vec3 solve() {
double[][] res = fitter3D.fit();
if (res == null || res.length < 2) return null;
double[] deriv_0 = new double[3];
for (int i = 0; i < 3; i++) {
deriv_0[i] = res[1][i] / 3;
Expand Down Expand Up @@ -140,14 +144,18 @@ public void addPoint(double x, double y) {
}

public double[] fit() {
Matrix xMatrixTransposed = this.xMatrix.transpose();
Matrix result = xMatrixTransposed
.times(this.xMatrix)
.inverse()
.times(xMatrixTransposed)
.times(this.yMatrix)
.transpose();
return result.getArray()[0];
try {
Matrix xMatrixTransposed = this.xMatrix.transpose();
Matrix result = xMatrixTransposed
.times(this.xMatrix)
.inverse()
.times(xMatrixTransposed)
.times(this.yMatrix)
.transpose();
return result.getArray()[0];
} catch (RuntimeException ignored) {
return null;
}
}

public void clear() {
Expand Down Expand Up @@ -175,7 +183,9 @@ public void addPoint(double t, Vec3 point) {
public double[][] fit() {
double[][] coefficients = new double[3][];
for (int i = 0; i < 3; i++) {
coefficients[i] = this.fitters[i].fit();
double[] res = this.fitters[i].fit();
if (res == null) return null;
coefficients[i] = res;
}
return new Matrix(coefficients).transpose().getArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/nofrills/misc/RenderColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RenderColor(float r, float g, float b, float a) {
this.g = Math.clamp(g, 0.0f, 1.0f);
this.b = Math.clamp(b, 0.0f, 1.0f);
this.a = Math.clamp(a, 0.0f, 1.0f);
this.hex = (((int) this.r * 255) << 16) + (((int) this.g * 255) << 8) + ((int) this.b * 255);
this.hex = ((int) (this.r * 255) << 16) + ((int) (this.g * 255) << 8) + (int) (this.b * 255);
this.argb = ARGB.colorFromFloat(this.a, this.r, this.g, this.b);
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/nofrills/misc/SlotOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public class SlotOptions {
public static final ConcurrentHashMap<Slot, Flags> slotFlags = new ConcurrentHashMap<>();

public static ItemStack stackWithName(ItemStack stack, String name) {
stack.set(DataComponents.CUSTOM_NAME, Component.nullToEmpty(name));
if (!stack.isEmpty()) {
stack.set(DataComponents.CUSTOM_NAME, Component.nullToEmpty(name));
}
return stack;
}

public static ItemStack stackWithName(ItemStack stack, Component name) {
stack.set(DataComponents.CUSTOM_NAME, name);
if (!stack.isEmpty()) {
stack.set(DataComponents.CUSTOM_NAME, name);
}
return stack;
}

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/nofrills/mixin/StringDecomposerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
@Mixin(StringDecomposer.class)
public class StringDecomposerMixin {

private static final ThreadLocal<Boolean> IS_REPLACING = ThreadLocal.withInitial(() -> false);

@WrapOperation(method = "iterateFormatted(Ljava/lang/String;ILnet/minecraft/network/chat/Style;Lnet/minecraft/util/FormattedCharSink;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/StringDecomposer;iterateFormatted(Ljava/lang/String;ILnet/minecraft/network/chat/Style;Lnet/minecraft/network/chat/Style;Lnet/minecraft/util/FormattedCharSink;)Z"))
private static boolean onVisitFormatted(String string, int offset, Style currentStyle, Style resetStyle, FormattedCharSink output, Operation<Boolean> original) {
if (StreamerMode.isActive()) {
Optional<String> replacement = StreamerMode.replaceIfNeeded(string);
if (replacement.isPresent()) {
return original.call(replacement.get(), offset, currentStyle, resetStyle, output);
if (!IS_REPLACING.get() && StreamerMode.isActive()) {
IS_REPLACING.set(true);
try {
Optional<String> replacement = StreamerMode.replaceIfNeeded(string);
if (replacement.isPresent()) {
return original.call(replacement.get(), offset, currentStyle, resetStyle, output);
}
} finally {
IS_REPLACING.set(false);
}
}
return original.call(string, offset, currentStyle, resetStyle, output);
Expand Down
Loading