Java Code Examples for net.minecraft.nbt.CompoundTag#contains()
The following examples show how to use
net.minecraft.nbt.CompoundTag#contains() .
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: ModifyCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private NbtPath parseNbtPath(CompoundTag tag, String path) { String[] parts = path.split("\\."); CompoundTag base = tag; if(base == null) return null; for(int i = 0; i < parts.length - 1; i++) { String part = parts[i]; if(!base.contains(part) || !(base.get(part) instanceof CompoundTag)) return null; base = base.getCompound(part); } if(!base.contains(parts[parts.length - 1])) return null; return new NbtPath(base, parts[parts.length - 1]); }
Example 2
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
public static List<ItemStack> getItemsInContainer(ItemStack item) { List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR))); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.contains("BlockEntityTag")) { CompoundTag nbt2 = nbt.getCompound("BlockEntityTag"); if (nbt2.contains("Items")) { ListTag nbt3 = (ListTag) nbt2.get("Items"); for (int i = 0; i < nbt3.size(); i++) { items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i))); } } } return items; }
Example 3
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
public static List<ItemStack> getItemsInContainer(ItemStack item) { List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR))); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.contains("BlockEntityTag")) { CompoundTag nbt2 = nbt.getCompound("BlockEntityTag"); if (nbt2.contains("Items")) { ListTag nbt3 = (ListTag) nbt2.get("Items"); for (int i = 0; i < nbt3.size(); i++) { items.set(nbt3.getCompound(i).getByte("Slot"), ItemStack.fromTag(nbt3.getCompound(i))); } } } return items; }
Example 4
Source File: ConfigurableElectricMachineBlockEntity.java From Galacticraft-Rewoven with MIT License | 6 votes |
public void fromTag(CompoundTag tag) { CompoundTag compoundTag = tag.getCompound("security"); if (compoundTag.contains("owner")) { if (!this.hasOwner()) { this.owner = compoundTag.getUuid("owner"); } } if (compoundTag.contains("team")) { if (!this.hasTeam()) { this.team = new Identifier(compoundTag.getString("team")); } } this.username = compoundTag.getString("username"); this.publicity = Publicity.valueOf(compoundTag.getString("publicity")); }
Example 5
Source File: ItemStackMixin.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "<init>(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN")) private void deserializeCapabilities(CompoundTag tag, CallbackInfo callbackInfo) { // TODO: See above TODO gatherCapabilities(null); if (tag.contains("ForgeCaps")) { deserializeCaps(tag.getCompound("ForgeCaps")); } }
Example 6
Source File: InventoryHelper.java From fabric-carpet with MIT License | 5 votes |
public static boolean shulkerBoxHasItems(ItemStack stack) { CompoundTag tag = stack.getTag(); if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND)) return false; CompoundTag bet = tag.getCompound("BlockEntityTag"); return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty(); }
Example 7
Source File: InventoryHelper.java From fabric-carpet with MIT License | 5 votes |
public static boolean cleanUpShulkerBoxTag(ItemStack stack) { boolean changed = false; CompoundTag tag = stack.getTag(); if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND)) return false; CompoundTag bet = tag.getCompound("BlockEntityTag"); if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty()) { bet.remove("Items"); changed = true; } if (bet.isEmpty()) { tag.remove("BlockEntityTag"); changed = true; } if (tag.isEmpty()) { stack.setTag(null); changed = true; } return changed; }
Example 8
Source File: ItemContentUtils.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
public static List<List<String>> getTextInBook(ItemStack item) { List<String> pages = new ArrayList<>(); CompoundTag nbt = item.getTag(); if (nbt != null && nbt.contains("pages")) { ListTag nbt2 = nbt.getList("pages", 8); for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i)); } List<List<String>> finalPages = new ArrayList<>(); for (String s: pages) { String buffer = ""; List<String> pageBuffer = new ArrayList<>(); for (char c: s.toCharArray()) { if (MinecraftClient.getInstance().textRenderer.getStringWidth(buffer) > 114 || buffer.endsWith("\n")) { pageBuffer.add(buffer.replace("\n", "")); buffer = ""; } buffer += c; } pageBuffer.add(buffer); finalPages.add(pageBuffer); } return finalPages; }
Example 9
Source File: PistonBlockEntity_movableTEMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "fromTag", at = @At(value = "TAIL")) private void onFromTag(CompoundTag compoundTag_1, CallbackInfo ci) { if (CarpetSettings.movableBlockEntities && compoundTag_1.contains("carriedTileEntityCM", 10)) { if (this.pushedBlock.getBlock() instanceof BlockEntityProvider) this.carriedBlockEntity = ((BlockEntityProvider) (this.pushedBlock.getBlock())).createBlockEntity(this.world); if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null this.carriedBlockEntity.fromTag(compoundTag_1.getCompound("carriedTileEntityCM")); } }
Example 10
Source File: ChunkSerializerMixin.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Redirect(method = "deserialize", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk")) private static WorldChunk newWorldChunk( World newWorld, ChunkPos newChunkPos, Biome[] newBiomes, UpgradeData newUpgradeData, TickScheduler<Block> newTickScheduler, TickScheduler<Fluid> newTickScheduler2, long newL, @Nullable ChunkSection[] newChunkSections, @Nullable Consumer<WorldChunk> newConsumer, ServerWorld serverWorld, StructureManager structureManager, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, CompoundTag compoundTag) { WorldChunk chunk = new WorldChunk(newWorld, newChunkPos, newBiomes, newUpgradeData, newTickScheduler, newTickScheduler2, newL, newChunkSections, newConsumer); CompoundTag level = compoundTag.getCompound("Level"); if (level.contains("ForgeCaps")) { ((CapabilityProviderHolder) chunk).deserializeCaps(level.getCompound("ForgeCaps")); } return chunk; }
Example 11
Source File: CarpetClient.java From fabric-carpet with MIT License | 5 votes |
public static void onClientCommand(Tag t) { CarpetSettings.LOG.info("Server Response:"); CompoundTag tag = (CompoundTag)t; CarpetSettings.LOG.info(" - id: "+tag.getString("id")); CarpetSettings.LOG.info(" - code: "+tag.getInt("code")); if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error")); if (tag.contains("output")) { ListTag outputTag = (ListTag) tag.get("output"); for (int i = 0; i < outputTag.size(); i++) CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString()); } }
Example 12
Source File: EntityMixin.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
@Inject( method = "fromTag", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V") ) private void onFromTag(CompoundTag compoundTag_1, CallbackInfo ci) { if (this.shouldSetPositionOnLoad()) { this.refreshPosition(); } if (CarpetExtraSettings.reloadSuffocationFix && compoundTag_1.contains("CM_Box", 9)) { ListTag box_tag = compoundTag_1.getList("CM_Box", 6); Box box = new Box(box_tag.getDouble(0), box_tag.getDouble(1), box_tag.getDouble(2), box_tag.getDouble(3), box_tag.getDouble(4), box_tag.getDouble(5)); double deltaX = ((box.x1 + box.x2) / 2.0D) - this.x; double deltaY = box.y1 - this.y; double deltaZ = ((box.z1 + box.z2) / 2.0D) - this.z; // Credits: MrGrim (MUP) -> Sanity check. // If the position and BoundingBox center point are > 0.1 blocks apart then do not restore the BoundingBox. In vanilla // this should never happen, but mods might not be aware that the BoundingBox is stored and that the entity // position will be reset to it. if (((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)) < 0.01D) { this.setBoundingBox(box); } } }
Example 13
Source File: MixinBedBlockEntity.java From multiconnect with MIT License | 5 votes |
@Override public void fromTag(BlockState blockState, CompoundTag tag) { super.fromTag(blockState, tag); if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) { if (tag.contains("color")) setBedColor(tag.getInt("color")); } }
Example 14
Source File: Items_1_12_2.java From multiconnect with MIT License | 5 votes |
private static ItemStack invertBannerColors(ItemStack stack) { stack = stack.copy(); CompoundTag blockEntityTag = stack.getSubTag("BlockEntityTag"); if (blockEntityTag != null && blockEntityTag.contains("Patterns", 9)) { ListTag patterns = blockEntityTag.getList("Patterns", 10); for (Tag t : patterns) { CompoundTag pattern = (CompoundTag) t; if (pattern.contains("Color", 3)) pattern.putInt("Color", 15 - pattern.getInt("Color")); } } return stack; }
Example 15
Source File: FlowerPotBlockEntity.java From multiconnect with MIT License | 5 votes |
@Override public void fromTag(BlockState blockState, CompoundTag tag) { super.fromTag(blockState, tag); Item flowerPotItem; if (tag.contains("Item", 8)) flowerPotItem = Registry.ITEM.get(new Identifier(tag.getString("Item"))); else flowerPotItem = Registry.ITEM.get(tag.getInt("Item")); int meta = tag.getInt("Data"); setFlowerPotItemStack(Items_1_12_2.oldItemStackToNew(new ItemStack(flowerPotItem), meta)); }
Example 16
Source File: InfusionPillarBlockEntity.java From the-hallow with MIT License | 5 votes |
@Override public void fromTag(CompoundTag entityTag) { super.fromTag(entityTag); if (entityTag.contains("stored_item")) { this.storedStack = new ItemStack(Registry.ITEM.getOrEmpty(new Identifier(entityTag.getString("stored_item"))).get()); } }
Example 17
Source File: InfusionAltarBlockEntity.java From the-hallow with MIT License | 5 votes |
@Override public void fromTag(CompoundTag entityTag) { super.fromTag(entityTag); if (entityTag.contains("stored_item")) { this.storedStack = new ItemStack(Registry.ITEM.getOrEmpty(new Identifier(entityTag.getString("stored_item"))).get()); } }
Example 18
Source File: GalacticraftEnergy.java From Galacticraft-Rewoven with MIT License | 5 votes |
public static boolean isOxygenItem(ItemStack itemStack) { if (!itemStack.hasTag()) { return false; } CompoundTag tag = itemStack.getTag() == null ? new CompoundTag() : itemStack.getTag(); return tag.contains(OxygenTankItem.OXYGEN_NBT_KEY) && tag.contains(OxygenTankItem.MAX_OXYGEN_NBT_KEY); }
Example 19
Source File: EntityMixin.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
@Inject(method = "fromTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V")) private void deserializeCapabilities(CompoundTag tag, CallbackInfo callbackInfo) { if (tag.contains("ForgeCaps")) { deserializeCaps(tag.getCompound("ForgeCaps")); } }
Example 20
Source File: BlockEntityMixin.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
@Inject(method = "fromTag", at = @At("RETURN")) private void deserializeCapabilities(CompoundTag compoundTag, CallbackInfo callbackInfo) { if (getCapabilities() != null && compoundTag.contains("ForgeCaps")) { deserializeCaps(compoundTag.getCompound("ForgeCaps")); } }