|
| 1 | +package dev.ftb.mods.ftbmaterials.config; |
| 2 | + |
| 3 | +import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; |
| 4 | +import dev.ftb.mods.ftblibrary.snbt.config.BaseValue; |
| 5 | +import dev.ftb.mods.ftblibrary.snbt.config.SNBTConfig; |
| 6 | +import net.minecraft.Util; |
| 7 | +import net.minecraft.nbt.CompoundTag; |
| 8 | +import org.jetbrains.annotations.Nullable; |
| 9 | + |
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +public class StringStringMapValue extends BaseValue<Map<String, Map<String,String>>> { |
| 14 | + protected StringStringMapValue(@Nullable SNBTConfig c, String n, Map<String, Map<String, String>> def) { |
| 15 | + super(c, n, def); |
| 16 | + |
| 17 | + super.set(new HashMap<>(def)); |
| 18 | + } |
| 19 | + |
| 20 | + @Override |
| 21 | + public void write(SNBTCompoundTag tag) { |
| 22 | + SNBTCompoundTag mapTag = new SNBTCompoundTag(); |
| 23 | + get().forEach((k, subMap) -> { |
| 24 | + mapTag.put(k, Util.make(new CompoundTag(), t -> subMap.forEach(t::putString))); |
| 25 | + }); |
| 26 | + |
| 27 | + tag.put(this.key, mapTag); |
| 28 | + comment.forEach(c -> tag.comment(key, c)); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void read(SNBTCompoundTag tag) { |
| 33 | + Map<String, Map<String, String>> map = new HashMap<>(); |
| 34 | + |
| 35 | + SNBTCompoundTag mapTag = tag.getCompound(key); |
| 36 | + for (String key : mapTag.getAllKeys()) { |
| 37 | + Map<String, String> subMap = new HashMap<>(); |
| 38 | + map.put(key, subMap); |
| 39 | + CompoundTag subTag = mapTag.getCompound(key); |
| 40 | + subTag.getAllKeys().forEach(k1 -> subMap.put(k1, subTag.getString(k1))); |
| 41 | + } |
| 42 | + |
| 43 | + set(map); |
| 44 | + } |
| 45 | +} |
0 commit comments