Search in sources :

Example 6 with Config

use of net.silentchaos512.gear.config.Config in project SilentGems by SilentChaos512.

the class ToolHelper method addExampleRecipe.

public static void addExampleRecipe(Item item, EnumMaterialTier[] tiers, String[] lines, Object... extraParams) {
    // New ingredient-based recipes
    ConfigOptionToolClass config = item instanceof ITool ? ((ITool) item).getConfig() : null;
    for (EnumMaterialTier tier : tiers) {
        // Only add recipes for valid tiers
        if (config != null && !config.validTiers.contains(tier))
            continue;
        // Head parts for tier
        List<ItemStack> heads = new ArrayList<>();
        for (ToolPart part : ToolPartRegistry.getMains()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getTier() == tier && StackHelper.isValid(part.getCraftingStack()))
            heads.add(part.getCraftingStack());
        IngredientSL headIngredient = IngredientSL.from(heads.toArray(new ItemStack[0]));
        // Rods for tier
        List<ItemStack> rods = new ArrayList<>();
        for (ToolPart part : ToolPartRegistry.getRods()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getCompatibleTiers().contains(tier))
            rods.add(part.getCraftingStack());
        IngredientSL rodIngredient = IngredientSL.from(rods.toArray(new ItemStack[0]));
        // Armor frames
        List<ItemStack> frames = new ArrayList<>();
        if (item instanceof ItemGemArmor) {
            EntityEquipmentSlot slot = ((ItemGemArmor) item).armorType;
            for (ToolPart part : ToolPartRegistry.getValues()) if (part instanceof ArmorPartFrame && ((ArmorPartFrame) part).getSlot() == slot && part.getTier() == tier && !part.isBlacklisted(part.getCraftingStack()))
                frames.add(part.getCraftingStack());
        }
        IngredientSL frameIngredient = IngredientSL.from(frames.toArray(new ItemStack[0]));
        ResourceLocation recipeName = new ResourceLocation(item.getRegistryName().toString() + "_" + tier.name().toLowerCase() + "_example");
        ItemStack result = new ItemStack(item);
        NBTTagCompound tags = new NBTTagCompound();
        tags.setInteger(NBT_EXAMPLE_TOOL_TIER, tier.ordinal());
        result.setTagCompound(tags);
        // Super ugly, but I've got never better at the moment.
        List<Object> params = new ArrayList<>();
        for (String line : lines) params.add(line);
        if (recipeContainsKey(lines, "h")) {
            params.add('h');
            params.add(headIngredient);
        }
        if (recipeContainsKey(lines, "r")) {
            params.add('r');
            params.add(rodIngredient);
        }
        if (recipeContainsKey(lines, "a")) {
            params.add('a');
            params.add(frameIngredient);
        }
        for (Object obj : extraParams) params.add(obj);
        EXAMPLE_RECIPES.add(SilentGems.registry.recipes.makeShaped(recipeName.getResourcePath(), result, params.toArray()));
    }
}
Also used : IngredientSL(net.silentchaos512.lib.recipe.IngredientSL) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ITool(net.silentchaos512.gems.api.ITool) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ResourceLocation(net.minecraft.util.ResourceLocation) ConfigOptionToolClass(net.silentchaos512.gems.config.ConfigOptionToolClass) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) ItemGemArmor(net.silentchaos512.gems.item.armor.ItemGemArmor) ItemStack(net.minecraft.item.ItemStack) ArmorPartFrame(net.silentchaos512.gems.api.tool.part.ArmorPartFrame)

Example 7 with Config

use of net.silentchaos512.gear.config.Config in project SilentGems by SilentChaos512.

the class GemsWorldGenerator method selectState.

/**
 * Selects an IBlockState for the config. For gems, it will normally choose one randomly each call. For essence ores,
 * it selects the appropriate ore.
 *
 * @param config
 * @param random
 * @return
 */
