@SubscribeEvent public void onSheared(EntityInteractSpecific event) { ItemStack rainbow = BaublesApi.getBaublesHandler((EntityPlayer)event.getEntityPlayer()).getStackInSlot(6); if (rainbow == null || (rainbow != null && rainbow.getItem() != this)) return; if (!(event.getTarget() instanceof IShearable)) return; if (!(event.getTarget() instanceof EntitySheep) || (event.getTarget() instanceof EntitySheep && ((EntitySheep)event.getTarget()).getSheared())) return; if (event.getItemStack() == null || (event.getItemStack() != null && !(event.getItemStack().getItem() instanceof ItemShears))) return; int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, event.getItemStack()); if (!event.getWorld().isRemote) { List<ItemStack> wools = ((IShearable)event.getTarget()).onSheared(event.getItemStack(), event.getWorld(), event.getPos(), fortune); for (ItemStack is : wools) { Random rand = new Random(); is.setItemDamage(rand.nextInt(15)); EntityItem wool = new EntityItem(event.getWorld(), event.getTarget().posX, event.getTarget().posY, event.getTarget().posZ, is); event.getWorld().spawnEntityInWorld(wool); } } }
@Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) { if(!this.hasEnoughEnergy(stack, energyCostUseSmall)) { return false; } this.consumePower(stack, entity, energyCostUseSmall); if(this.getMode(stack) == Mode.SHEARS) { if (block.getMaterial() != Material.leaves && block != Blocks.web && block != Blocks.tallgrass && block != Blocks.vine && block != Blocks.tripwire && !(block instanceof IShearable)) { return super.onBlockDestroyed(stack, world, block, x, y, z, entity); } else { return true; } } return super.onBlockDestroyed(stack, world, block, x, y, z, entity); }
public boolean onBlockDestroyed(ItemStack item, World world, int id, int y, int z, int s, EntityLivingBase user) { Random rand = new Random(); if(getMaterial() == ToolMaterialMedieval.IGNOTUMITE) { if(user instanceof EntityPlayer) { ((EntityPlayer)user).getFoodStats().addStats(1, 0.2F); } } if (id != Block.leaves.blockID && id != Block.web.blockID && id != Block.tallGrass.blockID && id != Block.vine.blockID && id != Block.tripWire.blockID && !(Block.blocksList[id] instanceof IShearable)) { return super.onBlockDestroyed(item, world, id, y, z, s, user); } else { return true; } }
@Override public TurtleCommandResult useTool(ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction) { if (!Config.enableShearTurtle) return TurtleCommandResult.failure("Shearing turtles have been disabled"); FakeTurtlePlayer player = new FakeTurtlePlayer(turtle); switch (verb) { case Attack: List<Entity> entities = TurtleUtil.getEntitiesNearTurtle(turtle, player, direction); Entity ent = TurtleUtil.getClosestShearableEntity(entities, player); if (ent != null) if (((IShearable) ent).isShearable(new ItemStack(Items.shears), ent.worldObj, (int) ent.posX, (int) ent.posY, (int) ent.posZ)) { TurtleUtil.addItemListToInv(((IShearable) ent).onSheared(new ItemStack(Items.shears), ent.worldObj, (int) ent.posX, (int) ent.posY, (int) ent.posZ, 0), turtle); return TurtleCommandResult.success(); } return TurtleCommandResult.failure(); case Dig: List<ItemStack> items = TurtleUtil.harvestBlock(turtle, player, direction, new ItemStack(Items.shears)); if (items != null) { TurtleUtil.addItemListToInv(items, turtle); return TurtleCommandResult.success(); } return TurtleCommandResult.failure(); } return TurtleCommandResult.failure("An unknown error has occurred, please tell the mod author"); }
@Override public List<ItemStack> getDrops(World world, Random unused, Map<String, Boolean> harvesterSettings, int x, int y, int z) { final Block targetBlock = world.getBlock(x, y, z); if (harvesterSettings.get("silkTouch").equals(Boolean.TRUE)) { if (targetBlock instanceof IShearable) { final ItemStack shears = new ItemStack(Items.shears, 1, 0); final IShearable shearable = (IShearable) targetBlock; if (shearable.isShearable(shears, world, x, y, z)) return shearable.onSheared(shears, world, x, y, z, 0); } if (Item.getItemFromBlock(targetBlock) != null) { final List<ItemStack> drops = Lists.newArrayList(); drops.add(new ItemStack(targetBlock, 1, targetBlock.getDamageValue(world, x, y, z))); return drops; } } return targetBlock.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0); }
protected EntityAnimal findAnimalToShear(int n) { if (!hasUpgrade(UpgradeType.SHEARING)) return null; Point3I point = getPoint(n); boundCheck = new AxisAlignedBB(point.getX(), point.getY()-1, point.getZ(), point.getX()+1, point.getY()+2, point.getZ()+1); List<EntityAnimal> entities = world.getEntitiesWithinAABB(EntityAnimal.class, boundCheck); if (!entities.isEmpty()) { for (EntityAnimal animal: entities) { if ( !slots[SLOT_SHEARS].isEmpty() ) { if (animal instanceof IShearable) { if (((IShearable)animal).isShearable(slots[SLOT_SHEARS], world, point.toPosition())) { return animal; } } } } } return null; }
protected void shearAnimal(EntityAnimal animal) { if ( (!slots[SLOT_SHEARS].isEmpty()) && (hasUpgrade(UpgradeType.SHEARING)) ) { if (animal instanceof IShearable) { int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation("fortune"), slots[SLOT_SHEARS]); List<ItemStack> items = ((IShearable)animal).onSheared(slots[SLOT_SHEARS], world, pos, fortuneLevel); //get the drops for (ItemStack item : items) { addToInventory(item); } if (ToolHelper.damageTool(slots[SLOT_SHEARS], world, pos.getX(), pos.getY(), pos.getZ())) { destroyTool(SLOT_SHEARS); } currentTime = waitTime; addPartialUpdate("currentTime", currentTime); } } }
@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; }
/** * Build the properties for the given block and store them into the internal map */ private BlockProperties(Block block){ // Lava is considered to NOT be a liquid, and is therefore not wallable. This is so we can build cities on the lava surface. isWater = block.getMaterial() == Material.water || block == Blocks.ice; isStair = block instanceof BlockStairs; isTree = block instanceof BlockLog || block instanceof IShearable || block instanceof BlockSnow; isFlowing = isWater || block.getMaterial() == Material.lava || block instanceof BlockDynamicLiquid || block instanceof BlockFalling; isWallable = isWater || block instanceof BlockAir || isTree || block instanceof BlockWeb || block instanceof BlockPumpkin || block instanceof BlockMelon || block instanceof BlockHugeMushroom || block instanceof IPlantable; isOre = block instanceof BlockClay || block instanceof BlockRedstoneOre || block instanceof BlockOre; isGround = block == Blocks.stone || block instanceof BlockDirt || block instanceof BlockGrass || block instanceof BlockGravel || block instanceof BlockSand || block instanceof BlockNetherrack || block instanceof BlockSoulSand || block instanceof BlockMycelium; // Define by what it is not. Not IS_WALLABLE and not a naturally occurring solid block (obsidian/bedrock are exceptions) isArtificial = !(isWallable || isOre || isGround); isDelayed = isStair || isFlowing || block instanceof BlockTorch || block instanceof BlockGlowstone || block instanceof BlockDoor || block instanceof BlockLever || block instanceof BlockSign || block instanceof BlockFire || block instanceof BlockButton || block instanceof BlockVine || block instanceof BlockRedstoneWire || block instanceof BlockDispenser || block instanceof BlockFurnace; // Define by what it is not. isLoaded = !(isWallable || isFlowing || block instanceof BlockTorch || block instanceof BlockLadder); props.put(block, this); }
@Override protected void onImpact(RayTraceResult objectPosition) { if (objectPosition.entityHit != null) { Entity entity = objectPosition.entityHit; entity.motionX += motionX; entity.motionY += motionY; entity.motionZ += motionZ; if (!entity.world.isRemote && entity instanceof IShearable) { IShearable shearable = (IShearable) entity; BlockPos pos = new BlockPos(posX, posY, posZ); if (shearable.isShearable(ItemStack.EMPTY, world, pos)) { List<ItemStack> drops = shearable.onSheared(ItemStack.EMPTY, world, pos, 0); for (ItemStack stack : drops) { PneumaticCraftUtils.dropItemOnGround(stack, world, entity.posX, entity.posY, entity.posZ); } } } } else { Block block = world.getBlockState(objectPosition.getBlockPos()).getBlock(); if (block instanceof IPlantable || block instanceof BlockLeaves) { motionX = oldMotionX; motionY = oldMotionY; motionZ = oldMotionZ; } else { setDead(); } } hitCounter++; if (hitCounter > 20) setDead(); }
public List<ItemStack> chop(Queue<BlockPos> cache, boolean shear) { BlockPos p = cache.peek(); NonNullList<ItemStack> stacks = NonNullList.create(); if (BlockUtils.isLeaves(world, p) || BlockUtils.isLog(world, p)) { IBlockState s = world.getBlockState(p); if (s.getBlock() instanceof IShearable && shear) { stacks.addAll(((IShearable) s.getBlock()).onSheared(new ItemStack(Items.SHEARS), world, p, 0)); } else { s.getBlock().getDrops(stacks, world, p, s, 0); } world.setBlockToAir(p); } cache.poll(); return stacks; }
@Override public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) { if (player.world.isRemote || player.capabilities.isCreativeMode) { return false; } IBlockState state = player.world.getBlockState(pos); Block block = state.getBlock(); if (canShear(itemstack,state) && block instanceof IShearable) { IShearable target = (IShearable)block; if (target.isShearable(itemstack, player.world, pos)) { List<ItemStack> drops = target.onSheared(itemstack, player.world, pos, getEnchantmentLevel(net.minecraft.init.Enchantments.FORTUNE, itemstack)); for (ItemStack stack : drops) { InventoryUtil.addItemToPlayer(player,stack); } itemstack.damageItem(1, player); player.addStat(getBlockStats(block)); player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11); //TODO: Move to IShearable implementors in 1.12+ return true; } } return false; }
public static ArrayList<ItemStack> getIdentifierItems(World world, EntityPlayer player, MovingObjectPosition hit) { int x = hit.blockX; int y = hit.blockY; int z = hit.blockZ; Block mouseoverBlock = world.getBlock(x, y, z); ArrayList<ItemStack> items = new ArrayList<ItemStack>(); ArrayList<IHighlightHandler> handlers = new ArrayList<IHighlightHandler>(); if (highlightIdentifiers.containsKey(null)) handlers.addAll(highlightIdentifiers.get(null)); if (highlightIdentifiers.containsKey(mouseoverBlock)) handlers.addAll(highlightIdentifiers.get(mouseoverBlock)); for (IHighlightHandler ident : handlers) { ItemStack item = ident.identifyHighlight(world, player, hit); if (item != null) items.add(item); } if (items.size() > 0) return items; ItemStack pick = mouseoverBlock.getPickBlock(hit, world, x, y, z); if (pick != null) items.add(pick); try { items.addAll(mouseoverBlock.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0)); } catch (Exception ignored) {} if (mouseoverBlock instanceof IShearable) { IShearable shearable = (IShearable) mouseoverBlock; if (shearable.isShearable(new ItemStack(Items.shears), world, x, y, z)) items.addAll(shearable.onSheared(new ItemStack(Items.shears), world, x, y, z, 0)); } if (items.size() == 0) items.add(0, new ItemStack(mouseoverBlock, 1, world.getBlockMetadata(x, y, z))); return items; }
@SuppressWarnings("deprecation") private static boolean isBlockValidForCover(Block block) { try { if(block == Blocks.AIR || block instanceof IShearable)return false; IBlockState state = block.getDefaultState(); if (block.hasTileEntity() || block.hasTileEntity(block.getDefaultState())) return false; if(!state.isFullCube())return false; return true; } catch (Throwable ignored) { return false; } }
private void scanForSheep(List<EntityAnimal> sheep) { scanForAnimals(sheep, sheepToBreed, maxSheepCount); for (EntityAnimal animal : sheep) { if (animal instanceof IShearable) { IShearable sheep1 = (IShearable) animal; if (sheep1.isShearable(null, getWorld(), new BlockPos(animal))) { sheepToShear.add(animal.getEntityId()); } } } }
public static ArrayList<ItemStack> getIdentifierItems(World world, EntityPlayer player, MovingObjectPosition hit) { BlockPos pos = hit.getBlockPos(); IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); ArrayList<ItemStack> items = new ArrayList<ItemStack>(); ArrayList<IHighlightHandler> handlers = new ArrayList<IHighlightHandler>(); if (highlightIdentifiers.containsKey(null)) handlers.addAll(highlightIdentifiers.get(null)); if (highlightIdentifiers.containsKey(block)) handlers.addAll(highlightIdentifiers.get(block)); for (IHighlightHandler ident : handlers) { ItemStack item = ident.identifyHighlight(world, player, hit); if (item != null) items.add(item); } if (items.size() > 0) return items; ItemStack pick = block.getPickBlock(hit, world, pos); if (pick != null) items.add(pick); try { items.addAll(block.getDrops(world, pos, state, 0)); } catch (Exception ignored) {} if (block instanceof IShearable) { IShearable shearable = (IShearable) block; if (shearable.isShearable(new ItemStack(Items.shears), world, pos)) items.addAll(shearable.onSheared(new ItemStack(Items.shears), world, pos, 0)); } if (items.size() == 0) items.add(0, new ItemStack(block, 1, block.getMetaFromState(state))); return items; }
@Override public List<ItemStack> shear(ItemStack stack, int fortune) { List<ItemStack> result = Lists.newArrayList(); EntityAnimal animal = this.getAnimal(); if ((animal instanceof IShearable)) { IShearable shearable = (IShearable)animal; if (shearable.isShearable(stack, animal.getEntityWorld(), animal.getPosition())) { result = shearable.onSheared(stack, animal.getEntityWorld(), animal.getPosition(), fortune); } } return result; }
@Override public boolean canHarvestBlock(Block block, ItemStack stack) { if(getEnergyStored(stack) > 0 && isEmpowered(stack)) return block instanceof IShearable || block == Blocks.web || block == Blocks.redstone_wire || block == Blocks.tripwire; else return false; }
@Override public float getDigSpeed(ItemStack stack, Block block, int meta) { if(getEnergyStored(stack) >= getEnergyPerUse(stack, block, meta)){ if(block instanceof IShearable && isEmpowered(stack)) return 100.0F; else if(block.getMaterial() == Material.cloth) return super.getDigSpeed(stack, block, meta) * 3; else return super.getDigSpeed(stack, block, meta); }else return 1.0F; }
@Override public int getEnergyPerUse(ItemStack stack, Block block, int meta) { if(isEmpowered(stack)) return block instanceof IShearable ? getEnergyPerUse(stack) / 5 : getEnergyPerUse(stack); else return getEnergyPerUse(stack); }
@Override public void onEntityCollidedWithBlock(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); } } }
@Override public float getStrVsBlock(ItemStack item, Block block, int meta) { if(block.blockMaterial == Material.leaves || block instanceof IShearable || ((Item.shears.getStrVsBlock(item, block)) > super.getStrVsBlock(item, block, meta))) { return this.efficiencyOnProperMaterial; } return super.getStrVsBlock(item, block, meta); }
/** * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if * sword */ @Override public float getStrVsBlock(ItemStack item, Block block, int meta) { if(block.blockMaterial == Material.leaves || block instanceof IShearable || ((Item.shears.getStrVsBlock(item, block)) > super.getStrVsBlock(item, block, meta))) { if(block.blockMaterial == Material.cloth) { return 5.0F; } return 15.0F; } return super.getStrVsBlock(item, block, meta); }
public static Entity getClosestShearableEntity(List<Entity> list, Entity ent) { Vec3 from = Vec3.createVectorHelper(ent.posX, ent.posY, ent.posZ); Entity returnVal = null; double lastDistance = Double.MAX_VALUE; for (Entity entity : list) if (entity instanceof IShearable) { Vec3 to = Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ); if (to.distanceTo(from) < lastDistance) returnVal = entity; } return returnVal; }
@Override public boolean attack(ITurtleAccess turtle, Entity ent) { for (ItemStack is : ((IShearable)ent).onSheared(getCraftingItem(), ent.worldObj, (int)ent.posX, (int)ent.posY, (int)ent.posZ, 0)) { Util.storeOrDrop(turtle, is); } return true; }
@Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entityLivingBase) { if (block != Blocks.vine && !(block instanceof IShearable)) { return super.onBlockDestroyed(stack, world, block, x, y, z, entityLivingBase); } else { return true; } }
@Override public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, net.minecraft.entity.player.EntityPlayer player) { //Compare To: @ItemShears if (player.worldObj.isRemote) { return false; } Block block = player.worldObj.getBlockState(pos).getBlock(); if (block instanceof net.minecraftforge.common.IShearable) { net.minecraftforge.common.IShearable target = (net.minecraftforge.common.IShearable)block; if (target.isShearable(itemstack, player.worldObj, pos)) { java.util.List<ItemStack> drops = target.onSheared(itemstack, player.worldObj, pos, net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.enchantment.Enchantment.fortune.effectId, itemstack)); java.util.Random rand = new java.util.Random(); drops = this.getDrops(drops, rand); for(ItemStack stack : drops) { float f = 0.7F; double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; net.minecraft.entity.item.EntityItem entityitem = new net.minecraft.entity.item.EntityItem(player.worldObj, (double)pos.getX() + d, (double)pos.getY() + d1, (double)pos.getZ() + d2, stack); entityitem.setDefaultPickupDelay(); player.worldObj.spawnEntityInWorld(entityitem); } itemstack.damageItem(1, player); player.addStat(net.minecraft.stats.StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1); } } return false; }
@Override protected ArrayList<ItemStack> harvestBlock(World world, int x, int y, int z) { final Block block = world.getBlock(x, y, z); final int metadata = world.getBlockMetadata(x, y, z); if (block instanceof IShearable) { return ((IShearable) block).onSheared(craftingStack, world, x, y, z, 0); } return block.getDrops(world, x, y, z, metadata, 0); }
public boolean onBlockDestroyed(ItemStack p_150894_1_, World p_150894_2_, Block p_150894_3_, int p_150894_4_, int p_150894_5_, int p_150894_6_, EntityLivingBase p_150894_7_) { if (p_150894_3_.getMaterial() != Material.leaves && p_150894_3_ != Blocks.web && p_150894_3_ != Blocks.tallgrass && p_150894_3_ != Blocks.vine && p_150894_3_ != Blocks.tripwire && !(p_150894_3_ instanceof IShearable)) { return super.onBlockDestroyed(p_150894_1_, p_150894_2_, p_150894_3_, p_150894_4_, p_150894_5_, p_150894_6_, p_150894_7_); } else { return true; } }
@Override public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity) { if (entity.worldObj.isRemote) { return false; } if (entity instanceof IShearable) { IShearable target = (IShearable)entity; if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ)) { // Cauldron start PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) player.getBukkitEntity(), entity.getBukkitEntity()); player.worldObj.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } // Cauldron end ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack)); Random rand = new Random(); for(ItemStack stack : drops) { 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 onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player) { if (player.worldObj.isRemote) { return false; } Block block = player.worldObj.getBlock(x, y, z); if (block instanceof IShearable) { IShearable target = (IShearable)block; if (target.isShearable(itemstack, player.worldObj, x, y, z)) { ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack)); Random rand = new Random(); for(ItemStack stack : drops) { float f = 0.7F; double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d1 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; double d2 = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack); entityitem.delayBeforeCanPickup = 10; player.worldObj.spawnEntityInWorld(entityitem); } itemstack.damageItem(1, player); player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1); } } return false; }
@Override public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity) { if (entity.worldObj.isRemote) { return false; } if (entity instanceof IShearable) { IShearable target = (IShearable)entity; if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ)) { ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack)); Random rand = new Random(); for(ItemStack stack : drops) { 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 onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) { if (player.worldObj.isRemote) { return false; } Block block = player.worldObj.getBlock(x, y, z); if (block instanceof IShearable) { IShearable target = (IShearable) block; if (target.isShearable(stack, player.worldObj, x, y, z)) { ArrayList<ItemStack> drops = target.onSheared(stack, player.worldObj, x, y, z, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)); Random rand = new Random(); for (ItemStack drop : drops) { float f = 0.7F; double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(player.worldObj, (double) x + d, (double) y + d1, (double) z + d2, drop); entityitem.delayBeforeCanPickup = 10; player.worldObj.spawnEntityInWorld(entityitem); } stack.damageItem(1, player); player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(block)], 1); } } return false; }
public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) { if (par3 != Block.leaves.blockID && par3 != Block.web.blockID && par3 != Block.tallGrass.blockID && par3 != Block.vine.blockID && par3 != Block.tripWire.blockID && !(Block.blocksList[par3] instanceof IShearable)) { return super.onBlockDestroyed(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLivingBase); } else { return true; } }