1
2
Fork
You've already forked itemframes
2

removing duplicated entities can overshoot #5

Closed
opened 2024年06月06日 00:25:10 +02:00 by tour-ist · 4 comments

If you have 2 itemframes back to back, only one of them will show the item in it.

The reason is that the "remove duplicated entities"-implementation checks whether there is an itemframe entity in a distance of 0.5 nodes. But if you place your frames like shown in the image, the distance is only 1 - 2*6.5/16 = 0.19. So both entities count as duplicates and thus one is removed...

changing the radius here to 0.1 should do the trick

Line 27 in 3f249d1
local objs = minetest.get_objects_inside_radius(pos, 0.5)
If you have 2 itemframes back to back, only one of them will show the item in it. The reason is that the "remove duplicated entities"-implementation checks whether there is an itemframe entity in a distance of 0.5 nodes. But if you place your frames like shown in the image, the distance is only `1 - 2*6.5/16 = 0.19`. So both entities count as duplicates and thus one is removed... changing the radius here to 0.1 should do the trick https://codeberg.org/tenplus1/itemframes/src/commit/3f249d1032c9c492849a9664b56fd3b07f65c3cc/init.lua#L27

Itemframes really shouldn't be that close together, and changing item radius to 0.1 affects frame updates causing glitches, so I'll leave it at 0.5 for now but look into making the redraw/update functions play nice.

Itemframes really shouldn't be that close together, and changing item radius to 0.1 affects frame updates causing glitches, so I'll leave it at 0.5 for now but look into making the redraw/update functions play nice.

Here's an illustration of the "overshooting" issue:
itemframe_vizlib
itemframe_item

It happens because the center argument of get_objects_inside_radius() is set to the item's center, not to the center of the node.

If you just round the position with vector.round() like this:

		local pos = self.object:get_pos() ; if not pos then return end
		local node_pos = vector.round(pos) 
		
		-- vizlib.draw_cube(pos, 0.5, {color = "red"})
		-- vizlib.draw_cube(node_pos, 0.5, {color = "green"})
		
		local objs = minetest.get_objects_inside_radius(node_pos, 0.5)

where items are removed and entity position is used: in on_activate and in remove_item, the issue will be gone :)
(lbm actually uses node coordinates and does not seem to need rounding)

Here's an illustration of the "overshooting" issue: ![itemframe_vizlib](/attachments/e275b576-ebd1-4b0c-a38a-a2a053f0e9fd) ![itemframe_item](/attachments/9532491e-f19b-42b2-b10c-040f7484c3ad) It happens because the `center` argument of `get_objects_inside_radius()` is set to the item's center, not to the center of the node. If you just round the position with `vector.round()` like this: ```lua local pos = self.object:get_pos() ; if not pos then return end local node_pos = vector.round(pos) -- vizlib.draw_cube(pos, 0.5, {color = "red"}) -- vizlib.draw_cube(node_pos, 0.5, {color = "green"}) local objs = minetest.get_objects_inside_radius(node_pos, 0.5) ``` where items are removed and entity position is used: in `on_activate` and in `remove_item`, the issue will be gone :) (lbm actually uses node coordinates and does not seem to need rounding)

Updated with new removal function, works fine my end, please let me know if ok yours :)

Updated with new removal function, works fine my end, please let me know if ok yours :)

screenshot_20241204_230252
Seems to work, weirdness is possible again. Thank you :)

![screenshot_20241204_230252](/attachments/46e25999-37fd-4e82-a8e4-6a796e60499c) Seems to work, weirdness is possible again. Thank you :)
Sign in to join this conversation.
No Branch/Tag specified
master
No results found.
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tenplus1/itemframes#5
Reference in a new issue
tenplus1/itemframes
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?