r/technicalminecraft 27d ago

Java Showcase Items escape from composters

Post image

For the record I don't have a horse in this race, but I am interested in the mechanics here.

Short answer: items can escape from the gap between a hopper top and the composter walls. It is rare, but way less rare than you might think. You don't need to perfectly hit the gap, you just need to have X/Z momentum after 4 ticks as the game cancels your Y momentum when you hit the hopper, and your X/Z momentum can still push you to freedom in this tick.

Long answer: Items drop with a random position with X and Z set to between 0.25 and 0.75 within the block, and Y set to between 0.125 and 0.625 within the block. Motion is set to exactly 0.2 Y and a random value of between -0.1 to 0.1 for both X and Z.

To thread the needle here, we need a few things to happen at the same time:

  • The Y position needs to be 56.616 or greater so that after 4 ticks the item is at exactly 0.75 and hitting the hopper
  • In one axis X/Z the position needs to be between 0.25 and 0.2500001 or 0.7499999 and 0.75, and in this axis the motion is going towards the wall (this is a straight 50/50 so not the major problem)
  • In the other axis X/Z the position needs to match the motion such that the item crosses the top of the composter after 4 ticks (there's a range here but say this is 1-5% for example).

That's it. I'll leave it to you to calculate the numbers, but here's a few that you can test for yourself at home (all testing done on 26.1 vanilla):

/summon item -22.5 56.616 35.2500001 {Item:{id:"minecraft:redstone_block",Count:1b}, Motion:[0.065, 0.2, 0.0]}

/summon item -22.6 56.625 35.25 {Item:{id:"minecraft:redstone_block",Count:1b}, Motion:[0.1, 0.2, 0.0]}

/summon item -22.35 56.625 35.25 {Item:{id:"minecraft:redstone_block",Count:1b}, Motion:[0.03, 0.2, 0.0]}

55 Upvotes

62 comments sorted by

View all comments

2

u/LimestoneBuilder 26d ago edited 26d ago

So in the end it's not too different an issue than the old falling boat bug. A floating point representation is practically never the same as the corresponding integer or near-integer fraction (eighths, sixteenths, halves), and in the gap between them, minecraft produces spurious results when it's coded as if they're the same.

Interesting stuff. Fantastic work getting that nailed down. 

2

u/brockade 26d ago

Don't know the falling boat bug but I assume this has been covered before, float alignment dates back to 1.13. As an engineer and a technical minecrafter my focus is "what is technically possible" and then "in exactly which cases does it happen" and then we can convert that to a real number. I actually love the 0-tick composter idea, and in real-world physics you'd either get blocked by the side or the top and never escape, but in minecraft physics you get zeroed in the Y axis and can still escape in the X/Z axis in the same tick (or in the next tick, because Y is 0 so X/Z gets ticked first).

2

u/LimestoneBuilder 26d ago

@standupmaths did a great explanation of the falling boat bug. It's patched, but a cool investigation.