mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-25 06:17:59 +01:00
39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
|
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 {
|
||
|
|
||
|
private Race defaultRace = Unicopia.getConfig().getPrefferedRace();
|
||
|
|
||
|
public WorldTribeManager(ServerWorld world) {
|
||
|
super("unicopia:tribes" + world.getDimension().getSuffix());
|
||
|
}
|
||
|
|
||
|
public Race getDefaultRace() {
|
||
|
return defaultRace;
|
||
|
}
|
||
|
|
||
|
@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()));
|
||
|
}
|
||
|
}
|