4

I'm working on a custom crafting system and I'm trying to use donkeys/mules as a way for players to put in crafting items. The mule's chest is used for inserting items and having an item output. This is how I spawn one such mule:

/summon minecraft:mule ~ ~ ~ {Tame:1b,Silent:1b,NoAI:1b,ChestedHorse:1b,ActiveEffects:[{Id:14b,Amplifier:1b,Duration:1000000,ShowParticles:0b}]}

Using this, and invisible mule, and players can access the chest, where the custom crafting would take place. The only problem with this is that the player is able to ride the mule, so I add a passenger to prevent this.

/summon minecraft:mule ~ ~ ~ {Tame:1b,Silent:1b,NoAI:1b,ChestedHorse:1b,Passengers:[{id:"minecraft:armor_stand",Marker:1b,Invisible:1b}],ActiveEffects:[{Id:14b,Amplifier:1b,Duration:1000000,ShowParticles:0b}]}

However, doing so makes the player unable to access the chest. Is there any way to make a mule unrideable, but also making that mule's chest accessable to players?

4
  • 1
    I think this is impossible. But it's probably possible to get the player off the mule instantly, which would still put them at the dismount location. Would that be acceptable? And is there a specific reason why you need to use a mule, no other inventory? Aug 4 '19 at 19:29
  • @FabianRöling Getting the player off the mule instantly would be acceptable for sure. The reason I'm trying to use a mule is that I have recipes that require both items with custom NBT data to output and items w/ NBT data for input. There might be a better way for this, but I haven't been able to think of anything else that doesn't require a resource pack which is something I'm trying to avoid.
    – Hydra
    Aug 4 '19 at 20:13
  • Why not just a dropper or something like that? It even has a 3×3 inventory. Aug 4 '19 at 20:39
  • @FabianRöling Problem with a dropper is that I would like the player to be able to view the item they are about to craft. The only way I've been able to set this up with a dropper is the crafted items are immediately turned into the output. And I'm also looking to make the crafting block appear like a proper crafting table as I really don't want to use resource packs for this project. I can do this if the player is interacting with an invisible entity. What did you have in mind for instantly getting the player off the mule?
    – Hydra
    Aug 5 '19 at 0:50
1

I think it is probably impossible to prevent mounting a mule while still giving the player access to its chest.

But you can make a player automatically dismount a mule by checking the RootVehicle tag of the player (the NBT of the mule doesn't actually change when it's ridden) and then placing water at the player's head (for some reason not the mule's head), which will automatically dismount the player for being in water. Then you can clear the water again one tick later. An easy way to do this would be a repeating command chain with these commands in them:

execute at @e[tag=water] run fill ~ ~1.62 ~ ~ ~1.62 ~ air replace water
kill @e[tag=water]
execute as @p at @s if entity @s[nbt={RootVehicle:{}}] run summon armor_stand ~ ~ ~ {Tags:["water"],NoGravity:1,NoAI:1,Invisible:1,Marker:1}
execute at @e[tag=water] run fill ~ ~1.62 ~ ~ ~1.62 ~ water replace air

The last two commands actually execute before the first two, putting them in a chain in this order is just an easy way to delay the execution of the first two by one tick.

What these commands do:

#3: Whenever the nearest player (you'll want to adjust this to your needs) has the RootVehicle tag (meaning they ride on something, you'll want to adjust this to your needs as well, for example with an additional check for something inside the RootVehicle tag that verifies that it's a mule, or just simple proximity to a mule), you summon a marker armour stand at the player's location. This is needed because you won't be on top of the mule anymore after placing the water, so you couldn't use it for removing the water again.
#4: Put water at the player's head to dismount them from the mule. I'm using the exact eye position of a non-sneaking player here, because while you sneak, you always either access the chest or instantly dismount yourself. If the mule is currently in the air or not aligned some other way, these exact coordinates will still always put the water at the right block. Something to consider: If you mount the mule in a way that your head ends up inside a block, then the water will not be placed. You can of course simply remove "replace air", but then you can overwrite blocks. If both alternatives aren't acceptable, you have to use a different solution for dismounting, maybe teleporting the player could work.
#1: Wait one tick and then replace the water with air again. It shouldn't flow anywhere within that one tick.
#2: Kill the marker armour stand. You might also want to adjust this to your needs, in case you could have other things tagged "water".

0

I solved the problem by my self bc armor stand bugs on 1.15, I leave what I do for anyone else who need it, I put 4 command block

1:

/execute at @a[nbt={RootVehicle:{}}] run data merge entity @e[tupe=mule,limit=1,sort=nearest] {Tame:0b,Temper:-35}

This one uses nbt of player to see if is riding something in that case change mule tag tame to 0 and set temper under 0 to make it leave faster (on 35 falls in love an change to tamed) that in a repeater command.

2:

/scoreboard objectives add IsShifting minecraft.custom:minecraft.sneak_time

This one uses to become mule rideable again but pressing shift or sneak button you can only acces to chest, and makes impossible to ridie while shifting

3: /scoreboard players set @a[scores={IsShifting=1..} IsShifting 0

That’s only a reset to tea when the player are shifting

4:

/execute as @a[scores={IsShifting=1..}] run data merge entity @e[tupe=mule,limit=1,sort=nearest] {Tame:1b,Temper:-35}

This make posible access to the chest while shifting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.