protected IBlockState selectState(ConfigOptionOreGen config, Random random, World world, int posX, int posZ) {
    if (config == GemsConfig.WORLD_GEN_GEMS) {
        EnumGem gem;
        if (GemsConfig.GEM_REGIONS_ENABLED) {
            // Gem Regions
            long dimension = (long) world.provider.getDimension();
            long cx = (long) posX / 16 / GemsConfig.GEM_REGIONS_SIZE;
            long cz = (long) posZ / 16 / GemsConfig.GEM_REGIONS_SIZE;
            long seed = (world.getSeed() << 40L) | ((dimension & 0xFF) << 32L) | ((cz & 0xFFFF) << 16L) | (cx & 0xFFFF);
            Random regionRandom = new Random(seed);
            EnumGem firstGem = EnumGem.values()[regionRandom.nextInt(16)];
            EnumGem secondGem = EnumGem.values()[regionRandom.nextInt(16)];
            if (regionRandom.nextFloat() < GemsConfig.GEM_REGIONS_SECOND_GEM_CHANCE && random.nextBoolean()) {
                gem = secondGem;
            } else {
                gem = firstGem;
            }
        } else {
            // Classic logic
            int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS)).getMeta();
            gem = EnumGem.values()[meta];
        }
        return ModBlocks.gemOre.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else if (config == GemsConfig.WORLD_GEN_CHAOS) {
        return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.CHAOS);
    } else if (config == GemsConfig.WORLD_GEN_GEMS_DARK) {
        int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_DARK)).getMeta();
        EnumGem gem = EnumGem.values()[meta];
        return ModBlocks.gemOreDark.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else if (config == GemsConfig.WORLD_GEN_ENDER) {
        return ModBlocks.essenceOre.getDefaultState().withProperty(BlockEssenceOre.VARIANT, BlockEssenceOre.Type.ENDER);
    } else if (config == GemsConfig.WORLD_GEN_GEMS_LIGHT) {
        int meta = ((WeightedRandomItemSG) WeightedRandom.getRandomItem(random, GemsConfig.GEM_WEIGHTS_LIGHT)).getMeta();
        EnumGem gem = EnumGem.values()[meta];
        return ModBlocks.gemOreLight.getDefaultState().withProperty(EnumGem.VARIANT_GEM, gem);
    } else {
        SilentGems.logHelper.severe("GemsWorldGenerator - Unknown ore config: " + config.name);
        return null;
    }
}
Also used : Random(java.util.Random) WeightedRandom(net.minecraft.util.WeightedRandom) EnumGem(net.silentchaos512.gems.lib.EnumGem) WeightedRandomItemSG(net.silentchaos512.gems.util.WeightedRandomItemSG)

Example 8 with Config

use of net.silentchaos512.gear.config.Config in project Silent-Gear by SilentChaos512.

the class GearData method tryRecalculateStats.

