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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#startRiding() . 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: EntityDabSquirrel.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void mountTo(EntityPlayer player) {
	player.rotationYaw = this.rotationYaw;
	player.rotationPitch = this.rotationPitch;

	if (!this.world.isRemote) {
		player.startRiding(this);
	}
}
 
Example 2
Source File: BlockSeat.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos,
		IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY,
		float hitZ) {
	
	if(!world.isRemote) {
		List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(player, new AxisAlignedBB(pos, pos.add(1,1,1)));

		//Try to mount player to dummy entity in the block
		for(Entity e : list) {
			if(e instanceof EntityDummy) {
				if(!e.getPassengers().isEmpty()) {
					return true;
				}
				else {
					//Ensure that the entity is in the correct position
					e.setPosition(pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f);
					player.startRiding(e);
					return true;
				}
			}
		}
		EntityDummy entity = new EntityDummy(world, pos.getX() + 0.5f, pos.getY() + 0.2f, pos.getZ() + 0.5f);
		world.spawnEntity(entity);
		player.startRiding(entity);
	}

	return true;
}
 
Example 3
Source File: EntityCart.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
	if (this.isBeingRidden() && getPassengers().get(0) instanceof EntityPlayer && getPassengers().get(0) != player)
	{
		return true;
	}
	else
	{
		double angle = Helper.normalizeAngle(getAngleToEntity(player));
		double fAngle = Helper.normalizeAngle(getFacingAngle());
		double revAngle =Helper.normalizeAngle(fAngle + 180);
		System.out.println(angle+"/"+fAngle);
		if(pullEntity == null && (angle > (fAngle - 25) && angle < (fAngle + 25)))
		{
			setPullEntity(player);
		}
		else if(this.getPassengers().size() < 1 && (angle > revAngle - 25 && angle < revAngle + 25))
		{
			player.startRiding(this);
			this.noClip = true;
		}
		else
		{
			PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(player).entityForInventory = this;
			if(!world.isRemote)
			{
				player.openGui(TFC.instance, 1, world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
			}
		}

		return true;
	}
}
 
Example 4
Source File: EntityChair.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean processInitialInteract(EntityPlayer player, EnumHand hand)
{
    if (player.getEntityWorld().isRemote == false && this.getPassengers().contains(player) == false)
    {
        player.startRiding(this);
        return true;
    }

    return false;
}
 
Example 5
Source File: ItemMobHarness.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean handleInteraction(ItemStack stack, EntityPlayer player, Entity entity)
{
    if (player.isSneaking() == false)
    {
        //EntityUtils.unmountFirstRider(entity);
        player.startRiding(entity, true);
        addAITask(entity, true);

        return true;
    }

    // Harness bound to something, mount the entity
    if (this.hasTarget(stack))
    {
        this.mountTarget(stack, player.getEntityWorld(), player, entity);
    }
    // Empty harness
    else
    {
        // Empty harness, player looking up and ridden by something: dismount the rider
        if (player.rotationPitch < -80.0f && player.isBeingRidden())
        {
            player.removePassengers();
        }
        // Empty harness, target is riding something: dismount target
        else if (entity.isRiding())
        {
            entity.dismountRidingEntity();
        }
        // Empty harness, target not riding anything, store/link target
        else
        {
            this.storeTarget(stack, entity);
        }
    }

    return true;
}
 
Example 6
Source File: BlockCaptainsChair.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
    EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(worldIn, pos);
        if (physicsObject.isPresent()) {
            PhysicsWrapperEntity wrapperEntity = physicsObject.get()
                .getWrapperEntity();
            if (playerIn.getLowestRidingEntity() != wrapperEntity.getLowestRidingEntity()) {
                TileEntity tileEntity = worldIn.getTileEntity(pos);
                if (tileEntity instanceof TileEntityCaptainsChair) {
                    Vector playerPos = new Vector(playerIn);

                    wrapperEntity.getPhysicsObject()
                        .getShipTransformationManager()
                        .fromLocalToGlobal(playerPos);

                    playerIn.posX = playerPos.X;
                    playerIn.posY = playerPos.Y;
                    playerIn.posZ = playerPos.Z;

                    IDraggable entityDraggable = EntityDraggable
                        .getDraggableFromEntity(playerIn);
                    // Only mount the player if they're standing on the ship.
                    if (entityDraggable.getWorldBelowFeet() == wrapperEntity) {
                        playerIn.startRiding(wrapperEntity);
                        Vector localMountPos = getPlayerMountOffset(state, pos);
                        ValkyrienUtils.fixEntityToShip(playerIn, localMountPos,
                            wrapperEntity.getPhysicsObject());
                    }

                    ((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
                    wrapperEntity.getPhysicsObject()
                        .getShipTransformationManager()
                        .fromGlobalToLocal(playerPos);

                    playerIn.posX = playerPos.X;
                    playerIn.posY = playerPos.Y;
                    playerIn.posZ = playerPos.Z;
                }
            }
        }
    }

    return true;
}
 
