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;
}
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);
}
}
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);
}
}
Aggregations