当前位置: 首页>>代码示例>>Java>>正文


Java PlayerMovementEvent类代码示例

本文整理汇总了Java中ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent的典型用法代码示例。如果您正苦于以下问题:Java PlayerMovementEvent类的具体用法?Java PlayerMovementEvent怎么用?Java PlayerMovementEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PlayerMovementEvent类属于ethanjones.cubes.core.event.entity.living.player包,在下文中一共展示了PlayerMovementEvent类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: preventNoclip

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
@EventHandler
public void preventNoclip(PlayerMovementEvent event) {
	Player player = event.getPlayer();
	Vector3 pos = event.newPosition;
	if (world.getArea(CoordinateConverter.area(pos.x), CoordinateConverter.area(pos.z)) != null
			&& !event.isCanceled()) {
		int blockX = CoordinateConverter.block(pos.x);
		int blockZ = CoordinateConverter.block(pos.z);
		int minBlockY = CoordinateConverter.block(pos.y - player.height);
		int maxBlockY = CoordinateConverter.block(pos.y + 0.2f);
		for (int y = minBlockY; y <= maxBlockY; y++) {
			if (world.getBlock(blockX, y, blockZ) != null) {
				event.setCanceled(true);
				return;
			}
		}

		limit(pos, +r, 0, player.height);
		limit(pos, -r, 0, player.height);
		limit(pos, 0, +r, player.height);
		limit(pos, 0, -r, player.height);
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:24,代码来源:PlayerCollision.java

示例2: updatePositionIf

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
private void updatePositionIf(World world, float time, Side side) {
	if (!motion.isZero() || !WorldGravity.onBlock(world, tmpVector, height, PLAYER_RADIUS)) {
		tmpVector.add(motion.x * time, motion.y * time, motion.z * time);
		motion.y -= GRAVITY * time;

		if (WorldGravity.onBlock(world, tmpVector, height, PLAYER_RADIUS) && motion.y < 0) {
			tmpVector.y = WorldGravity.getBlockY(tmpVector, height) + 1 + height;
			motion.y = 0f;
		}

		if (!new PlayerMovementEvent(this, tmpVector).post().isCanceled()) {
			position.set(tmpVector);
			if (side == Side.Server)
				world.syncEntity(uuid);
		}
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:18,代码来源:Player.java

示例3: setPositionIf

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
private void setPositionIf(Vector3 newPosition, boolean clientKnows, Vector3 newAngle) {
	if (newPosition != null) {
		float x = newPosition.x;
		float y = newPosition.y;
		float z = newPosition.z;
		if (new PlayerMovementEvent(client.getPlayer(), newPosition).post().isCanceled()) {
			// cancel move
			if (!clientKnows)
				return;
			// client knows new position, need to send old position
			newPosition = client.getPlayer().position.cpy();
			newAngle = client.getPlayer().angle.cpy();
			clientKnows = false;
		} else if (newPosition.x != x || newPosition.y != y || newPosition.z != z) {
			// event handler changed new position
			clientKnows = false;
		}
	}
	if (newPosition == null)
		newPosition = client.getPlayer().position.cpy();
	if (newAngle == null)
		newAngle = client.getPlayer().angle.cpy();
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:24,代码来源:PlayerManager.java

示例4: preventNoclip

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
@EventHandler
public void preventNoclip(PlayerMovementEvent event) {
  Player player = event.getPlayer();
  Vector3 pos = event.newPosition;
  if (world.getArea(CoordinateConverter.area(pos.x), CoordinateConverter.area(pos.z)) != null && !event.isCanceled()) {
    int blockX = CoordinateConverter.block(pos.x);
    int blockZ = CoordinateConverter.block(pos.z);
    int minBlockY = CoordinateConverter.block(pos.y - player.height);
    int maxBlockY = CoordinateConverter.block(pos.y + 0.2f);
    for (int y = minBlockY; y <= maxBlockY; y++) {
      if (world.getBlock(blockX, y, blockZ) != null) {
        event.setCanceled(true);
        return;
      }
    }

    limit(pos, +r, 0, player.height);
    limit(pos, -r, 0, player.height);
    limit(pos, 0, +r, player.height);
    limit(pos, 0, -r, player.height);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:23,代码来源:PlayerCollision.java

示例5: tryMove

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
private void tryMove() {
	if (tmpMovement.isZero())
		return;
	tmpMovement.add(camera.position);
	if (!new PlayerMovementEvent(Cubes.getClient().player, tmpMovement).post().isCanceled()) {
		camera.position.set(tmpMovement);
	}
	tmpMovement.setZero();
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:10,代码来源:CameraController.java

示例6: tryMove

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
private void tryMove() {
  if (tmpMovement.isZero()) return;
  tmpMovement.add(camera.position);
  if (!new PlayerMovementEvent(Cubes.getClient().player, tmpMovement).post().isCanceled()) {
    camera.position.set(tmpMovement);
  }
  tmpMovement.setZero();
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:9,代码来源:CameraController.java

示例7: setPosition

import ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent; //导入依赖的package包/类
public void setPosition(Vector3 newPosition, Vector3 newAngle, boolean clientKnows) {
  synchronized (this) {
    if (newPosition != null) {
      float x = newPosition.x, y = newPosition.y, z = newPosition.z;
      if (new PlayerMovementEvent(client.getPlayer(), newPosition).post().isCanceled()) {
        // cancel move
        if (!clientKnows) return;
        // client knows new position, need to send old position
        newPosition = client.getPlayer().position.cpy();
        newAngle = client.getPlayer().angle.cpy();
        clientKnows = false;
      } else if (newPosition.x != x || newPosition.y != y || newPosition.z != z) {
        // event handler changed new position
        clientKnows = false;
      }
    }
    
    if (newPosition == null) newPosition = client.getPlayer().position.cpy();
    if (newAngle == null) newAngle = client.getPlayer().angle.cpy();
    
    AreaReference newRef = new AreaReference().setFromPositionVector3(newPosition);
    AreaReference oldRef = new AreaReference().setFromPositionVector3(client.getPlayer().position);
    if (!newRef.equals(oldRef)) {
      WorldRegion newRegion = new WorldRegion(newRef, loadDistance);
      WorldRegion oldRegion = new WorldRegion(oldRef, loadDistance);
      AreaReferenceSet difference = new AreaReferenceSet();
      difference.addAll(newRegion.getAreaReferences());
      difference.removeAll(oldRegion.getAreaReferences());
      
      for (AreaReference areaReference : difference) {
        Area area = server.world.getArea(areaReference, false); //don't request individually, request in a batch
        if (area != null && area.featuresGenerated()) sendArea(area);
      }
      
      server.world.requestRegion(difference, null);
      
      for (Entity entity : Cubes.getServer().world.entities.values()) {
        if (!(entity instanceof Player) && newRegion.contains(entity.position) && !oldRegion.contains(entity.position)) {
          PacketEntityAdd packet = new PacketEntityAdd();
          packet.entity = entity;
          NetworkingManager.sendPacketToClient(packet, client);
        }
      }
      
      playerArea.setFromAreaReference(newRef);
    }
    
    client.getPlayer().position.set(newPosition);
    client.getPlayer().angle.set(newAngle);
    
    if (client.getPlayer().position.y < -10f) teleportToSpawn();
    
    if (!clientKnows) NetworkingManager.sendPacketToClient(new PacketPlayerMovement(client.getPlayer()), client);
    NetworkingManager.sendPacketToOtherClients(new PacketOtherPlayerMovement(client.getPlayer()), client);
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:57,代码来源:PlayerManager.java


注:本文中的ethanjones.cubes.core.event.entity.living.player.PlayerMovementEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。