コード例 #1
0
ファイル: Entity.java プロジェクト: ItsLucas/Nukkit
  protected void initEntity() {
    if (this.namedTag.contains("ActiveEffects")) {
      ListTag<CompoundTag> effects = this.namedTag.getList("ActiveEffects", CompoundTag.class);
      for (CompoundTag e : effects.getAll()) {
        Effect effect = Effect.getEffect(e.getByte("Id"));
        if (effect == null) {
          continue;
        }

        effect
            .setAmplifier(e.getByte("Amplifier"))
            .setDuration(e.getInt("Duration"))
            .setVisible(e.getBoolean("showParticles"));

        this.addEffect(effect);
      }
    }

    if (this.namedTag.contains("CustomName")) {
      this.setNameTag(this.namedTag.getString("CustomName"));
      if (this.namedTag.contains("CustomNameVisible")) {
        this.setNameTagVisible(this.namedTag.getBoolean("CustomNameVisible"));
      }
    }

    this.scheduleUpdate();
  }
コード例 #2
0
ファイル: BlockEntityChest.java プロジェクト: ItsLucas/Nukkit
  @Override
  public CompoundTag getSpawnCompound() {
    CompoundTag c;
    if (this.isPaired()) {
      c =
          new CompoundTag()
              .putString("id", BlockEntity.CHEST)
              .putInt("x", (int) this.x)
              .putInt("y", (int) this.y)
              .putInt("z", (int) this.z)
              .putInt("pairx", this.namedTag.getInt("pairx"))
              .putInt("pairz", this.namedTag.getInt("pairz"));
    } else {
      c =
          new CompoundTag()
              .putString("id", BlockEntity.CHEST)
              .putInt("x", (int) this.x)
              .putInt("y", (int) this.y)
              .putInt("z", (int) this.z);
    }

    if (this.hasName()) {
      c.put("CustomName", this.namedTag.get("CustomName"));
    }

    return c;
  }
コード例 #3
0
ファイル: BlockEntityChest.java プロジェクト: ItsLucas/Nukkit
 @Override
 public Item getItem(int index) {
   int i = this.getSlotIndex(index);
   if (i < 0) {
     return new ItemBlock(new BlockAir(), 0, 0);
   } else {
     CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
     return Item.get(data.getShort("id"), data.getShort("Damage"), data.getByte("Count"));
   }
 }
コード例 #4
0
ファイル: BaseFullChunk.java プロジェクト: ChaptersPE/Nukkit
  public void initChunk() {
    if (this.getProvider() != null && !this.isInit) {
      boolean changed = false;
      if (this.NBTentities != null) {
        this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.startTiming();
        for (CompoundTag nbt : NBTentities) {
          if (!nbt.contains("id")) {
            this.setChanged();
            continue;
          }
          ListTag pos = nbt.getList("Pos");
          if ((((NumberTag) pos.get(0)).getData().intValue() >> 4) != this.vector2.x
              || ((((NumberTag) pos.get(2)).getData().intValue() >> 4) != this.vector2.z)) {
            changed = true;
            continue;
          }
          Entity entity = Entity.createEntity(nbt.getString("id"), this, nbt);
          if (entity != null) {
            entity.spawnToAll();
          } else {
            changed = true;
            continue;
          }
        }
        this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.stopTiming();

        this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.startTiming();
        for (CompoundTag nbt : NBTtiles) {
          if (nbt != null) {
            if (!nbt.contains("id")) {
              changed = true;
              continue;
            }
            if ((nbt.getInt("x") >> 4) != this.vector2.x
                || ((nbt.getInt("z") >> 4) != this.vector2.z)) {
              changed = true;
              continue;
            }
            BlockEntity blockEntity = BlockEntity.createBlockEntity(nbt.getString("id"), this, nbt);
            if (blockEntity == null) {
              changed = true;
              continue;
            }
          }
        }

        this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.stopTiming();

        this.NBTentities = null;
        this.NBTtiles = null;
      }

      this.setChanged(changed);

      this.isInit = true;
    }
  }
コード例 #5
0
ファイル: BrewingStand.java プロジェクト: qq505916481/Nukkit
  @Override
  public boolean place(
      Item item,
      Block block,
      Block target,
      int face,
      double fx,
      double fy,
      double fz,
      Player player) {
    int faces[] = {4, 2, 5, 3};

    meta = faces[player != null ? player.getDirection() : 0];
    getLevel().setBlock(block, this, true, true);

    CompoundTag nbt =
        new CompoundTag()
            .putList(new ListTag<>("Items"))
            .putString("id", Tile.BREWING_STAND)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z);

    if (item.hasCustomName()) {
      nbt.putString("CustomName", item.getCustomName());
    }

    if (item.hasCustomBlockData()) {
      Map<String, Tag> customData = item.getCustomBlockData().getTags();
      Iterator iter = customData.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry tag = (Map.Entry) iter.next();
        nbt.put((String) tag.getKey(), (Tag) tag.getValue());
      }
    }

    new cn.nukkit.tile.BrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);

    return true;
  }
コード例 #6
0
ファイル: Anvil.java プロジェクト: Superboomer/Nukkit
 public static ChunkSection createChunkSection(byte Y) {
   CompoundTag nbt = new CompoundTag();
   nbt.putByte("Y", Y);
   nbt.putByteArray("Blocks", new byte[4096]);
   nbt.putByteArray("Data", new byte[2048]);
   byte[] sl = new byte[2048];
   Arrays.fill(sl, (byte) 0xff);
   nbt.putByteArray("SkyLight", sl);
   nbt.putByteArray("BlockLight", new byte[2048]);
   return new ChunkSection(nbt);
 }