[SPIGOT-3789] Can't Remove Entity Equipment in Same Tick Spawned without using Consumer Created: 29/Jan/18 Updated: 01/Jan/24 Resolved: 01/Jan/24 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Nathan Wolf | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I am trying to spawn a Vex without a sword, using LivingEntity.getEquipment.setItemInMainHand. Replacing the sword (with a stick, for instance) works, but setting it to air (or null) does not. I've tried delaying the set for some ticks after spawning, but that doesn't work either. I was thinking it may be a client bug, related to this MC issue but I am able to spawn a vex without a sword using the vanilla /summon command:
/summon Vex ~ ~ ~ {HandItems:[{id:air,Count:1},{}]}
Is there something I'm doing wrong, or some other way to spawn a Vex without a sword? Has anyone been able to do it?
|
| Comments |
| Comment by Marvin Rieple [ 01/Jan/24 ] |
|
Can no longer reproduce in 1.20.4. |
| Comment by CodingAir [ 12/Sep/20 ] |
|
My local server is running on git-Spigot-3a70bd9-bf3d720 (MC: 1.16.3) (Implementing API version 1.16.3-R0.1-SNAPSHOT) and it crashes instantly after running player.getInventory().setItemInMainHand(null); //or player.getInventory().setItem(player.getInventory().getHeldItemSlot(), null); crashes the server instantly. Error attached.
[13:55:13] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.AssertionError: TRAP
at net.minecraft.server.v1_16_R2.ItemStack.checkEmpty(ItemStack.java:99) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.ItemStack.setCount(ItemStack.java:890) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.PlayerInteractManager.a(PlayerInteractManager.java:407) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.PlayerConnection.a(PlayerConnection.java:1347) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:28) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.TickTask.run(SourceFile:18) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.MinecraftServer.ba(MinecraftServer.java:941) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.MinecraftServer.executeNext(MinecraftServer.java:934) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeAll(SourceFile:103) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.MinecraftServer.sleepForTick(MinecraftServer.java:917) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:850) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_261]
|
| Comment by md_5 [ 29/Jan/18 ] |
|
Needs to be set in consumer or with 1 tick delay. Patches to fix welcome. |
| Comment by Nathan Wolf [ 29/Jan/18 ] |
|
I think the Consumer path may be where the magic is- that was unfamiliar to me, and unfortunately I don't have access to it in my plugin, in the name of backwards compatibility. I took your code and put it in my interact handler, modified a little to fit my plugin, and changed to spawnEntity without a Consumer- it does not seem to work. I also tried waiting a few ticks: if (isLeftClick && itemInHand.getType() == Material.STICK) { Location up = event.getClickedBlock().getRelative(org.bukkit.block.BlockFace.UP).getLocation(); final LivingEntity entity = (LivingEntity)player.getWorld().spawnEntity(up, EntityType.valueOf("VEX")); entity.getEquipment().setItemInMainHand(null); entity.getEquipment().setItemInOffHand(new ItemStack(Material.STICK)); entity.setAI(false); Bukkit.getScheduler().scheduleSyncDelayedTask(controller.getPlugin(), new Runnable() { @Override public void run() { entity.getEquipment().setItemInMainHand(null); } }, 10); } That gets me a Vex with a stick in the offhand and a sword in the main hand. If you have a moment to try it out like that, I'd appreciate it. It may be that the sword can't be removed once the Vex is spawned, for some arcane Mojang reasons?
|
| Comment by Senmori [ 29/Jan/18 ] |
|
No, setAI(false) was just so the vex's didn't fly all over the place. It still works without that call. You might have to wait a tick after they spawn if you don't use the consumer, but you can set the equipment. |
| Comment by Nathan Wolf [ 29/Jan/18 ] |
|
Thank you for trying it and double-checking me! Is setAI(false) required for this to work? Otherwise that looks just like what I'm doing... |
| Comment by Senmori [ 29/Jan/18 ] |
|
Attached picture works for me. Here's the code: https://gist.github.com/Senmori/b4e884ca16a40cf683d84eff94c53359 I tried with new ItemStack(Material.AIR) as well. Works the same.
|