Search in sources :

Example 1 with ItemMobCatcher

use of convenientadditions.item.tools.mobCatcher.ItemMobCatcher in project ConvenientAdditions by Necr0.

the class RecipeSoulGem method matches.

/**
     * Used to check if a recipe matches current crafting inventory
     */
public boolean matches(InventoryCrafting inv, World worldIn) {
    List<ItemStack> list = getStacks(inv);
    if (list.size() != 2)
        return false;
    ItemStack catcher = null;
    for (ItemStack i : list) {
        if (i.getItem() instanceof ItemMobCatcher) {
            if (((ItemMobCatcher) i.getItem()).getEntityId(i) != null) {
                catcher = i.copy();
            }
        }
    }
    if (catcher == null)
        return false;
    for (ItemStack i : list) {
        for (int id : OreDictionary.getOreIDs(i)) {
            String name = OreDictionary.getOreName(id);
            if (name.equals("gemDiamond"))
                return true;
        }
    }
    return false;
}
Also used : ItemMobCatcher(convenientadditions.item.tools.mobCatcher.ItemMobCatcher) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemMobCatcher

use of convenientadditions.item.tools.mobCatcher.ItemMobCatcher in project ConvenientAdditions by Necr0.

the class RecipeSoulGem method getCraftingResult.

/**
     * Returns an Item that is the result of this recipe
     */
public ItemStack getCraftingResult(InventoryCrafting inv) {
    List<ItemStack> list = getStacks(inv);
    String catcher_id = null;
    for (ItemStack i : list) {
        if (i.getItem() instanceof ItemMobCatcher) {
            String tmp_id = ((ItemMobCatcher) i.getItem()).getEntityId(i);
            if (tmp_id != null) {
                catcher_id = tmp_id;
            }
        }
    }
    if (catcher_id == null) {
        return ItemStack.EMPTY;
    } else {
        return ModItems.itemSoulGem.setEntityId(new ItemStack(ModItems.itemSoulGem), catcher_id);
    }
}
Also used : ItemMobCatcher(convenientadditions.item.tools.mobCatcher.ItemMobCatcher) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemMobCatcher

use of convenientadditions.item.tools.mobCatcher.ItemMobCatcher in project ConvenientAdditions by Necr0.

the class EntityMobCatcher method onImpact.

@Override
protected void onImpact(RayTraceResult result) {
    if (this.world.isRemote || mobCatcherItem.isEmpty() || !(mobCatcherItem.getItem() instanceof ItemMobCatcher))
        return;
    if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
        Entity target = result.entityHit;
        if (target instanceof EntityCreature && !target.isDead) {
            List<String> blacklist = new ArrayList<>();
            blacklist.addAll(BLACKLIST_INTERNAL);
            blacklist.addAll(Arrays.asList(ModConfigTools.mobCatcher_blacklist));
            if (!blacklist.contains(EntityRegistry.getEntry(target.getClass()).getRegistryName().toString())) {
                boolean hostile = target instanceof IMob;
                ItemMobCatcher item = (ItemMobCatcher) mobCatcherItem.getItem();
                List<String> bosslist = new ArrayList<>();
                bosslist.addAll(BOSSLIST_INTERNAL);
                bosslist.addAll(Arrays.asList(ModConfigTools.mobCatcher_bosses));
                if ((item.type.captureHostile || !hostile) && (item.type.captureBoss || !bosslist.contains(EntityRegistry.getEntry(target.getClass()).getRegistryName().toString()))) {
                    EntityCreature t = (EntityCreature) target;
                    float resistance = hostile ? 1.25f : 1;
                    float weakness = (t.getMaxHealth() / t.getHealth());
                    float captureStrength = item.type.captureStrength + .5f;
                    if (captureStrength <= 0 || this.world.rand.nextFloat() < (1 - (weakness / (1.5 * captureStrength) * resistance))) {
                        if (!mobCatcherItem.hasTagCompound())
                            mobCatcherItem.setTagCompound(new NBTTagCompound());
                        NBTTagCompound nbt = mobCatcherItem.getTagCompound();
                        nbt.setTag("CONTAINED_ENTITY", t.serializeNBT());
                        nbt.setString("CONTAINED_ENTITY_ID", EntityRegistry.getEntry(target.getClass()).getRegistryName().toString());
                        mobCatcherItem.setItemDamage(1);
                        world.playSound(null, result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, .5f, 2f);
                        t.setDead();
                        dropItem(result.hitVec);
                    } else {
                        breakCatcher(result.hitVec);
                    }
                } else {
                    breakCatcher(result.hitVec);
                }
            }
        }
    } else if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
        dropItem(result.hitVec);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IMob(net.minecraft.entity.monster.IMob) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemMobCatcher(convenientadditions.item.tools.mobCatcher.ItemMobCatcher) EntityCreature(net.minecraft.entity.EntityCreature)

Aggregations

ItemMobCatcher (convenientadditions.item.tools.mobCatcher.ItemMobCatcher)3 ItemStack (net.minecraft.item.ItemStack)2 ArrayList (java.util.ArrayList)1 Entity (net.minecraft.entity.Entity)1 EntityCreature (net.minecraft.entity.EntityCreature)1 IMob (net.minecraft.entity.monster.IMob)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1