Unicopia/src/main/java/com/minelittlepony/unicopia/WorldTribeManager.java

41 lines
1.2 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia;
2021-08-04 15:38:03 +02:00
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentState;
import net.minecraft.world.dimension.DimensionType;
public class WorldTribeManager extends PersistentState {
private Race defaultRace = Unicopia.getConfig().preferredRace.get();
2021-08-04 15:38:03 +02:00
public WorldTribeManager() {}
public WorldTribeManager(NbtCompound nbt) {
defaultRace = Race.fromName(nbt.getString("defaultRace"));
}
public Race getDefaultRace() {
return defaultRace;
}
public Race setDefaultRace(Race race) {
return defaultRace = race;
}
@Override
2021-08-04 15:38:03 +02:00
public NbtCompound writeNbt(NbtCompound tag) {
tag.putString("defaultRace", defaultRace.name());
return tag;
}
2021-12-23 23:38:02 +01:00
@SuppressWarnings("deprecation")
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()));
}
}