@SuppressWarnings({ "OverlyLongMethod", "OverlyComplexMethod" })
private static void tryRecalculateStats(ItemStack gear, @Nullable Player player) {
    if (checkNonGearItem(gear, "recalculateStats"))
        return;
    getUUID(gear);
    TraitHelper.activateTraits(gear, 0f, (trait, level, value) -> {
        trait.onRecalculatePre(new TraitActionContext(player, level, gear));
        return 0f;
    });
    ICoreItem item = (ICoreItem) gear.getItem();
    PartDataList parts = getConstructionParts(gear);
    CompoundTag propertiesCompound = getData(gear, NBT_ROOT_PROPERTIES);
    if (!propertiesCompound.contains(NBT_LOCK_STATS))
        propertiesCompound.putBoolean(NBT_LOCK_STATS, false);
    String playerName = player != null ? player.getScoreboardName() : "somebody";
    String playersItemText = String.format("%s's %s", playerName, gear.getHoverName().getString());
    final boolean statsUnlocked = !propertiesCompound.getBoolean(NBT_LOCK_STATS);
    final boolean partsListValid = !parts.isEmpty() && !parts.getMains().isEmpty();
    if (statsUnlocked && partsListValid) {
        // We should recalculate the item's stats!
        if (player != null) {
            SilentGear.LOGGER.debug("Recalculating for {}", playersItemText);
        }
        clearCachedData(gear);
        propertiesCompound.putString("ModVersion", SilentGear.getVersion());
        Map<ITrait, Integer> traits = TraitHelper.getTraits(gear, item.getGearType(), parts);
        // Get all stat modifiers from all parts and item class modifiers
        StatModifierMap stats = getStatModifiers(gear, item, parts);
        // For debugging
        Map<ItemStat, Float> oldStatValues = getCurrentStatsForDebugging(gear);
        // Cache traits in properties compound as well
        ListTag traitList = new ListTag();
        traits.forEach((trait, level) -> traitList.add(trait.write(level)));
        propertiesCompound.put("Traits", traitList);
        propertiesCompound.remove(NBT_SYNERGY);
        // Calculate and write stats
        int maxDamage = gear.getMaxDamage() > 0 ? gear.getMaxDamage() : 1;
        final float damageRatio = Mth.clamp((float) gear.getDamageValue() / maxDamage, 0f, 1f);
        CompoundTag statsCompound = new CompoundTag();
        for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(gear))) {
            StatGearKey key = StatGearKey.of(stat, item.getGearType());
            Collection<StatInstance> modifiers = stats.get(key);
            GearType statGearType = stats.getMostSpecificKey(key).getGearType();
            final float initialValue = stat.compute(stat.getBaseValue(), true, item.getGearType(), statGearType, modifiers);
            // Allow traits to modify stat
            final float withTraits = TraitHelper.activateTraits(gear, initialValue, (trait, level, val) -> {
                TraitActionContext context = new TraitActionContext(player, level, gear);
                return trait.onGetStat(context, stat, val, damageRatio);
            });
            final float value = Config.Common.getStatWithMultiplier(stat, withTraits);
            if (!Mth.equal(value, 0f) || stats.containsKey(key)) {
                ResourceLocation statId = Objects.requireNonNull(stat.getRegistryName());
                // Remove old keys
                propertiesCompound.remove(statId.getPath());
                statsCompound.putFloat(statId.toString(), stat.clampValue(value));
            }
        }
        // Put missing relevant stats in the map to avoid recalculate stats packet spam
        for (ItemStat stat : item.getRelevantStats(gear)) {
            String statKey = stat.getStatId().toString();
            if (!statsCompound.contains(statKey)) {
                statsCompound.putFloat(statKey, stat.getDefaultValue());
            }
        }
        propertiesCompound.put(NBT_STATS, statsCompound);
        if (player != null) {
            printStatsForDebugging(gear, stats, oldStatValues);
        }
        // Remove enchantments if mod is configured to. Must be done before traits add enchantments!
        if (gear.getOrCreateTag().contains("Enchantments") && Config.Common.forceRemoveEnchantments.get()) {
            SilentGear.LOGGER.debug("Forcibly removing all enchantments from {} as per config settings", playersItemText);
            gear.removeTagKey("Enchantments");
        }
        // Remove trait-added enchantments then let traits re-add them
        EnchantmentTrait.removeTraitEnchantments(gear);
        TraitHelper.activateTraits(gear, 0f, (trait, level, value) -> {
            trait.onRecalculatePost(new TraitActionContext(player, level, gear));
            return 0f;
        });
    } else {
        SilentGear.LOGGER.debug("Not recalculating stats for {}", playersItemText);
    }
    // Update rendering info even if we didn't update stats
    updateRenderingInfo(gear, parts);
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) ITrait(net.silentchaos512.gear.api.traits.ITrait) ListTag(net.minecraft.nbt.ListTag) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) GearType(net.silentchaos512.gear.api.item.GearType) ResourceLocation(net.minecraft.resources.ResourceLocation) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundTag(net.minecraft.nbt.CompoundTag) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Aggregations

EnumGem (net.silentchaos512.gems.lib.EnumGem)4 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 WorldGenMinable (net.minecraft.world.gen.feature.WorldGenMinable)3 ConfigOptionOreGen (net.silentchaos512.gems.config.ConfigOptionOreGen)3 Predicate (com.google.common.base.Predicate)2 WeightedRandomItemSG (net.silentchaos512.gems.util.WeightedRandomItemSG)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1 ItemStack (net.minecraft.item.ItemStack)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ListTag (net.minecraft.nbt.ListTag)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 WeightedRandom (net.minecraft.util.WeightedRandom)1 GearType (net.silentchaos512.gear.api.item.GearType)1