예제 #1
0
  @Override
  public void setChunk(int chunkX, int chunkZ, FullChunk chunk) {
    if (!(chunk instanceof Chunk)) {
      throw new ChunkException("Invalid Chunk class");
    }
    chunk.setProvider(this);
    int regionX = getRegionIndexX(chunkX);
    int regionZ = getRegionIndexZ(chunkZ);
    this.loadRegion(regionX, regionZ);

    chunk.setX(chunkX);
    chunk.setZ(chunkZ);
    String index = Level.chunkHash(chunkX, chunkZ);
    this.chunks.put(index, (Chunk) chunk);
  }
예제 #2
0
  public Tile(FullChunk chunk, CompoundTag nbt) {
    if (chunk == null || chunk.getProvider() == null) {
      throw new ChunkException("Invalid garbage Chunk given to Tile");
    }
    this.server = chunk.getProvider().getLevel().getServer();
    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.namedTag = nbt;
    this.name = "";
    this.lastUpdate = System.currentTimeMillis();
    this.id = Tile.tileCount++;
    this.x = this.namedTag.getInt("x");
    this.y = this.namedTag.getInt("y");
    this.z = this.namedTag.getInt("z");

    this.chunk.addTile(this);
    this.getLevel().addTile(this);
  }
예제 #3
0
 private int getHighestWorkableBlock(FullChunk chunk, int x, int z) {
   int y;
   for (y = 127; y >= 0; y--) {
     int b = chunk.getBlockId(x, y, z);
     if (b == Block.AIR) {
       break;
     }
   }
   return y == 0 ? -1 : y;
 }
예제 #4
0
파일: Entity.java 프로젝트: ItsLucas/Nukkit
  protected final void init(FullChunk chunk, CompoundTag nbt) {
    if ((chunk == null || chunk.getProvider() == null)) {
      throw new ChunkException("Invalid garbage Chunk given to Entity");
    }

    this.isPlayer = this instanceof Player;
    this.temporalVector = new Vector3();

    this.id = Entity.entityCount++;
    this.justCreated = true;
    this.namedTag = nbt;

    this.chunk = chunk;
    this.setLevel(chunk.getProvider().getLevel());
    this.server = chunk.getProvider().getLevel().getServer();

    this.boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);

    ListTag<DoubleTag> posList = this.namedTag.getList("Pos", DoubleTag.class);
    ListTag<FloatTag> rotationList = this.namedTag.getList("Rotation", FloatTag.class);
    ListTag<DoubleTag> motionList = this.namedTag.getList("Motion", DoubleTag.class);
    this.setPositionAndRotation(
        this.temporalVector.setComponents(
            posList.get(0).data, posList.get(1).data, posList.get(2).data),
        rotationList.get(0).data,
        rotationList.get(1).data);

    this.setMotion(
        this.temporalVector.setComponents(
            motionList.get(0).data, motionList.get(1).data, motionList.get(2).data));

    if (!this.namedTag.contains("FallDistance")) {
      this.namedTag.putFloat("FallDistance", 0);
    }
    this.fallDistance = this.namedTag.getFloat("FallDistance");

    if (!this.namedTag.contains("Fire")) {
      this.namedTag.putShort("Fire", 0);
    }
    this.fireTicks = this.namedTag.getShort("Fire");

    if (!this.namedTag.contains("Air")) {
      this.namedTag.putShort("Air", 300);
    }
    this.setDataProperty(new ShortEntityData(DATA_AIR, this.namedTag.getShort("Air")));

    if (!this.namedTag.contains("OnGround")) {
      this.namedTag.putBoolean("OnGround", false);
    }
    this.onGround = this.namedTag.getBoolean("OnGround");

    if (!this.namedTag.contains("Invulnerable")) {
      this.namedTag.putBoolean("Invulnerable", false);
    }
    this.invulnerable = this.namedTag.getBoolean("Invulnerable");

    this.chunk.addEntity(this);
    this.level.addEntity(this);

    this.initEntity();

    this.lastUpdate = this.server.getTick();
    this.server.getPluginManager().callEvent(new EntitySpawnEvent(this));

    this.scheduleUpdate();
  }
예제 #5
0
  @Override
  public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
    FullChunk chunk = this.getChunk(x, z, false);
    if (chunk == null) {
      throw new ChunkException("Invalid Chunk Set");
    }

    byte[] tiles = new byte[0];

    if (!chunk.getTiles().isEmpty()) {
      List<CompoundTag> tagList = new ArrayList<>();

      for (Tile tile : chunk.getTiles().values()) {
        if (tile instanceof Spawnable) {
          tagList.add(((Spawnable) tile).getSpawnCompound());
        }
      }

      try {
        tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    BinaryStream extraData = new BinaryStream();
    extraData.putLInt(chunk.getBlockExtraDataArray().size());
    for (Integer key : chunk.getBlockExtraDataArray().values()) {
      extraData.putLInt(key);
      extraData.putLShort(chunk.getBlockExtraDataArray().get(key));
    }

    BinaryStream stream = new BinaryStream();
    stream.put(chunk.getBlockIdArray());
    stream.put(chunk.getBlockDataArray());
    stream.put(chunk.getBlockSkyLightArray());
    stream.put(chunk.getBlockLightArray());
    for (int height : chunk.getHeightMapArray()) {
      stream.putByte((byte) (height & 0xff));
    }
    for (int color : chunk.getBiomeColorArray()) {
      stream.put(Binary.writeInt(color));
    }
    stream.put(extraData.getBuffer());
    stream.put(tiles);

    this.getLevel()
        .chunkRequestCallback(x, z, stream.getBuffer(), FullChunkDataPacket.ORDER_LAYERED);

    return null;
  }