當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。