use of net.minecraft.world.DimensionType in project SpongeCommon by SpongePowered.
the class WorldManager method registerExistingSpongeDimensions.
/**
* Handles registering existing Sponge dimensions that are not the root dimension (known as overworld).
*/
private static void registerExistingSpongeDimensions(Path rootPath) {
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(rootPath, LEVEL_AND_SPONGE)) {
for (Path worldPath : stream) {
final Path spongeLevelPath = worldPath.resolve("level_sponge.dat");
final String worldFolderName = worldPath.getFileName().toString();
NBTTagCompound compound;
try {
compound = CompressedStreamTools.readCompressed(Files.newInputStream(spongeLevelPath));
} catch (IOException e) {
SpongeImpl.getLogger().error("Failed loading Sponge data for World [{}]}. Report to Sponge ASAP.", worldFolderName, e);
continue;
}
NBTTagCompound spongeDataCompound = compound.getCompoundTag(NbtDataUtil.SPONGE_DATA);
if (!compound.hasKey(NbtDataUtil.SPONGE_DATA)) {
SpongeImpl.getLogger().error("World [{}] has Sponge related data in the form of [level-sponge.dat] but the structure is not proper." + " Generally, the data is within a [{}] tag but it is not for this world. Report to Sponge ASAP.", worldFolderName, NbtDataUtil.SPONGE_DATA);
continue;
}
if (!spongeDataCompound.hasKey(NbtDataUtil.DIMENSION_ID)) {
SpongeImpl.getLogger().error("World [{}] has no dimension id. Report this to Sponge ASAP.", worldFolderName);
continue;
}
int dimensionId = spongeDataCompound.getInteger(NbtDataUtil.DIMENSION_ID);
if (dimensionId == Integer.MIN_VALUE) {
// temporary fix for existing worlds created with wrong dimension id
dimensionId = WorldManager.getNextFreeDimensionId();
}
// We do not handle Vanilla dimensions, skip them
if (dimensionId == 0 || dimensionId == -1 || dimensionId == 1) {
continue;
}
spongeDataCompound = DataUtil.spongeDataFixer.process(FixTypes.LEVEL, spongeDataCompound);
String dimensionTypeId = "overworld";
if (spongeDataCompound.hasKey(NbtDataUtil.DIMENSION_TYPE)) {
dimensionTypeId = spongeDataCompound.getString(NbtDataUtil.DIMENSION_TYPE);
} else {
SpongeImpl.getLogger().warn("World [{}] (DIM{}) has no specified dimension type. Defaulting to [{}}]...", worldFolderName, dimensionId, DimensionTypes.OVERWORLD.getName());
}
dimensionTypeId = fixDimensionTypeId(dimensionTypeId);
org.spongepowered.api.world.DimensionType dimensionType = Sponge.getRegistry().getType(org.spongepowered.api.world.DimensionType.class, dimensionTypeId).orElse(null);
if (dimensionType == null) {
SpongeImpl.getLogger().warn("World [{}] (DIM{}) has specified dimension type that is not registered. Skipping...", worldFolderName, dimensionId);
continue;
}
spongeDataCompound.setString(NbtDataUtil.DIMENSION_TYPE, dimensionTypeId);
if (!spongeDataCompound.hasUniqueId(NbtDataUtil.UUID)) {
SpongeImpl.getLogger().error("World [{}] (DIM{}) has no valid unique identifier. This is a critical error and should be reported" + " to Sponge ASAP.", worldFolderName, dimensionId);
continue;
}
worldFolderByDimensionId.put(dimensionId, worldFolderName);
registerDimensionPath(dimensionId, rootPath.resolve(worldFolderName));
registerDimension(dimensionId, (DimensionType) (Object) dimensionType);
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.minecraft.world.DimensionType in project EnderIO by SleepyTrousers.
the class TelepadTarget method getDimenionName.
@Nonnull
public static String getDimenionName(int dim) {
if (!DimensionManager.isDimensionRegistered(dim)) {
return Integer.toString(dim);
}
DimensionType type = DimensionManager.getProviderType(dim);
if (type == null) {
return Integer.toString(dim);
}
String name = type.getName();
int[] dims = DimensionManager.getDimensions(type);
if (dims != null && dims.length > 1) {
name += " " + dim;
}
return name;
}
use of net.minecraft.world.DimensionType in project BiomeTweaker by superckl.
the class BiomeTweaker method generateOutputFiles.
public void generateOutputFiles() throws IOException {
LogHelper.info("Generating Biome status report...");
final JsonArray array = new JsonArray();
final Iterator<Biome> it = Biome.REGISTRY.iterator();
while (it.hasNext()) {
final Biome gen = it.next();
if (gen == null)
continue;
array.add(BiomeHelper.fillJsonObject(gen));
}
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
final File baseDir = new File(this.config.getBtConfigFolder(), "output/");
final File biomeDir = new File(baseDir, "/biome/");
biomeDir.mkdirs();
for (final File file : biomeDir.listFiles()) if (file.getName().endsWith(".json"))
file.delete();
if (this.config.isOutputSeperateFiles())
for (final JsonElement element : array) {
final JsonObject obj = (JsonObject) element;
final StringBuilder fileName = new StringBuilder(obj.get("Name").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(" (").append(obj.get("Resource Location").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(")").append(".json");
final File biomeOutput = new File(biomeDir, fileName.toString());
if (biomeOutput.exists())
biomeOutput.delete();
biomeOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(biomeOutput));
writer.newLine();
writer.write(gson.toJson(obj));
}
else {
final File biomeOutput = new File(biomeDir, "BiomeTweaker - Biome Status Report.json");
if (biomeOutput.exists())
biomeOutput.delete();
biomeOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(biomeOutput));
writer.write("//Yeah, it's a doozy.");
writer.newLine();
writer.write(gson.toJson(array));
}
LogHelper.info("Generating LivingEntity status report...");
final File entityDir = new File(baseDir, "/entity/");
entityDir.mkdirs();
for (final File file : entityDir.listFiles()) if (file.getName().endsWith(".json"))
file.delete();
final Iterator<EntityEntry> entityIt = ForgeRegistries.ENTITIES.getValues().iterator();
final JsonArray entityArray = new JsonArray();
while (entityIt.hasNext()) {
final EntityEntry entry = entityIt.next();
if (!EntityLiving.class.isAssignableFrom(entry.getEntityClass()))
continue;
entityArray.add(EntityHelper.populateObject(entry));
}
if (this.config.isOutputSeperateFiles())
for (final JsonElement ele : entityArray) {
final JsonObject obj = (JsonObject) ele;
final StringBuilder fileName = new StringBuilder(obj.get("Name").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(" (").append(obj.get("Registry ID").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(")").append(".json");
final File entityOutput = new File(entityDir, fileName.toString());
if (entityOutput.exists())
entityOutput.delete();
entityOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(entityOutput));
writer.newLine();
writer.write(gson.toJson(obj));
}
else {
final File entityOutput = new File(entityDir, "BiomeTweaker - EntityLiving Status Report.json");
if (entityOutput.exists())
entityOutput.delete();
entityOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(entityOutput));
writer.write("//Yeah, it's a doozy.");
writer.newLine();
writer.write(gson.toJson(entityArray));
}
LogHelper.info("Generating Dimension status report...");
final File dimDir = new File(baseDir, "/dimension/");
dimDir.mkdirs();
for (final File file : dimDir.listFiles()) if (file.getName().endsWith(".json"))
file.delete();
final DimensionType[] dimTypes = DimensionType.values();
final JsonArray dimArray = new JsonArray();
for (final DimensionType dimType : dimTypes) dimArray.add(DimensionHelper.populateObject(dimType));
if (this.config.isOutputSeperateFiles())
for (final JsonElement ele : dimArray) {
final JsonObject obj = (JsonObject) ele;
final StringBuilder fileName = new StringBuilder(obj.get("Name").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(" (").append(obj.get("Suffix").getAsString().replaceAll("[^a-zA-Z0-9.-]", "_")).append(")").append(".json");
final File dimOutput = new File(dimDir, fileName.toString());
if (dimOutput.exists())
dimOutput.delete();
dimOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(dimOutput));
writer.newLine();
writer.write(gson.toJson(obj));
}
else {
final File dimOutput = new File(entityDir, "BiomeTweaker - Dimension Status Report.json");
if (dimOutput.exists())
dimOutput.delete();
dimOutput.createNewFile();
@Cleanup final BufferedWriter writer = new BufferedWriter(new FileWriter(dimOutput));
writer.write("//Yeah, it's a doozy.");
writer.newLine();
writer.write(gson.toJson(entityArray));
}
}
use of net.minecraft.world.DimensionType in project SpongeForge by SpongePowered.
the class MixinDimensionManager method createProviderFor.
@Overwrite
public static WorldProvider createProviderFor(int dim) {
final DimensionType dimensionType = WorldManager.getDimensionType(dim).orElseThrow(() -> new RuntimeException("Attempt to create " + "provider for dimension id [" + dim + "] failed because it has not been registered!"));
try {
final WorldProvider provider = dimensionType.createDimension();
provider.setDimension(dim);
return provider;
} catch (Exception e) {
throw new RuntimeException("Failed to create provider for dimension id [" + dim + "]!");
}
}
use of net.minecraft.world.DimensionType in project SpongeForge by SpongePowered.
the class MixinDimensionManager method initDimension.
/**
* @author Zidane - June 2nd, 2016
* @reason Forge's initDimension is very different from Sponge's multi-world. We basically rig it into our system so mods work.
* @param dim The dimension to load
*/
@Overwrite
public static void initDimension(int dim) {
// World is already loaded, bail
if (WorldManager.getWorldByDimensionId(dim).isPresent()) {
return;
}
if (dim == 0) {
throw new RuntimeException("Attempt made to initialize overworld!");
}
WorldManager.getWorldByDimensionId(0).orElseThrow(() -> new RuntimeException("Attempt made to initialize " + "dimension before overworld is loaded!"));
DimensionType dimensionType = WorldManager.getDimensionType(dim).orElse(null);
if (dimensionType == null) {
SpongeImpl.getLogger().warn("Attempt made to initialize dimension id {} which isn't registered!" + ", falling back to overworld.", dim);
return;
}
final WorldProvider provider = dimensionType.createDimension();
// make sure to set the dimension id to avoid getting a null save folder
provider.setDimension(dim);
String worldFolder = WorldManager.getWorldFolderByDimensionId(dim).orElse(provider.getSaveFolder());
WorldProperties properties = WorldManager.getWorldProperties(worldFolder).orElse(null);
final Path worldPath = WorldManager.getCurrentSavesDirectory().get().resolve(worldFolder);
if (properties == null || !Files.isDirectory(worldPath)) {
if (properties != null) {
WorldManager.unregisterWorldProperties(properties, false);
}
String modId = StaticMixinForgeHelper.getModIdFromClass(provider.getClass());
WorldArchetype archetype = Sponge.getRegistry().getType(WorldArchetype.class, modId + ":" + dimensionType.getName().toLowerCase()).orElse(null);
if (archetype == null) {
final WorldArchetype.Builder builder = WorldArchetype.builder().dimension((org.spongepowered.api.world.DimensionType) (Object) dimensionType).keepsSpawnLoaded(dimensionType.shouldLoadSpawn());
archetype = builder.build(modId + ":" + dimensionType.getName().toLowerCase(), dimensionType.getName());
}
IMixinWorldSettings worldSettings = (IMixinWorldSettings) archetype;
worldSettings.setDimensionType((org.spongepowered.api.world.DimensionType) (Object) dimensionType);
worldSettings.setLoadOnStartup(false);
properties = WorldManager.createWorldProperties(worldFolder, archetype, dim);
((IMixinWorldInfo) properties).setDimensionId(dim);
((IMixinWorldInfo) properties).setIsMod(true);
}
if (!properties.isEnabled()) {
return;
}
Optional<WorldServer> optWorld = WorldManager.loadWorld(properties);
if (!optWorld.isPresent()) {
SpongeImpl.getLogger().error("Could not load world [{}]!", properties.getWorldName());
}
}
Aggregations