Skip to content

Fix Contraption voiding Container content (#5420) #8774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: mc1.20.1/dev
Choose a base branch
from

Conversation

Allmoz
Copy link
Contributor

@Allmoz Allmoz commented Jun 23, 2025

Is this a valid aproach to fix #5420 ?
the method seems like a delicate area, so I keep it minimal

@Allmoz Allmoz force-pushed the contraption_conteiner branch from fa6b195 to 73635d2 Compare June 23, 2025 00:59
@VoidLeech VoidLeech added pr type: fix PR fixes a bug pr flag: simple PR has minimal changes labels Jun 23, 2025
CompoundTag tag = block.nbt();
if(tag != null){
BlockEntity blockEntity = BlockEntity.loadStatic(targetPos, state, tag);
if (blockEntity instanceof Container container)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container is probably (definitely, the Placard for example already doesn't implement it) too limited.

Copy link
Contributor Author

@Allmoz Allmoz Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue i have found is that most methods access the block entity using the Position and Level directly, so they don't work in this case where the block entity is not actually anywhere. I was thinking to maybe use Item Requirements from the schematicanon implementation, it seems to complement this approach (would not work with placards until #8550). To me seems like a weird way to patch it and i'm not sure is desirable in the codebase, but gonna give it a try if no one stops me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah tricky I don’t know what the proper solution would be. Using item requirements wouldn’t work though. Storage contents are almost never included in that (for good reason).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was adding exceptions for create containers, but maybe SmartBlockEntity.destroy() is enough for the majority of cases

@Allmoz Allmoz force-pushed the contraption_conteiner branch 2 times, most recently from 77e54dc to 845d199 Compare June 25, 2025 02:37
@Allmoz
Copy link
Contributor Author

Allmoz commented Jun 25, 2025

@VoidLeech :) added SmartBlockEntity, and sadly also ItemVaultBlockEntity, since it seems that it does not implement the destroy behavior like the others. dunno though if there are other vanilla or create exceptions that are not being covered, from the top of your head do you know other entity block that might not be covered?

edit: placard of course...

@Allmoz Allmoz force-pushed the contraption_conteiner branch from 845d199 to 78a793b Compare June 25, 2025 03:11
@Allmoz
Copy link
Contributor Author

Allmoz commented Jul 8, 2025

Tested vanilla, the only issue i found is Shulkers Boxes content being dropped (should I add an exception?)
From create I need to add, Schematicannon, Shafts (braced), Item Drain(with item waiting), Mechanical Crafter and Toolbox (probably make an exception with the shulker to drop the item with full nbt).

Belts...are a whole other problem, content gets correctly dropped, but not shafts, and belts get duplicated (it a new dupe even without this PR). this one i don't know how to approach, i probably would just let the belt of that particular block get lost, is that ok? (it would not fix the dupe, but it would not make it bigger)

@Allmoz
Copy link
Contributor Author

Allmoz commented Jul 8, 2025

The belt case is similar to #5879. the only difference is that is not a piston taking out the belt segment, is the belt is being placed over a block that cannot be mined (tested it with bedrock)

@Allmoz Allmoz force-pushed the contraption_conteiner branch from 78a793b to 4a4a004 Compare July 10, 2025 13:23
@Allmoz
Copy link
Contributor Author

Allmoz commented Jul 10, 2025

small test setup image

@VoidLeech VoidLeech removed the pr flag: simple PR has minimal changes label Jul 10, 2025
@Allmoz Allmoz force-pushed the contraption_conteiner branch from 4a4a004 to f50f4cd Compare July 10, 2025 16:59
@Allmoz
Copy link
Contributor Author

Allmoz commented Jul 10, 2025

Added all exceptions i could find following the original logic of each block. Had to add two getters, I followed the style guide of the neighbouring code or similar blocks. @VoidLeech 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr type: fix PR fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NBT Data Loosed on Contraption Disassembly
2 participants