Search in sources :

Example 1 with TerrainType

use of mcjty.rftoolsdim.dimensions.types.TerrainType in project RFToolsDimensions by McJty.

the class GuiEssencePainter method validateDimlets.

private void validateDimlets() {
    List<String> tooltips = new ArrayList<String>();
    TerrainType terrainType = null;
    int cntTerrain = 0;
    int cntBiomes = 0;
    int cntController = 0;
    int cntOwner = 0;
    for (int i = EssencePainterContainer.SLOT_DIMLETS; i < EssencePainterContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            if (key.getType() == DimletType.DIMLET_TERRAIN) {
                cntTerrain++;
                terrainType = DimletObjectMapping.getTerrain(key);
            } else if (key.getType() == DimletType.DIMLET_BIOME) {
                cntBiomes++;
            } else if (key.getType() == DimletType.DIMLET_CONTROLLER) {
                cntController++;
            } else if (key.getType() == DimletType.DIMLET_SPECIAL && DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_OWNER) {
                cntOwner++;
            }
        }
    }
    if (cntOwner > 1) {
        tooltips.add("Using more then one owner dimlet is not useful!");
    }
    if (GeneralConfiguration.ownerDimletsNeeded && cntOwner != 1) {
        tooltips.add("You cannot make a dimension without an owner dimlet!");
        storeButton.setEnabled(false);
    }
    if (cntTerrain > 1) {
        tooltips.add("Using more then one TERRAIN is not useful!");
        terrainType = null;
    }
    if (cntController > 1) {
        tooltips.add("Using more then one CONTROLLER is not useful!");
    }
    List<DimletKey> modifiers = new ArrayList<DimletKey>();
    for (int i = EssencePainterContainer.SLOT_DIMLETS; i < EssencePainterContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            DimletType type = key.getType();
            if (type.dimletType.isModifier()) {
                modifiers.add(key);
            } else {
                List<DimletKey> modifiersForType = extractModifiersForType(modifiers, type);
                if (type == DimletType.DIMLET_TERRAIN) {
                    if (DimletObjectMapping.getTerrain(key) == TerrainType.TERRAIN_VOID && !modifiersForType.isEmpty()) {
                        tooltips.add("VOID terrain cannot use modifiers");
                    }
                } else if (type == DimletType.DIMLET_FEATURE) {
                    FeatureType featureType = DimletObjectMapping.getFeature(key);
                    Counter<DimletType> modifierAmountUsed = new Counter<DimletType>();
                    for (DimletKey modifier : modifiersForType) {
                        modifierAmountUsed.increment(modifier.getType());
                    }
                    for (Map.Entry<DimletType, Integer> entry : modifierAmountUsed.entrySet()) {
                        Integer amountSupported = featureType.getSupportedModifierAmount(entry.getKey());
                        if (amountSupported == null) {
                            tooltips.add(shortenName(featureType.name()) + " does not use " + shortenName(entry.getKey().name()) + " modifiers!");
                        } else if (amountSupported == 1 && entry.getValue() > 1) {
                            tooltips.add(shortenName(featureType.name()) + " only needs one " + shortenName(entry.getKey().name()) + " modifier!");
                        }
                    }
                    if (terrainType == null && !featureType.supportsAllTerrains()) {
                        tooltips.add(shortenName(featureType.name()) + " is possibly useless as it does not work on all terrains!");
                    }
                    if (terrainType != null && !featureType.isTerrainSupported(terrainType)) {
                        tooltips.add(shortenName(featureType.name()) + " does not work for terrain " + shortenName(terrainType.name()) + "!");
                    }
                } else if (type == DimletType.DIMLET_CONTROLLER) {
                    ControllerType controllerType = DimletObjectMapping.getController(key);
                    int neededBiomes = controllerType.getNeededBiomes();
                    if (neededBiomes != -1) {
                        if (cntBiomes > neededBiomes) {
                            tooltips.add("Too many biomes specified for " + shortenName(controllerType.name()) + "!");
                        } else if (cntBiomes < neededBiomes) {
                            tooltips.add("Too few biomes specified for " + shortenName(controllerType.name()) + "!");
                        }
                    }
                }
            }
        }
    }
    if (!modifiers.isEmpty()) {
        tooltips.add("There are dangling modifiers in this descriptor");
    }
    boolean error = true;
    if (tooltips.isEmpty()) {
        tooltips.add("Everything appears to be alright");
        error = false;
    }
    validateField.setTooltips(tooltips.toArray(new String[tooltips.size()]));
    validateField.setColor(error ? 0xFF0000 : 0x008800);
    validateField.setText(error ? "Warn" : "Ok");
}
Also used : FeatureType(mcjty.rftoolsdim.dimensions.types.FeatureType) ArrayList(java.util.ArrayList) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ControllerType(mcjty.rftoolsdim.dimensions.types.ControllerType) Counter(mcjty.lib.varia.Counter) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TerrainType

