net.minecraftforge.common.IShearable Java Examples

The following examples show how to use net.minecraftforge.common.IShearable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Shearables.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void shearEntity(ItemStack stack, IWorld world, BlockPos pos, IShearable target) {
	if (!(target instanceof Entity)) {
		throw new IllegalArgumentException("Tried to call shearEntity on something that was not an entity!");
	}

	Entity entity = (Entity) target;

	List<ItemStack> drops = target.onSheared(stack, world, pos, EnchantmentHelper.getLevel(Enchantments.FORTUNE, stack));
	Random rand = world.getRandom();

	for (ItemStack drop : drops) {
		ItemEntity item = entity.dropStack(drop, 1.0F);

		if (item == null) {
			continue;
		}

		float accelerationX = (rand.nextFloat() - rand.nextFloat()) * 0.1F;
		float accelerationY = rand.nextFloat() * 0.05F;
		float accelerationZ = (rand.nextFloat() - rand.nextFloat()) * 0.1F;

		item.setVelocity(item.getVelocity().add(accelerationX, accelerationY, accelerationZ));
	}

	if (stack.damage(1, world.getRandom(), null)) {
		stack.setCount(0);
	}
}
 
Example #2
Source File: MixinShearsItem.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean useOnEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity entity, Hand hand) {
	if (entity.world.isClient) {
		return false;
	}

	// Avoid duplicating vanilla interactions
	if (this == Items.SHEARS) {
		EntityType<?> type = entity.getType();

		if (type == EntityType.MOOSHROOM || type == EntityType.SHEEP || type == EntityType.SNOW_GOLEM) {
			return false;
		}
	}

	if (entity instanceof IShearable) {
		IShearable target = (IShearable) entity;
		BlockPos pos = entity.getBlockPos();

		if (target.isShearable(stack, entity.world, pos)) {
			Shearables.shearEntity(stack, entity.world, pos, target);
		}

		return true;
	}

	return false;
}
 
Example #3
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean applyShearBehavior(ItemStack itemStack, BlockPos pos, EntityPlayer player) {
    Block block = player.world.getBlockState(pos).getBlock();
    if (block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(itemStack, player.world, pos)) {
            int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack);
            List<ItemStack> drops = target.onSheared(itemStack, player.world, pos, fortuneLevel);
            dropListOfItems(player.world, pos, drops);
                     player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: ItemInfo.java    From NotEnoughItems with MIT License 5 votes vote down vote up
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;
}
 
Example #5
Source File: ItemBaseChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: ItemBaseOmnitool.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #7
Source File: EntityVortex.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onImpact(MovingObjectPosition objectPosition){
    if(objectPosition.entityHit != null) {
        Entity entity = objectPosition.entityHit;
        entity.motionX += motionX;
        entity.motionY += motionY;
        entity.motionZ += motionZ;
        if(!entity.worldObj.isRemote && entity instanceof IShearable) {
            IShearable shearable = (IShearable)entity;
            int x = (int)Math.floor(posX);
            int y = (int)Math.floor(posY);
            int z = (int)Math.floor(posZ);
            if(shearable.isShearable(null, worldObj, x, y, z)) {
                List<ItemStack> drops = shearable.onSheared(null, worldObj, x, y, z, 0);
                for(ItemStack stack : drops) {
                    PneumaticCraftUtils.dropItemOnGround(stack, worldObj, entity.posX, entity.posY, entity.posZ);
                }
            }
        }

    } else {
        Block block = worldObj.getBlock(objectPosition.blockX, objectPosition.blockY, objectPosition.blockZ);
        if(block instanceof IPlantable || block instanceof BlockLeaves) {
            motionX = oldMotionX;
            motionY = oldMotionY;
            motionZ = oldMotionZ;
        } else {
            setDead();
        }
    }
    hitCounter++;
    if(hitCounter > 20) setDead();
}