Search in sources :

Example 6 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project MCDoom by AzureDoom.

the class DoomEquipmentUtils method getNbtForEnchantments.

public static NbtCompound getNbtForEnchantments(ItemStack breakingStack, ItemStack ruinedStack) {
    Set<String> enchantmentStrings = new HashSet<>();
    for (Map.Entry<Enchantment, Integer> ench : EnchantmentHelper.get(breakingStack).entrySet()) {
        String enchantString = Registry.ENCHANTMENT.getId(ench.getKey()) + ">" + ench.getValue();
        enchantmentStrings.add(enchantString);
    }
    if (!enchantmentStrings.isEmpty()) {
        NbtCompound tag = ruinedStack.getNbt();
        if (tag == null)
            tag = new NbtCompound();
        tag.putString(TAG, String.join(",", enchantmentStrings));
        return tag;
    }
    return null;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) Enchantment(net.minecraft.enchantment.Enchantment) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Polymorph by TheIllusiveC4.

the class AbstractStackRecipeData method readNbt.

@Override
public void readNbt(NbtCompound pCompound) {
    if (pCompound.contains("SelectedRecipe")) {
        this.loadedRecipe = new Identifier(pCompound.getString("SelectedRecipe"));
    }
    if (pCompound.contains("RecipeDataSet")) {
        Set<RecipePair> dataset = this.getRecipesList();
        dataset.clear();
        NbtList list = pCompound.getList("RecipeDataSet", NbtType.COMPOUND);
        for (NbtElement inbt : list) {
            NbtCompound tag = (NbtCompound) inbt;
            Identifier id = Identifier.tryParse(tag.getString("Id"));
            ItemStack stack = ItemStack.fromNbt(tag.getCompound("ItemStack"));
            dataset.add(new RecipePairImpl(id, stack));
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair) NbtCompound(net.minecraft.nbt.NbtCompound) RecipePairImpl(top.theillusivec4.polymorph.common.impl.RecipePairImpl) NbtList(net.minecraft.nbt.NbtList) NbtElement(net.minecraft.nbt.NbtElement) ItemStack(net.minecraft.item.ItemStack)

Example 8 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Rug by RubixDev.

the class PeekCommand method execute.

private static int execute(CommandContext<ServerCommandSource> context, boolean isEnderChest) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    PlayerManager playerManager = source.getServer().getPlayerManager();
    GameProfile targetPlayerProfile = GameProfileArgumentType.getProfileArgument(context, "player").iterator().next();
    ServerPlayerEntity targetPlayer = playerManager.getPlayer(targetPlayerProfile.getName());
    ServerPlayerEntity executingPlayer = source.getPlayer();
    if (targetPlayer == null) {
        targetPlayer = playerManager.createPlayer(targetPlayerProfile);
        NbtCompound targetPlayerData = playerManager.loadPlayerData(targetPlayer);
        if (targetPlayerData == null) {
            source.sendError(Text.of("Targeted player's data could not be found. Was he ever in this world?"));
            return 0;
        }
        @SuppressWarnings("deprecation") ServerWorld world = source.getServer().getWorld(DimensionType.worldFromDimensionNbt(new Dynamic<>(NbtOps.INSTANCE, targetPlayerData.get("Dimension"))).result().orElseThrow());
        if (world != null)
            targetPlayer.setWorld(world);
    }
    if (isEnderChest) {
        showEnderChest(executingPlayer, targetPlayer);
    } else {
        showInventory(executingPlayer, targetPlayer);
    }
    return 1;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Dynamic(com.mojang.serialization.Dynamic) NbtCompound(net.minecraft.nbt.NbtCompound) PlayerManager(net.minecraft.server.PlayerManager) GameProfile(com.mojang.authlib.GameProfile) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 9 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Rug by RubixDev.

the class BlockMixin method onDropStacks.

@Inject(method = "dropStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)V", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)Ljava/util/List;"))
private static void onDropStacks(BlockState state, World world, BlockPos pos, BlockEntity blockEntity, Entity entity, ItemStack stack, CallbackInfo ci) {
    boolean usesSilkTouch = EnchantmentHelper.get(stack).containsKey(Enchantments.SILK_TOUCH) && stack.getItem() != Items.ENCHANTED_BOOK;
    if (RugSettings.silkTouchFarmland && state.isOf(Blocks.FARMLAND) && usesSilkTouch) {
        dropStack(world, pos, new ItemStack(Items.FARMLAND));
        ci.cancel();
    } else if (RugSettings.silkTouchPathBlocks && state.isOf(Blocks.DIRT_PATH) && usesSilkTouch) {
        dropStack(world, pos, new ItemStack(Items.DIRT_PATH));
        ci.cancel();
    } else if (RugSettings.silkTouchBuddingAmethysts && state.isOf(Blocks.BUDDING_AMETHYST) && usesSilkTouch) {
        dropStack(world, pos, new ItemStack(Items.BUDDING_AMETHYST));
        ci.cancel();
    } else if (RugSettings.silkTouchSpawners && state.isOf(Blocks.SPAWNER) && usesSilkTouch) {
        ItemStack newStack = new ItemStack(Items.SPAWNER);
        NbtCompound tag = blockEntity.createNbt();
        tag.remove("id");
        tag.remove("x");
        tag.remove("y");
        tag.remove("z");
        newStack.setSubNbt("BlockEntityTag", tag);
        dropStack(world, pos, newStack);
        ci.cancel();
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Primeval by devs-immortal.

the class PitKilnBlockEntity method toInitialChunkDataNbt.

@Override
public NbtCompound toInitialChunkDataNbt() {
    NbtCompound nbtCompound = new NbtCompound();
    for (int i = 0; i < 4; i++) {
        nbtCompound.put(("Item" + i), this.inventory[i].writeNbt(new NbtCompound()));
    }
    nbtCompound.putInt("burnTimer", this.burnTimer);
    return nbtCompound;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Aggregations

NbtCompound (net.minecraft.nbt.NbtCompound)314 NbtList (net.minecraft.nbt.NbtList)92 ItemStack (net.minecraft.item.ItemStack)67 NbtElement (net.minecraft.nbt.NbtElement)28 IOException (java.io.IOException)25 LiteralText (net.minecraft.text.LiteralText)24 Identifier (net.minecraft.util.Identifier)24 BlockPos (net.minecraft.util.math.BlockPos)20 Inject (org.spongepowered.asm.mixin.injection.Inject)20 NbtString (net.minecraft.nbt.NbtString)16 File (java.io.File)13 HashMap (java.util.HashMap)10 List (java.util.List)9 Text (net.minecraft.text.Text)9 Vec3d (net.minecraft.util.math.Vec3d)9 Map (java.util.Map)8 Items (net.minecraft.item.Items)8 TranslatableText (net.minecraft.text.TranslatableText)8 BlockEntity (net.minecraft.block.entity.BlockEntity)7 Item (net.minecraft.item.Item)7