Search in sources :

Example 1 with CaveVein

use of cavern.config.manager.CaveVein 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 2 with CaveVein

use of cavern.config.manager.CaveVein in project Cavern2 by kegare.

the class GuiVeinsEditor method drawScreen.

@Override
public void drawScreen(int mouseX, int mouseY, float ticks) {
    veinList.drawScreen(mouseX, mouseY, ticks);
    drawCenteredString(fontRenderer, I18n.format(Config.LANG_KEY + "veins"), width / 2, 15, 0xFFFFFF);
    super.drawScreen(mouseX, mouseY, ticks);
    if (editMode) {
        GuiTextField textField;
        for (int i = 0; i < editFieldList.size(); ++i) {
            textField = editFieldList.get(i);
            textField.drawTextBox();
            drawString(fontRenderer, editLabelList.get(i), textField.x - maxLabelWidth - 10, textField.y + 3, 0xBBBBBB);
        }
        if (blockHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.block";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (targetHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.targetBlock";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (weightHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.weight";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (chanceHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.chance";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (sizeHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.size";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (heightHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.height";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        } else if (biomesHoverChecker.checkHover(mouseX, mouseY)) {
            List<String> hover = Lists.newArrayList();
            String key = Config.LANG_KEY + "veins.biomes";
            hover.add(TextFormatting.GRAY + I18n.format(key));
            hover.addAll(fontRenderer.listFormattedStringToWidth(I18n.format(key + ".tooltip"), 300));
            drawHoveringText(hover, mouseX, mouseY);
        }
    } else {
        filterTextField.drawTextBox();
    }
    if (detailHoverChecker.checkHover(mouseX, mouseY)) {
        drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "detail.hover"), 300), mouseX, mouseY);
    } else if (instantHoverChecker.checkHover(mouseX, mouseY)) {
        drawHoveringText(fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "instant.hover"), 300), mouseX, mouseY);
    } else if (veinList.isMouseYWithinSlotBounds(mouseY) && isCtrlKeyDown()) {
        CaveVein vein = veinList.contents.get(veinList.getSlotIndexFromScreenCoords(mouseX, mouseY), null);
        if (vein != null) {
            List<String> info = Lists.newArrayList();
            String prefix = TextFormatting.GRAY.toString();
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.block") + ": " + vein.getBlockMeta().getName());
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.targetBlock") + ": " + vein.getTarget().getName());
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.weight") + ": " + vein.getWeight());
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.chance") + ": " + vein.getChance());
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.size") + ": " + vein.getSize());
            info.add(prefix + I18n.format(Config.LANG_KEY + "veins.height") + ": " + vein.getMinHeight() + ", " + vein.getMaxHeight());
            String[] biomes = vein.getBiomes();
            if (biomes != null && biomes.length > 0) {
                List<String> list = fontRenderer.listFormattedStringToWidth(I18n.format(Config.LANG_KEY + "veins.biomes") + ": " + Joiner.on(", ").join(biomes), 300);
                for (String text : list) {
                    info.add(prefix + text);
                }
            }
            drawHoveringText(info, mouseX, mouseY);
        }
    }
    if (veinList.selected.size() > 1 && mouseX <= 100 && mouseY <= 20) {
        drawString(fontRenderer, I18n.format(Config.LANG_KEY + "select.entry.selected", veinList.selected.size()), 5, 5, 0xEFEFEF);
    }
}
Also used : List(java.util.List) GuiTextField(net.minecraft.client.gui.GuiTextField) CaveVein(cavern.config.manager.CaveVein)

Example 3 with CaveVein

use of cavern.config.manager.CaveVein in project Cavern2 by kegare.

the class GuiVeinsEditor method refreshVeins.

public void refreshVeins(Collection<CaveVein> veins) {
    veinList.veins.clear();
    veinList.contents.clear();
    for (CaveVein vein : veins) {
        veinList.veins.addIfAbsent(vein);
        veinList.contents.addIfAbsent(vein);
    }
}
Also used : CaveVein(cavern.config.manager.CaveVein)

Example 4 with CaveVein

use of cavern.config.manager.CaveVein 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 5 with CaveVein

use of cavern.config.manager.CaveVein 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

CaveVein (cavern.config.manager.CaveVein)12 BlockMeta (cavern.util.BlockMeta)8 File (java.io.File)7 List (java.util.List)3 GuiTextField (net.minecraft.client.gui.GuiTextField)3 Biome (net.minecraft.world.biome.Biome)3 CaveConfigGui (cavern.client.config.CaveConfigGui)2 CavernConfig (cavern.config.CavernConfig)2 Config (cavern.config.Config)2 CaveVeinManager (cavern.config.manager.CaveVeinManager)2 ArrayListExtended (cavern.util.ArrayListExtended)2 CaveFilters (cavern.util.CaveFilters)2 CaveUtils (cavern.util.CaveUtils)2 Joiner (com.google.common.base.Joiner)2 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2