net.minecraft.nbt.CompoundTag Java Examples
The following examples show how to use
net.minecraft.nbt.CompoundTag.
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: StandardWrenchItem.java From Galacticraft-Rewoven with MIT License | 6 votes |
private void use(PlayerEntity player, BlockState state, WorldAccess iWorld, BlockPos pos, ItemStack stack) { Block block = state.getBlock(); if (block instanceof Rotatable) { StateManager<Block, BlockState> manager = block.getStateManager(); Collection<Property<?>> collection = manager.getProperties(); String string_1 = Registry.BLOCK.getId(block).toString(); if (!collection.isEmpty()) { CompoundTag compoundTag_1 = stack.getOrCreateSubTag("wrenchProp"); String string_2 = compoundTag_1.getString(string_1); Property<?> property = manager.getProperty(string_2); if (property == null) { property = collection.iterator().next(); } if (property.getName().equals("facing")) { BlockState blockState_2 = cycle(state, property, player.isSneaking()); iWorld.setBlockState(pos, blockState_2, 18); stack.damage(2, player, (playerEntity) -> playerEntity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); } } } }
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: PassengerFeature.java From MineLittlePony with MIT License | 6 votes |
private void renderShoulderParrot(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float headYaw, float headPitch, boolean left) { CompoundTag riderTag = left ? entity.getShoulderEntityLeft() : entity.getShoulderEntityRight(); EntityType.get(riderTag.getString("id")).filter(p -> p == EntityType.PARROT).ifPresent((entityType) -> { stack.push(); getContextModel().transform(BodyPart.BODY, stack); stack.translate(left ? 0.25 : -0.25, entity.isInSneakingPose() ? -0.5 : -0.25, 0.35); stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(left ? -5 : 5)); VertexConsumer vertexConsumer = renderContext.getBuffer(model.getLayer(ParrotEntityRenderer.TEXTURES[riderTag.getInt("Variant")])); model.poseOnShoulder(stack, vertexConsumer, lightUv, OverlayTexture.DEFAULT_UV, limbDistance, limbAngle, headYaw, headPitch, entity.age); stack.pop(); }); }
Example #4
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 #5
Source File: PotionCmd.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private ListTag convertEffectsToNbt(ItemStack stack) { ListTag nbt = new ListTag(); List<StatusEffectInstance> effects = PotionUtil.getCustomPotionEffects(stack); for(StatusEffectInstance effect : effects) { CompoundTag tag = new CompoundTag(); int id = StatusEffect.getRawId(effect.getEffectType()); tag.putInt("Id", id); tag.putInt("Amplifier", effect.getAmplifier()); tag.putInt("Duration", effect.getDuration()); nbt.add(tag); } return nbt; }
Example #6
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 #7
Source File: BlockValue.java From fabric-carpet with MIT License | 6 votes |
public CompoundTag getData() { if (data != null) { if (data.isEmpty()) return null; return data; } if (world != null && pos != null) { BlockEntity be = getBlockEntity(world, pos); CompoundTag tag = new CompoundTag(); if (be == null) { data = tag; return null; } data = be.toTag(tag); return data; } return null; }
Example #8
Source File: CmdSkull.java From bleachhack-1.14 with GNU General Public License v3.0 | 6 votes |
@Override public void onCommand(String command, String[] args) throws Exception { ItemStack item = new ItemStack(Items.PLAYER_HEAD, 64); if (args.length < 2) { item.setTag(StringNbtReader.parse("{SkullOwner:{Name:\"" + args[0] + "\"}}")); } else if (args[0].equalsIgnoreCase("img")) { CompoundTag tag = StringNbtReader.parse("{SkullOwner:{Id:\"" + UUID.randomUUID() + "\",Properties:{textures:[{Value:\"" + Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"" + args[1] + "\"}}}").getBytes()) + "\"}]}}}"); item.setTag(tag); System.out.println(tag); } mc.player.inventory.addPickBlock(item); }
Example #9
Source File: GuardianEntityMixin.java From fabric-carpet with MIT License | 6 votes |
@Override public void onStruckByLightning(LightningEntity lightning) { if (!this.world.isClient && !this.removed && CarpetSettings.renewableSponges && !((Object)this instanceof ElderGuardianEntity)) { ElderGuardianEntity elderGuardian = new ElderGuardianEntity(EntityType.ELDER_GUARDIAN ,this.world); elderGuardian.refreshPositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch); elderGuardian.initialize(this.world ,this.world.getLocalDifficulty(elderGuardian.getBlockPos()), SpawnType.CONVERSION, (EntityData)null, (CompoundTag)null); elderGuardian.setAiDisabled(this.isAiDisabled()); if (this.hasCustomName()) { elderGuardian.setCustomName(this.getCustomName()); elderGuardian.setCustomNameVisible(this.isCustomNameVisible()); } this.world.spawnEntity(elderGuardian); this.remove(); } else { super.onStruckByLightning(lightning); } }
Example #10
Source File: HallowedTreasureChestEntity.java From the-hallow with MIT License | 6 votes |
@Override protected void writeCustomDataToTag(CompoundTag compoundTag) { compoundTag.putBoolean("shouldReplace", shouldReplace); compoundTag.putBoolean("hasReplaced", hasReplaced); compoundTag.putInt("spinProgress", spinProgress); compoundTag.putInt("endProgress", endProgress); compoundTag.putInt("hingeProgress", hingeProgress); compoundTag.putBoolean("isSpinningUp", isSpinningUp); compoundTag.putBoolean("isEnding", isEnding); compoundTag.putBoolean("isOpeningHinge", isOpeningHinge); compoundTag.putFloat("rotation", rotation); compoundTag.putFloat("previousRotation", previousRotation); }
Example #11
Source File: Items_1_12_2.java From multiconnect with MIT License | 5 votes |
private static void newEnchantmentListToOld(ListTag enchantments) { for (int i = 0; i < enchantments.size(); i++) { CompoundTag ench = enchantments.getCompound(i); Identifier name = Identifier.tryParse(ench.getString("id")); Enchantment enchObj = Registry.ENCHANTMENT.get(name); if (enchObj == null) { enchantments.remove(i); i--; } else { ench.putInt("id", Registry.ENCHANTMENT.getRawId(enchObj)); } } }
Example #12
Source File: Items_1_12_2.java From multiconnect with MIT License | 5 votes |
private static void oldEnchantmentListToNew(ListTag enchantments) { for (int i = 0; i < enchantments.size(); i++) { CompoundTag ench = enchantments.getCompound(i); int id = ench.getInt("id"); Identifier name = Registry.ENCHANTMENT.getId(Registry.ENCHANTMENT.get(id)); if (name == null) { enchantments.remove(i); i--; } else { ench.putString("id", name.toString()); } } }
Example #13
Source File: CandyComponent.java From the-hallow with MIT License | 5 votes |
@Override public void fromTag(CompoundTag tag) { ListTag list = tag.getList("entities", 10); for (int i = 0; i < list.size(); i++) { CompoundTag item = list.getCompound(i); lastGivenCandy.put(item.getUuid("uuid"), item.getLong("time")); } }
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: MixinBannerBlockEntity.java From multiconnect with MIT License | 5 votes |
@Inject(method = "fromTag", at = @At("RETURN")) private void onFromTag(BlockState blockState, CompoundTag tag, CallbackInfo ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) { for (Tag t : patternListTag) { if (t instanceof CompoundTag) { CompoundTag pattern = (CompoundTag) t; pattern.putInt("Color", 15 - pattern.getInt("Color")); } } } }
Example #16
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 #17
Source File: ClientNetworkHandler.java From fabric-carpet with MIT License | 5 votes |
private static void onSyncData(PacketByteBuf data, ClientPlayerEntity player) { CompoundTag compound = data.readCompoundTag(); if (compound == null) return; for (String key: compound.getKeys()) { if (dataHandlers.containsKey(key)) dataHandlers.get(key).accept(player, compound.get(key)); else CarpetSettings.LOG.error("Unknown carpet data: "+key); } }
Example #18
Source File: MixinClientChunkManager.java From multiconnect with MIT License | 5 votes |
@Inject(method = "loadChunkFromPacket", at = @At("RETURN")) private void onLoadChunkFromPacket(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag heightmaps, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) { if (ConnectionInfo.protocolVersion <= Protocols.V1_14_4) { if (ci.getReturnValue() != null) { Biome[] biomeData = PendingBiomeData.getPendingBiomeData(x, z); if (biomeData != null) { ((IBiomeStorage_1_14_4) ci.getReturnValue()).multiconnect_setBiomeArray_1_14_4(biomeData); PendingBiomeData.setPendingBiomeData(x, z, null); } } } }
Example #19
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 #20
Source File: ServerCrasherHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private CompoundTag createNBT() { try { return StringNbtReader.parse( "{display:{Lore:['\"\u00a7r1. Place item in dispenser.\"','\"\u00a7r2. Dispense item.\"','\"\u00a7r3. Ssss... BOOM!\"'],Name:'{\"text\":\"\u00a7rServer Creeper\"}'},EntityTag:{CustomName:\"TEST\",id:\"Creeper\",CustomNameVisible:1}}"); }catch(CommandSyntaxException e) { throw new RuntimeException(e); } }
Example #21
Source File: TrollPotionHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public void onEnable() { // check gamemode if(!MC.player.abilities.creativeMode) { ChatUtils.error("Creative mode only."); setEnabled(false); return; } // generate potion ItemStack stack = new ItemStack(Items.SPLASH_POTION); ListTag effects = new ListTag(); for(int i = 1; i <= 23; i++) { CompoundTag effect = new CompoundTag(); effect.putInt("Amplifier", Integer.MAX_VALUE); effect.putInt("Duration", Integer.MAX_VALUE); effect.putInt("Id", i); effects.add(effect); } CompoundTag nbt = new CompoundTag(); nbt.put("CustomPotionEffects", effects); stack.setTag(nbt); String name = "\u00a7rSplash Potion of Trolling"; stack.setCustomName(new LiteralText(name)); // give potion if(placeStackInHotbar(stack)) ChatUtils.message("Potion created."); else ChatUtils.error("Please clear a slot in your hotbar."); setEnabled(false); }
Example #22
Source File: CandyComponent.java From the-hallow with MIT License | 5 votes |
@Override public CompoundTag toTag(CompoundTag tag) { ListTag list = new ListTag(); Iterator<Map.Entry<UUID, Long>> iterator = lastGivenCandy.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<UUID, Long> entry = iterator.next(); CompoundTag item = new CompoundTag(); item.putUuid("uuid", entry.getKey()); item.putLong("time", entry.getValue()); list.add(item); } tag.put("entities", list); return tag; }
Example #23
Source File: TinyPumpkinBlockEntity.java From the-hallow with MIT License | 5 votes |
@Override public CompoundTag toTag(CompoundTag t) { CompoundTag tag = super.toTag(t); tag.put("Left", leftItem.toTag(new CompoundTag())); tag.put("Right", rightItem.toTag(new CompoundTag())); return tag; }
Example #24
Source File: MapValue.java From fabric-carpet with MIT License | 5 votes |
@Override public Tag toTag(boolean force) { CompoundTag tag = new CompoundTag() ; map.forEach( (k, v) -> { if (!force && !(k instanceof StringValue)) throw new NBTSerializableValue.IncompatibleTypeException(k); tag.put(k.getString(), v.toTag(force)); }); return tag; }
Example #25
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 #26
Source File: ChunkSize.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onTick(EventTick event) { if (System.currentTimeMillis() - 1500 < timer) return; timer = System.currentTimeMillis(); if (mc.world.getWorldChunk(mc.player.getBlockPos()) == null) return; new Thread(() -> { CompoundTag tag = serialize(mc.world, mc.world.getWorldChunk(mc.player.getBlockPos())); DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new DeflaterOutputStream(new ByteArrayOutputStream(8096)))); try { NbtIo.writeCompressed(tag, output); } catch (IOException e) {} size = output.size(); }).start(); }
Example #27
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 #28
Source File: InfusionAltarBlockEntity.java From the-hallow with MIT License | 5 votes |
@Override public CompoundTag toTag(CompoundTag entityTag) { super.toTag(entityTag); if (!storedStack.isEmpty()) { entityTag.putString("stored_item", Registry.ITEM.getId(storedStack.getItem()).toString()); } return entityTag; }
Example #29
Source File: ServerNetworkHandler.java From fabric-carpet with MIT License | 5 votes |
private static void onClientData(ServerPlayerEntity player, PacketByteBuf data) { CompoundTag compound = data.readCompoundTag(); if (compound == null) return; for (String key: compound.getKeys()) { if (dataHandlers.containsKey(key)) dataHandlers.get(key).accept(player, compound.get(key)); else CarpetSettings.LOG.warn("Unknown carpet client data: "+key); } }
Example #30
Source File: PlayerManager_fakePlayersMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable<CompoundTag> cir) { if (serverPlayerEntity_1 instanceof EntityPlayerMPFake) { ((EntityPlayerMPFake) serverPlayerEntity_1).fixStartingPosition.run(); } }