mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-20 20:12:27 +00:00
46 lines
1.4 KiB
Java
46 lines
1.4 KiB
Java
package me.towdium.jecalculation.data.structure;
|
|
|
|
import me.towdium.jecalculation.data.label.ILabel;
|
|
import me.towdium.jecalculation.polyfill.NBTHelper;
|
|
import me.towdium.jecalculation.utils.Utilities;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.StreamSupport;
|
|
|
|
public class Recents {
|
|
public static final String IDENTIFIER = "recent";
|
|
Utilities.Recent<ILabel> record = new Utilities.Recent<>((a, b) -> a == ILabel.EMPTY || a.equals(b), 9);
|
|
|
|
public Recents(NBTTagList nbt) {
|
|
List<ILabel> ls = StreamSupport.stream(NBTHelper.spliterator(nbt), false)
|
|
.filter(n -> n instanceof NBTTagCompound)
|
|
.map(n -> ILabel.DESERIALIZER.deserialize((NBTTagCompound) n))
|
|
.collect(Collectors.toList());
|
|
new Utilities.ReversedIterator<>(ls).forEachRemaining(l -> record.push(l));
|
|
}
|
|
|
|
public Recents() {
|
|
}
|
|
|
|
public void push(ILabel label) {
|
|
record.push(label);
|
|
}
|
|
|
|
public ILabel getLatest() {
|
|
return record.toList().get(0);
|
|
}
|
|
|
|
public List<ILabel> getRecords() {
|
|
return record.toList();
|
|
}
|
|
|
|
public NBTTagList serialize() {
|
|
NBTTagList ret = new NBTTagList();
|
|
record.toList().forEach(l -> ret.appendTag(ILabel.DESERIALIZER.serialize(l)));
|
|
return ret;
|
|
}
|
|
}
|