TransWikia.com

Is it possible to let players pick up and use certain items in Minecraft, without breaking blocks?

Arqade Asked by user3391326 on June 25, 2021

I wanted to make an escape the room style game in minecraft for my kids. Is it possible to allow players to pick up and use specific items (eg pick up a bucket, fill with water, put out fire) but not destroy any blocks (so they can’t escape the room by just breaking walls)?

2 Answers

You can use NBT tags on a tool to allow your kids to break certain blocks with that tool

Till give you a stone pickaxe that you can use to break stone and iron ore, even if you are in adventure mode, this pickaxe will also be unbreakable, which may be good in your case:

/give @s minecraft:stone_pickaxe{Unbreakable:1,CanDestroy:["minecraft:stone","minecraft:iron_ore"]}

Use this if you want the pickaxe to break as it usually would:

/give @s minecraft:stone_pickaxe{CanDestroy:["minecraft:stone","minecraft:iron_ore"]}

This will give you a bucket that you can use to pick up water:

/give @s minecraft:bucket{CanPlaceOn:["minecraft:water"]}

And this will give you a water bucket, where you can place the water on stone

/give @s minecraft:water_bucket{CanPlaceOn:["minecraft:stone"]}

Note: Some NBT-tags on a bucket will reset after using it, so I have not found a way to get a bucket that can pick up water AND place it somewhere else

I recommend to only use the first, or second command as it seems like this works inconsistently with fluids.

Answered by user232393 on June 25, 2021

As mentioned in the answer by user232393, CanDestroy and CanPlaceOn can allow specific items to break or interact with specific blocks in Adventure Mode. In fact, that's the sole purpose of these NBT tags.

For a bucket that can pick up water and place it, the setup is a bit more complicated. It also assumes that you want the water to always be placible on the same blocks; that, however, would be a good idea already due to consistency alone - it will be easier for your kids to understand that e.g. prismarine = you can place water here.

tl.dr.: Datapacks to the rescue.

This approach also eliminates the need to prepare your map with items that have NBT tags. You can simply use items from the Creative Menu and have the datapack handle the rest.

First, you want an advancement. Name it whatever you like (I think lower snake case might be a requirement) and place it in your datapack at data/<yournamespace>/advancements where <yournamespace> is a namespace of your choice. Let's assume you use maputilsas namespace and name your advancement pick_up_bucket, then the file you create needs to be data/maputils/advancements/pick_up_bucket.json.

You'll want an advancement that's not displayed in game, so you need a no-display parent advancement. The simplest choice is minecraft:recipes/root. The reward should be a command function, e.g. handle_bucket. As a trigger, you should use inventory_changed with a check for a bucket.

Here's the full JSON:

{
    "parent": "minecraft:recipes/root",
    "criteria": {
        "main": {
            "trigger": "minecraft:inventory_changed",
            "conditions": {
                "items": [
                    "item": "minecraft:bucket"
                ]
            }
        }
    },
    "rewards": {
        "function": "maputils:handle_bucket"
    }
}

Now, for the aforementioned function. You'll first want to disable the advancement, so it can be repeated. Then, you need to take away the ordinary bucket. And finally not least, you need to hand out the modified bucket with the NBT tags. (Note: In the example below, I'm assuming you want the bucket to pick up water both from the environment and from cauldrons.)

So, the finished data/maputils/functions/handle_bucket.mcfunction looks like this:

advancement revoke @s maputils:pick_up_bucket
clear @s minecraft:bucket
give @s minecraft:bucket{CanPlaceOn:["minecraft:water","minecraft:cauldron"]}

Now, do the same for water buckets. Remember to replace the CanPlaceOn tag in the function's last command with whatever blocks you want your kids to be able to place water on. If there's any more items that are supposed to function like this (such as a Beacon they're supposed to craft and place on some gold blocks, or having them break a furnace and place it on a hopper), same procedure.

Answered by Egor Hans on June 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP