cn.nukkit.event.vehicle.VehicleMoveEvent Java Examples
The following examples show how to use
cn.nukkit.event.vehicle.VehicleMoveEvent.
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: EntityMinecartAbstract.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } if (!this.isAlive()) { ++this.deadTicks; if (this.deadTicks >= 10) { this.despawnFromAll(); this.close(); } return this.deadTicks < 10; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0) { return false; } this.lastUpdate = currentTick; if (isAlive()) { super.onUpdate(currentTick); // Entity variables lastX = x; lastY = y; lastZ = z; motionY -= 0.03999999910593033D; int dx = MathHelper.floor(x); int dy = MathHelper.floor(y); int dz = MathHelper.floor(z); // Some hack to check rails if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) { --dy; } Block block = level.getBlock(new Vector3(dx, dy, dz)); // Ensure that the block is a rail if (Rail.isRailBlock(block)) { processMovement(dx, dy, dz, (BlockRail) block); if (block instanceof BlockRailActivator) { // Activate the minecart/TNT activate(dx, dy, dz, (block.getDamage() & 0x8) != 0); } } else { setFalling(); } checkBlockCollision(); // Minecart head pitch = 0; double diffX = this.lastX - this.x; double diffZ = this.lastZ - this.z; double yawToChange = yaw; if (diffX * diffX + diffZ * diffZ > 0.001D) { yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D); } // Reverse yaw if yaw is below 0 if (yawToChange < 0) { // -90-(-90)-(-90) = 90 yawToChange -= yawToChange - yawToChange; } setRotation(yawToChange, pitch); Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } // Collisions for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) { if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) { entity.applyEntityCollision(this); } } // Easier if ((linkedEntity != null) && (!linkedEntity.isAlive())) { if (linkedEntity.riding == this) { linkedEntity.riding = null; } linkedEntity = null; } // No need to onGround or Motion diff! This always have an update return true; } return false; }
Example #2
Source File: EntityBoat.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { super.onUpdate(currentTick); this.motionY = (this.level.getBlock(new Vector3(this.x, this.y, this.z)).getBoundingBox() != null || this.isInsideOfWater()) ? getGravity() : -0.08; if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1 - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor(); } this.motionX *= friction; this.motionY *= 1 - this.getDrag(); this.motionZ *= friction; if (this.onGround) { this.motionY *= -0.5; } Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } this.updateMovement(); } return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; }
Example #3
Source File: EntityBoat.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { super.onUpdate(currentTick); double waterDiff = getWaterLevel(); if (!hasControllingPassenger()) { if (waterDiff > SINKING_DEPTH && !sinking) { sinking = true; } else if (waterDiff < -SINKING_DEPTH && sinking) { sinking = false; } if (waterDiff < -SINKING_DEPTH) { this.motionY = Math.min(0.05, this.motionY + 0.005); } else if (waterDiff < 0 || !sinking) { this.motionY = this.motionY > SINKING_MAX_SPEED ? Math.max(this.motionY - 0.02, SINKING_MAX_SPEED) : this.motionY + SINKING_SPEED; // this.motionY = this.motionY + SINKING_SPEED > SINKING_MAX_SPEED ? this.motionY - SINKING_SPEED : this.motionY + SINKING_SPEED; } } if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1 - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor(); } this.motionX *= friction; if (!hasControllingPassenger()) { if (waterDiff > SINKING_DEPTH || sinking) { this.motionY = waterDiff > 0.5 ? this.motionY - this.getGravity() : (this.motionY - SINKING_SPEED < -SINKING_MAX_SPEED ? this.motionY : this.motionY - SINKING_SPEED); } } this.motionZ *= friction; Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } //TODO: lily pad collision this.updateMovement(); if (this.passengers.size() < 2) { for (Entity entity : this.level.getCollidingEntities(this.boundingBox.grow(0.20000000298023224, 0.0D, 0.20000000298023224), this)) { if (entity.riding != null || !(entity instanceof EntityLiving) || entity instanceof Player || entity instanceof EntityWaterAnimal || isPassenger(entity)) { continue; } this.mountEntity(entity); if (this.passengers.size() >= 2) { break; } } } } return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; }
Example #4
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } if (!this.isAlive()) { ++this.deadTicks; if (this.deadTicks >= 10) { this.despawnFromAll(); this.close(); } return this.deadTicks < 10; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0) { return false; } this.lastUpdate = currentTick; if (isAlive()) { super.onUpdate(currentTick); // Entity variables lastX = x; lastY = y; lastZ = z; motionY -= 0.03999999910593033D; int dx = MathHelper.floor(x); int dy = MathHelper.floor(y); int dz = MathHelper.floor(z); // Some hack to check rails if (Rail.isRailBlock(level.getBlockIdAt(dx, dy - 1, dz))) { --dy; } Block block = level.getBlock(new Vector3(dx, dy, dz)); // Ensure that the block is a rail if (Rail.isRailBlock(block)) { processMovement(dx, dy, dz, (BlockRail) block); if (block instanceof BlockRailActivator) { // Activate the minecart/TNT activate(dx, dy, dz, (block.getDamage() & 0x8) != 0); } } else { setFalling(); } checkBlockCollision(); // Minecart head pitch = 0; double diffX = this.lastX - this.x; double diffZ = this.lastZ - this.z; double yawToChange = yaw; if (diffX * diffX + diffZ * diffZ > 0.001D) { yawToChange = (Math.atan2(diffZ, diffX) * 180 / 3.141592653589793D); } // Reverse yaw if yaw is below 0 if (yawToChange < 0) { // -90-(-90)-(-90) = 90 yawToChange -= yawToChange - yawToChange; } setRotation(yawToChange, pitch); Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } // Collisions for (Entity entity : level.getNearbyEntities(boundingBox.grow(0.2D, 0, 0.2D), this)) { if (entity != linkedEntity && entity instanceof EntityMinecartAbstract) { entity.applyEntityCollision(this); } } // Easier if ((linkedEntity != null) && (!linkedEntity.isAlive())) { if (linkedEntity.riding == this) { linkedEntity.riding = null; } linkedEntity = null; } // No need to onGround or Motion diff! This always have an update return true; } return false; }
Example #5
Source File: EntityBoat.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; boolean hasUpdate = this.entityBaseTick(tickDiff); if (this.isAlive()) { super.onUpdate(currentTick); this.motionY = (this.level.getBlock(new Vector3(this.x, this.y, this.z)).getBoundingBox() != null || this.isInsideOfWater()) ? getGravity() : -0.08; if (this.checkObstruction(this.x, this.y, this.z)) { hasUpdate = true; } this.move(this.motionX, this.motionY, this.motionZ); double friction = 1 - this.getDrag(); if (this.onGround && (Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionZ) > 0.00001)) { friction *= this.getLevel().getBlock(this.temporalVector.setComponents((int) Math.floor(this.x), (int) Math.floor(this.y - 1), (int) Math.floor(this.z) - 1)).getFrictionFactor(); } this.motionX *= friction; this.motionY *= 1 - this.getDrag(); this.motionZ *= friction; if (this.onGround) { this.motionY *= -0.5; } Location from = new Location(lastX, lastY, lastZ, lastYaw, lastPitch, level); Location to = new Location(this.x, this.y, this.z, this.yaw, this.pitch, level); this.getServer().getPluginManager().callEvent(new VehicleUpdateEvent(this)); if (!from.equals(to)) { this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to)); } this.updateMovement(); } return hasUpdate || !this.onGround || Math.abs(this.motionX) > 0.00001 || Math.abs(this.motionY) > 0.00001 || Math.abs(this.motionZ) > 0.00001; }