forum Forumsplay_arrow Minecraft fiber_manual_record Redstone

1

empty slot detection?

1 emerald2 replies907 views
created 09/05/2016 10:14 pm by stormshroom
last reply 09/06/2016 1:57 pm
I am making a system in which a a player's inventory has constant replaceitem commands running to create a custom UI. I want to make it so that any player who clicks an item (thus making the slot empty) will trigger an event. I have tried the following datatags on myself and I know they do not work, as they produce the same output for having an item and having no item:
{Inventory:[{Slot:0b,id:minecraft:air}]} both negative
{Inventory:[{Slot:0b}]} both positive
{Inventory:[{Slot:0b,Count:1b}]} both positive
{Inventory:[{Slot:0b,Count:0b}]} both negative

there is a command that sets the score for anyone with the tag and another one that resets it which activates before.

does anybody know what to do?
Posted by avatar
stormshroom
Level 1 : New Explorer
5

2 replies

1
09/06/2016 1:57 pm
Level 55 : Grandmaster Cyborg
Pepijn
avatar
What Greystalk said above me will work when you only have to deal with one player, if you want this to work for multiplayer I think the above mentioned commands will mess up.

I guess I will explain why your previous attempts failed. When a slot is empty in Minecraft, it is just not stored anywhere (that slot does not 'exist' till an item is placed in it). This means you can't really test for it. The usual method of solving this problem is to test for when the slot is NOT empty, and basically invert the output (which can be done in various ways).
1
09/06/2016 11:30 am
Level 30 : Artisan Ninja
Greystalk
avatar
Okay, so I did some testing, and I got this to work with the following commands.

repeat, always active
/testfor @p {Inventory:[{Slot:1b,id:"minecraft:nether_star"}]}

This next command will basically test to see if the above is not true, as in, the player clicks on the item.

repeat, always active, one block above the previous command block
/testforblock ~ ~-1 ~ minecraft:repeating_command_block -1 {SuccessCount:0}

Now put in whatever commands you want, such as a tp or whatever. After those, you need two more command blocks. One to clear the star that the player is holding.

chain, conditional, always active
clear @a nether_star

and one to replace it.

chain, always active
/replaceitem entity @a slot.hotbar.1 minecraft:nether_star 1 0

Planet Minecraft

Browse

Site

© 2010 - 2019
planetminecraft.com

Welcome