2020-09-23 21:56:57 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
import net.minecraft.world.PersistentState;
|
|
|
|
import net.minecraft.world.dimension.DimensionType;
|
|
|
|
|
|
|
|
public class WorldTribeManager extends PersistentState {
|
|
|
|
|
2021-02-07 18:57:35 +01:00
|
|
|
private Race defaultRace = Unicopia.getConfig().preferredRace.get();
|
2020-09-23 21:56:57 +02:00
|
|
|
|
|
|
|
public WorldTribeManager(ServerWorld world) {
|
2021-01-26 21:32:19 +01:00
|
|
|
super(nameFor(world.getDimension()));
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Race getDefaultRace() {
|
|
|
|
return defaultRace;
|
|
|
|
}
|
|
|
|
|
2021-02-07 18:57:35 +01:00
|
|
|
public Race setDefaultRace(Race race) {
|
|
|
|
return defaultRace = race;
|
|
|
|
}
|
|
|
|
|
2020-09-23 21:56:57 +02:00
|
|
|
@Override
|
|
|
|
public void fromTag(CompoundTag tag) {
|
|
|
|
defaultRace = Race.fromName(tag.getString("defaultRace"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CompoundTag toTag(CompoundTag tag) {
|
|
|
|
tag.putString("defaultRace", defaultRace.name());
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String nameFor(DimensionType dimension) {
|
|
|
|
return "unicopia:tribes" + dimension.getSuffix();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WorldTribeManager forWorld(ServerWorld world) {
|
|
|
|
return world.getPersistentStateManager().getOrCreate(() -> new WorldTribeManager(world), nameFor(world.getDimension()));
|
|
|
|
}
|
|
|
|
}
|