Search in sources :

Example 16 with EnumGem

use of net.silentchaos512.gems.lib.EnumGem in project SilentGems by SilentChaos512.

the class ItemHoldingGem method addRecipes.

@Override
public void addRecipes(RecipeMaker recipes) {
    for (EnumGem gem : EnumGem.values()) {
        ItemStack stack = new ItemStack(this);
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setShort(NBT_GEM_ID, (short) gem.ordinal());
        recipes.addShapedOre("holding_gem_" + gem.name(), stack, "gcg", "s s", "gcg", 'g', "ingotGold", 'c', ModItems.craftingMaterial.chaosEssenceEnriched, 's', gem.getItemOreName());
    }
}
Also used : EnumGem(net.silentchaos512.gems.lib.EnumGem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 17 with EnumGem

use of net.silentchaos512.gems.lib.EnumGem in project SilentGems by SilentChaos512.

the class ToolRandomizer method randomizeArmor.

public ItemStack randomizeArmor(ItemStack armor, float superChance) {
    if (!ToolHelper.hasNoConstruction(armor))
        return armor;
    IArmor itool = (IArmor) armor.getItem();
    // Regular or super?
    boolean superTier = SilentGems.random.nextFloat() < superChance;
    // How many gems?
    boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
    boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
    boolean gem4 = gem3 && SilentGems.random.nextFloat() < FOURTH_GEM_CHANCE;
    // Gem array
    EnumGem[] gems;
    if (gem4) {
        gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
    } else if (gem3) {
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, EnumGem.getRandom(), EnumGem.getRandom(), g1 };
    } else if (gem2) {
        EnumGem g1 = EnumGem.getRandom();
        EnumGem g2 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g2, g1, g2 };
    } else {
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g1, g1, g1 };
    }
    // Crafting stack array
    ItemStack[] craftingStacks = new ItemStack[gems.length];
    for (int i = 0; i < craftingStacks.length; ++i) {
        craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
    }
    ItemStack frame = ModItems.armorFrame.getFrameForArmorPiece((ItemArmor) armor.getItem(), superTier ? EnumMaterialTier.SUPER : EnumMaterialTier.REGULAR);
    ItemStack temp = ArmorHelper.constructArmor(armor.getItem(), frame, craftingStacks);
    // Set name
    String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
    ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
    armor.setTagCompound(temp.getTagCompound());
    return temp;
}
Also used : EnumGem(net.silentchaos512.gems.lib.EnumGem) ItemStack(net.minecraft.item.ItemStack) IArmor(net.silentchaos512.gems.api.IArmor)

Example 18 with EnumGem

use of net.silentchaos512.gems.lib.EnumGem in project SilentGems by SilentChaos512.

the class ToolRandomizer method randomize.

public ItemStack randomize(ItemStack tool, float superChance) {
    if (tool.getItem() instanceof IArmor)
        return randomizeArmor(tool, superChance);
    if (!(tool.getItem() instanceof ITool) || !ToolHelper.hasNoConstruction(tool))
        return tool;
    ITool itool = (ITool) tool.getItem();
    // Regular or super?
    boolean superTier = !itool.getValidTiers().contains(EnumMaterialTier.REGULAR) || (SilentGems.random.nextFloat() < superChance && itool.getValidTiers().contains(EnumMaterialTier.SUPER));
    // How many gems?
    boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
    boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
    // Gem array
    EnumGem[] gems;
    if (gem3) {
        // 3 gems
        gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
    } else if (gem2) {
        // 2 gems (3rd = 1st)
        EnumGem g1 = EnumGem.getRandom();
        EnumGem g2 = EnumGem.getRandom();
        if (tool.getItem() == ModItems.sword)
            gems = new EnumGem[] { g1, g2 };
        else
            gems = new EnumGem[] { g1, g2, g1 };
    } else {
        // 1 gem
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g1, g1 };
    }
    // Crafting stack array
    ItemStack[] craftingStacks = new ItemStack[gems.length];
    for (int i = 0; i < craftingStacks.length; ++i) {
        craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
    }
    // Select rod
    ItemStack rod;
    if (superTier) {
        ItemStack[] choices = new ItemStack[] { ModItems.craftingMaterial.toolRodGold, ModItems.craftingMaterial.toolRodSilver, ModItems.craftingMaterial.toolRodIron };
        rod = choices[SilentGems.random.nextInt(choices.length)];
    } else {
        ItemStack[] choices = new ItemStack[] { new ItemStack(Items.STICK), new ItemStack(Items.BONE), ModItems.craftingMaterial.toolRodIron };
        rod = choices[SilentGems.random.nextInt(choices.length)];
    }
    ItemStack temp = ToolHelper.constructTool(tool.getItem(), rod, craftingStacks);
    if (temp.getItem() instanceof ItemGemKatana)
        temp = ((ItemGemKatana) temp.getItem()).addDefaultGrip(temp);
    // Set name
    String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
    ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
    tool.setTagCompound(temp.getTagCompound());
    return temp;
}
Also used : EnumGem(net.silentchaos512.gems.lib.EnumGem) ItemStack(net.minecraft.item.ItemStack) IArmor(net.silentchaos512.gems.api.IArmor) ITool(net.silentchaos512.gems.api.ITool) ItemGemKatana(net.silentchaos512.gems.item.tool.ItemGemKatana)

