1.17.x Keeping Items in a Glass Case (Block)

Discussion in 'Spigot Plugin Development' started by CablePlays, Jun 20, 2021.

  1. I'm creating an item shop that is a simple block with a glass block on top of it. I want to have the item being sold at the shop inside of the glass case, but I don't know how to make it stay there.

    I have tried setting the items' velocity to "new Vector()" every tick but that didn't work.

    Any help is appreciated!
     
  2. what are you trying to make?
     
  3. Like I said, an item shop. But I can also say that it's a sign shop. The sign is on a block with a glass block on top of it. So when the player right-clicks the sign, they buy an item. I want that item to be displayed in the glass block, but of course I can't get it to stay there without popping out of the glass.
     
  4. Why don't you use an invisible item frame?
     
    • Creative Creative x 1
  5. That sounds interesting! I'll try that now to see what it's like, but I'd still prefer the spinning item in the glass case if anybody still has ideas.

    I've seen servers do this before, would I need to use packets to spawn fake items or intercept packets to prevent the items from moving maybe?
     
  6. How about an item on an armor stand? I was forgetting about it.
     
    • Useful Useful x 1
  7. I've just created the item it the invisible item frame inside of the glass block by preventing the frame from breaking, and it does look pretty cool.

    That would probably be even cooler because then I can put the item in the center of the glass block. I'm going to use that for now until somebody comes up with a way to have the item spinning in the case. Thanks!
     
    • Friendly Friendly x 1
  8. You'll probably need to use packets, as I don't think there is a way to totally disable item physics.

    Try using ProtocolLib, you can probably google plenty of examples of spawning fake entities.

    Intercepting packets telling the client that the item has moved isn't ideal, because then the actual item will be lying on the floor somewhere despite appearing to be in the glass. This means someone could pick it up, or someone could burn the item in lava by placing a lava bucket in a seemingly random location. It's best to have the item be totally fake.
     
    • Agree Agree x 1
  9. I agree with @repeater64. Using packets is the best way to display items without creating a mess. I highly suggest taking advantage of the holographic displays plugin. It has a developer api that you can use to display items. They even have a wiki page on it here. Using said developer api is your best option because it allows you to build this without a lot of knowledge of NMS and the backend of minecraft. It also is great because a lot of servers already use this plugin so having it as a dependency isn't that big of a deal. (Also sinise it is packet based, the items won't slip out of the glass block)
     
  10. i think if you turn off gravity it disables velocity
     
  11. Unfortunately it does not, although creating flying items could make for a pretty cool minigame!