Example 7
Source File: TileEntityPassengerChair.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public void tryToMountPlayerToChair(EntityPlayer player, Vec3d mountPos) {
    if (getWorld().isRemote) {
        throw new IllegalStateException(
            "tryToMountPlayerToChair is not designed to be called on client side!");
    }
    boolean isChairEmpty;
    if (chairEntityUUID != null) {
        Entity chairEntity = ((WorldServer) getWorld()).getEntityFromUuid(chairEntityUUID);
        if (chairEntity != null) {
            if (chairEntity.isDead || chairEntity.isBeingRidden()) {
                // Dead entity, chair is empty.
                this.chairEntityUUID = null;
                markDirty();
                isChairEmpty = true;
            } else {
                // Everything checks out, this chair is not empty.
                isChairEmpty = false;
            }
        } else {
            // Either null or not a chair entity (somehow?). Just consider this chair as empty
            this.chairEntityUUID = null;
            markDirty();
            isChairEmpty = true;
        }
    } else {
        // No UUID for a chair entity, so this chair must be empty.
        isChairEmpty = true;
    }
    if (isChairEmpty) {
        // Chair is guaranteed empty.
        Optional<PhysicsObject> physicsObject = ValkyrienUtils
            .getPhysicsObject(getWorld(), getPos());
        CoordinateSpaceType mountCoordType =
            physicsObject.isPresent() ? CoordinateSpaceType.SUBSPACE_COORDINATES
                : CoordinateSpaceType.GLOBAL_COORDINATES;
        EntityMountableChair entityMountable = new EntityMountableChair(getWorld(), mountPos,
            mountCoordType, getPos());
        chairEntityUUID = entityMountable.getPersistentID();
        markDirty();
        getWorld().spawnEntity(entityMountable);
        player.startRiding(entityMountable);
    }
}
 
Example 8
Source File: EntityRocket.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
protected boolean interact(EntityPlayer player) {
	//Actual interact code needs to be moved to a packet receive on the server

	ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);

	//Handle linkers and right-click with fuel
	if(heldItem != null) {
		float fuelMult;
		FluidStack fluidStack;

		if(heldItem.getItem() instanceof ItemLinker) {
			if(ItemLinker.isSet(heldItem)) {


				TileEntity tile = this.world.getTileEntity(ItemLinker.getMasterCoords(heldItem));

				if(tile instanceof IInfrastructure) {
					IInfrastructure infrastructure = (IInfrastructure)tile;
					if(this.getDistance(ItemLinker.getMasterX(heldItem), this.posY, ItemLinker.getMasterZ(heldItem)) < infrastructure.getMaxLinkDistance() + Math.max(storage.getSizeX(), storage.getSizeZ())) {
						if(!connectedInfrastructure.contains(tile)) {

							linkInfrastructure(infrastructure);
							if(!world.isRemote) {
								player.sendMessage(new TextComponentString("Linked Sucessfully"));
							}
							ItemLinker.resetPosition(heldItem);

							return true;
						}
						else if(!world.isRemote)
							player.sendMessage(new TextComponentString("Already linked!"));
					}
					else if(!world.isRemote)
						player.sendMessage(new TextComponentString("The object you are trying to link is too far away"));
				}
				else if(!world.isRemote)
					player.sendMessage(new TextComponentString("This cannot be linked to a rocket!"));
			}
			else if(!world.isRemote)
				player.sendMessage(new TextComponentString("Nothing to be linked"));
			return false;
		}

		else if((FluidUtils.containsFluid(heldItem) && (fluidStack = FluidUtils.getFluidForItem(heldItem)) != null && (fuelMult = FuelRegistry.instance.getMultiplier(FuelType.LIQUID, fluidStack.getFluid())) > 0 )) { 


			int amountToAdd = (int) (fuelMult*fluidStack.amount);
			this.addFuelAmount(amountToAdd);

			//if the player is not in creative then try to use the fluid container
			if(!player.capabilities.isCreativeMode) {
				heldItem = heldItem.copy();
				heldItem.setCount(1);
				IFluidHandlerItem handler = FluidUtils.getFluidHandler(heldItem);
				handler.drain(fluidStack.amount, true);
				ItemStack emptyStack = handler.getContainer();

				if(player.inventory.addItemStackToInventory(emptyStack)) {
					player.getHeldItem(EnumHand.MAIN_HAND).splitStack(1);
					if(player.getHeldItem(EnumHand.MAIN_HAND).isEmpty())
						player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); 
				}

			}

			return true;
		}
	}

	//If player is holding shift open GUI
	if(player.isSneaking()) {
		openGui(player);
	}
	else if(stats.hasSeat()) { //If pilot seat is open mount entity there
		if(stats.hasSeat() && this.getPassengers().isEmpty()) {
			if(!world.isRemote)
				player.startRiding(this);
		}
		/*else if(stats.getNumPassengerSeats() > 0) { //If a passenger seat exists and one is empty, mount the player to it
			for(int i = 0; i < stats.getNumPassengerSeats(); i++) {
				if(this.mountedEntities[i] == null || this.mountedEntities[i].get() == null) {
					player.ridingEntity = this;
					this.mountedEntities[i] = new WeakReference<Entity>(player);
					break;
				}
			}
		}*/
	}
	return true;
}