Java Code Examples for net.minecraft.entity.player.EntityPlayer#swingItem()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#swingItem() . 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: TileExtendedNodeJar.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
public int onWandRightClick(World world, ItemStack wandstack, EntityPlayer player, int x, int y, int z, int side, int md) {
    if (!world.isRemote) {
        this.drop = false;
        world.setBlock(x, y, z, ConfigBlocks.blockAiry, 0, 3);
        TileExtendedNode tn = (TileExtendedNode) world.getTileEntity(x, y, z);
        if (tn != null) {
            tn.setAspects(getAspects());
            tn.setNodeModifier(getNodeModifier());
            tn.setNodeType(getNodeType());
            tn.setExtendedNodeType(getExtendedNodeType());
            new Injector(tn, TileNode.class).setField("id", getId());
            tn.readBehaviorSnapshot(getBehaviorSnapshot());
            world.markBlockForUpdate(x, y, z);
            tn.markDirty();
        }
    }
    world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(ConfigBlocks.blockJar) + 61440);
    player.worldObj.playSound(x + 0.5D, y + 0.5D, z + 0.5D, "random.glass", 1.0F, 0.9F + player.worldObj.rand.nextFloat() * 0.2F, false);
    player.swingItem();
    return 0;
}
 
Example 2
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
private void feedBaby(EntityAnimal animal, EntityPlayer player, ItemStack stack) {
	int currentAge = animal.getGrowingAge();
	int age = (int) (-currentAge * 0.1F);
	animal.setGrowingAge(currentAge + age);
	player.swingItem();

	Random itemRand = animal.worldObj.rand;
	for (int i = 0; i < 3; i++) {
		double d0 = itemRand.nextGaussian() * 0.02D;
		double d1 = itemRand.nextGaussian() * 0.02D;
		double d2 = itemRand.nextGaussian() * 0.02D;
		animal.worldObj.spawnParticle("happyVillager", animal.posX + itemRand.nextFloat() * 0.5, animal.posY + 0.5 + itemRand.nextFloat() * 0.5, animal.posZ + itemRand.nextFloat() * 0.5, d0, d1, d2);
	}

	if (!player.capabilities.isCreativeMode)
		if (--stack.stackSize <= 0)
			player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
 
Example 3
Source File: BlockCraftingGrid.java    From Translocators with MIT License 6 votes vote down vote up
public boolean placeBlock(World world, EntityPlayer player, int x, int y, int z, int side) {
    if(disableCraftingGridKey)
        return false;

    Block block = world.getBlock(x, y, z);
    if(side != 1 && block != Blocks.snow_layer)
        return false;

    if (block != Blocks.vine && block != Blocks.tallgrass && block != Blocks.deadbush
            && !block.isReplaceable(world, x, y, z))
        y++;

    if (!world.isSideSolid(x, y-1, z, ForgeDirection.UP))
        return false;

    if (!world.canPlaceEntityOnSide(this, x, y, z, false, 1, null, null))
        return false;

    player.swingItem();
    if(!world.setBlock(x, y, z, this))
        return false;

    onBlockPlacedBy(world, x, y, z, player, null);
    return true;
}
 
Example 4
Source File: TileCraftingGrid.java    From Translocators with MIT License 6 votes vote down vote up
public void craft(EntityPlayer player) {
    InventoryCrafting craftMatrix = getCraftMatrix();

    for (int i = 0; i < 4; i++) {
        ItemStack mresult = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj);
        if (mresult != null) {
            doCraft(mresult, craftMatrix, player);
            break;
        }

        rotateItems(craftMatrix);
    }
    player.swingItem();
    dropItems();
    worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
 
Example 5
Source File: ItemThorHammerBroken.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX + 8, player.posY, player.posZ - 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX - 8, player.posY, player.posZ + 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX - 8, player.posY, player.posZ - 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX + 8, player.posY, player.posZ + 8));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX, player.posY + 4, player.posZ));
    world.spawnEntityInWorld(new EntityAlumentum(world, player.posX, player.posY + 8, player.posZ));

    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example 6
Source File: ItemStreamChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) {
    Block bi = world.getBlock(x, y, z);
    if ((!player.isSneaking()) && (Utils.isWoodLog(world, x, y, z))) {
        if (!world.isRemote) {
            if (BlockUtils.breakFurthestBlock(world, x, y, z, bi, player)) {
                world.playSoundEffect(x, y, z, "thaumcraft:bubble", 0.15F, 1.0F);
                ElectricItem.manager.use(itemstack, cost, player);
                this.alternateServer = (!this.alternateServer);
            }
        } else {
            player.swingItem();
            ElectricItem.manager.use(itemstack, cost, player);
            this.alternateClient = (!this.alternateClient);
        }
    }
    return super.onItemUse(itemstack, player, world, x, y, z, par7, par8, par9, par10);
}
 