use of mcjty.rftoolsdim.dimensions.types.TerrainType in project RFToolsDimensions by McJty.

the class GuiDimensionEnscriber method validateDimlets.

private void validateDimlets() {
    List<String> tooltips = new ArrayList<String>();
    TerrainType terrainType = null;
    int cntTerrain = 0;
    int cntBiomes = 0;
    int cntController = 0;
    int cntOwner = 0;
    for (int i = DimensionEnscriberContainer.SLOT_DIMLETS; i < DimensionEnscriberContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            if (key.getType() == DimletType.DIMLET_TERRAIN) {
                cntTerrain++;
                terrainType = DimletObjectMapping.getTerrain(key);
            } else if (key.getType() == DimletType.DIMLET_BIOME) {
                cntBiomes++;
            } else if (key.getType() == DimletType.DIMLET_CONTROLLER) {
                cntController++;
            } else if (key.getType() == DimletType.DIMLET_SPECIAL && DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_OWNER) {
                cntOwner++;
            }
        }
    }
    if (cntOwner > 1) {
        tooltips.add("Using more then one owner dimlet is not useful!");
    }
    if (GeneralConfiguration.ownerDimletsNeeded && cntOwner != 1) {
        tooltips.add("You cannot make a dimension without an owner dimlet!");
        storeButton.setEnabled(false);
    }
    if (cntTerrain > 1) {
        tooltips.add("Using more then one TERRAIN is not useful!");
        terrainType = null;
    }
    if (cntController > 1) {
        tooltips.add("Using more then one CONTROLLER is not useful!");
    }
    List<DimletKey> modifiers = new ArrayList<DimletKey>();
    for (int i = DimensionEnscriberContainer.SLOT_DIMLETS; i < DimensionEnscriberContainer.SLOT_TAB; i++) {
        Slot slot = inventorySlots.getSlot(i);
        if (slot != null && ItemStackTools.isValid(slot.getStack())) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
            DimletType type = key.getType();
            if (type.dimletType.isModifier()) {
                modifiers.add(key);
            } else {
                List<DimletKey> modifiersForType = extractModifiersForType(modifiers, type);
                if (type == DimletType.DIMLET_TERRAIN) {
                    if (DimletObjectMapping.getTerrain(key) == TerrainType.TERRAIN_VOID && !modifiersForType.isEmpty()) {
                        tooltips.add("VOID terrain cannot use modifiers");
                    }
                } else if (type == DimletType.DIMLET_FEATURE) {
                    FeatureType featureType = DimletObjectMapping.getFeature(key);
                    Counter<DimletType> modifierAmountUsed = new Counter<DimletType>();
                    for (DimletKey modifier : modifiersForType) {
                        modifierAmountUsed.increment(modifier.getType());
                    }
                    for (Map.Entry<DimletType, Integer> entry : modifierAmountUsed.entrySet()) {
                        Integer amountSupported = featureType.getSupportedModifierAmount(entry.getKey());
                        if (amountSupported == null) {
                            tooltips.add(shortenName(featureType.name()) + " does not use " + shortenName(entry.getKey().name()) + " modifiers!");
                        } else if (amountSupported == 1 && entry.getValue() > 1) {
                            tooltips.add(shortenName(featureType.name()) + " only needs one " + shortenName(entry.getKey().name()) + " modifier!");
                        }
                    }
                    if (terrainType == null && !featureType.supportsAllTerrains()) {
                        tooltips.add(shortenName(featureType.name()) + " is possibly useless as it does not work on all terrains!");
                    }
                    if (terrainType != null && !featureType.isTerrainSupported(terrainType)) {
                        tooltips.add(shortenName(featureType.name()) + " does not work for terrain " + shortenName(terrainType.name()) + "!");
                    }
                } else if (type == DimletType.DIMLET_CONTROLLER) {
                    ControllerType controllerType = DimletObjectMapping.getController(key);
                    int neededBiomes = controllerType.getNeededBiomes();
                    if (neededBiomes != -1) {
                        if (cntBiomes > neededBiomes) {
                            tooltips.add("Too many biomes specified for " + shortenName(controllerType.name()) + "!");
                        } else if (cntBiomes < neededBiomes) {
                            tooltips.add("Too few biomes specified for " + shortenName(controllerType.name()) + "!");
                        }
                    }
                }
            }
        }
    }
    if (!modifiers.isEmpty()) {
        tooltips.add("There are dangling modifiers in this descriptor");
    }
    boolean error = true;
    if (tooltips.isEmpty()) {
        tooltips.add("Everything appears to be alright");
        error = false;
    }
    validateField.setTooltips(tooltips.toArray(new String[tooltips.size()]));
    validateField.setColor(error ? 0xFF0000 : 0x008800);
    validateField.setText(error ? "Warn" : "Ok");
}
Also used : FeatureType(mcjty.rftoolsdim.dimensions.types.FeatureType) ArrayList(java.util.ArrayList) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) ControllerType(mcjty.rftoolsdim.dimensions.types.ControllerType) Counter(mcjty.lib.varia.Counter) DimletType(mcjty.rftoolsdim.dimensions.dimlets.types.DimletType) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TerrainType

