Search in sources :

Example 26 with ActionResult

use of net.minecraft.util.ActionResult in project BiomesOPlenty by Glitchfiend.

the class ItemMudball method onItemRightClick.

// throw a mudball on right click
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!player.capabilities.isCreativeMode) {
        stack.setCount(stack.getCount() - 1);
    }
    world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    if (!world.isRemote) {
        EntityMudball mudball = new EntityMudball(world, player);
        mudball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
        world.spawnEntity(mudball);
    }
    player.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
Also used : EntityMudball(biomesoplenty.common.entities.projectiles.EntityMudball) EnumActionResult(net.minecraft.util.EnumActionResult) ActionResult(net.minecraft.util.ActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 27 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemPearcelArrow method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    Random rand = new Random();
    if (player.inventory.hasItemStack(infItem)) {
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            stack.getTagCompound().setBoolean("inf", true);
            player.inventory.clearMatchingItems(infItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.inf")));
            }
        } else {
            stack.getTagCompound().setBoolean("inf", true);
            player.inventory.clearMatchingItems(infItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.inf")));
            }
        }
    }
    if (player.inventory.hasItemStack(powItem)) {
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            stack.getTagCompound().setBoolean("pow", true);
            player.inventory.clearMatchingItems(powItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.pow")));
            }
        } else {
            stack.getTagCompound().setBoolean("pow", true);
            player.inventory.clearMatchingItems(powItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.pow")));
            }
        }
    }
    if (player.inventory.hasItemStack(knockItem)) {
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            stack.getTagCompound().setBoolean("knock", true);
            player.inventory.clearMatchingItems(knockItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.knock")));
            }
        } else {
            stack.getTagCompound().setBoolean("knock", true);
            player.inventory.clearMatchingItems(knockItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.knock")));
            }
        }
    }
    if (player.inventory.hasItemStack(zoomItem)) {
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            stack.getTagCompound().setBoolean("zoom", true);
            player.inventory.clearMatchingItems(zoomItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.zoom")));
            }
        } else {
            stack.getTagCompound().setBoolean("zoom", true);
            player.inventory.clearMatchingItems(zoomItem.getItem(), 0, 1, null);
            player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 2.0F, rand.nextFloat() * 2.5F);
            if (!world.isRemote) {
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_arrow.upgraded.zoom")));
            }
        }
    }
    return new ActionResult(EnumActionResult.PASS, stack);
}
Also used : Random(java.util.Random) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 28 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemEnderPearcel method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    float velocity = ConfigurationHandler.enderPearcelVelocity;
    if (!player.isCreative()) {
        if (hasEnoughEnergy(stack, ConfigurationHandler.rfPerUse_enderPearcel, player)) {
            useEnergy(stack, ConfigurationHandler.rfPerUse_enderPearcel, false, player);
        } else {
            stack.damageItem(1, player);
        }
    }
    if (ConfigurationHandler.doEnderPearcelCooldown) {
        player.getCooldownTracker().setCooldown(this, ConfigurationHandler.enderPearcelCooldownTime * 20);
    }
    world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F);
    if (!world.isRemote) {
        EntityEnderPearcel pearl = new EntityEnderPearcel(world, player);
        pearl.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, velocity, 0.0F);
        world.spawnEntity(pearl);
    }
    return new ActionResult(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityEnderPearcel(com.miningmark48.pearcelmod.entity.EntityEnderPearcel)

Example 29 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemPearcelBlockPlacer method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack item, World world, EntityPlayer player, EnumHand hand) {
    if (player.isSneaking()) {
        if (!item.hasTagCompound()) {
            item.setTagCompound(new NBTTagCompound());
            item.getTagCompound().setInteger("mode", 1);
        } else {
            if (item.getTagCompound().getInteger("mode") == 1) {
                item.getTagCompound().setInteger("mode", 2);
                if (!world.isRemote) {
                    player.sendMessage(new TextComponentTranslation(TextFormatting.GOLD + (Translate.toLocal("chat.item.pbp.modeChange"))));
                }
            } else {
                item.getTagCompound().setInteger("mode", 1);
                if (!world.isRemote) {
                    player.sendMessage(new TextComponentTranslation(TextFormatting.GOLD + (Translate.toLocal("chat.item.pbp.modeChange"))));
                }
            }
        }
        return new ActionResult(EnumActionResult.PASS, item);
    } else {
        return new ActionResult(EnumActionResult.PASS, item);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 30 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemPearcelMagnet method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setBoolean("enabled", false);
        stack.getTagCompound().setString("mode", "Attracts");
    }
    if (!world.isRemote) {
        if (!player.isSneaking()) {
            if (stack.getTagCompound().getBoolean("enabled")) {
                stack.getTagCompound().setBoolean("enabled", false);
                player.sendMessage(new TextComponentString(TextFormatting.DARK_RED + Translate.toLocal("chat.item.pearcel_magnet.disabled")));
            } else {
                stack.getTagCompound().setBoolean("enabled", true);
                player.sendMessage(new TextComponentString(TextFormatting.GOLD + Translate.toLocal("chat.item.pearcel_magnet.enabled")));
            }
        } else {
            if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                stack.getTagCompound().setString("mode", "Repels");
                player.sendMessage(new TextComponentString(TextFormatting.RED + Translate.toLocal("chat.item.pearcel_magnet.repels")));
            } else {
                stack.getTagCompound().setString("mode", "Attracts");
                player.sendMessage(new TextComponentString(TextFormatting.GREEN + Translate.toLocal("chat.item.pearcel_magnet.attracts")));
            }
        }
    }
    return new ActionResult(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ActionResult (net.minecraft.util.ActionResult)311 ItemStack (net.minecraft.item.ItemStack)240 EnumActionResult (net.minecraft.util.EnumActionResult)221 BlockPos (net.minecraft.util.math.BlockPos)56 Nonnull (javax.annotation.Nonnull)46 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)45 RayTraceResult (net.minecraft.util.math.RayTraceResult)39 Vec3d (net.minecraft.util.math.Vec3d)18 IBlockState (net.minecraft.block.state.IBlockState)16 TextComponentString (net.minecraft.util.text.TextComponentString)16 Entity (net.minecraft.entity.Entity)15 Inject (org.spongepowered.asm.mixin.injection.Inject)15 Block (net.minecraft.block.Block)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)14 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)14 World (net.minecraft.world.World)13 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)8