Example 7
Source File: WandOverlord.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
public boolean hellfire(World world, ItemStack wand, EntityPlayer player, int x, int y, int z, int side) {
    if (world.isRemote || wand == null || !(wand.getItem() instanceof ItemWandCasting) || ((ItemWandCasting) wand.getItem()).getFocusItem(wand) != null || !ResearchManager.isResearchComplete(player.getCommandSenderName(), "HELLFIRE") || !player.canPlayerEdit(x, y, z, side, new ItemStack(Items.fire_charge)))
        return false;

    if (world.isAirBlock(x, y + 1, z) && ((ItemWandCasting) wand.getItem()).consumeVis(wand, player, Aspect.FIRE, 2, false)) {
        world.playSoundEffect((double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, "fire.ignite", 1.0F, world.rand.nextFloat() * 0.4F + 0.8F);
        world.setBlock(x, y + 1, z, Blocks.fire);
        player.swingItem();
        return true;
    } else
        return false;
}
 
Example 8
Source File: ItemRidingCrop.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (player.ridingEntity != null && player.ridingEntity instanceof EntityLivingBase) {
        EntityLivingBase mount = (EntityLivingBase) player.ridingEntity;
        stack.damageItem(1, player);
        player.swingItem();
        // mount.attackEntityFrom(DamageSource.causePlayerDamage(player),
        // 4.0F);
        mount.attackEntityFrom(DamageSource.generic, 1.0F);
        mount.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 200, 5));
    }
    return stack;
}
 
Example 9
Source File: ItemTaintShovel.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float par8, float par9, float par10) {
    int purified = 0;
    for(int ex = x - 5;ex < x + 6;ex++){
        for(int wy = y - 4;wy < y + 5;wy++){
            for(int zee = z - 5;zee < z + 6;zee++){
                Block target = world.getBlock(ex, wy, zee);
                if(target != null && (target == ConfigBlocks.blockFluxGoo || target == ConfigBlocks.blockFluxGas)){
                    purified++;
                    world.setBlockToAir(ex, wy, zee);
                    float d1 = ((float) ex + world.rand.nextFloat());
                    float d2 = ((float) wy + world.rand.nextFloat());
                    float d0 = ((float) zee + world.rand.nextFloat());
                    Thaumcraft.proxy.nodeBolt(world, (float)player.posX, (float)player.posY, (float)player.posZ, d1, d2, d0);
                }
            }
        }
    }
    if(purified > 0){
        itemstack.damageItem(Math.min(purified, 15), player);
        player.swingItem();
        world.playSoundEffect((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, "thaumcraft:wandfail", 0.2F, 0.2F + world.rand.nextFloat() * 0.2F);
        return true;
    }
    else
        return super.onItemUse(itemstack, player, world, x, y, z, side, par8, par9, par10);
}
 
Example 10
Source File: ItemThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    float f = 1.0F;
    float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
    float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
    double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
    double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
    double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
    Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
    float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
    float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
    float f5 = -MathHelper.cos(-f1 * 0.01745329F);
    float f6 = MathHelper.sin(-f1 * 0.01745329F);
    float f7 = f4 * f5;
    float f8 = f6;
    float f9 = f3 * f5;
    double d3 = 5000D;
    Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
    MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    if (movingobjectposition == null) {
        return itemstack;
    }
    if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        int i = movingobjectposition.blockX;
        int j = movingobjectposition.blockY;
        int k = movingobjectposition.blockZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
    } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
        Entity entityhit = movingobjectposition.entityHit;
        double x = entityhit.posX;
        double y = entityhit.posY;
        double z = entityhit.posZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
    }
    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example 11
Source File: ItemMaterials.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (stack != null && stack.getItemDamage() == 6) {
        player.swingItem();
        float f = 1.0F;
        float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
        float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
        double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
        double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
        double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
        Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
        float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
        float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
        float f5 = -MathHelper.cos(-f1 * 0.01745329F);
        float f6 = MathHelper.sin(-f1 * 0.01745329F);
        float f7 = f4 * f5;
        float f8 = f6;
        float f9 = f3 * f5;
        double d3 = 5000D;
        Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
        MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
        if (movingobjectposition == null) {
            return stack;
        }
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
        } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
            Entity entityhit = movingobjectposition.entityHit;
            double x = entityhit.posX;
            double y = entityhit.posY;
            double z = entityhit.posZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
        }
        if (player.capabilities.isCreativeMode) {
            return stack;
        } else {
            player.inventory.consumeInventoryItem(this);
            return stack;
        }
    }
    return stack;
}
 
