cn.nukkit.level.Position Java Examples

The following examples show how to use cn.nukkit.level.Position. 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: Entity.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
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 #2
Source File: ProjectileDispenseBehavior.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: Block.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Block get(int id, Integer meta, Position pos) {
    Block block;
    try {
        Class<? extends Block> c = list[id];
        if (c != null) {
            Constructor<? extends Block> constructor = c.getDeclaredConstructor(int.class);
            constructor.setAccessible(true);
            block = (Block) constructor.newInstance(meta);
        } else {
            block = new BlockUnknown(id, meta);
        }
    } catch (Exception e) {
        block = new BlockUnknown(id, meta);
    }

    if (pos != null) {
        block.x = pos.x;
        block.y = pos.y;
        block.z = pos.z;
        block.level = pos.level;
    }
    return block;
}
 
Example #4
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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 #5
Source File: ProjectileDispenseBehavior.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: EntityThrownTrident.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public Entity create(Object type, Position source, Object... args) {
    FullChunk chunk = source.getLevel().getChunk((int) source.x >> 4, (int) source.z >> 4);
    if (chunk == null) return null;

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", source.x + 0.5))
                    .add(new DoubleTag("", source.y))
                    .add(new DoubleTag("", source.z + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", new Random().nextFloat() * 360))
                    .add(new FloatTag("", 0)));

    return Entity.createEntity(type.toString(), chunk, nbt, args);
}
 
Example #7
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
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;

    this.recalculateBoundingBox(false); // Don't need to send BB height/width to client on position change

    this.checkChunks();

    return true;
}
 
Example #8
Source File: Block.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Block get(int id, Integer meta, Position pos) {
    Block block = fullList[(id << 4) | (meta == null ? 0 : meta)].clone();
    if (pos != null) {
        block.x = pos.x;
        block.y = pos.y;
        block.z = pos.z;
        block.level = pos.level;
    }
    return block;
}
 
Example #9
Source File: Block.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
final public void position(Position v) {
    this.x = (int) v.x;
    this.y = (int) v.y;
    this.z = (int) v.z;
    this.level = v.level;
    this.boundingBox = null;
}
 
Example #10
Source File: PlayerInteractEvent.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
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 #11
Source File: SummonCommand.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    if (sender instanceof ConsoleCommandSender) {
        sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
        return true;
    }

    if (args.length < 2) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return false;
    }

    Position pos = new Position(Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]), ((Player) sender).getLevel());

    CompoundTag nbt = new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", pos.getX() + 0.5))
                    .add(new DoubleTag("", pos.getY()))
                    .add(new DoubleTag("", pos.getZ() + 0.5)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", new Random().nextFloat() * 360))
                    .add(new FloatTag("", 0)));

    Entity entity = Entity.createEntity(args[0], pos.getLevel().getChunk((int) pos.getX() >> 4, (int) pos.getZ() >> 4, true), nbt);

    entity.spawnToAll();
    return true;
}
 
Example #12
Source File: Block.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Block get(int id, Integer meta, Position pos) {
    Block block = fullList[(id << 4) | (meta == null ? 0 : meta)].clone();
    if (pos != null) {
        block.x = pos.x;
        block.y = pos.y;
        block.z = pos.z;
        block.level = pos.level;
    }
    return block;
}
 
Example #13
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public Position getHighestStandablePositionAt(Position pos) {
    int x = pos.getFloorX();
    int z = pos.getFloorZ();
    for (int y = 127; y >= 0; y--) {
        if (pos.level.getBlock(this.temporalVector.setComponents(x, y, z)).isSolid()) {
            return new Position(x + 0.5, pos.level.getBlock(this.temporalVector.setComponents(x, y, z)).getBoundingBox().getMaxY(), z + 0.5, pos.level);
        }
    }
    return null;
}
 
Example #14
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public Position getStandablePositionAt(Position pos) {
    int x = pos.getFloorX();
    int y = pos.getFloorY() + 1;
    int z = pos.getFloorZ();
    for (; y <= 128; y++) {
        if (!pos.level.getBlock(this.temporalVector.setComponents(x, y, z)).isSolid() && !pos.level.getBlock(this.temporalVector.setComponents(x, y + 1, z)).isSolid()) {
            return new Position(x + 0.5, pos.level.getBlock(this.temporalVector.setComponents(x, y - 1, z)).getBoundingBox().getMaxY(), z + 0.5, pos.level);
        }
    }
    return null;
}
 
Example #15
Source File: PlayerInteractEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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 #16
Source File: NukkitQueue.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendChunk(int x, int z, int bitMask) {
    Collection<Player> players = faweNukkit.getPlugin().getServer().getOnlinePlayers().values();
    int view = faweNukkit.getPlugin().getServer().getViewDistance();
    for (Player player : players) {
        Position pos = player.getPosition();
        int pcx = pos.getFloorX() >> 4;
        int pcz = pos.getFloorZ() >> 4;
        if (Math.abs(pcx - x) > view || Math.abs(pcz - z) > view) {
            continue;
        }
        world.requestChunk(x, z, player);
    }
}
 
Example #17
Source File: PlayerInteractEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
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 #18
Source File: PlayerRespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerRespawnEvent(Player player, Position position) {
    this(player, position, false);
}
 
Example #19
Source File: EntityDespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getPosition() {
    return this.entity.getPosition();
}
 
Example #20
Source File: SpawnChangeEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getPreviousSpawn() {
    return previousSpawn;
}
 
Example #21
Source File: SpawnChangeEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public SpawnChangeEvent(Level level, Position previousSpawn) {
    super(level);
    this.previousSpawn = previousSpawn;
}
 
Example #22
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getPosition() {
    return this.entity.getPosition();
}
 
Example #23
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private Location vectorToLocation(Level baseLevel, Vector3 vector) {
    if (vector instanceof Location) return (Location) vector;
    if (vector instanceof Position) return ((Position) vector).getLocation();
    return new Location(vector.getX(), vector.getY(), vector.getZ(), 0, 0, baseLevel);
}
 
Example #24
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private Location vectorToLocation(Level baseLevel, Vector3 vector) {
    if (vector instanceof Location) return (Location) vector;
    if (vector instanceof Position) return ((Position) vector).getLocation();
    return new Location(vector.getX(), vector.getY(), vector.getZ(), 0, 0, baseLevel);
}
 
Example #25
Source File: PlayerRespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setRespawnPosition(Position position) {
    this.position = position;
}
 
Example #26
Source File: SpawnChangeEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getPreviousSpawn() {
    return previousSpawn;
}
 
Example #27
Source File: PlayerRespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setRespawnPosition(Position position) {
    this.position = position;
}
 
Example #28
Source File: SpawnChangeEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public SpawnChangeEvent(Level level, Position previousSpawn) {
    super(level);
    this.previousSpawn = previousSpawn;
}
 
Example #29
Source File: EntitySpawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getPosition() {
    return this.entity.getPosition();
}
 
Example #30
Source File: PlayerRespawnEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerRespawnEvent(Player player, Position position, boolean firstSpawn) {
    this.player = player;
    this.position = position;
    this.firstSpawn = firstSpawn;
}