Search in sources :

Example 6 with BlockMeta

use of cavern.util.BlockMeta in project Cavern2 by kegare.

the class GuiVeinsEditor method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button.enabled) {
        switch(button.id) {
            case 0:
                if (editMode) {
                    for (CaveVein vein : veinList.selected) {
                        if (!Strings.isNullOrEmpty(blockField.getText())) {
                            Block block = Block.getBlockFromName(blockField.getText());
                            if (block != null && block != Blocks.AIR) {
                                int meta = BlockMeta.getMetaFromString(block, blockMetaField.getText());
                                if (meta < 0) {
                                    meta = 0;
                                }
                                vein.setBlockMeta(new BlockMeta(block, meta));
                            }
                        }
                        if (!Strings.isNullOrEmpty(targetField.getText())) {
                            Block block = Block.getBlockFromName(targetField.getText());
                            if (block != null && block != Blocks.AIR) {
                                int meta = BlockMeta.getMetaFromString(block, targetMetaField.getText());
                                if (meta < 0) {
                                    meta = 0;
                                }
                                vein.setTarget(new BlockMeta(block, meta));
                            }
                        }
                        if (!Strings.isNullOrEmpty(weightField.getText())) {
                            vein.setWeight(NumberUtils.toInt(weightField.getText(), vein.getWeight()));
                        }
                        if (!Strings.isNullOrEmpty(chanceField.getText())) {
                            vein.setChance(NumberUtils.toDouble(chanceField.getText(), vein.getChance()));
                        }
                        if (!Strings.isNullOrEmpty(sizeField.getText())) {
                            vein.setSize(NumberUtils.toInt(sizeField.getText(), vein.getSize()));
                        }
                        if (!Strings.isNullOrEmpty(minHeightField.getText())) {
                            vein.setMinHeight(NumberUtils.toInt(minHeightField.getText(), vein.getMinHeight()));
                        }
                        if (!Strings.isNullOrEmpty(maxHeightField.getText())) {
                            vein.setMaxHeight(NumberUtils.toInt(maxHeightField.getText(), vein.getMaxHeight()));
                        }
                        if (!Strings.isNullOrEmpty(biomesField.getText())) {
                            String text = biomesField.getText();
                            Set<String> biomes = Sets.newTreeSet();
                            if (text.contains(",")) {
                                for (String str : Splitter.on(',').trimResults().omitEmptyStrings().split(text)) {
                                    if (Strings.isNullOrEmpty(str)) {
                                        biomes.add(str);
                                    }
                                }
                            } else {
                                biomes.add(text);
                            }
                            if (!biomes.isEmpty()) {
                                vein.setBiomes(biomes.toArray(new String[biomes.size()]));
                            }
                        }
                    }
                    actionPerformed(cancelButton);
                    veinList.scrollToTop();
                    veinList.scrollToSelected();
                } else {
                    manager.getCaveVeins().clear();
                    try {
                        FileUtils.forceDelete(new File(manager.config.toString()));
                        manager.config.load();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    CavernConfig.generateVeinsConfig(manager, veinList.veins);
                    Config.saveConfig(manager.config);
                    actionPerformed(cancelButton);
                    veinList.selected.clear();
                    veinList.scrollToTop();
                }
                break;
            case 1:
                if (editMode) {
                    actionPerformed(cancelButton);
                } else if (!veinList.selected.isEmpty()) {
                    editMode = true;
                    initGui();
                    veinList.scrollToTop();
                    veinList.scrollToSelected();
                    if (veinList.selected.size() > 1) {
                        blockField.setText("");
                        blockMetaField.setText("");
                        targetField.setText("");
                        targetMetaField.setText("");
                        weightField.setText("");
                        chanceField.setText("");
                        sizeField.setText("");
                        minHeightField.setText("");
                        maxHeightField.setText("");
                        biomesField.setText("");
                    } else
                        for (CaveVein vein : veinList.selected) {
                            if (vein != null) {
                                blockField.setText(vein.getBlockMeta().getBlockName());
                                blockMetaField.setText(vein.getBlockMeta().getMetaString());
                                targetField.setText(vein.getTarget().getBlockName());
                                targetMetaField.setText(vein.getTarget().getMetaString());
                                weightField.setText(Integer.toString(vein.getWeight()));
                                chanceField.setText(Double.toString(vein.getChance()));
                                sizeField.setText(Integer.toString(vein.getSize()));
                                minHeightField.setText(Integer.toString(vein.getMinHeight()));
                                maxHeightField.setText(Integer.toString(vein.getMaxHeight()));
                                String[] biomes = vein.getBiomes();
                                if (biomes == null || biomes.length <= 0) {
                                    biomesField.setText("");
                                } else {
                                    biomesField.setText(Joiner.on(", ").join(biomes));
                                }
                            }
                        }
                }
                break;
            case 2:
                if (editMode) {
                    editMode = false;
                    initGui();
                } else {
                    mc.displayGuiScreen(parent);
                }
                break;
            case 3:
                mc.displayGuiScreen(new GuiSelectBlock(this, selected -> {
                    if (editMode) {
                        return;
                    }
                    veinList.selected.clear();
                    for (BlockMeta blockMeta : selected) {
                        CaveVein vein = new CaveVein(blockMeta, 1, 1, 1, 255);
                        veinList.veins.addIfAbsent(vein);
                        veinList.contents.addIfAbsent(vein);
                        veinList.selected.add(vein);
                    }
                    veinList.scrollToTop();
                    veinList.scrollToSelected();
                }));
                break;
            case 4:
                for (CaveVein vein : veinList.selected) {
                    veinList.veins.remove(vein);
                    veinList.contents.remove(vein);
                }
                veinList.selected.clear();
                break;
            case 5:
                veinList.veins.forEach(entry -> veinList.selected.add(entry));
                actionPerformed(removeButton);
                break;
            case 6:
                CaveConfigGui.detailInfo = detailInfo.isChecked();
                break;
            case 7:
                CaveConfigGui.instantFilter = instantFilter.isChecked();
                break;
            default:
                veinList.actionPerformed(button);
        }
    }
}
Also used : Blocks(net.minecraft.init.Blocks) CaveVein(cavern.config.manager.CaveVein) CaveFilters(cavern.util.CaveFilters) GuiButtonExt(net.minecraftforge.fml.client.config.GuiButtonExt) CavernConfig(cavern.config.CavernConfig) CaveVeinManager(cavern.config.manager.CaveVeinManager) Keyboard(org.lwjgl.input.Keyboard) CharUtils(org.apache.commons.lang3.CharUtils) Config(cavern.config.Config) I18n(net.minecraft.client.resources.I18n) Strings(com.google.common.base.Strings) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) Map(java.util.Map) CaveConfigGui(cavern.client.config.CaveConfigGui) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Splitter(com.google.common.base.Splitter) GuiTextField(net.minecraft.client.gui.GuiTextField) GuiCheckBox(net.minecraftforge.fml.client.config.GuiCheckBox) GuiButton(net.minecraft.client.gui.GuiButton) Items(net.minecraft.init.Items) Collection(java.util.Collection) TextFormatting(net.minecraft.util.text.TextFormatting) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) File(java.io.File) Sets(com.google.common.collect.Sets) BlockMeta(cavern.util.BlockMeta) List(java.util.List) GuiScreen(net.minecraft.client.gui.GuiScreen) CaveUtils(cavern.util.CaveUtils) HoverChecker(net.minecraftforge.fml.client.config.HoverChecker) NumberUtils(org.apache.commons.lang3.math.NumberUtils) ArrayListExtended(cavern.util.ArrayListExtended) Comparator(java.util.Comparator) Collections(java.util.Collections) Biome(net.minecraft.world.biome.Biome) Joiner(com.google.common.base.Joiner) Block(net.minecraft.block.Block) BlockMeta(cavern.util.BlockMeta) File(java.io.File) IOException(java.io.IOException) CaveVein(cavern.config.manager.CaveVein)

