cn.nukkit.nbt.tag.ListTag Java Examples
The following examples show how to use
cn.nukkit.nbt.tag.ListTag.
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: BlockFurnaceBurning.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = {2, 5, 3, 4}; this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.FURNACE) .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(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityFurnace furnace = (BlockEntityFurnace) BlockEntity.createBlockEntity(BlockEntity.FURNACE, this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt); return furnace != null; }
Example #2
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse, Entity source) { this.getLevel().setBlock(this, Block.get(BlockID.AIR), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putShort("Fuse", fuse); Entity tnt = Entity.createEntity("PrimedTnt", this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt, source ); if(tnt == null) { return; } tnt.spawnToAll(); this.level.addSound(this, Sound.RANDOM_FUSE); }
Example #3
Source File: BlockEntityHopper.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initBlockEntity() { if (this.namedTag.contains("TransferCooldown")) { this.transferCooldown = this.namedTag.getInt("TransferCooldown"); } this.inventory = new HopperInventory(this); if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) { this.namedTag.putList(new ListTag<CompoundTag>("Items")); } for (int i = 0; i < this.getSize(); i++) { this.inventory.setItem(i, this.getItem(i)); } this.pickupArea = new SimpleAxisAlignedBB(this.x, this.y, this.z, this.x + 1, this.y + 2, this.z + 1); this.scheduleUpdate(); super.initBlockEntity(); }
Example #4
Source File: EntityThrownTrident.java From Nukkit with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: EntityVillager.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void addTradeItems(byte rewardExp, int maxUses, int uses, Item buyA, Item buyB, Item sell) { CompoundTag tag; if (this.namedTag.contains("Offers")) { tag = this.namedTag.getCompound("Offers"); } else { tag = new CompoundTag().putList(new ListTag<CompoundTag>("Recipes")); } CompoundTag nbt = new CompoundTag() .putByte("rewardExp", rewardExp) .putInt("maxUses", maxUses) .putInt("uses", uses) .putCompound("buyA", NBTIO.putItemHelper(buyA)) .putCompound("buyB", NBTIO.putItemHelper(buyB)) .putCompound("sell", NBTIO.putItemHelper(sell)); tag.getList("Recipes", CompoundTag.class).add(nbt); this.namedTag.putCompound("Offers", tag); }
Example #6
Source File: Item.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public boolean hasEnchantments() { if (!this.hasCompoundTag()) { return false; } CompoundTag tag = this.getNamedTag(); if (tag.contains("ench")) { Tag enchTag = tag.get("ench"); if (enchTag instanceof ListTag) { return true; } } return false; }
Example #7
Source File: Item.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public Enchantment[] getEnchantments() { if (!this.hasEnchantments()) { return new Enchantment[0]; } List<Enchantment> enchantments = new ArrayList<>(); ListTag<CompoundTag> ench = this.getNamedTag().getList("ench", CompoundTag.class); for (CompoundTag entry : ench.getAll()) { Enchantment e = Enchantment.getEnchantment(entry.getShort("id")); if (e != null) { e.setLevel(entry.getShort("lvl")); enchantments.add(e); } } return enchantments.stream().toArray(Enchantment[]::new); }
Example #8
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
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(); }
Example #9
Source File: ItemBookWritable.java From Nukkit with GNU General Public License v3.0 | 6 votes |
/** * Inserts a new page with the given text and moves other pages upwards. * @return boolean indicating success */ public boolean insertPage(int pageId, String pageText) { Preconditions.checkArgument(pageId >= 0 && pageId < 50, "Page number " + pageId + " is out of range"); CompoundTag tag = this.hasCompoundTag() ? this.getNamedTag() : new CompoundTag(); ListTag<CompoundTag> pages; if (!tag.contains("pages") || !(tag.get("pages") instanceof ListTag)) { pages = new ListTag<>("pages"); tag.putList(pages); } else { pages = tag.getList("pages", CompoundTag.class); } if (pages.size() <= pageId) { for (int current = pages.size(); current <= pageId; current++) { pages.add(createPageTag()); } pages.get(pageId).putString("text", pageText); } else { pages.add(pageId, createPageTag(pageText)); } this.setCompoundTag(tag); return true; }
Example #10
Source File: Item.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public String[] getLore() { Tag tag = this.getNamedTagEntry("display"); ArrayList<String> lines = new ArrayList<>(); if (tag instanceof CompoundTag) { CompoundTag nbt = (CompoundTag) tag; ListTag<StringTag> lore = nbt.getList("Lore", StringTag.class); if (lore.size() > 0) { for (StringTag stringTag : lore.getAll()) { lines.add(stringTag.data); } } } return lines.toArray(new String[0]); }
Example #11
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse) { this.getLevel().setBlock(this, new BlockAir(), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putShort("Fuse", fuse); Entity tnt = new EntityPrimedTNT( this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt ); tnt.spawnToAll(); this.level.addSound(this, Sound.RANDOM_FUSE); }
Example #12
Source File: BlockEntityBrewingStand.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public BlockEntityBrewingStand(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); inventory = new BrewingInventory(this); if (!namedTag.contains("Items") || !(namedTag.get("Items") instanceof ListTag)) { namedTag.putList(new ListTag<CompoundTag>("Items")); } for (int i = 0; i < getSize(); i++) { inventory.setItem(i, this.getItem(i)); } if (!namedTag.contains("CookTime") || namedTag.getShort("CookTime") > MAX_BREW_TIME) { this.brewTime = MAX_BREW_TIME; } else { this.brewTime = namedTag.getShort("CookTime"); } this.fuelAmount = namedTag.getShort("FuelAmount"); this.fuelTotal = namedTag.getShort("FuelTotal"); if (brewTime < MAX_BREW_TIME) { this.scheduleUpdate(); } }
Example #13
Source File: BlockTNT.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse) { this.getLevel().setBlock(this, new BlockAir(), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putByte("Fuse", fuse); Entity tnt = new EntityPrimedTNT( this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt ); tnt.spawnToAll(); this.level.addSound(new TNTPrimeSound(this)); }
Example #14
Source File: BlockEntityChest.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initBlockEntity() { this.inventory = new ChestInventory(this); if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) { this.namedTag.putList(new ListTag<CompoundTag>("Items")); } /* for (int i = 0; i < this.getSize(); i++) { this.inventory.setItem(i, this.getItem(i)); } */ ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items"); for (CompoundTag compound : list.getAll()) { Item item = NBTIO.getItemHelper(compound); this.inventory.slots.put(compound.getByte("Slot"), item); } super.initBlockEntity(); }
Example #15
Source File: BlockEntityHopper.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public BlockEntityHopper(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); if (this.namedTag.contains("TransferCooldown")) { this.transferCooldown = this.namedTag.getInt("TransferCooldown"); } this.inventory = new HopperInventory(this); if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) { this.namedTag.putList(new ListTag<CompoundTag>("Items")); } for (int i = 0; i < this.getSize(); i++) { this.inventory.setItem(i, this.getItem(i)); } this.pickupArea = new AxisAlignedBB(this.x, this.y, this.z, this.x + 1, this.y + 2, this.z + 1); this.scheduleUpdate(); }
Example #16
Source File: BlockRedstoneComparator.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (super.place(item, block, target, face, fx, fy, fz, player)) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.COMPARATOR) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); new BlockEntityComparator(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); onUpdate(Level.BLOCK_UPDATE_REDSTONE); return true; } return false; }
Example #17
Source File: BinaryStream.java From Nukkit with GNU General Public License v3.0 | 6 votes |
private List<String> extractStringList(Item item, String tagName) { CompoundTag namedTag = item.getNamedTag(); if (namedTag == null) { return Collections.emptyList(); } ListTag<StringTag> listTag = namedTag.getList(tagName, StringTag.class); if (listTag == null) { return Collections.emptyList(); } int size = listTag.size(); List<String> values = new ArrayList<>(size); for (int i = 0; i < size; i++) { StringTag stringTag = listTag.get(i); if (stringTag != null) { values.add(stringTag.data); } } return values; }
Example #18
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 6 votes |
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(); }
Example #19
Source File: BlockEntityShulkerBox.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initBlockEntity() { this.inventory = new ShulkerBoxInventory(this); if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) { this.namedTag.putList(new ListTag<CompoundTag>("Items")); } ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items"); for (CompoundTag compound : list.getAll()) { Item item = NBTIO.getItemHelper(compound); this.inventory.slots.put(compound.getByte("Slot"), item); } if (!this.namedTag.contains("facing")) { this.namedTag.putByte("facing", 0); } super.initBlockEntity(); }
Example #20
Source File: BlockEntityHopper.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override protected void initBlockEntity() { if (this.namedTag.contains("TransferCooldown")) { this.transferCooldown = this.namedTag.getInt("TransferCooldown"); } this.inventory = new HopperInventory(this); if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) { this.namedTag.putList(new ListTag<CompoundTag>("Items")); } for (int i = 0; i < this.getSize(); i++) { this.inventory.setItem(i, this.getItem(i)); } this.pickupArea = new SimpleAxisAlignedBB(this.x, this.y, this.z, this.x + 1, this.y + 2, this.z + 1); this.scheduleUpdate(); super.initBlockEntity(); }
Example #21
Source File: BlockEntityHopper.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected int getSlotIndex(int index) { ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class); for (int i = 0; i < list.size(); i++) { if (list.get(i).getByte("Slot") == index) { return i; } } return -1; }
Example #22
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 #23
Source File: ItemBookWritten.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public Item writeBook(String author, String title, String[] pages) { ListTag<CompoundTag> pageList = new ListTag<>("pages"); for (String page : pages) { pageList.add(new CompoundTag().putString("photoname", "").putString("text", page)); } return writeBook(author, title, pageList); }
Example #24
Source File: BlockEntityFurnace.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void saveNBT() { this.namedTag.putList(new ListTag<CompoundTag>("Items")); for (int index = 0; index < this.getSize(); index++) { this.setItem(index, this.inventory.getItem(index)); } this.namedTag.putShort("CookTime", cookTime); this.namedTag.putShort("BurnTime", burnTime); this.namedTag.putShort("BurnDuration", burnDuration); this.namedTag.putShort("MaxTime", maxTime); }
Example #25
Source File: BlockEntityShulkerBox.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void saveNBT() { this.namedTag.putList(new ListTag<CompoundTag>("Items")); for (int index = 0; index < this.getSize(); index++) { this.setItem(index, this.inventory.getItem(index)); } }
Example #26
Source File: BlockEntityBrewingStand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void saveNBT() { namedTag.putList(new ListTag<CompoundTag>("Items")); for (int index = 0; index < getSize(); index++) { this.setItem(index, inventory.getItem(index)); } namedTag.putShort("CookTime", brewTime); namedTag.putShort("FuelAmount", this.fuelAmount); namedTag.putShort("FuelTotal", this.fuelTotal); }
Example #27
Source File: ItemMinecartTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartTNT minecart = new EntityMinecartTNT( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example #28
Source File: BlockEntityChest.java From Nukkit with GNU General Public License v3.0 | 5 votes |
protected int getSlotIndex(int index) { ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class); for (int i = 0; i < list.size(); i++) { if (list.get(i).getByte("Slot") == index) { return i; } } return -1; }
Example #29
Source File: BlockEntityShulkerBox.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected int getSlotIndex(int index) { ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class); for (int i = 0; i < list.size(); i++) { if (list.get(i).getByte("Slot") == index) { return i; } } return -1; }
Example #30
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
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")); } if(this.namedTag.contains("CustomNameAlwaysVisible")){ this.setNameTagAlwaysVisible(this.namedTag.getBoolean("CustomNameAlwaysVisible")); } } this.setDataFlag(DATA_FLAGS, DATA_FLAG_HAS_COLLISION, true); this.dataProperties.putFloat(DATA_BOUNDING_BOX_HEIGHT, this.getHeight()); this.dataProperties.putFloat(DATA_BOUNDING_BOX_WIDTH, this.getWidth()); this.dataProperties.putInt(DATA_HEALTH, (int) this.getHealth()); this.scheduleUpdate(); }