mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-22 17:37:38 +00:00
Fix crash when joining a dedicated server
We can't use FriendlyByte.readCollection to read to a pre-allocated/array-backed NonNullList, as that doesn't implement List.add. Instead, we just need to do a normal loop. We add a couple of tests to round-trip our recipe specs. Unfortunately we can't test the recipes themselves as our own registries aren't set up, so this'll have to do for now.
This commit is contained in:
@@ -100,6 +100,29 @@ final class StructuralEqualities {
|
||||
}
|
||||
}
|
||||
|
||||
record ListEquality<T>(StructuralEquality<T> equality) implements StructuralEquality<List<T>> {
|
||||
@Override
|
||||
public boolean equals(List<T> left, List<T> right) {
|
||||
if (left.size() != right.size()) return false;
|
||||
for (var i = 0; i < left.size(); i++) {
|
||||
if (!equality.equals(left.get(i), right.get(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describe(Description description, List<T> object) {
|
||||
description.appendText("[");
|
||||
var separator = false;
|
||||
for (var value : object) {
|
||||
if (separator) description.appendText(", ");
|
||||
separator = true;
|
||||
equality.describe(description, value);
|
||||
}
|
||||
description.appendText("]");
|
||||
}
|
||||
}
|
||||
|
||||
static final class EqualityMatcher<T> extends TypeSafeMatcher<T> {
|
||||
private final StructuralEquality<T> equality;
|
||||
private final T equalTo;
|
||||
|
@@ -36,6 +36,15 @@ public interface StructuralEquality<T> {
|
||||
*/
|
||||
void describe(Description description, T object);
|
||||
|
||||
/**
|
||||
* Lift this equality to a list of values.
|
||||
*
|
||||
* @return A equality for a list of values.
|
||||
*/
|
||||
default StructuralEquality<List<T>> list() {
|
||||
return new StructuralEqualities.ListEquality<>(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this equality instance to a {@link Matcher}.
|
||||
*
|
||||
|
Reference in New Issue
Block a user