Example 7 with BlockMeta

use of cavern.util.BlockMeta in project Cavern2 by kegare.

the class GuiBiomesEditor method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button.enabled) {
        switch(button.id) {
            case 0:
                if (editMode) {
                    for (CaveBiome caveBiome : biomeList.selected) {
                        if (!Strings.isNullOrEmpty(weightField.getText())) {
                            caveBiome.setWeight(NumberUtils.toInt(weightField.getText(), caveBiome.getWeight()));
                        }
                        if (!Strings.isNullOrEmpty(terrainBlockField.getText())) {
                            Block block = Block.getBlockFromName(terrainBlockField.getText());
                            if (block != null && block != Blocks.AIR) {
                                int meta = BlockMeta.getMetaFromString(block, terrainBlockMetaField.getText());
                                if (meta < 0) {
                                    meta = 0;
                                }
                                caveBiome.setTerrainBlock(new BlockMeta(block, meta));
                            }
                        }
                        if (!Strings.isNullOrEmpty(topBlockField.getText())) {
                            Block block = Block.getBlockFromName(topBlockField.getText());
                            if (block != null && block != Blocks.AIR) {
                                int meta = BlockMeta.getMetaFromString(block, topBlockMetaField.getText());
                                if (meta < 0) {
                                    meta = 0;
                                }
                                caveBiome.setTopBlock(new BlockMeta(block, meta));
                            }
                        }
                    }
                    actionPerformed(cancelButton);
                    biomeList.scrollToTop();
                    biomeList.scrollToSelected();
                } else {
                    manager.getCaveBiomes().clear();
                    try {
                        FileUtils.forceDelete(new File(manager.config.toString()));
                        manager.config.load();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Collections.sort(biomeList.biomes);
                    CavernConfig.generateBiomesConfig(manager, biomeList.biomes);
                    Config.saveConfig(manager.config);
                    actionPerformed(cancelButton);
                    biomeList.selected.clear();
                    biomeList.scrollToTop();
                }
                break;
            case 1:
                if (editMode) {
                    actionPerformed(cancelButton);
                } else if (!biomeList.selected.isEmpty()) {
                    editMode = true;
                    initGui();
                    biomeList.scrollToTop();
                    biomeList.scrollToSelected();
                    if (biomeList.selected.size() > 1) {
                        weightField.setText("");
                        terrainBlockField.setText("");
                        terrainBlockMetaField.setText("");
                        topBlockField.setText("");
                        topBlockMetaField.setText("");
                    } else
                        for (CaveBiome biome : biomeList.selected) {
                            if (biome != null) {
                                weightField.setText(Integer.toString(biome.getWeight()));
                                terrainBlockField.setText(biome.getTerrainBlock().getBlockName());
                                terrainBlockMetaField.setText(biome.getTerrainBlock().getMetaString());
                                topBlockField.setText(biome.getTopBlock().getBlockName());
                                topBlockMetaField.setText(biome.getTopBlock().getMetaString());
                            }
                        }
                }
                break;
            case 2:
                if (editMode) {
                    editMode = false;
                    initGui();
                } else {
                    mc.displayGuiScreen(parent);
                }
                break;
            case 3:
                Set<Biome> invisibleBiomes = biomeList.biomes.stream().map(CaveBiome::getBiome).collect(Collectors.toSet());
                mc.displayGuiScreen(new GuiSelectBiome(this, new ISelectorCallback<Biome>() {

                    @Override
                    public boolean isValidEntry(Biome entry) {
                        return entry != null && !invisibleBiomes.contains(entry);
                    }

                    @Override
                    public void onSelected(List<Biome> selected) {
                        if (editMode) {
                            return;
                        }
                        biomeList.selected.clear();
                        for (Biome biome : selected) {
                            CaveBiome caveBiome = new CaveBiome(biome, 10);
                            biomeList.biomes.addIfAbsent(caveBiome);
                            biomeList.contents.addIfAbsent(caveBiome);
                            biomeList.selected.add(caveBiome);
                        }
                        biomeList.scrollToTop();
                        biomeList.scrollToSelected();
                    }
                }));
                break;
            case 4:
                for (CaveBiome biome : biomeList.selected) {
                    biomeList.biomes.remove(biome);
                    biomeList.contents.remove(biome);
                }
                biomeList.selected.clear();
                break;
            case 5:
                biomeList.biomes.forEach(entry -> biomeList.selected.add(entry));
                actionPerformed(removeButton);
                break;
            case 6:
                CaveConfigGui.detailInfo = detailInfo.isChecked();
                break;
            case 7:
                CaveConfigGui.instantFilter = instantFilter.isChecked();
                break;
            default:
                biomeList.actionPerformed(button);
        }
    }
}
Also used : CaveBiome(cavern.config.manager.CaveBiome) Biome(net.minecraft.world.biome.Biome) CaveBiome(cavern.config.manager.CaveBiome) Block(net.minecraft.block.Block) List(java.util.List) BlockMeta(cavern.util.BlockMeta) File(java.io.File) IOException(java.io.IOException)

