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

The following are Jave code examples for showing how to use isRiding() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: DecompiledMinecraft   File: ItemCarrotOnAStick.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 2
Project: DecompiledMinecraft   File: ItemCarrotOnAStick.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 3
Project: BaseClient   File: ItemCarrotOnAStick.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 4
Project: BaseClient   File: ItemCarrotOnAStick.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.isRiding() && playerIn.ridingEntity instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.ridingEntity;

        if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
        {
            entitypig.getAIControlledByPlayer().boostSpeed();
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.fishing_rod);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return itemstack;
            }
        }
    }

    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    return itemStackIn;
}
 
Example 5
Project: Zombe-Modpack   File: Motion.java   View Source Code Vote up 6 votes
private static void emulateSendMotion(EntityPlayer player) {
    // emulate client player's sendMotion
    Vec3d newPosition = null;
    if (player.isRiding()) {
        // needs improvement
        newPosition = getPosition(player);
        emulateHandleMotion(player, newPosition, getOnGround(player));
    } else if (getView() == player) {
        double dx = getX(sentPosition) - getX(player);
        double dy = getY(sentPosition) - getY(player);
        double dz = getZ(sentPosition) - getZ(player);
        boolean sync = (dx*dx + dy*dy + dz*dz > 9.0E-4D
            || ticksForForceSync >= 20);
        ++ticksForForceSync;
        if (sync) {
            newPosition = sentPosition = getPosition(player);
            ticksForForceSync = 0;
        }
        emulateHandleMotion(player, newPosition, getOnGround(player));
    }
}
 
Example 6
Project: CustomWorldGen   File: ItemCarrotOnAStick.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    if (playerIn.isRiding() && playerIn.getRidingEntity() instanceof EntityPig)
    {
        EntityPig entitypig = (EntityPig)playerIn.getRidingEntity();

        if (itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7 && entitypig.boost())
        {
            itemStackIn.damageItem(7, playerIn);

            if (itemStackIn.stackSize == 0)
            {
                ItemStack itemstack = new ItemStack(Items.FISHING_ROD);
                itemstack.setTagCompound(itemStackIn.getTagCompound());
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }

            return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
        }
    }

    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
 
Example 7
Project: Zombe-Modpack   File: Fly.java   View Source Code Vote up 5 votes
private static void afterMove(EntityPlayer ent, Vec3d move) {
    if (isSleeping(ent) || ent.isRiding()) return;
    if (ent == flyPlayer) {
        playerClassActive = true;
        playerOnGround = getOnGround(ent);

        if (modFlyAllowed) {
            if (getMotionX(ent) != 0) setMotionX(ent, motionX);
            if (getMotionY(ent) != 0) setMotionY(ent, motionY);
            if (getMotionZ(ent) != 0) setMotionZ(ent, motionZ);
            if (playerFly) {
                flyPlayer.movementInput.sneak = false;
                setFall(ent, 0f); setOnGround(ent, true);
                setSteps(ent, flySteps);
                setFlying(ent, true);
                if (ent.capabilities.allowFlying)
                ent.sendPlayerAbilities();
            } else if (flew && !getOnGround(ent)) {
                setFall(ent, 0f); setOnGround(ent, true);
                if (ent.capabilities.allowFlying)
                ent.sendPlayerAbilities();
            }
            else flew = false;
        }
    }
    if (ent == flyDummy) {
        dummyOnGround = getOnGround(ent);
        if (getMotionX(ent) != 0) setMotionX(ent, motionX);
        if (getMotionY(ent) != 0) setMotionY(ent, motionY);
        if (getMotionZ(ent) != 0) setMotionZ(ent, motionZ);
        if (dummyFly) {
            flyDummy.movementInput.sneak = false;
            setSteps(ent, flySteps);
            setFlying(ent, true);
        }
        setFall(ent, 0f);
        setOnGround(ent, true);
    }
}
 
Example 8
Project: Backmemed   File: ItemCarrotOnAStick.java   View Source Code Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (itemStackIn.isRemote)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        if (worldIn.isRiding() && worldIn.getRidingEntity() instanceof EntityPig)
        {
            EntityPig entitypig = (EntityPig)worldIn.getRidingEntity();

            if (itemstack.getMaxDamage() - itemstack.getMetadata() >= 7 && entitypig.boost())
            {
                itemstack.damageItem(7, worldIn);

                if (itemstack.func_190926_b())
                {
                    ItemStack itemstack1 = new ItemStack(Items.FISHING_ROD);
                    itemstack1.setTagCompound(itemstack.getTagCompound());
                    return new ActionResult(EnumActionResult.SUCCESS, itemstack1);
                }

                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
        }

        worldIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
}
 
