mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-28 11:29:19 +00:00
3.5.6
This commit is contained in:
@@ -20,7 +20,9 @@ package net.momirealms.customcrops.api.mechanic.world;
|
||||
import com.flowpowered.nbt.CompoundMap;
|
||||
import com.flowpowered.nbt.Tag;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
@@ -64,4 +66,28 @@ public class SynchronizedCompoundMap {
|
||||
SynchronizedCompoundMap that = (SynchronizedCompoundMap) o;
|
||||
return Objects.equals(compoundMap, that.compoundMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return compoundMapToString(compoundMap);
|
||||
}
|
||||
|
||||
private String compoundMapToString(CompoundMap compoundMap) {
|
||||
StringJoiner joiner = new StringJoiner(", ");
|
||||
for (Map.Entry<String, Tag<?>> entry : compoundMap.entrySet()) {
|
||||
Tag<?> tag = entry.getValue();
|
||||
String tagValue;
|
||||
switch (tag.getType()) {
|
||||
case TAG_STRING, TAG_BYTE, TAG_DOUBLE, TAG_FLOAT, TAG_INT, TAG_INT_ARRAY, TAG_LONG, TAG_SHORT, TAG_SHORT_ARRAY, TAG_LONG_ARRAY, TAG_BYTE_ARRAY ->
|
||||
tagValue = tag.getValue().toString();
|
||||
case TAG_COMPOUND -> tagValue = compoundMapToString(tag.getAsCompoundTag().get().getValue());
|
||||
case TAG_LIST -> tagValue = tag.getAsListTag().get().getValue().toString();
|
||||
default -> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
joiner.add("\"" + entry.getKey() + "\":\"" + tagValue + "\"");
|
||||
}
|
||||
return "{" + joiner + "}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user