cn.nukkit.utils.LevelException Java Examples

The following examples show how to use cn.nukkit.utils.LevelException. 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: BaseLevelProvider.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

}
 
Example #2
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

    this.spawn = new Vector3(this.levelData.getInt("SpawnX"), this.levelData.getInt("SpawnY"), this.levelData.getInt("SpawnZ"));
}
 
Example #3
Source File: BaseLevelProvider.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

    this.spawn = new Vector3(this.levelData.getInt("SpawnX"), this.levelData.getInt("SpawnY"), this.levelData.getInt("SpawnZ"));
}
 
Example #4
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void removeEntity(Entity entity) {
    if (entity.getLevel() != this) {
        throw new LevelException("Invalid Entity level");
    }

    if (entity instanceof Player) {
        this.players.remove(entity.getId());
        this.checkSleep();
    } else {
        entity.close();
    }

    this.entities.remove(entity.getId());
    this.updateEntities.remove(entity.getId());
}
 
Example #5
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void addEntity(Entity entity) {
    if (entity.getLevel() != this) {
        throw new LevelException("Invalid Entity level");
    }

    if (entity instanceof Player) {
        this.players.put(entity.getId(), (Player) entity);
    }
    this.entities.put(entity.getId(), entity);
}
 
Example #6
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void addBlockEntity(BlockEntity blockEntity) {
    if (blockEntity.getLevel() != this) {
        throw new LevelException("Invalid Block Entity level");
    }
    blockEntities.put(blockEntity.getId(), blockEntity);
    this.clearChunkCache((int) blockEntity.getX() >> 4, (int) blockEntity.getZ() >> 4);
}
 
Example #7
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void removeBlockEntity(BlockEntity blockEntity) {
    if (blockEntity.getLevel() != this) {
        throw new LevelException("Invalid Block Entity level");
    }
    blockEntities.remove(blockEntity.getId());
    updateBlockEntities.remove(blockEntity.getId());
    this.clearChunkCache((int) blockEntity.getX() >> 4, (int) blockEntity.getZ() >> 4);
}
 
Example #8
Source File: BlockThin.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected AxisAlignedBB recalculateBoundingBox() {
    final double offNW = 7.0 / 16.0;
    final double offSE = 9.0 / 16.0;
    final double onNW = 0.0;
    final double onSE = 1.0;
    double w = offNW;
    double e = offSE;
    double n = offNW;
    double s = offSE;
    try {
        boolean north = this.canConnect(this.north());
        boolean south = this.canConnect(this.south());
        boolean west = this.canConnect(this.west());
        boolean east = this.canConnect(this.east());
        w = west ? onNW : offNW;
        e = east ? onSE : offSE;
        n = north ? onNW : offNW;
        s = south ? onSE : offSE;
    } catch (LevelException ignore) {
        //null sucks
    }
    return new SimpleAxisAlignedBB(
            this.x + w,
            this.y,
            this.z + n,
            this.x + e,
            this.y + 1,
            this.z + s
    );
}
 
Example #9
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Block getLevelBlock() {
    if (this.isValid()) return this.level.getBlock(this);
    else throw new LevelException("Undefined Level reference");
}
 
Example #10
Source File: BlockThin.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
protected AxisAlignedBB recalculateBoundingBox() {
    double f = 0.4375;
    double f1 = 0.5625;
    double f2 = 0.4375;
    double f3 = 0.5625;
    try {
        boolean flag = this.canConnect(this.north());
        boolean flag1 = this.canConnect(this.south());
        boolean flag2 = this.canConnect(this.west());
        boolean flag3 = this.canConnect(this.east());
        if ((!flag2 || !flag3) && (flag2 || flag3 || flag || flag1)) {
            if (flag2) {
                f = 0;
            } else if (flag3) {
                f1 = 1;
            }
        } else {
            f = 0;
            f1 = 1;
        }
        if ((!flag || !flag1) && (flag2 || flag3 || flag || flag1)) {
            if (flag) {
                f2 = 0;
            } else if (flag1) {
                f3 = 1;
            }
        } else {
            f2 = 0;
            f3 = 1;
        }
    } catch (LevelException ignore) {
        //null sucks
    }
    return new SimpleAxisAlignedBB(
            this.x + f,
            this.y,
            this.z + f2,
            this.x + f1,
            this.y + 1,
            this.z + f3
    );
}
 
Example #11
Source File: Location.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, this.yaw, this.pitch, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #12
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, 0, 0, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #13
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Block getLevelBlock() {
    if (this.isValid()) return this.level.getBlock(this);
    else throw new LevelException("Undefined Level reference");
}
 
Example #14
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getSide(BlockFace face, int step) {
    if (!this.isValid()) {
        throw new LevelException("Undefined Level reference");
    }
    return Position.fromObject(super.getSide(face, step), this.level);
}
 
Example #15
Source File: Location.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, this.yaw, this.pitch, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #16
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, 0, 0, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #17
Source File: Position.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Position getSide(BlockFace face, int step) {
    if (!this.isValid()) {
        throw new LevelException("Undefined Level reference");
    }
    return Position.fromObject(super.getSide(face, step), this.level);
}
 
Example #18
Source File: Position.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Position getSide(BlockFace face, int step) {
    if (!this.isValid()) {
        throw new LevelException("Undefined Level reference");
    }
    return Position.fromObject(super.getSide(face, step), this.level);
}
 
Example #19
Source File: BlockThin.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
protected AxisAlignedBB recalculateBoundingBox() {
    double f = 0.4375;
    double f1 = 0.5625;
    double f2 = 0.4375;
    double f3 = 0.5625;
    try {
        boolean flag = this.canConnect(this.north());
        boolean flag1 = this.canConnect(this.south());
        boolean flag2 = this.canConnect(this.west());
        boolean flag3 = this.canConnect(this.east());
        if ((!flag2 || !flag3) && (flag2 || flag3 || flag || flag1)) {
            if (flag2) {
                f = 0;
            } else if (flag3) {
                f1 = 1;
            }
        } else {
            f = 0;
            f1 = 1;
        }
        if ((!flag || !flag1) && (flag2 || flag3 || flag || flag1)) {
            if (flag) {
                f2 = 0;
            } else if (flag1) {
                f3 = 1;
            }
        } else {
            f2 = 0;
            f3 = 1;
        }
    } catch (LevelException ignore) {
        //null sucks
    }
    return new AxisAlignedBB(
            this.x + f,
            this.y,
            this.z + f2,
            this.x + f1,
            this.y + 1,
            this.z + f3
    );
}
 
Example #20
Source File: Location.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, this.yaw, this.pitch, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #21
Source File: Position.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Location getLocation() {
    if (this.isValid()) return new Location(this.x, this.y, this.z, 0, 0, this.level);
    else throw new LevelException("Undefined Level reference");
}
 
Example #22
Source File: Position.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public Block getLevelBlock() {
    if (this.isValid()) return this.level.getBlock(this);
    else throw new LevelException("Undefined Level reference");
}