Example 9
Project: Zombe-Modpack   File: Motion.java   View Source Code Vote up 4 votes
private static void emulateHandleMotion(EntityPlayer player, Vec3d newPosition, boolean packetOnGround) {
    // emulate server handling of C03PacketPlayer
    Vec3d oldPosition = serverPosition;
    if (newPosition == null) newPosition = oldPosition;
    if (player.isRiding()) {
        // needs improvement
        serverPosition = serverNextPosition = newPosition;
        serverMotion   = serverNextMotion;
        return;
    }
    if (isSleeping(player)) {
        // needs improvement
        serverPosition = serverNextPosition = oldPosition;
        serverMotion   = serverNextMotion;
        return;
    }
    // server update part
    if (!anticipated) {
        setPosition(serverDummy, serverPosition);
        setMotion(serverDummy,   serverMotion);
        serverDummy.onUpdate();
        serverNextPosition = getPosition(serverDummy);
        serverNextMotion   = getMotion(serverDummy);
    }
    serverPosition = serverNextPosition;
    serverMotion   = serverNextMotion;
    anticipated = false;
    // moved too quickly check
    if (isMultiplayer() && isMoveTooQuick(newPosition)) {
        serverNextPosition = serverPosition = oldPosition;
        // note: motion is kept as is and a position packet is sent
        return;
    }
    // server movement attempt
    setPosition(serverDummy, oldPosition);
    double spacing = 0.0625;
    boolean wasFree = getWorld(player).getCollisionBoxes(player, getAABB(serverDummy).contract(spacing)).isEmpty();
    if (getOnGround(serverDummy) && !packetOnGround
     && getX(player) > getX(oldPosition)) {
        serverDummy.jump();
    }
    Vec3d move = newPosition.subtract(oldPosition);
    serverDummy.moveEntity(MoverType.SELF, getX(move), getY(move), getZ(move));
    setOnGround(serverDummy, packetOnGround);
    // moved wrongly check
    boolean moveWrong = false;
    if (!isSleeping(player) && !isCreative(player)
     && wasMoveWrong(serverDummy, newPosition)) {
        moveWrong = true;
    }
    setPosition(serverDummy, newPosition);
    if (!getNoclip(player)) {
        boolean isFree = getWorld(player).getCollisionBoxes(player, getAABB(serverDummy).contract(spacing)).isEmpty();
        if (wasFree && (moveWrong || !isFree) && !isSleeping(player)) {
            serverNextPosition = serverPosition = oldPosition;
            // note: motion is kept as is and a position packet is sent
            return;
        }
    }
    setOnGround(serverDummy, packetOnGround);
    // serverUpdateMountedMovingPlayer(serverDummy)
    // serverDummy.handleFalling(getY(serverDummy) - getY(oldPosition), packetOnGround);
    serverNextPosition = serverPosition = getPosition(serverDummy);
    serverNextMotion   = serverMotion   = getMotion(serverDummy);
}
 
Example 10
Project: Zombe-Modpack   File: Fly.java   View Source Code Vote up 4 votes
private static Vec3d beforeMove(EntityPlayer ent, Vec3d move) {
    if (isSleeping(ent) || ent.isRiding()) return move;
    double mx = motionX = getX(move),
           my = motionY = getY(move),
           mz = motionZ = getZ(move);
    flySteps = 0;
    if (modFlyAllowed && ent == flyPlayer || ent == flyDummy) {
        flySteps = getSteps(ent);
        if (ent == flyPlayer && playerFly || ent == flyDummy && dummyFly) {
            if (ent == flyPlayer) flyPlayer.movementInput.sneak = false;
            else                  flyDummy .movementInput.sneak = false;
            my = 0d;
            if (optNoInertia || ent != controlledEntity) {
                mx = my = mz = 0;
            }
            if (ent == controlledEntity) {
                if (flyUp)   my += optSpeedVertical;
                if (flyDown) my -= optSpeedVertical;
                if (flyFree) {
                    double siny = Math.sin(getYaw(ent) * TO_RADIANS);
                    double cosy = Math.cos(getYaw(ent) * TO_RADIANS);
                    double sinp = Math.sin(getPitch(ent) * TO_RADIANS);
                    double cosp = Math.cos(getPitch(ent) * TO_RADIANS);
                    double mf = -mx * siny + mz * cosy;
                    double mv = -mf * sinp;
                    mf *=  1-cosp;
                    mx -= -mf * siny;
                    mz -=  mf * cosy;
                    my += mv;
                }
                if (flyForward) {
                    double moves = optSpeedForward;
                    double movef = -moves * Math.cos(getPitch(ent) * TO_RADIANS);
                    double movev = -moves * Math.sin(getPitch(ent) * TO_RADIANS);
                    mx += movef * Math.sin(getYaw(ent) * TO_RADIANS);
                    mz += -movef * Math.cos(getYaw(ent) * TO_RADIANS);
                    my += movev;
                }
                double mul = flySpeed ? optSpeedMulModifier : optSpeedMulNormal;
                if (optNoInertia) mul *= 2;
                mx *= mul; my *= mul; mz *= mul;
            }
            setFall(ent, 0f);
            if (ent == flyPlayer) flew = true;
        } else if (ent == controlledEntity && flyRun) {
            mx *= optRunSpeedMul;
            mz *= optRunSpeedMul;
            int id = getIdAt(getWorld(), fix(getX(ent)), fix(getY(ent)), fix(getZ(ent)));
            // if in ladders, water or lava
            if (id == 65 || id >= 8 && id <= 11) my *= optRunSpeedVMul;
        }
    }
    setMotion(ent, mx,my,mz);
    return new Vec3d(mx,my,mz);
}