Example 19 with EnumGem

use of net.silentchaos512.gems.lib.EnumGem 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 20 with EnumGem

use of net.silentchaos512.gems.lib.EnumGem in project SilentGems by SilentChaos512.

the class ModuleEntityRandomEquipment method generateRandomMeleeWeapon.

public static ItemStack generateRandomMeleeWeapon(EntityLivingBase entity, Random rand) {
    EnumDifficulty worldDiff = entity.world.getDifficulty();
    DifficultyInstance localDiff = entity.world.getDifficultyForLocation(entity.getPosition());
    boolean superTier = selectBasedOnDifficulty(SUPER_CHANCE, worldDiff, localDiff, rand);
    boolean genKatana = superTier && rand.nextFloat() < KATANA_CHANCE;
    boolean genMachete = !genKatana && rand.nextFloat() < MACHETE_CHANCE;
    ItemGemSword item;
    int maxGemCount;
    if (genMachete) {
        item = ModItems.machete;
        maxGemCount = 3;
    } else if (genKatana) {
        item = ModItems.katana;
        maxGemCount = 3;
    } else {
        item = ModItems.sword;
        maxGemCount = rand.nextFloat() < SWORD_EXTRA_GEM_CHANCE ? 3 : 2;
    }
    Set<EnumGem> gemSet = selectRandomGems(maxGemCount, rand);
    List<EnumGem> gemList = expandGemsSet(gemSet, maxGemCount, rand);
    List<ItemStack> mats = Lists.newArrayList();
    for (EnumGem gem : gemList) mats.add(superTier ? gem.getItemSuper() : gem.getItem());
    // SilentGems.logHelper.debug(superTier, gemList);
    return item.constructTool(superTier, mats.toArray(new ItemStack[mats.size()]));
}
Also used : DifficultyInstance(net.minecraft.world.DifficultyInstance) EnumGem(net.silentchaos512.gems.lib.EnumGem) ItemGemSword(net.silentchaos512.gems.item.tool.ItemGemSword) ItemStack(net.minecraft.item.ItemStack) EnumDifficulty(net.minecraft.world.EnumDifficulty)

Aggregations

EnumGem (net.silentchaos512.gems.lib.EnumGem)27 ItemStack (net.minecraft.item.ItemStack)16 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)3 Random (java.util.Random)2 IArmor (net.silentchaos512.gems.api.IArmor)2 WeightedRandomItemSG (net.silentchaos512.gems.util.WeightedRandomItemSG)2 RecipeMaker (net.silentchaos512.lib.registry.RecipeMaker)2 Predicate (com.google.common.base.Predicate)1 Block (net.minecraft.block.Block)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 IItemColor (net.minecraft.client.renderer.color.IItemColor)1 ItemColors (net.minecraft.client.renderer.color.ItemColors)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1 Item (net.minecraft.item.Item)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 WeightedRandom (net.minecraft.util.WeightedRandom)1