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;
|
2022-03-26 20:34:15 +01:00
|
|
|
import net.minecraft.util.registry.RegistryEntry;
|
2020-09-23 21:56:57 +02:00
|
|
|
import net.minecraft.world.PersistentState;
|
|
|
|
import net.minecraft.world.dimension.DimensionType;
|
2022-06-25 00:19:55 +02:00
|
|
|
import net.minecraft.world.dimension.DimensionTypes;
|
2020-09-23 21:56:57 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-26 20:34:15 +01:00
|
|
|
public static String nameFor(RegistryEntry<DimensionType> dimension) {
|
2022-06-25 00:19:55 +02:00
|
|
|
if (dimension.matchesKey(DimensionTypes.THE_END)) {
|
2022-03-26 20:34:15 +01:00
|
|
|
return "unicopia:tribes_end";
|
|
|
|
}
|
|
|
|
return "unicopia:tribes";
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static WorldTribeManager forWorld(ServerWorld world) {
|
2022-06-25 00:19:55 +02:00
|
|
|
return world.getPersistentStateManager().getOrCreate(WorldTribeManager::new, WorldTribeManager::new, nameFor(world.getDimensionEntry()));
|
2020-09-23 21:56:57 +02:00
|
|
|
}
|
|
|
|
}
|