Example 12
Source File: ItemElectricThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else if (ElectricItem.manager.canUse(itemstack, lightningCost)) {
        player.swingItem();
        // Corners
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ - 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ + 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ - 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ + 8));

        // Fronts
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX, player.posY, player.posZ - 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX, player.posY, player.posZ + 8));

        // Others
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ + 1));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ + 2));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ + 3));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ + 4));

        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ - 1));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ - 2));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 8, player.posY, player.posZ - 3));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 8, player.posY, player.posZ - 4));

        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 1, player.posY, player.posZ + 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 2, player.posY, player.posZ - 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 3, player.posY, player.posZ + 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX + 4, player.posY, player.posZ - 8));

        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 1, player.posY, player.posZ + 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 2, player.posY, player.posZ - 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 3, player.posY, player.posZ + 8));
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX - 4, player.posY, player.posZ - 8));

        EntityArcher archer;
        archer = new EntityArcher(world);
        archer.setPosition(player.posX + 8, player.posY + 2, player.posZ - 8);
        world.spawnEntityInWorld(archer);

        EntityArcher archer1;
        archer1 = new EntityArcher(world);
        archer1.setPosition(player.posX - 8, player.posY + 2, player.posZ + 8);
        world.spawnEntityInWorld(archer1);

        EntityArcher archer2;
        archer2 = new EntityArcher(world);
        archer2.setPosition(player.posX - 8, player.posY + 2, player.posZ - 8);
        world.spawnEntityInWorld(archer2);

        EntityArcher archer3;
        archer3 = new EntityArcher(world);
        archer3.setPosition(player.posX + 8, player.posY + 2, player.posZ + 8);
        world.spawnEntityInWorld(archer3);
        ElectricItem.manager.use(itemstack, lightningCost, player);
        return itemstack;
    } else {
        world.spawnEntityInWorld(new EntityLightningBolt(world, player.posX, player.posY, player.posZ));
        player.addPotionEffect(new PotionEffect(Potion.harm.getId(), 1, 1));
        return itemstack;
    }
}
 
Example 13
Source File: ItemRockbreakerDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    if (!player.isSneaking()) {
        for (int i = 0; i < player.inventory.mainInventory.length; i++) {
            ItemStack torchStack = player.inventory.mainInventory[i];
            if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
                continue;
            }
            Item item = torchStack.getItem();
            if (!(item instanceof ItemBlock)) {
                continue;
            }
            int oldMeta = torchStack.getItemDamage();
            int oldSize = torchStack.stackSize;
            boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
            if (player.capabilities.isCreativeMode) {
                torchStack.setItemDamage(oldMeta);
                torchStack.stackSize = oldSize;
            } else if (torchStack.stackSize <= 0) {
                ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
                player.inventory.mainInventory[i] = null;
            }
            if (result) {
                return true;
            }
        }
    } else {
        ElectricItem.manager.use(stack, searchCost, player);
        if (!world.isRemote) {
            world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "thaumcraft:wandfail", 0.2F, 0.2F + world.rand.nextFloat() * 0.2F);
            return super.onItemUse(stack, player, world, x, y, z, side, xOffset, xOffset, zOffset);
        }
        Minecraft mc = Minecraft.getMinecraft();
        Thaumcraft.instance.renderEventHandler.startScan(player, x, y, z, System.currentTimeMillis() + 5000L);
        player.swingItem();
        return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
Example 14
Source File: FMPPlacementListener.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static boolean place(EntityPlayer player, World world){
    MovingObjectPosition hit = RayTracer.reTrace(world, player);
    if(hit == null) return false;

    BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
    ItemStack held = player.getHeldItem();
    PartPressureTube part = null;
    if(held == null) return false;

    Block heldBlock = Block.getBlockFromItem(held.getItem());
    if(heldBlock == Blockss.pressureTube) {
        part = new PartPressureTube();
    } else if(heldBlock == Blockss.advancedPressureTube) {
        part = new PartAdvancedPressureTube();
    }

    if(part == null) return false;

    if(world.isRemote && !player.isSneaking())//attempt to use block activated like normal and tell the server the right stuff
    {
        Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
        Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
        if(!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z)) {
            player.swingItem();
            PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float)f.x, (float)f.y, (float)f.z));
            return true;
        }
    }

    TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
    if(tile == null || !tile.canAddPart(part)) {
        pos = pos.offset(hit.sideHit);
        tile = TileMultipart.getOrConvertTile(world, pos);
        if(tile == null || !tile.canAddPart(part)) return false;
    }

    if(!world.isRemote) {
        TileMultipart.addPart(world, pos, part);
        world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F);
        if(!player.capabilities.isCreativeMode) {
            held.stackSize--;
            if(held.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
                MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
            }
        }
    } else {
        player.swingItem();
        NetworkHandler.sendToServer(new PacketFMPPlacePart());
    }
    return true;
}