Example 8 with BlockMeta

use of cavern.util.BlockMeta in project Cavern2 by kegare.

the class AquaCavernConfig method syncBiomesConfig.

public static void syncBiomesConfig() {
    if (biomeManager.config == null) {
        biomeManager.config = Config.loadConfig("aquacavern", "biomes");
    } else {
        biomeManager.getCaveBiomes().clear();
    }
    if (biomeManager.config.getCategoryNames().isEmpty()) {
        List<CaveBiome> biomes = Lists.newArrayList();
        biomes.add(new CaveBiome(Biomes.OCEAN, 100));
        biomes.add(new CaveBiome(Biomes.PLAINS, 50));
        biomes.add(new CaveBiome(Biomes.DESERT, 10));
        biomes.add(new CaveBiome(Biomes.DESERT_HILLS, 5));
        biomes.add(new CaveBiome(Biomes.FOREST, 50));
        biomes.add(new CaveBiome(Biomes.FOREST_HILLS, 10));
        biomes.add(new CaveBiome(Biomes.TAIGA, 70));
        biomes.add(new CaveBiome(Biomes.TAIGA_HILLS, 10));
        biomes.add(new CaveBiome(Biomes.JUNGLE, 50));
        biomes.add(new CaveBiome(Biomes.JUNGLE_HILLS, 10));
        biomes.add(new CaveBiome(Biomes.SWAMPLAND, 30));
        biomes.add(new CaveBiome(Biomes.EXTREME_HILLS, 20));
        biomes.add(new CaveBiome(Biomes.ICE_PLAINS, 80));
        biomes.add(new CaveBiome(Biomes.ICE_MOUNTAINS, 10));
        biomes.add(new CaveBiome(Biomes.SAVANNA, 50));
        biomes.add(new CaveBiome(Biomes.MESA, 30, new BlockMeta(Blocks.RED_SANDSTONE.getDefaultState())));
        CavernConfig.generateBiomesConfig(biomeManager, biomes);
    } else {
        CavernConfig.addBiomesFromConfig(biomeManager);
    }
    Config.saveConfig(biomeManager.config);
}
Also used : CaveBiome(cavern.config.manager.CaveBiome) BlockMeta(cavern.util.BlockMeta)