use of mcjty.rftoolsdim.dimensions.types.TerrainType in project RFToolsDimensions by McJty.

the class CmdCreateDimension method execute.

@Override
public void execute(ICommandSender sender, String[] args) {
    if (args.length < 3) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "The name and terrain parameters are missing!"));
        return;
    } else if (args.length > 3) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Too many parameters!"));
        return;
    }
    String name = fetchString(sender, args, 1, "");
    String terrainName = fetchString(sender, args, 2, "Void");
    TerrainType terrainType = TerrainType.getTerrainById(terrainName);
    if (terrainType == null) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "Unknown terrain type!"));
        return;
    }
    if (!(sender instanceof EntityPlayer)) {
        ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.RED + "You must be a player to use this command!"));
        return;
    }
    EntityPlayer player = (EntityPlayer) sender;
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(sender.getEntityWorld());
    List<DimletKey> descriptors = new ArrayList<>();
    descriptors.add(new DimletKey(DimletType.DIMLET_TERRAIN, terrainType.getId()));
    DimensionDescriptor descriptor = new DimensionDescriptor(descriptors, 0);
    int dim = 0;
    try {
        dim = dimensionManager.createNewDimension(sender.getEntityWorld(), descriptor, name, player.getDisplayName().toString(), player.getPersistentID());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    ChatTools.addChatMessage(sender, new TextComponentString(TextFormatting.GREEN + "Created dimension: " + dim));
    dimensionManager.save(sender.getEntityWorld());
}
Also used : DimensionDescriptor(mcjty.rftoolsdim.dimensions.description.DimensionDescriptor) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 4 with TerrainType

use of mcjty.rftoolsdim.dimensions.types.TerrainType in project RFToolsDimensions by McJty.

the class FeatureDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    TerrainType terrainType = dimensionInformation.getTerrainType();
    Set<FeatureType> featureTypes = dimensionInformation.getFeatureTypes();
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_FEATURE, dimlets);
    if (dimlets.isEmpty()) {
        while (random.nextFloat() < WorldgenConfiguration.randomFeatureChance) {
            DimletKey key = DimletRandomizer.getRandomFeature(random);
            if (key != null) {
                FeatureType featureType = DimletObjectMapping.getFeature(key);
                if (!featureTypes.contains(featureType) && featureType.isTerrainSupported(terrainType)) {
                    dimensionInformation.updateCostFactor(key);
                    featureTypes.add(featureType);
                    List<DimletKey> modifiers = Collections.emptyList();
                    // @todo randomize those?
                    dimlets.add(Pair.of(key, modifiers));
                }
            }
        }
    }
    Map<FeatureType, List<DimletKey>> modifiersForFeature = new HashMap<FeatureType, List<DimletKey>>();
    for (Pair<DimletKey, List<DimletKey>> dimlet : dimlets) {
        FeatureType featureType = DimletObjectMapping.getFeature(dimlet.getLeft());
        featureTypes.add(featureType);
        modifiersForFeature.put(featureType, dimlet.getRight());
    }
    dimensionInformation.setFluidsForLakes(getRandomFluidArray(random, dimensionInformation, featureTypes, modifiersForFeature, FeatureType.FEATURE_LAKES, true));
    dimensionInformation.setExtraOregen(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_OREGEN, true));
    dimensionInformation.setTendrilBlock(dimensionInformation.getFeatureBlock(random, modifiersForFeature, FeatureType.FEATURE_TENDRILS));
    dimensionInformation.setSphereBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_ORBS, false));
    dimensionInformation.setPyramidBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_PYRAMIDS, false));
    dimensionInformation.setHugeSphereBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_HUGEORBS, false));
    dimensionInformation.setScatteredSphereBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_SCATTEREDORBS, false));
    dimensionInformation.setLiquidSphereBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_LIQUIDORBS, false));
    dimensionInformation.setLiquidSphereFluids(getRandomFluidArray(random, dimensionInformation, featureTypes, modifiersForFeature, FeatureType.FEATURE_LIQUIDORBS, false));
    dimensionInformation.setHugeLiquidSphereBlocks(getRandomBlockArray(random, featureTypes, modifiersForFeature, FeatureType.FEATURE_HUGELIQUIDORBS, false));
    dimensionInformation.setHugeLiquidSphereFluids(getRandomFluidArray(random, dimensionInformation, featureTypes, modifiersForFeature, FeatureType.FEATURE_HUGELIQUIDORBS, false));
    dimensionInformation.setCanyonBlock(dimensionInformation.getFeatureBlock(random, modifiersForFeature, FeatureType.FEATURE_CANYONS));
}
Also used : FeatureType(mcjty.rftoolsdim.dimensions.types.FeatureType) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 5 with TerrainType

