public boolean shearEntity(ItemStack stack, World world, EntityPlayer player, Entity entity, int fortune) { if(!(entity instanceof IShearable)) { return false; } IShearable shearable = (IShearable) entity; if(shearable.isShearable(stack, world, entity.getPosition())) { if(!world.isRemote) { List<ItemStack> drops = shearable.onSheared(stack, world, entity.getPosition(), fortune); Random rand = world.rand; for(ItemStack drop : drops) { EntityItem entityItem = entity.entityDropItem(drop, 1.0F); if(entityItem != null) { entityItem.motionY += rand.nextFloat() * 0.05F; entityItem.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F; entityItem.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F; } } } ToolHelper.damageTool(stack, 1, player); return true; } return false; }
if(block instanceof IShearable) { IShearable target = (IShearable) block; if(target.isShearable(itemstack, world, pos)) { int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemstack); List<ItemStack> drops = target.onSheared(itemstack, world, pos, fortune);
@Override public boolean itemInteractionForEntity(@Nonnull ItemStack itemstack, EntityPlayer player, EntityLivingBase entity, EnumHand hand) { if(entity.world.isRemote) return false; if(entity instanceof IShearable) { IShearable target = (IShearable)entity; if(target.isShearable(itemstack, entity.world, new BlockPos(entity))) { List<ItemStack> drops = target.onSheared(itemstack, entity.world, new BlockPos(entity), EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemstack)); for(ItemStack stack : drops) { entity.entityDropItem(stack, 1.0F); } ToolCommons.damageItem(itemstack, 1, player, MANA_PER_DAMAGE); } return true; } return false; }
@Override public boolean onBlockStartBreak(@Nonnull ItemStack itemstack, @Nonnull BlockPos pos, EntityPlayer player) { if (player.world.isRemote) return false; Block block = player.world.getBlockState(pos).getBlock(); if(block instanceof IShearable) { IShearable target = (IShearable)block; if(target.isShearable(itemstack, player.world, pos)) { List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemstack)); Random rand = new Random(); for(ItemStack stack : drops) { float f = 0.7F; double d = rand.nextFloat() * f + (1D - f) * 0.5; double d1 = rand.nextFloat() * f + (1D - f) * 0.5; double d2 = rand.nextFloat() * f + (1D - f) * 0.5; EntityItem entityitem = new EntityItem(player.world, pos.getX() + d, pos.getY() + d1, pos.getZ() + d2, stack); entityitem.setPickupDelay(10); player.world.spawnEntity(entityitem); } ToolCommons.damageItem(itemstack, 1, player, MANA_PER_DAMAGE); player.addStat(StatList.getBlockStats(block), 1); return true; } } return false; }
if(entity instanceof IShearable && ((IShearable) entity).isShearable(stack, world, new BlockPos(entity))) { shearables.add(entity); } else if(entity instanceof EntityCow) {
@Override public void onUsingTick(ItemStack stack, EntityLivingBase living, int count) { if(living.world.isRemote) return; if(count != getMaxItemUseDuration(stack) && count % 5 == 0) { int range = 12; List sheep = living.world.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(living.posX - range, living.posY - range, living.posZ - range, living.posX + range, living.posY + range, living.posZ + range), Predicates.instanceOf(IShearable.class)); if(sheep.size() > 0) { for(IShearable target : (List<IShearable>) sheep) { Entity entity = (Entity) target; if(target.isShearable(stack, entity.world, new BlockPos(entity))) { List<ItemStack> drops = target.onSheared(stack, entity.world, new BlockPos(entity), EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack)); for(ItemStack drop : drops) { entity.entityDropItem(drop, 1.0F); } ToolCommons.damageItem(stack, 1, living, MANA_PER_DAMAGE); break; } } } } }
@Override public boolean apply(@Nullable Entity entity) { return entity instanceof IShearable && !entity.isDead && ((IShearable) entity).isShearable(Prep.getEmpty(), entity.world, entity.getPosition()); }
if (target.isShearable(itemstack, player.world, pos))
@Override public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) { if (entity instanceof IShearable) { IShearable sheep = (IShearable) entity; ItemStack fake = new ItemStack(Items.SHEARS); if (sheep.isShearable(fake, world, pos)) { List<ItemStack> drops = sheep.onSheared(fake, world, pos, FORTUNE);//since iShearable doesnt do drops, but DOES do sound/make sheep naked UtilItemStack.dropItemStacksInWorld(world, pos, drops); } } }
/** * Returns true if the item can be used on the given entity, e.g. shears on sheep. COPY from vanilla SHEARS */ @Override public boolean itemInteractionForEntity(ItemStack itemstack, net.minecraft.entity.player.EntityPlayer player, EntityLivingBase entity, net.minecraft.util.EnumHand hand) { if (entity.world.isRemote) { return false; } if (entity instanceof net.minecraftforge.common.IShearable) { net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable) entity; BlockPos pos = new BlockPos(entity.posX, entity.posY, entity.posZ); if (target.isShearable(itemstack, entity.world, pos)) { java.util.List<ItemStack> drops = target.onSheared(itemstack, entity.world, pos, net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack)); java.util.Random rand = new java.util.Random(); for (ItemStack stack : drops) { net.minecraft.entity.item.EntityItem ent = entity.entityDropItem(stack, 1.0F); ent.motionY += rand.nextFloat() * 0.05F; ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F; ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F; } itemstack.damageItem(1, entity); } return true; } return false; }
@Override public boolean onHitEntity(Entity entityHit, DamageSource source, float ammount) { if(!source.getDamageType().equals("piercing.arrow")) { if(entityHit != this.shootingEntity && entityHit.attackEntityFrom(getPiercingDamage(), ammount)) { this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); } if (entityHit instanceof IShearable) { if (((IShearable) entityHit).isShearable(ItemStack.EMPTY, world, new BlockPos(entityHit))) { List<ItemStack> drops = ((IShearable) entityHit).onSheared(ItemStack.EMPTY, world, new BlockPos(entityHit), 1); if(!world.isRemote) { for (ItemStack stack : drops) { EntityItem ent = entityHit.entityDropItem(stack, 1.0F); if (ent != null) { ent.motionY += rand.nextFloat() * 0.05F; ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F; ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F; } } } } } return true; } return false; }
@Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity, EnumHand hand) { if (ServerHelper.isClientWorld(entity.world)) { entity.rotationYaw += 90; entity.rotationYaw %= 360; return false; } if (entity instanceof IShearable) { IShearable target = (IShearable) entity; BlockPos pos = new BlockPos(entity.posX, entity.posY, entity.posZ); if (target.isShearable(stack, entity.world, pos)) { List<ItemStack> drops = target.onSheared(stack, entity.world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack)); for (ItemStack drop : drops) { EntityItem ent = entity.entityDropItem(drop, 1.0F); ent.motionY += MathHelper.RANDOM.nextFloat() * 0.05F; ent.motionX += (MathHelper.RANDOM.nextFloat() - MathHelper.RANDOM.nextFloat()) * 0.1F; ent.motionZ += (MathHelper.RANDOM.nextFloat() - MathHelper.RANDOM.nextFloat()) * 0.1F; } if (!player.capabilities.isCreativeMode) { useEnergy(stack, false); } entity.rotationYaw += 90; entity.rotationYaw %= 360; } return true; } entity.rotationYaw += 90; entity.rotationYaw %= 360; return false; }
private boolean shear(BlockPos position, IShearable block, ItemStack shears) { if (block.isShearable(shears, world, position)) { List<ItemStack> drops = block.onSheared(shears, world, position, getFortune()); drops = InventoryTools.insertItems(plantableInventory, drops, false); InventoryTools.insertOrDropItems(mainInventory, drops, world, pos); world.setBlockToAir(position); return true; } return false; }
if (block instanceof net.minecraftforge.common.IShearable) { net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable) block; if (target.isShearable(itemstack, player.world, pos)) { java.util.List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack));
if(shearable.isShearable(selfStack, world, blockPos)) { drops.clear(); int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, selfStack);
} else if (block.getBlock() instanceof IShearable) { IShearable target = (IShearable) block.getBlock(); if (target.isShearable(ItemStack.EMPTY, world, pos)) { List<ItemStack> drops = target.onSheared(ItemStack.EMPTY, world, pos, 1); if (!world.isRemote) {
@Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player) { if (ServerHelper.isClientWorld(player.world)) { return false; } Block block = player.world.getBlockState(pos).getBlock(); if (block instanceof IShearable) { IShearable target = (IShearable) block; if (target.isShearable(stack, player.world, pos)) { List<ItemStack> drops = target.onSheared(stack, player.world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack)); for (ItemStack drop : drops) { float f = 0.7F; double d = MathHelper.RANDOM.nextFloat() * f + (1.0F - f) * 0.5D; double d1 = MathHelper.RANDOM.nextFloat() * f + (1.0F - f) * 0.5D; double d2 = MathHelper.RANDOM.nextFloat() * f + (1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(player.world, pos.getX() + d, pos.getY() + d1, pos.getZ() + d2, drop); entityitem.setPickupDelay(10); player.world.spawnEntity(entityitem); } if (!player.capabilities.isCreativeMode) { useEnergy(stack, false); } player.addStat(StatList.getBlockStats(block), 1); } } return false; }
for (int dz = -DarkSteelConfig.shearsBlockAreaBoostWhenPowered.get(); dz <= DarkSteelConfig.shearsBlockAreaBoostWhenPowered.get(); dz++) { Block block2 = player.world.getBlockState(new BlockPos(x + dx, y + dy, z + dz)).getBlock(); if (block2 instanceof IShearable && ((IShearable) block2).isShearable(itemstack, player.world, new BlockPos(x + dx, y + dy, z + dz))) { res.add(new BlockPos(x + dx, y + dy, z + dz));
if (!((IShearable) state.getBlock()).isShearable(shears, world, pos)) { return null;
/** * Called when tools that act as shears start breaking a block. Free operation. */ protected void shearBlock(ItemStack stack, BlockPos pos, EntityPlayer player) { if (player.getEntityWorld().isRemote) { return; } Block block = player.getEntityWorld().getBlockState(pos).getBlock(); if (block instanceof IShearable) { IShearable target = (IShearable) block; if (target.isShearable(stack, player.getEntityWorld(), pos) && PlayerHelper.hasBreakPermission(((EntityPlayerMP) player), pos)) { List<ItemStack> drops = target.onSheared(stack, player.getEntityWorld(), pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack)); WorldHelper.createLootDrop(drops, player.getEntityWorld(), pos); stack.damageItem(1, player); player.addStat(StatList.getBlockStats(block), 1); } } }