Search in sources :

Example 1 with ISpawnEntry

use of com.mcmoddev.orespawn.api.os3.ISpawnEntry in project OreSpawn by MinecraftModDevelopmentMods.

the class FeatureBase method spawnMungeSW.

protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius, ISpawnEntry spawnData, int count) {
    Random prng = this.random;
    int quantity = count;
    IBlockList possibleOres = spawnData.getBlocks();
    OreSpawnBlockMatcher replacer = spawnData.getMatcher();
    for (int dy = (int) (-1 * radius); dy < radius; dy++) {
        for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) {
            for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) {
                if ((dx * dx + dy * dy + dz * dz) <= rSqr) {
                    IBlockState oreBlock = possibleOres.getRandomBlock(prng);
                    spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData);
                    quantity--;
                }
                if (quantity <= 0) {
                    return;
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) OreSpawnBlockMatcher(com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher)

Example 2 with ISpawnEntry

use of com.mcmoddev.orespawn.api.os3.ISpawnEntry in project OreSpawn by MinecraftModDevelopmentMods.

the class OreSpawnWriter method saveSingle.

private static void saveSingle(Path filePath, Gson gson) {
    JsonObject root = new JsonObject();
    root.addProperty(ConfigNames.FILE_VERSION, "2.0");
    JsonObject spawns = new JsonObject();
    String k = filePath.getFileName().toString();
    Path saveDir = Constants.CONFDIR.resolve("forced-saves");
    Path conf = saveDir.resolve(k);
    if (!saveDir.toFile().exists()) {
        saveDir.toFile().mkdirs();
    }
    try (BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
        OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> {
            JsonObject thisSpawn = new JsonObject();
            ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName);
            thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled());
            thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen());
            thisSpawn.addProperty(ConfigNames.FEATURE, spawnEntry.getFeature().getFeatureName());
            thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize());
            thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize());
            thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize());
            thisSpawn.add(ConfigNames.PARAMETERS, spawnEntry.getFeature().getFeatureParameters());
            spawns.add(spawnName, thisSpawn);
        });
        root.add(ConfigNames.SPAWNS, spawns);
        p.write(gson.toJson(root));
    } catch (IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config data " + conf.toString());
        report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION);
        OreSpawn.LOGGER.info(report.getCompleteReport());
    }
}
Also used : Path(java.nio.file.Path) ISpawnEntry(com.mcmoddev.orespawn.api.os3.ISpawnEntry) CrashReport(net.minecraft.crash.CrashReport) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 3 with ISpawnEntry

use of com.mcmoddev.orespawn.api.os3.ISpawnEntry in project OreSpawn by MinecraftModDevelopmentMods.

the class FeatureBase method spawnMungeNE.

protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, ISpawnEntry spawnData, int count) {
    Random prng = this.random;
    int quantity = count;
    IBlockList possibleOres = spawnData.getBlocks();
    OreSpawnBlockMatcher replacer = spawnData.getMatcher();
    for (int dy = (int) (-1 * radius); dy < radius; dy++) {
        for (int dz = (int) (-1 * radius); dz < radius; dz++) {
            for (int dx = (int) (-1 * radius); dx < radius; dx++) {
                if ((dx * dx + dy * dy + dz * dz) <= rSqr) {
                    IBlockState oreBlock = possibleOres.getRandomBlock(prng);
                    spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData);
                    quantity--;
                }
                if (quantity <= 0) {
                    return;
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) OreSpawnBlockMatcher(com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher)

Aggregations

OreSpawnBlockMatcher (com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher)2 IBlockState (net.minecraft.block.state.IBlockState)2 JsonObject (com.google.gson.JsonObject)1 ISpawnEntry (com.mcmoddev.orespawn.api.os3.ISpawnEntry)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CrashReport (net.minecraft.crash.CrashReport)1