Search in sources :

Example 1 with EnumDifficulty

use of net.minecraft.world.EnumDifficulty in project SilentGems by SilentChaos512.

the class ModuleEntityRandomEquipment method tryGiveMobEquipment.

public static void tryGiveMobEquipment(EntityLivingBase entity) {
    if (!MODULE_ENABLED || entity.world.isRemote || !(entity instanceof EntityMob))
        return;
    EnumDifficulty worldDiff = entity.world.getDifficulty();
    DifficultyInstance localDiff = entity.world.getDifficultyForLocation(entity.getPosition());
    Random rand = SilentGems.random;
    ItemStack sword = null;
    // chances of spawning with equipment.
    if (entity instanceof EntityZombie) {
        if (selectBasedOnDifficulty(SWORD_MULTI_ZOMBIE * SWORD_CHANCE, worldDiff, localDiff, rand))
            sword = generateRandomMeleeWeapon(entity, rand);
    } else if (entity instanceof EntitySkeleton) {
        if (selectBasedOnDifficulty(SWORD_MULTI_SKELETON * SWORD_CHANCE, worldDiff, localDiff, rand))
            sword = generateRandomMeleeWeapon(entity, rand);
    }
    /*else if (EntityList.NAME_TO_CLASS.get("headcrumbs.Human") == entity.getClass()) {
      if (selectBasedOnDifficulty(SWORD_MULTI_HUMAN * SWORD_CHANCE, worldDiff, localDiff, rand)) {
        // A little easter egg...
        if (entity.getName().equals(Names.SILENT_CHAOS_512)) {
          sword = SILENT_KATANA.copy();
          sword.setStackDisplayName("Silent's Creatively Named Katana");
        } else {
          sword = generateRandomMeleeWeapon(entity, rand);
        }
      }
    }*/
    // FIXME
    ItemStack currentMain = entity.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
    if (StackHelper.isValid(sword) && (StackHelper.isEmpty(currentMain) || !currentMain.hasTagCompound())) {
        String makerName = SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Mob", entity.getName());
        ToolHelper.setOriginalOwner(sword, makerName);
        entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, sword);
        if (entity instanceof EntityLiving)
            ((EntityLiving) entity).setDropChance(EntityEquipmentSlot.MAINHAND, EQUIPMENT_DROP_CHANCE);
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Random(java.util.Random) EntityLiving(net.minecraft.entity.EntityLiving) EntityZombie(net.minecraft.entity.monster.EntityZombie) DifficultyInstance(net.minecraft.world.DifficultyInstance) EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) ItemStack(net.minecraft.item.ItemStack) EnumDifficulty(net.minecraft.world.EnumDifficulty)

Example 2 with EnumDifficulty

use of net.minecraft.world.EnumDifficulty 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)

Example 3 with EnumDifficulty

use of net.minecraft.world.EnumDifficulty in project Charset by CharsetMC.

the class CharsetTweakMobEqualizer method upgradeMob.

@SubscribeEvent(priority = EventPriority.LOW)
public void upgradeMob(LivingSpawnEvent.SpecialSpawn event) {
    EnumDifficulty difficulty = event.getWorld().getDifficulty();
    if (difficulty == null || difficulty.getDifficultyId() <= 1) {
        return;
    }
    if (!(event.getEntityLiving() instanceof EntityMob)) {
        return;
    }
    EntityMob ent = (EntityMob) event.getEntityLiving();
    // 2) Should we add more granular setups (like only some elements of armor, but at a higher frequency)?
    if (event.getWorld().rand.nextInt(400) > difficulty.getDifficultyId()) {
        return;
    }
    if (!ent.canPickUpLoot())
        return;
    EntityPlayer template = pickNearPlayer(event);
    if (template == null) {
        return;
    }
    int equipmentCount = 0;
    ItemStack[] equipmentCopies = new ItemStack[6];
    boolean copyArmor = event.getEntity() instanceof IRangedAttackMob || event.getWorld().rand.nextBoolean();
    boolean copyWeapon = !(event.getEntity() instanceof IRangedAttackMob) || event.getWorld().rand.nextBoolean();
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (slot.getSlotType() == EntityEquipmentSlot.Type.ARMOR && copyArmor) {
            ItemStack is = template.getItemStackFromSlot(slot);
            if (!is.isEmpty() && is.getItem().isValidArmor(is, slot, ent)) {
                equipmentCopies[slot.ordinal()] = is.copy();
                equipmentCount++;
            } else {
                equipmentCopies[slot.ordinal()] = ItemStack.EMPTY;
            }
        }
    }
    List<ItemStack> carriedWeapons = new ArrayList<ItemStack>();
    if (copyWeapon) {
        ItemStack currentWeapon = ent.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
        double currentWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, currentWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
        for (int i = 0; i < 9; i++) {
            ItemStack playerWeapon = template.inventory.getStackInSlot(i);
            if (playerWeapon.isEmpty() || playerWeapon.getCount() != 1 || playerWeapon.getMaxStackSize() != 1) {
                continue;
            }
            EnumAction act = playerWeapon.getItemUseAction();
            if (act != EnumAction.BLOCK && act != EnumAction.NONE && act != EnumAction.BOW) {
                continue;
            }
            double playerWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, playerWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
            if (playerWeaponDmg > currentWeaponDmg) {
                carriedWeapons.add(playerWeapon.copy());
            }
        }
    }
    if (!carriedWeapons.isEmpty()) {
        equipmentCopies[0] = carriedWeapons.get(event.getWorld().rand.nextInt(carriedWeapons.size())).copy();
        equipmentCount++;
    }
    if (equipmentCount <= 0) {
        return;
    }
    event.setCanceled(true);
    ent.onInitialSpawn(ent.world.getDifficultyForLocation(new BlockPos(event.getEntity())), null);
    // We need to cancel the event so that we can call this before the below happens
    ent.setCanPickUpLoot(false);
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (equipmentCopies[slot.ordinal()] != null) {
            ent.setItemStackToSlot(slot, equipmentCopies[slot.ordinal()]);
        }
        ent.setDropChance(slot, 0);
    }
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ArrayList(java.util.ArrayList) IRangedAttackMob(net.minecraft.entity.IRangedAttackMob) EnumAction(net.minecraft.item.EnumAction) EntityMob(net.minecraft.entity.monster.EntityMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EnumDifficulty(net.minecraft.world.EnumDifficulty) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ItemStack (net.minecraft.item.ItemStack)3 EnumDifficulty (net.minecraft.world.EnumDifficulty)3 EntityMob (net.minecraft.entity.monster.EntityMob)2 DifficultyInstance (net.minecraft.world.DifficultyInstance)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 EntityLiving (net.minecraft.entity.EntityLiving)1 IRangedAttackMob (net.minecraft.entity.IRangedAttackMob)1 EntitySkeleton (net.minecraft.entity.monster.EntitySkeleton)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1 EnumAction (net.minecraft.item.EnumAction)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 ItemGemSword (net.silentchaos512.gems.item.tool.ItemGemSword)1 EnumGem (net.silentchaos512.gems.lib.EnumGem)1