Example 9 with BlockMeta

use of cavern.util.BlockMeta in project Cavern2 by kegare.

the class AquaCavernConfig method syncVeinsConfig.

public static void syncVeinsConfig() {
    if (veinManager.config == null) {
        veinManager.config = Config.loadConfig("aquacavern", "veins");
    } else {
        veinManager.getCaveVeins().clear();
    }
    if (veinManager.config.getCategoryNames().isEmpty()) {
        List<CaveVein> veins = Lists.newArrayList();
        veins.add(new CaveVein(new BlockMeta(Blocks.STONE, BlockStone.EnumType.GRANITE.getMetadata()), 30, 25, 1, 255));
        veins.add(new CaveVein(new BlockMeta(Blocks.STONE, BlockStone.EnumType.DIORITE.getMetadata()), 32, 25, 1, 255));
        veins.add(new CaveVein(new BlockMeta(Blocks.STONE, BlockStone.EnumType.ANDESITE.getMetadata()), 32, 25, 1, 255));
        veins.add(new CaveVein(new BlockMeta(Blocks.COAL_ORE, 0), 40, 17, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.IRON_ORE, 0), 40, 10, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.GOLD_ORE, 0), 8, 7, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.REDSTONE_ORE, 0), 12, 7, 1, 40));
        veins.add(new CaveVein(new BlockMeta(Blocks.LAPIS_ORE, 0), 8, 5, 1, 50));
        veins.add(new CaveVein(new BlockMeta(Blocks.DIAMOND_ORE, 0), 3, 6, 1, 20));
        veins.add(new CaveVein(new BlockMeta(Blocks.EMERALD_ORE, 0), 8, 5, 50, 127));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.AQUAMARINE_ORE.getMetadata()), 30, 8, 20, 127));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.MAGNITE_ORE.getMetadata()), 35, 10, 1, 127));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.RANDOMITE_ORE.getMetadata()), 28, 6, 1, 127));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.HEXCITE_ORE.getMetadata()), 6, 5, 1, 30));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.FISSURED_STONE.getMetadata()), 70, 3, 1, 255));
        veins.add(new CaveVein(new BlockMeta(Blocks.DIRT, 0), 20, 25, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.GRAVEL, 0), 10, 20, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.CLAY, 0), 30, 20, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.SAND, BlockSand.EnumType.SAND.getMetadata()), 15, 20, 1, 127));
        if (Config.highProfiles) {
            veins.add(new CaveVein(new BlockMeta(Blocks.COAL_ORE, 0), 35, 20, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.IRON_ORE, 0), 30, 12, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.GOLD_ORE, 0), 5, 8, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.LAPIS_ORE, 0), 4, 7, 128, 255));
            veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.AQUAMARINE_ORE.getMetadata()), 12, 12, 128, 255, Type.COLD, Type.WATER, Type.WET));
            veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.MAGNITE_ORE.getMetadata()), 30, 10, 128, 255));
            veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.RANDOMITE_ORE.getMetadata()), 28, 4, 128, 255));
            veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.HEXCITE_ORE.getMetadata()), 4, 5, 200, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.DIRT, 0), 20, 25, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.GRAVEL, 0), 10, 20, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.CLAY, 0), 30, 20, 128, 255));
            veins.add(new CaveVein(new BlockMeta(Blocks.SAND, BlockSand.EnumType.SAND.getMetadata()), 10, 20, 128, 255, Type.SANDY));
        }
        CavernConfig.generateVeinsConfig(veinManager, veins);
    } else {
        if (CavernConfig.addVeinsFromConfig(veinManager)) {
            try {
                FileUtils.forceDelete(new File(veinManager.config.toString()));
                veinManager.getCaveVeins().clear();
                veinManager.config = null;
                syncVeinsConfig();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    Config.saveConfig(veinManager.config);
}
Also used : BlockMeta(cavern.util.BlockMeta) File(java.io.File) CaveVein(cavern.config.manager.CaveVein)

Example 10 with BlockMeta

use of cavern.util.BlockMeta in project Cavern2 by kegare.

the class CavelandConfig method syncVeinsConfig.

public static void syncVeinsConfig() {
    if (veinManager.config == null) {
        veinManager.config = Config.loadConfig("caveland", "veins");
    } else {
        veinManager.getCaveVeins().clear();
    }
    if (veinManager.config.getCategoryNames().isEmpty()) {
        List<CaveVein> veins = Lists.newArrayList();
        veins.add(new CaveVein(new BlockMeta(Blocks.COAL_ORE, 0), 30, 17, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.COAL_ORE, 0), 20, 15, 1, 10));
        veins.add(new CaveVein(new BlockMeta(Blocks.IRON_ORE, 0), 30, 10, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.IRON_ORE, 0), 20, 8, 1, 10));
        veins.add(new CaveVein(new BlockMeta(Blocks.GRAVEL, 0), 30, 20, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.GRAVEL, 0), 10, 10, 1, 10));
        veins.add(new CaveVein(new BlockMeta(Blocks.SAND, BlockSand.EnumType.SAND.getMetadata()), 20, 20, 1, 127));
        veins.add(new CaveVein(new BlockMeta(Blocks.SAND, BlockSand.EnumType.SAND.getMetadata()), 7, 10, 1, 10));
        veins.add(new CaveVein(new BlockMeta(CaveBlocks.CAVE_BLOCK, BlockCave.EnumType.FISSURED_STONE.getMetadata()), 30, 2, 1, 10));
        CavernConfig.generateVeinsConfig(veinManager, veins);
    } else {
        if (CavernConfig.addVeinsFromConfig(veinManager)) {
            try {
                FileUtils.forceDelete(new File(veinManager.config.toString()));
                veinManager.getCaveVeins().clear();
                veinManager.config = null;
                syncVeinsConfig();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    Config.saveConfig(veinManager.config);
}
Also used : BlockMeta(cavern.util.BlockMeta) File(java.io.File) CaveVein(cavern.config.manager.CaveVein)

Aggregations

BlockMeta (cavern.util.BlockMeta)21 CaveVein (cavern.config.manager.CaveVein)7 File (java.io.File)7 CaveBiome (cavern.config.manager.CaveBiome)5 Biome (net.minecraft.world.biome.Biome)4 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 ItemStack (net.minecraft.item.ItemStack)3 Strings (com.google.common.base.Strings)2 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 ConfigCategory (net.minecraftforge.common.config.ConfigCategory)2 IIceEquipment (cavern.api.IIceEquipment)1 IMinerStats (cavern.api.IMinerStats)1 IMiningData (cavern.api.IMiningData)1 CaveConfigGui (cavern.client.config.CaveConfigGui)1