Search in sources :

Example 16 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class WeatherDimletType method constructDimension.

@Override
public void constructDimension(List<Pair<DimletKey, List<DimletKey>>> dimlets, Random random, DimensionInformation dimensionInformation) {
    dimlets = DimensionInformation.extractType(DimletType.DIMLET_WEATHER, dimlets);
    WeatherDescriptor.Builder builder = new WeatherDescriptor.Builder();
    if (dimlets.isEmpty()) {
        while (random.nextFloat() > DimletConfiguration.randomWeatherChance) {
            List<DimletKey> keys = new ArrayList<DimletKey>(DimletObjectMapping.idToWeatherDescriptor.keySet());
            DimletKey key = keys.get(random.nextInt(keys.size()));
            dimensionInformation.updateCostFactor(key);
            builder.combine(DimletObjectMapping.idToWeatherDescriptor.get(key));
        }
    } else {
        for (Pair<DimletKey, List<DimletKey>> dimlet : dimlets) {
            DimletKey key = dimlet.getKey();
            builder.combine(DimletObjectMapping.idToWeatherDescriptor.get(key));
        }
    }
    dimensionInformation.setWeatherDescriptor(builder.build());
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) WeatherDescriptor(mcjty.rftools.dimension.description.WeatherDescriptor) DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 17 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class RFToolsTradeHandler method getRandomSellDimlet.

private void getRandomSellDimlet(EntityVillager villager, MerchantRecipeList recipeList, Random random, float dimletBonus) {
    WeightedRandomSelector.Distribution<Integer> distribution = DimletRandomizer.randomDimlets.createDistribution(dimletBonus);
    DimletKey dimlet = DimletRandomizer.getRandomDimlet(distribution, random);
    if (dimlet != null) {
        DimletEntry entry = KnownDimletConfiguration.idToDimletEntry.get(dimlet);
        if (entry != null) {
            int rarity = entry.getRarity();
            ItemStack dimletStack = KnownDimletConfiguration.makeKnownDimlet(dimlet, villager.worldObj);
            recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald, (1 + random.nextInt(2)) * (rarity / 2 + 1)), dimletStack));
        }
    }
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) WeightedRandomSelector(mcjty.lib.varia.WeightedRandomSelector) DimletEntry(mcjty.rftools.items.dimlets.DimletEntry) DimletKey(mcjty.rftools.items.dimlets.DimletKey) ItemStack(net.minecraft.item.ItemStack)

Example 18 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class DimletScramblerTileEntity method isValidInput.

private boolean isValidInput(ItemStack input1, ItemStack input2, ItemStack input3) {
    if (input1 == null || input2 == null || input3 == null) {
        return false;
    }
    if (input1.getItem() != DimletSetup.knownDimlet || input2.getItem() != DimletSetup.knownDimlet || input3.getItem() != DimletSetup.knownDimlet) {
        return false;
    }
    DimletKey key1 = KnownDimletConfiguration.getDimletKey(input1, worldObj);
    DimletKey key2 = KnownDimletConfiguration.getDimletKey(input2, worldObj);
    DimletKey key3 = KnownDimletConfiguration.getDimletKey(input3, worldObj);
    int cntCraftable = (KnownDimletConfiguration.craftableDimlets.contains(key1) ? 1 : 0) + (KnownDimletConfiguration.craftableDimlets.contains(key2) ? 1 : 0) + (KnownDimletConfiguration.craftableDimlets.contains(key3) ? 1 : 0);
    // Only allow at most one craftable dimlet.
    return cntCraftable <= 1;
}
Also used : DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Example 19 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools 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 && slot.getStack() != null && slot.getStack().stackSize > 0) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack, Minecraft.getMinecraft().theWorld);
            if (key.getType() == DimletType.DIMLET_TERRAIN) {
                cntTerrain++;
                terrainType = DimletObjectMapping.idToTerrainType.get(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.idToSpecialType.get(key) == SpecialType.SPECIAL_OWNER) {
                cntOwner++;
            }
        }
    }
    if (cntOwner > 1) {
        tooltips.add("Using more then one owner dimlet is not useful!");
    }
    if (DimletConfiguration.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 && slot.getStack() != null && slot.getStack().stackSize > 0) {
            ItemStack stack = slot.getStack();
            DimletKey key = KnownDimletConfiguration.getDimletKey(stack, Minecraft.getMinecraft().theWorld);
            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.idToTerrainType.get(key) == TerrainType.TERRAIN_VOID && !modifiersForType.isEmpty()) {
                        tooltips.add("VOID terrain cannot use modifiers");
                    }
                } else if (type == DimletType.DIMLET_FEATURE) {
                    FeatureType featureType = DimletObjectMapping.idToFeatureType.get(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.idToControllerType.get(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.rftools.dimension.world.types.FeatureType) ArrayList(java.util.ArrayList) TerrainType(mcjty.rftools.dimension.world.types.TerrainType) DimletKey(mcjty.rftools.items.dimlets.DimletKey) ControllerType(mcjty.rftools.dimension.world.types.ControllerType) Counter(mcjty.lib.varia.Counter) DimletType(mcjty.rftools.items.dimlets.DimletType) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 20 with DimletKey

use of mcjty.rftools.items.dimlets.DimletKey in project RFTools by McJty.

the class DimletFilterTileEntity method findMostSpecificExtractionSide.

private int findMostSpecificExtractionSide(DimletEntry entry) {
    DimletKey key = entry.getKey();
    int rarity = entry.getRarity();
    int side = -1;
    int bestMatch = 0;
    int cr = KnownDimletConfiguration.craftableDimlets.contains(key) ? CRAFTABLE_YES : CRAFTABLE_NO;
    for (int i = 0; i < 6; i++) {
        if (isOutputMode(i)) {
            int match = 0;
            if (types[i] == null || types[i].equals(key.getType())) {
                if (types[i] == null) {
                    match += 1;
                } else {
                    match += 7;
                }
                if (rarity >= minRarity[i] && rarity <= maxRarity[i]) {
                    match += 7 - (maxRarity[i] - minRarity[i]);
                    if (craftable[i] == CRAFTABLE_DONTCARE || craftable[i] == cr) {
                        if (craftable[i] == CRAFTABLE_DONTCARE) {
                            match += 1;
                        } else {
                            match += 7;
                        }
                        if (match > bestMatch) {
                            bestMatch = match;
                            side = i;
                        }
                    }
                }
            }
        }
    }
    return side;
}
Also used : DimletKey(mcjty.rftools.items.dimlets.DimletKey)

Aggregations

DimletKey (mcjty.rftools.items.dimlets.DimletKey)37 ItemStack (net.minecraft.item.ItemStack)9 List (java.util.List)7 ArrayList (java.util.ArrayList)6 DimletEntry (mcjty.rftools.items.dimlets.DimletEntry)5 Block (net.minecraft.block.Block)4 BlockMeta (mcjty.lib.varia.BlockMeta)3 TerrainType (mcjty.rftools.dimension.world.types.TerrainType)3 Slot (net.minecraft.inventory.Slot)3 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 Map (java.util.Map)2 MobDescriptor (mcjty.rftools.dimension.description.MobDescriptor)2 ControllerType (mcjty.rftools.dimension.world.types.ControllerType)2 FeatureType (mcjty.rftools.dimension.world.types.FeatureType)2 DimletType (mcjty.rftools.items.dimlets.DimletType)2 MerchantRecipe (net.minecraft.village.MerchantRecipe)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Counter (mcjty.lib.varia.Counter)1