Java Code Examples for cn.nukkit.nbt.tag.CompoundTag#putInt()
The following examples show how to use
cn.nukkit.nbt.tag.CompoundTag#putInt() .
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: BlockEntityFlowerPot.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public BlockEntityFlowerPot(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("item")) { nbt.putShort("item", 0); } if (!nbt.contains("data")) { if (nbt.contains("mData")) { nbt.putInt("data", nbt.getInt("mData")); nbt.remove("mData"); } else { nbt.putInt("data", 0); } } this.namedTag = nbt; }
Example 2
Source File: BlockEntityComparator.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public BlockEntityComparator(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("OutputSignal")) { nbt.putInt("OutputSignal", 0); } this.outputSignal = nbt.getInt("OutputSignal"); }
Example 3
Source File: ItemBanner.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void correctNBT() { CompoundTag tag = this.getNamedTag() != null ? this.getNamedTag() : new CompoundTag(); if (!tag.contains("Base") || !(tag.get("Base") instanceof IntTag)) { tag.putInt("Base", this.meta); } this.setNamedTag(tag); }
Example 4
Source File: BlockEntityComparator.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public BlockEntityComparator(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("OutputSignal")) { nbt.putInt("OutputSignal", 0); } this.outputSignal = nbt.getInt("OutputSignal"); }
Example 5
Source File: ItemBookWritten.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public Item writeBook(String author, String title, ListTag<CompoundTag> pages) { if (pages.size() > 50 || pages.size() <= 0) return this; //Minecraft does not support more than 50 pages CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); tag.putString("author", author); tag.putString("title", title); tag.putList(pages); tag.putInt("generation", GENERATION_ORIGINAL); tag.putString("xuid", ""); return this.setNamedTag(tag); }
Example 6
Source File: BlockEntityBanner.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public BlockEntityBanner(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("Base")) { nbt.putInt("Base", 0); } if (!nbt.contains("Patterns")) { nbt.putList(new ListTag<>("Patterns")); } }
Example 7
Source File: BlockEntityComparator.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public BlockEntityComparator(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("OutputSignal")) { nbt.putInt("OutputSignal", 0); } this.outputSignal = nbt.getInt("OutputSignal"); }
Example 8
Source File: BlockEntityCommandBlock.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public BlockEntityCommandBlock(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("CustomName")) { nbt.putString("CustomName", ""); } if (!nbt.contains("commandBlockMode")) { nbt.putInt("commandBlockMode", 0); } if (!nbt.contains("Command")) { nbt.putString("Command", ""); } if (!nbt.contains("LastOutput")) { nbt.putString("LastOutput", ""); } if (!nbt.contains("powered")) { nbt.putBoolean("powered", false); } if (!nbt.contains("auto")) { nbt.putBoolean("auto", false); } if (!nbt.contains("conditionalMode")) { nbt.putBoolean("conditionalMode", false); } this.perm = new PermissibleBase(this); this.scheduleUpdate(); }
Example 9
Source File: BlockEntityMobSpawner.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public BlockEntityMobSpawner(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (!nbt.contains("EntityId")) { nbt.putInt("EntityId", 0); } if (!nbt.contains("SpawnCount")) { nbt.putInt("SpawnCount", 4); } if (!nbt.contains("SpawnRange")) { nbt.putInt("SpawnRange", 4); } if (!nbt.contains("MinSpawnDelay")) { nbt.putInt("MinSpawnDelay", 200); } if (!nbt.contains("MaxSpawnDelay")) { nbt.putInt("MaxSpawnDelay", 799); } if (!nbt.contains("Delay")) { nbt.putInt("Delay", NukkitMath.randomRange(new NukkitRandom(), nbt.getInt("MinSpawnDelay"), nbt.getInt("MaxSpawnDelay"))); } if (this.getNetworkId() > 0) { this.scheduleUpdate(); } }
Example 10
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.x); nbt.putInt("zPos", this.z); ListTag<CompoundTag> sectionList = new ListTag<>("Sections"); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", (section.getY())); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); sectionList.add(s); } nbt.putList(sectionList); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); nbt.putIntArray("HeightMap", this.getHeightMapArray()); ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getClass().getSimpleName()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }
Example 11
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toFastBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.x); nbt.putInt("zPos", this.z); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); nbt.putIntArray("HeightMap", this.getHeightMapArray()); for (cn.nukkit.level.format.ChunkSection section : this.getSections()) { if (section instanceof EmptyChunkSection) { continue; } CompoundTag s = new CompoundTag(null); s.putByte("Y", section.getY()); s.putByteArray("Blocks", section.getIdArray()); s.putByteArray("Data", section.getDataArray()); s.putByteArray("BlockLight", section.getLightArray()); s.putByteArray("SkyLight", section.getSkyLightArray()); nbt.getList("Sections", CompoundTag.class).add(s); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); List<BlockUpdateEntry> entries = this.provider.getLevel().getPendingBlockUpdates(this); if (entries != null) { ListTag<CompoundTag> tileTickTag = new ListTag<>("TileTicks"); long totalTime = this.provider.getLevel().getCurrentTick(); for (BlockUpdateEntry entry : entries) { CompoundTag entryNBT = new CompoundTag() .putString("i", entry.block.getClass().getSimpleName()) .putInt("x", entry.pos.getFloorX()) .putInt("y", entry.pos.getFloorY()) .putInt("z", entry.pos.getFloorZ()) .putInt("t", (int) (entry.delay - totalTime)) .putInt("p", entry.priority); tileTickTag.add(entryNBT); } nbt.putList(tileTickTag); } BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return NBTIO.write(chunk, ByteOrder.BIG_ENDIAN); } catch (IOException e) { throw new RuntimeException(e); } }
Example 12
Source File: ItemPotionSplash.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override protected void correctNBT(CompoundTag nbt) { nbt.putInt("PotionId", this.meta); }
Example 13
Source File: ItemBanner.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void setBaseColor(DyeColor color) { CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); tag.putInt("Base", color.getDyeData() & 0x0f); this.setDamage(color.getDyeData() & 0x0f); this.setNamedTag(tag); }
Example 14
Source File: Chunk.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.x); nbt.putInt("zPos", this.z); if (this.isGenerated()) { nbt.putByteArray("Blocks", this.getBlockIdArray()); nbt.putByteArray("Data", this.getBlockDataArray()); nbt.putByteArray("SkyLight", this.getBlockSkyLightArray()); nbt.putByteArray("BlockLight", this.getBlockLightArray()); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); nbt.putIntArray("HeightMap", this.getHeightMapArray()); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }
Example 15
Source File: ItemPotionSplash.java From Jupiter with GNU General Public License v3.0 | 4 votes |
protected void correctNBT(CompoundTag nbt) { nbt.putInt("PotionId", this.meta); }
Example 16
Source File: ItemPotionSplash.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override protected void correctNBT(CompoundTag nbt) { nbt.putInt("PotionId", this.meta); }
Example 17
Source File: Chunk.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public byte[] toBinary() { CompoundTag nbt = this.getNBT().copy(); nbt.putInt("xPos", this.getX()); nbt.putInt("zPos", this.getZ()); if (this.isGenerated()) { nbt.putByteArray("Blocks", this.getBlockIdArray()); nbt.putByteArray("Data", this.getBlockDataArray()); nbt.putByteArray("SkyLight", this.getBlockSkyLightArray()); nbt.putByteArray("BlockLight", this.getBlockLightArray()); nbt.putIntArray("BiomeColors", this.getBiomeColorArray()); int[] heightInts = new int[256]; byte[] heightBytes = this.getHeightMapArray(); for (int i = 0; i < heightInts.length; i++) { heightInts[i] = heightBytes[i] & 0xFF; } nbt.putIntArray("HeightMap", heightInts); } ArrayList<CompoundTag> entities = new ArrayList<>(); for (Entity entity : this.getEntities().values()) { if (!(entity instanceof Player) && !entity.closed) { entity.saveNBT(); entities.add(entity.namedTag); } } ListTag<CompoundTag> entityListTag = new ListTag<>("Entities"); entityListTag.setAll(entities); nbt.putList(entityListTag); ArrayList<CompoundTag> tiles = new ArrayList<>(); for (BlockEntity blockEntity : this.getBlockEntities().values()) { blockEntity.saveNBT(); tiles.add(blockEntity.namedTag); } ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities"); tileListTag.setAll(tiles); nbt.putList(tileListTag); BinaryStream extraData = new BinaryStream(); Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray(); extraData.putInt(extraDataArray.size()); for (Integer key : extraDataArray.keySet()) { extraData.putInt(key); extraData.putShort(extraDataArray.get(key)); } nbt.putByteArray("ExtraData", extraData.getBuffer()); CompoundTag chunk = new CompoundTag(""); chunk.putCompound("Level", nbt); try { return Zlib.deflate(NBTIO.write(chunk, ByteOrder.BIG_ENDIAN), RegionLoader.COMPRESSION_LEVEL); } catch (Exception e) { throw new RuntimeException(e); } }
Example 18
Source File: ItemColorArmor.java From Nukkit with GNU General Public License v3.0 | 3 votes |
/** * Set leather armor color * * @param r - red * @param g - green * @param b - blue * @return - Return colored item */ public ItemColorArmor setColor(int r, int g, int b) { int rgb = r << 16 | g << 8 | b; CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); tag.putInt("customColor", rgb); this.setNamedTag(tag); return this; }
Example 19
Source File: ItemColorArmor.java From Nukkit with GNU General Public License v3.0 | 3 votes |
/** * Set leather armor color * * @param r - red * @param g - green * @param b - blue * @return - Return colored item */ public ItemColorArmor setColor(int r, int g, int b) { int rgb = r << 16 | g << 8 | b; CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); tag.putInt("customColor", rgb); this.setNamedTag(tag); return this; }
Example 20
Source File: ItemColorArmor.java From Jupiter with GNU General Public License v3.0 | 3 votes |
/** * Set leather armor color * * @param r - red * @param g - green * @param b - blue * @return - Return colored item */ public ItemColorArmor setColor(int r, int g, int b) { int rgb = r << 16 | g << 8 | b; CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); tag.putInt("customColor", rgb); this.setNamedTag(tag); return this; }