2020-09-23 21:56:57 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import net.minecraft.nbt.NbtCompound;
|
2020-09-23 21:56:57 +02:00
|
|
|
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
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
public WorldTribeManager() {}
|
|
|
|
|
|
|
|
public WorldTribeManager(NbtCompound nbt) {
|
|
|
|
defaultRace = Race.fromName(nbt.getString("defaultRace"));
|
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
|
2021-08-04 15:38:03 +02:00
|
|
|
public NbtCompound writeNbt(NbtCompound tag) {
|
2020-09-23 21:56:57 +02:00
|
|
|
tag.putString("defaultRace", defaultRace.name());
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2021-12-23 23:38:02 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2020-09-23 21:56:57 +02:00
|
|
|
public static String nameFor(DimensionType dimension) {
|
|
|
|
return "unicopia:tribes" + dimension.getSuffix();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WorldTribeManager forWorld(ServerWorld world) {
|
2021-08-04 15:38:03 +02:00
|
|
|
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, nameFor(world.getDimension()));
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
|
|
|
}
|