renamed some things, made IotaType.serialize actually check if custom iotas are too big.

This commit is contained in:
Talia-12 2023-07-10 19:38:54 +10:00
parent 3c426a89ee
commit 77aa0e7380
3 changed files with 10 additions and 5 deletions

View file

@ -227,8 +227,8 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
}
@Override
public void produceParticles(ParticleSpray particles, FrozenPigment colorizer) {
particles.sprayParticles(this.world, colorizer);
public void produceParticles(ParticleSpray particles, FrozenPigment pigment) {
particles.sprayParticles(this.world, pigment);
}
@Override

View file

@ -78,7 +78,7 @@ public abstract class Iota {
* This method is called to determine whether the iota is above the max serialisation depth/serialisation count
* limits. It should return every "iota" that is a subelement of this iota.
* For example, if you implemented a Map<Iota, Iota>, then it should be an iterable over the keys *and*
* values of the map. If you implemented a typed List<Double> iota for some reason, you should instad override
* values of the map. If you implemented a typed List<Double> iota for some reason, you should instead override
* {@link Iota#size}.
*/
public @Nullable Iterable<Iota> subIotas() {

View file

@ -17,6 +17,7 @@ import net.minecraft.util.FormattedCharSequence;
import javax.annotation.Nullable;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
// Take notes from ForgeRegistryEntry
@ -64,7 +65,7 @@ public abstract class IotaType<T extends Iota> {
}
// We check if it's too big on serialization; if it is we just return a garbage.
if (iota instanceof ListIota listIota && isTooLargeToSerialize(listIota.getList())) {
if (isTooLargeToSerialize(List.of(iota), 0)) {
// Garbage will never be too large so we just recurse
return serialize(new GarbageIota());
}
@ -76,12 +77,16 @@ public abstract class IotaType<T extends Iota> {
}
public static boolean isTooLargeToSerialize(Iterable<Iota> examinee) {
return isTooLargeToSerialize(examinee, 1);
}
private static boolean isTooLargeToSerialize(Iterable<Iota> examinee, int startingCount) {
// We don't recurse here, just a work queue (or work stack, if we liked.)
// Each element is a found sub-iota, and how deep it is.
//
// TODO: is it worth trying to cache the depth and size statically on a SpellList.
var listsToExamine = new ArrayDeque<>(Collections.singleton(new Pair<>(examinee, 0)));
int totalEltsFound = 1; // count the first list
int totalEltsFound = startingCount; // count the first list
while (!listsToExamine.isEmpty()) {
var iotaPair = listsToExamine.removeFirst();
var sublist = iotaPair.getFirst();