Search in sources :

Example 21 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class FeatureDimletType method getRandomBlockArray.

private IBlockState[] getRandomBlockArray(Random random, Set<FeatureType> featureTypes, Map<FeatureType, List<DimletKey>> modifiersForFeature, FeatureType t, boolean allowEmpty) {
    IBlockState[] blockArray;
    if (featureTypes.contains(t)) {
        List<IBlockState> blocks = new ArrayList<>();
        List<Block> fluids = new ArrayList<Block>();
        DimensionInformation.getMaterialAndFluidModifiers(modifiersForFeature.get(t), blocks, fluids);
        // If no blocks are specified we will generate a few random ores.
        if (blocks.isEmpty()) {
            float chance = 1.1f;
            while (random.nextFloat() < chance) {
                DimletKey key = DimletRandomizer.getRandomMaterialBlock(random);
                if (key != null) {
                    IBlockState bm = DimletObjectMapping.getBlock(key);
                    if (bm != null) {
                        blocks.add(bm);
                        chance = chance * 0.80f;
                    }
                }
            }
        }
        blockArray = blocks.toArray(new IBlockState[blocks.size()]);
        for (int i = 0; i < blockArray.length; i++) {
            if (blockArray[i] == null) {
                blockArray[i] = Blocks.STONE.getDefaultState();
            }
        }
    } else {
        blockArray = new IBlockState[0];
    }
    if (allowEmpty || blockArray.length > 0) {
        return blockArray;
    }
    return new IBlockState[] { Blocks.STONE.getDefaultState() };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 22 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class BiomeDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    Set<DimletKey> biomeKeys = new HashSet<DimletKey>();
    List<Pair<DimletKey, List<DimletKey>>> biomeDimlets = DimensionInformation.extractType(DimletType.DIMLET_BIOME, dimlets);
    List<Pair<DimletKey, List<DimletKey>>> controllerDimlets = DimensionInformation.extractType(DimletType.DIMLET_CONTROLLER, dimlets);
    ControllerType controllerType;
    // First determine the controller to use.
    if (controllerDimlets.isEmpty()) {
        if (random.nextFloat() < WorldgenConfiguration.randomControllerChance) {
            DimletKey key = DimletRandomizer.getRandomController(random);
            if (key != null) {
                controllerType = DimletObjectMapping.getController(key);
            } else {
                controllerType = ControllerType.CONTROLLER_DEFAULT;
            }
        } else {
            if (biomeDimlets.isEmpty()) {
                controllerType = ControllerType.CONTROLLER_DEFAULT;
            } else if (biomeDimlets.size() > 1) {
                controllerType = ControllerType.CONTROLLER_FILTERED;
            } else {
                controllerType = ControllerType.CONTROLLER_SINGLE;
            }
        }
    } else {
        DimletKey key = controllerDimlets.get(random.nextInt(controllerDimlets.size())).getLeft();
        controllerType = DimletObjectMapping.getController(key);
    }
    dimensionInformation.setControllerType(controllerType);
    // Now see if we have to add or randomize biomes.
    for (Pair<DimletKey, List<DimletKey>> dimletWithModifiers : biomeDimlets) {
        DimletKey key = dimletWithModifiers.getKey();
        biomeKeys.add(key);
    }
    int neededBiomes = controllerType.getNeededBiomes();
    if (neededBiomes == -1) {
        // Can work with any number of biomes.
        if (biomeKeys.size() >= 2) {
            // We already have enough biomes
            neededBiomes = biomeKeys.size();
        } else {
            neededBiomes = random.nextInt(10) + 3;
        }
    }
    while (biomeKeys.size() < neededBiomes) {
        DimletKey key = DimletRandomizer.getRandomBiome(random);
        while (key == null || biomeKeys.contains(key)) {
            key = DimletRandomizer.getRandomBiome(random);
        }
        biomeKeys.add(key);
    }
    List<Biome> biomes = dimensionInformation.getBiomes();
    biomes.clear();
    for (DimletKey key : biomeKeys) {
        biomes.add(DimletObjectMapping.getBiome(key));
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) List(java.util.List) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ControllerType(mcjty.rftoolsdim.dimensions.types.ControllerType) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair)

Example 23 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class DimensionDescriptor method parseDescriptionString.

public static List<DimletKey> parseDescriptionString(String descriptionString) {
    if (descriptionString == null || descriptionString.isEmpty()) {
        return Collections.emptyList();
    }
    List<DimletKey> result = new ArrayList<>();
    String ds = descriptionString.substring(1);
    if (!ds.isEmpty()) {
        String[] opcodes = StringUtils.split(ds, ",");
        for (String oc : opcodes) {
            DimletKey key;
            if (oc.startsWith("#")) {
                // First comes '#', then the type of the actual dimlet.
                key = DimletKey.parseKey(oc.substring(1));
            } else if (oc.startsWith("?")) {
                // First comes '?', then the type of the actual dimlet
                key = DimletKey.parseKey(oc.substring(1));
            } else {
                key = DimletKey.parseKey(oc);
            }
            result.add(key);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 24 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class DimensionDescriptor method calculateCreationRfCost.

private int calculateCreationRfCost(List<Pair<DimletKey, List<DimletKey>>> dimlets, List<DimletKey> unusedModifiers, int tickCost) {
    int rf = DimletCosts.baseDimensionCreationCost;
    for (Pair<DimletKey, List<DimletKey>> dimletWithModifier : dimlets) {
        DimletKey key = dimletWithModifier.getLeft();
        DimletType type = key.getType();
        List<DimletKey> list = dimletWithModifier.getRight();
        if (list != null) {
            for (DimletKey modifier : list) {
                float mult = type.dimletType.getModifierCreateCostFactor(modifier.getType(), key);
                rf += (int) (getCreationCost(modifier.getType(), modifier) * mult);
            }
        }
        rf += getCreationCost(type, key);
    }
    for (DimletKey modifier : unusedModifiers) {
        rf += getCreationCost(modifier.getType(), modifier);
    }
    return rf;
}
Also used : DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) ArrayList(java.util.ArrayList) List(java.util.List) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 25 with DimletKey

use of mcjty.rftoolsdim.dimensions.dimlets.DimletKey in project RFToolsDimensions by McJty.

the class DigitDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_DIGIT, dimlets);
    String digitString = "";
    for (Pair<DimletKey, List<DimletKey>> dimletWithModifiers : dimlets) {
        DimletKey key = dimletWithModifiers.getKey();
        digitString += DimletObjectMapping.getDigit(key);
    }
    dimensionInformation.setDigitString(digitString);
}
Also used : List(java.util.List) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Aggregations

DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)61 ArrayList (java.util.ArrayList)19 List (java.util.List)15 Settings (mcjty.rftoolsdim.config.Settings)14 ItemStack (net.minecraft.item.ItemStack)14 DimletType (mcjty.rftoolsdim.dimensions.dimlets.types.DimletType)13 Block (net.minecraft.block.Block)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 IBlockState (net.minecraft.block.state.IBlockState)6 TerrainType (mcjty.rftoolsdim.dimensions.types.TerrainType)5 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)3 IDimletType (mcjty.rftoolsdim.dimensions.dimlets.types.IDimletType)3 ControllerType (mcjty.rftoolsdim.dimensions.types.ControllerType)3 FeatureType (mcjty.rftoolsdim.dimensions.types.FeatureType)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 Pair (org.apache.commons.lang3.tuple.Pair)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Argument (mcjty.lib.network.Argument)2