use of mcjty.rftoolsdim.dimensions.types.TerrainType in project RFToolsDimensions by McJty.

the class TerrainDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_TERRAIN, dimlets);
    List<DimletKey> modifiers;
    TerrainType terrainType = TerrainType.TERRAIN_VOID;
    if (dimlets.isEmpty()) {
        // Pick a random terrain type with a seed that is generated from all the
        // dimlets so we always get the same random value for these dimlets.
        DimletKey key = DimletRandomizer.getRandomTerrain(random);
        if (key != null) {
            dimensionInformation.updateCostFactor(key);
            terrainType = DimletObjectMapping.getTerrain(key);
        }
        modifiers = Collections.emptyList();
    } else {
        int index = random.nextInt(dimlets.size());
        DimletKey key = dimlets.get(index).getLeft();
        terrainType = DimletObjectMapping.getTerrain(key);
        modifiers = dimlets.get(index).getRight();
    }
    List<IBlockState> blocks = new ArrayList<>();
    List<Block> fluids = new ArrayList<>();
    DimensionInformation.getMaterialAndFluidModifiers(modifiers, blocks, fluids);
    dimensionInformation.setTerrainType(terrainType);
    IBlockState baseBlockForTerrain;
    if (dimensionInformation.isPatreonBitSet(Patreons.PATREON_LAYEREDMETA)) {
        baseBlockForTerrain = Blocks.STONE.getDefaultState();
    //            baseBlockForTerrain = new BlockMeta(Blocks.WOOL, 127);
    // @todo
    } else {
        if (!blocks.isEmpty()) {
            baseBlockForTerrain = blocks.get(random.nextInt(blocks.size()));
            if (baseBlockForTerrain == null) {
                // This is the default in case None was specified.
                baseBlockForTerrain = Blocks.STONE.getDefaultState();
            }
        } else {
            // If the terrain type is void we always pick stone as a random material.
            if (terrainType == TerrainType.TERRAIN_VOID) {
                baseBlockForTerrain = Blocks.STONE.getDefaultState();
            } else if (random.nextFloat() < WorldgenConfiguration.randomBaseBlockChance) {
                DimletKey key = DimletRandomizer.getRandomMaterialBlock(random);
                if (key != null) {
                    dimensionInformation.updateCostFactor(key);
                    baseBlockForTerrain = DimletObjectMapping.getBlock(key);
                } else {
                    baseBlockForTerrain = Blocks.STONE.getDefaultState();
                }
            } else {
                baseBlockForTerrain = Blocks.STONE.getDefaultState();
            }
        }
    }
    dimensionInformation.setBaseBlockForTerrain(baseBlockForTerrain);
    Block fluidForTerrain;
    if (!fluids.isEmpty()) {
        fluidForTerrain = fluids.get(random.nextInt(fluids.size()));
        if (fluidForTerrain == null) {
            // This is the default.
            fluidForTerrain = Blocks.WATER;
        }
    } else {
        // If the terrain type is void we always pick water as the random liquid.
        if (terrainType == TerrainType.TERRAIN_VOID) {
            fluidForTerrain = Blocks.WATER;
        } else if (random.nextFloat() < WorldgenConfiguration.randomOceanLiquidChance) {
            DimletKey key = DimletRandomizer.getRandomFluidBlock(random);
            if (key != null) {
                dimensionInformation.updateCostFactor(key);
                fluidForTerrain = DimletObjectMapping.getFluid(key);
            } else {
                fluidForTerrain = Blocks.WATER;
            }
        } else {
            fluidForTerrain = Blocks.WATER;
        }
    }
    dimensionInformation.setFluidForTerrain(fluidForTerrain);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey) TerrainType(mcjty.rftoolsdim.dimensions.types.TerrainType)

Aggregations

DimletKey (mcjty.rftoolsdim.dimensions.dimlets.DimletKey)5 TerrainType (mcjty.rftoolsdim.dimensions.types.TerrainType)5 ArrayList (java.util.ArrayList)4 FeatureType (mcjty.rftoolsdim.dimensions.types.FeatureType)3 Counter (mcjty.lib.varia.Counter)2 DimletType (mcjty.rftoolsdim.dimensions.dimlets.types.DimletType)2 ControllerType (mcjty.rftoolsdim.dimensions.types.ControllerType)2 Slot (net.minecraft.inventory.Slot)2 ItemStack (net.minecraft.item.ItemStack)2 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)1 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1