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

45 lines
1.3 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;
2022-03-26 20:34:15 +01:00
import net.minecraft.util.registry.RegistryEntry;
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;
public class WorldTribeManager extends PersistentState {
private Race defaultRace = Race.HUMAN;
2021-08-04 15:38:03 +02:00
public WorldTribeManager() {}
public WorldTribeManager(NbtCompound nbt) {
2022-08-27 15:07:29 +02:00
defaultRace = Race.fromName(nbt.getString("defaultRace"), Race.HUMAN);
}
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) {
2022-08-27 15:07:29 +02:00
tag.putString("defaultRace", Race.REGISTRY.getId(defaultRace).toString());
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";
}
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()));
}
}