cn.nukkit.math.Vector3 Java Examples
The following examples show how to use
cn.nukkit.math.Vector3.
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: BlockMycelium.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_RANDOM) { //TODO: light levels NukkitRandom random = new NukkitRandom(); x = random.nextRange((int) x - 1, (int) x + 1); y = random.nextRange((int) y - 1, (int) y + 1); z = random.nextRange((int) z - 1, (int) z + 1); Block block = this.getLevel().getBlock(new Vector3(x, y, z)); if (block.getId() == Block.DIRT) { if (block.up() instanceof BlockTransparent) { BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium()); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { this.getLevel().setBlock(block, ev.getNewState()); } } } } return 0; }
Example #2
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
private void computeSpreadBlockLight(int x, int y, int z, int currentLight, Queue<Vector3> queue, Map<BlockVector3, Boolean> visited) { int current = this.getBlockLightAt(x, y, z); BlockVector3 index = Level.blockHash(x, y, z); if (current < currentLight) { this.setBlockLightAt(x, y, z, currentLight); if (!visited.containsKey(index)) { visited.put(index, true); if (currentLight > 1) { queue.add(new Vector3(x, y, z)); } } } }
Example #3
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 6 votes |
private int getIndirectPower() { int power = 0; Vector3 pos = getLocation(); for (BlockFace face : BlockFace.values()) { int blockPower = this.getIndirectPower(pos.getSide(face), face); if (blockPower >= 15) { return 15; } if (blockPower > power) { power = blockPower; } } return power; }
Example #4
Source File: ItemArmor.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onClickAir(Player player, Vector3 directionVector) { if (this.isHelmet() && player.getInventory().getHelmet().isNull()) { if (player.getInventory().setHelmet(this)) player.getInventory().clear(player.getInventory().getHeldItemIndex()); } else if (this.isChestplate() && player.getInventory().getChestplate().isNull()) { if (player.getInventory().setChestplate(this)) player.getInventory().clear(player.getInventory().getHeldItemIndex()); } else if (this.isLeggings() && player.getInventory().getLeggings().isNull()) { if (player.getInventory().setHelmet(this)) player.getInventory().clear(player.getInventory().getHeldItemIndex()); } else if (this.isBoots() && player.getInventory().getBoots().isNull()) { if (player.getInventory().setBoots(this)) player.getInventory().clear(player.getInventory().getHeldItemIndex()); } return this.getCount() == 0; }
Example #5
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public boolean setPosition(Vector3 pos) { if (this.closed) { return false; } if (pos instanceof Position && ((Position) pos).level != null && ((Position) pos).level != this.level) { if (!this.switchLevel(((Position) pos).getLevel())) { return false; } } this.x = pos.x; this.y = pos.y; this.z = pos.z; double radius = this.getWidth() / 2d; this.boundingBox.setBounds(pos.x - radius, pos.y, pos.z - radius, pos.x + radius, pos.y + (this.getHeight() * this.scale), pos.z + radius); this.checkChunks(); return true; }
Example #6
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 6 votes |
private void computeRemoveBlockLight(int x, int y, int z, int currentLight, Queue<Object[]> queue, Queue<Vector3> spreadQueue, Map<BlockVector3, Boolean> visited, Map<BlockVector3, Boolean> spreadVisited) { int current = this.getBlockLightAt(x, y, z); BlockVector3 index = Level.blockHash(x, y, z); if (current != 0 && current < currentLight) { this.setBlockLightAt(x, y, z, 0); if (!visited.containsKey(index)) { visited.put(index, true); if (current > 1) { queue.add(new Object[]{new Vector3(x, y, z), current}); } } } else if (current >= currentLight) { if (!spreadVisited.containsKey(index)) { spreadVisited.put(index, true); spreadQueue.add(new Vector3(x, y, z)); } } }
Example #7
Source File: ContainerInventory.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void onOpen(Player who) { super.onOpen(who); ContainerOpenPacket pk = new ContainerOpenPacket(); pk.windowId = who.getWindowId(this); pk.type = this.getType().getNetworkType(); InventoryHolder holder = this.getHolder(); if (holder instanceof Vector3) { pk.x = (int) ((Vector3) holder).getX(); pk.y = (int) ((Vector3) holder).getY(); pk.z = (int) ((Vector3) holder).getZ(); } else { pk.x = pk.y = pk.z = 0; } if (holder instanceof Entity) { pk.entityId = ((Entity) holder).getId(); } who.dataPacket(pk); this.sendContents(who); }
Example #8
Source File: ContainerInventory.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void onOpen(Player who) { super.onOpen(who); ContainerOpenPacket pk = new ContainerOpenPacket(); pk.windowId = who.getWindowId(this); pk.type = this.getType().getNetworkType(); InventoryHolder holder = this.getHolder(); if (holder instanceof Vector3) { pk.x = (int) ((Vector3) holder).getX(); pk.y = (int) ((Vector3) holder).getY(); pk.z = (int) ((Vector3) holder).getZ(); } else { pk.x = pk.y = pk.z = 0; } who.dataPacket(pk); this.sendContents(who); }
Example #9
Source File: ProjectileDispenseBehavior.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void dispense(BlockDispenser source, Item item) { Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel()); CompoundTag nbt = Entity.getDefaultNBT(dispensePos); this.correctNBT(nbt); BlockFace face = source.getFacing(); Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt); if (projectile == null) { return; } projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6)); projectile.spawnToAll(); }
Example #10
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private int getMaxCurrentStrength(Vector3 pos, int maxStrength) { if (this.level.getBlockIdAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()) != this.getId()) { return maxStrength; } else { int strength = this.level.getBlockDataAt(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()); return strength > maxStrength ? strength : maxStrength; } }
Example #11
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private boolean isPowerSourceAt(BlockFace side) { Vector3 pos = getLocation(); Vector3 v = pos.getSide(side); Block block = this.level.getBlock(v); boolean flag = block.isNormalBlock(); boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock(); return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down())); }
Example #12
Source File: BlockUpdateScheduler.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean remove(Vector3 pos) { for (Map.Entry<Long, LinkedHashSet<BlockUpdateEntry>> tickUpdateSet : queuedUpdates.entrySet()) { if (tickUpdateSet.getValue().remove(pos)) { return true; } } return false; }
Example #13
Source File: EntityEnderPearl.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void teleport() { if (!this.level.equals(this.shootingEntity.getLevel())) { return; } this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL); if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0) { this.shootingEntity.attack(new EntityDamageByEntityEvent(this, shootingEntity, EntityDamageEvent.DamageCause.PROJECTILE, 5f, 0f)); } this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL); }
Example #14
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private int getIndirectPower(Vector3 pos, BlockFace face) { Block block = this.level.getBlock(pos); if (block.getId() == Block.REDSTONE_WIRE) { return 0; } return block.isNormalBlock() ? getStrongPower(pos.getSide(face), face) : block.getWeakPower(face); }
Example #15
Source File: BaseLevelProvider.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void setSpawn(Vector3 pos) { this.levelData.putInt("SpawnX", (int) pos.x); this.levelData.putInt("SpawnY", (int) pos.y); this.levelData.putInt("SpawnZ", (int) pos.z); spawn = pos; }
Example #16
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void updateAround(Vector3 pos, BlockFace face) { if (this.level.getBlock(pos).getId() == Block.REDSTONE_WIRE) { this.level.updateAroundRedstone(pos, face); for (BlockFace side : BlockFace.values()) { this.level.updateAroundRedstone(pos.getSide(side), side.getOpposite()); } } }
Example #17
Source File: EntitySheep.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item, Vector3 clickedPos) { if (item.getId() == Item.DYE) { this.setColor(((ItemDye) item).getDyeColor().getWoolData()); return true; } return item.getId() == Item.SHEARS && shear(); }
Example #18
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected void checkBlockCollision() { Vector3 vector = new Vector3(0, 0, 0); boolean portal = false; for (Block block : this.getCollisionBlocks()) { if (block.getId() == Block.NETHER_PORTAL) { portal = true; continue; } block.onEntityCollide(this); block.addVelocityToEntity(this, vector); } if (portal) { inPortalTicks++; } else { this.inPortalTicks = 0; } if (vector.lengthSquared() > 0) { vector = vector.normalize(); double d = 0.014d; this.motionX += vector.x * d; this.motionY += vector.y * d; this.motionZ += vector.z * d; } }
Example #19
Source File: PlayerInteractEvent.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public PlayerInteractEvent(Player player, Item item, Vector3 block, BlockFace face, Action action) { if (block instanceof Block) { this.blockTouched = (Block) block; this.touchVector = new Vector3(0, 0, 0); } else { this.touchVector = block; this.blockTouched = Block.get(Block.AIR, 0, new Position(0, 0, 0, player.level)); } this.player = player; this.item = item; this.blockFace = face; this.action = action; }
Example #20
Source File: PlayerInteractEvent.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public PlayerInteractEvent(Player player, Item item, Vector3 block, BlockFace face, Action action) { if (block instanceof Block) { this.blockTouched = (Block) block; this.touchVector = new Vector3(0, 0, 0); } else { this.touchVector = block; this.blockTouched = Block.get(Block.AIR, 0, new Position(0, 0, 0, player.level)); } this.player = player; this.item = item; this.blockFace = face; this.action = action; }
Example #21
Source File: ProjectileItem.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); this.count--; if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { projectile.spawnToAll(); player.getLevel().addSound(new LaunchSound(player), player.getViewers().values()); } } else { projectile.spawnToAll(); } } else { return false; } return true; }
Example #22
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private boolean isPowerSourceAt(BlockFace side) { Vector3 pos = getLocation(); Vector3 v = pos.getSide(side); Block block = this.level.getBlock(v); boolean flag = block.isNormalBlock(); boolean flag1 = this.level.getBlock(pos.up()).isNormalBlock(); return !flag1 && flag && canConnectUpwardsTo(this.level, v.up()) || (canConnectTo(block, side) || !flag && canConnectUpwardsTo(this.level, block.down())); }
Example #23
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void updateAroundRedstone(Vector3 pos, BlockFace face) { for (BlockFace side : BlockFace.values()) { /*if(face != null && side == face) { continue; }*/ this.getBlock(pos.getSide(side)).onUpdate(BLOCK_UPDATE_REDSTONE); } }
Example #24
Source File: Location.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public Vector3 getDirectionVector() { double pitch = ((getPitch() + 90) * Math.PI) / 180; double yaw = ((getYaw() + 90) * Math.PI) / 180; double x = Math.sin(pitch) * Math.cos(yaw); double z = Math.sin(pitch) * Math.sin(yaw); double y = Math.cos(pitch); return new Vector3(x, y, z).normalize(); }
Example #25
Source File: MovingObjectPosition.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static MovingObjectPosition fromEntity(Entity entity) { MovingObjectPosition objectPosition = new MovingObjectPosition(); objectPosition.typeOfHit = 1; objectPosition.entityHit = entity; objectPosition.hitVector = new Vector3(entity.x, entity.y, entity.z); return objectPosition; }
Example #26
Source File: EntityMob.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item, Vector3 clickedPos) { if (item.getId() == Item.NAME_TAG) { if (item.hasCustomName()) { this.setNameTag(item.getCustomName()); this.setNameTagVisible(true); player.getInventory().removeItem(item); return true; } } return false; }
Example #27
Source File: BlockLiquid.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected void triggerLavaMixEffects(Vector3 pos) { this.getLevel().addSound(pos.add(0.5, 0.5, 0.5), Sound.RANDOM_FIZZ, 1, 2.6F + (ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.8F); for (int i = 0; i < 8; ++i) { this.getLevel().addParticle(new SmokeParticle(pos.add(Math.random(), 1.2, Math.random()))); } }
Example #28
Source File: BlockLiquid.java From Nukkit with GNU General Public License v3.0 | 5 votes |
/** * Creates fizzing sound and smoke. Used when lava flows over block or mixes with water. */ protected void triggerLavaMixEffects(Vector3 pos) { this.getLevel().addSound(pos.add(0.5, 0.5, 0.5), Sound.RANDOM_FIZZ, 1, 2.6F + (ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.8F); for (int i = 0; i < 8; ++i) { this.getLevel().addParticle(new SmokeParticle(pos.add(Math.random(), 1.2, Math.random()))); } }
Example #29
Source File: BlockRedstoneDiode.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onBreak(Item item) { Vector3 pos = getLocation(); this.level.setBlock(this, new BlockAir(), true, true); for (BlockFace face : BlockFace.values()) { this.level.updateAroundRedstone(pos.getSide(face), null); } return true; }
Example #30
Source File: BlockEntityPistonArm.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public BlockEntityPistonArm(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (nbt.contains("Progress")) { this.progress = nbt.getFloat("Progress"); } if (nbt.contains("LastProgress")) { this.lastProgress = (float) nbt.getInt("LastProgress"); } if (nbt.contains("Sticky")) { this.sticky = nbt.getBoolean("Sticky"); } if (nbt.contains("Extending")) { this.extending = nbt.getBoolean("Extending"); } if (nbt.contains("powered")) { this.powered = nbt.getBoolean("powered"); } if (nbt.contains("AttachedBlocks")) { ListTag blocks = nbt.getList("AttachedBlocks", IntTag.class); if (blocks != null && blocks.size() > 0) { this.attachedBlock = new Vector3((double) ((IntTag) blocks.get(0)).getData().intValue(), (double) ((IntTag) blocks.get(1)).getData().intValue(), (double) ((IntTag) blocks.get(2)).getData().intValue()); } } else { nbt.putList(new ListTag("AttachedBlocks")); } }