DisableDrop tag for items

For PC edition

I thought of an item tag that would be useful to map makers, for custom items. It would be a boolean value, like this: DisableDrop:1

When set as shown above, if the item is in a player's inventory or a container, they can't drop the item. (Only affects manual dropping; the item drops as normal on death.)

This is useful for situations where the map-maker wants the player to have a custom item at all times, and doesn't want it to be accidentally dropped.

Players freely dropping items proves to be a problem in a couple of projects I've been working on. I'll use one of them as an example.

The player has to wear a mob head that modifies attributes, such as max health and movement speed. To prevent them from removing their mod head to gain health and move faster, I came up with a system to give players a consequence for removing their mob head, in the form of giving them slowness and blindness. However, if the player drops their mob head, they won't be able to move in order to pick it back up.

Another problem is that players can trade items or drop them accidentally. I wouldn't want to kill all dropped items because that would leave the players without the items they need for the rest of the round. An automatic resupply wouldn't work, because merely removing the item from a slot counts as the item not being in a player's inventory. The "hovering" item (held by the cursor) can't be detected by commands. A manual resupply wouldn't work either, because there isn't any good way to make sure all players know about it.

So you can see how this causes all sorts of problems that are difficult or impractical to work around. Simply disabling the ability to drop the item fixes everything.

Posted Jan 16, 2016, 12:46 AM UTC · edited

916

l believe that if you rapidly /entitydata items to have an extremely high pickup delay, they will be unable to drop items.

2
FVbicoRedstone•

Looks like you didn't read it, at the very start he explains: a tag for items, so you cannot drop it out of your inventory

2

I did read it. This is just a solution if you want no items to be droppable with Q. This could come in handy if you wanted only some items to be droppable,which is why I still upvoted it.

2
FVbicoRedstone•

/entitydata items to have an extremely high pickup delay

this does the exact opposite, setting to 0 will make it pick up-able, higher then 0 and it won't be able to be picked up

2
BoxfigsOP•

I seem to remember something like that, now that you mention it. It set the item's PickupDelay tag to 0, so players would pick up the item as soon as they dropped it.

The only foreseeable problem with that is if two players are in the exact same spot and one of them drops an item, the other player might pick it up. I'm not sure if that happens or not.

But it's a suitable solution in case DisableDrop isn't added. It's possible to make it apply only to certain items, too.

2
ReduxRedstone•

This really isnt a needed addition. This effect can be recreated with 2 command blocks and and one scoreboard. firstly create a scoreboard using the stat.drop criteria, in this example ill call it 'drop'. So i used: /scoreboard objectives add drop stat.drop to create the objective. Now in a repeating command block I have the command: execute @a[score_drop_min=1] ~ ~ ~ entitydata @e[type=Item,c=1] {PickupDelay:0} always running. This repeating command block is facing into a chain command block running this command: scoreboard players set @a drop 0 to reset the players score. The reason I used a scoreboard is so that the entitydata command ONLY changes the dropped items NBT, and not every item. You could use no scoreboards and only one repeating command block running: entitydata @e[type=Item] {PickupDelay:0} which will have the same result, except it will change all item's NBT

2
BoxfigsOP•

That's the sort of thing someone else mentioned.

That wouldn't trigger upon a player dying, would it? If it doesn't, that would be good for my other project, in which I want players not to be able to drop their bow while alive, but destroy their dropped bow on death. I can't use keepInventory because I want players to drop their arrows on death.

Also, do items dropped on death have a pickup delay? If so, I could kill all dropped bows that have an Age of 2.

I don't want it to affect arrows, so I could do something like this:

/scoreboard players tag @e[type=Item] bow {Item:{id:minecraft:bow}}

Then, I'd add tag=bow to the target selector arguments of the command you gave.

1
ReduxRedstone•

No, i don't believe it triggers on player death. The items shouldn't have a pickup delay but if they do its very short, maybe one tick. If you want to have the player drop arrows but not their bow, then yes. Just use /scoreboard players tag @e[type=Item] bow {Item:{id:minecraft:bow,Age:2}} then kill all items with the tag

1
Redmag3Redstone•

inventory detection, with clears for instances of 2+ item, and kill commands for the dropped item can work ... but what you offer is more simple, and efficient. This tag should disable transfering the item to another inventory, like a dropper.

1
BoxfigsOP•

inventory detection, with clears for instances of 2+ item, and kill commands for the dropped item can work

The problem with that is resupply, as I mentioned.

1
Redmag3Redstone•

scoreboard to give points, if the player has the item give 1 point, if the player doesnt have item set to 0 points. If player has 0 points give item.

1
BoxfigsOP•

Grabbing the item in the inventory without dropping it would trigger it.

The quantity limit would remove multiple instances of the item, but it would make it impossible for a player to move an item to a slot with a lower value, assuming /clear goes through the inventory in ascending slot order and targets the first item stack it finds.

1
Redmag3Redstone•

figured it out for your map, try this

  • /scoreboard players set @a Inventory 0
  • /scoreboard players set @a Inventory 1 {Inventory:[{id:minecraft:pumpkin,Count:1b,Slot:103}]}
  • /clear @a[score_Inventory=0] minecraft:pumpkin
  • /replaceitem entity @a[score_Inventory=0] slot.armor.head minecraft:pumpkin
1