Refactor compass code. #2197
No reviewers
Labels
No Label
#P1 CRITICAL
#P2: HIGH
#P3: elevated
#P4 priority: medium
#P6: low
#Review
annoying
API
bug
code quality
combat
commands
compatibility
configurability
contribution inside
controls
core feature
creative mode
delayed for engine release
documentation
duplicate
enhancement
environment
gameplay
graphics
ground content conflict
GUI/HUD
help wanted
incomplete feature
invalid / won't fix
items
looking for contributor
mapgen
meta
mineclone2+
Minecraft >= 1.13
Minecraft >= 1.17
missing feature
mobile
mobs
mod support
model needed
multiplayer
Needs adoption
needs discussion
needs engine change
needs more information
needs research
nodes
non-Minecraft feature
non-mob entities
performance
player
possible close
redstone
release notes
schematics
Skyblock
sounds
Testing / Retest
tools
translation
unconfirmed
mcl5
mcla
Media missing
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: VoxeLibre/VoxeLibre#2197
Loading…
Reference in New Issue
No description provided.
Delete Branch "get-compass-image-fix"
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?
This PR updates the lodestone code.
There are few user visible changes, all bugfixes:
stack_max = 1
.The main change visible to other mineclone code is the addition of a new API function
mcl_compass.get_compass_itemname(pos, dir, itemstack)
. The currently released version of mineclone still exports the functionmcl_compass.get_compass_image(pos, dir)
but this was modified by the initial lodestone addition PR to now becomemcl_compass.get_compass_image(pos, dir, itemstack)
. Although the handling of a possible missingitemname
in callers that have not been updated is gentle and at most causes a warning in the log and the compass image to be random, IMHO it is better to leave the current API unchanged (with limited functionality for lodestones) and provide a newer, shinier API altogether.Since the lodestone addition has not yet been published, I would like to see the API be updated as described above before the next release is made and the lodestone changes to the compass API are published in either form.
[edit]Update:
The old exported function has now been reverted back to the format it has in the last released mineclone2 and remains available for external users. The only current user of the compass API in mineclone2,
mcl_itemframes
, has been updated to the new API function.A summary "mcl_compass/API.md" has been added.
To be considered is the current far node handling in mcl_compass. I outlined some alternatives in MineClone2/MineClone2#2138 (comment) and will pursue this alternative implementation. If my efforts are successful, they may be added to this PR, or be put in a new PR.
Changelog so far:
get_compass_image()
into smaller functions. This allowsfor better code sharing between old and new API and globalstep fn.
get_compass_itemname()
function. It will be the new API ofchoice, `get_compass_image() will be deprecated soon.
Add new compass API.
WIP: Refactor compass code.to Refactor compass code.I thought your idea for the far node handling was great - after all for a lodestone to disappear it has to be dug. This would make emerging completely unnecessary.
I do think however it should be put in a new pr. I'll check this out and merge if all works out.
I think it's 0.75 time soon and this looks like it should be in.
We've done a lot of stuff since 0.74
Apart from doing the ususal luacheck, I did playtest the changes a bit and it behaved as it should.
crash in 5.4 when rightclicking lode stone:
mods/ITEMS/mcl_compass/init.lua:104: attempt to call upvalue 'vec_from_str' (a nil value)
why not use minetest.string_to_pos / pos_to_string like it did before ?
works in 5.5 though
If this is meant to be a joke, I am not laughing right now.
Why exactly not put the lodestone stuff in a separate mod?
Well i suppose you're a bit late to this particular party
Well, I guess that means “same procedure as every other time, some clown had zero interest in maintainability”.
Uh p sure it is in mcl_compasses in mcl5 so – either way is not gonna be great for compatibility.
I think you're making too big a deal out of these.
We can't always put everything in a new mod otherwise in a few years we'll have 5 variants of every mod updated in each year.
And please do not use msdos or utf8 or something as an example where this was done. There are a number of significant differences to those projects wouldn't you think. The 2 most notable being the amount of people working on it and people using it.
I get your point but you're being extremist again. Also calling people clowns isn't exactly nice so pls
The opposite is true – as actually, putting stuff in existing mods and keeping the same name leads to diverging versions of mods. If you wouly simply call this mod another name (like
mcl_compass2
) there would be zero compatibility problems. It is so simple, a name change! Wuzzy, for example recently realized thatdefault
in repixture should be calledrp_default
, as it has diverged too much from thedefault
mod in Minetest Game.By keeping the same name, yet incompatibly changing the API or dependency situation, you are not getting rid of dependency or compatibility problems. Instead, you are pretending, it does not exist.
I do not understand what you are trying to say here. Is this some kind of joke?
Okay.
Ok. I actually do not understand what you're trying to say comparing mcl to msdos or utf8.
What you are proposing is absolutely ridiculous for this situation.
EDIT and probably one of the reasons mcla never rarely anything done i might add.
I mentioned both of them when @kabou accused me of wanting to hinder innovation, as:
The capabilities of MSDOS were extended, but not incompatibly so.
UTF-8 extended ASCII in a backwards-compatible way.
I.e. both have innovation and compatibility.
Yes and both have/had hundreds of people working on them and thousands and more using them.
UTF-8 was basically invented by some clever people on a napkin … after multiple standards groups had come up with several worse ideas for this type of encoding:
https://www.cl.cam.ac.uk/~mgk25/ucs/utf-8-history.txt
Not sure why that full quote was necessary but the interesting part is what you didn't talk about there I suppose hehe.
@erlehmann complaining here at the 13th hour will get you nothing.
I agree with you about this with the new node stuff but like I said we can't start making a new mod every time something is added or changed. And I actually checked cdb if any mods are using MCL_beds or compass and unsurprisingly none are.
Please try to accept a compromise now and then. It won't get you anything to lose yourself in invalid (and unfair) comparisons like that anyways.
Plus this is a done deal now.
Anyways @kabou pls fix crash MineClone2/MineClone2#2197 (comment)
While I agree 99% on your changes, you can stack lodestone compasses in minecraft
@ -143,0 +207,4 @@
elseif item.name == "compass_lodestone" then
name_fmt = "mcl_compass:%d_lodestone"
img_fmt = "mcl_compass_compass_%02d.png^[colorize:purple:50"
stack_max = 1
In minecraft, you CAN stack lodestone compasses, as long as they belong to the same lodestone, but the different metadata would prevent you from doing so
Oh, I took that bit of information from https://minecraft.fandom.com/wiki/Compass . At the top right, below the images, it says that lodestone compasses are not stackable. I do not have an actual version of mc to cross reference.
Shall I revert this then?
@kabou Hmmm, thats strange, but other versions of the wiki actually say that it is stackable, however, I own a copy of Minecraft Java, here is a screenshot taken by me showing it, so yeah, I think this should be reverted...
![](https://git.minetest.land/attachments/70135f99-89fe-4781-9de3-2b4a007ae43c)
(I had to add the file to my inital comment because I can't upload files here...)
Allright, will revert.
I have removed the
stack_max
setting altogether, so it uses the default (which can be altered via settings).@ -2,3 +2,3 @@
Compasses are tools which point to the world origin (X@=0, Z@=0) or the spawn point in the Overworld.=Kompasse sind Werkzeuge, die zum Ursprungspunkt der Welt (X@=0, Z@=0) oder zum Einstiegspunkt der Welt zeigen.
Compass=Kompass
Points to the world origin=Zeigt zum Startpunkt der Welt
Compasses are tools which point to the world origin (X@=0, Z@=0) or the spawn point in the Overworld.=Kompasse sind Werkzeuge, die zum Ursprungspunkt der Welt (X@=0, Z@=0) oder zum Einstiegspunkt der Welt zeigen.
Suggestion for the translation (maybe I should make a seperate PR for that later):
Translation improvements are always good. I'll see if I can add it.
Translation added, thanks!
If you want to look at it like this, it's my fault: I made the PR to add lodestones in mineclone5's mcl_beds, and when I've created the very same PR for mcl2, i just used mcl_beds again so you can switch between mineclone 2 & 5 without too much stuff breaking, and that PR got merged, so unless we move the entire code to somewhere else (which wouldn't make sense in my opinion since it depends on mcl_compass while literally being a compass), it won't be in a separate mod, this PR just improves the existing code a bit
As I already wrote you privately, I have deduced that it is almost impossible to convince people that their design is bad, even if the alternative is super simple.
For the question if something is good or bad design, these kind of things are almost entirely irrelevant. IMO good design does not accidentally hinder use cases not yet envisioned – while bad design does.
A big difference between good and bad software architects is that one can figure out how to design software that can accomodate as-of-yet-unknown use cases easily in the future, while the other will claim “you can not know what you want in the future” is a reason to never even think about that.
Whatever, I give up. Clearly any effort I make to prevent entire categories of bugs is dwarfed by the sounds of LALALA I CAN NOT HEAR YOU & IT IS WAY TOO LATE TO SPEAK UP NOW.
As I also already told you privately (not sure why that needs to be mentioned but OK) if you would be less extremist and less rude about it you would probably have better chances getting what you want.
And you are probably correct about that. I just do not have the patience anymore.
Oops, got bitten by 5.5 vector-fu a second time. Thanks for spotting that. Will fix now.
There are many factors to consider in software design. One of those is code sharing. By putting every little thing into its own mod, we'll need even more mods for the code shared by those mods.
Since the main use case that you keep coming up with for rationalizing mod proliferation is some (largely mythical) external mods that moreover can claim absolute primacy over compatibility considerations, your position is not always perceived as reasonable by the people who try to develop mineclone as an integrated game.
So I pretty much refuted your arguments in that other thread by pointing out that you cannot process utf-8 in EDLIN.COM and you merrily ignored that. Have a look.
@cora I fixed the crash and added the translation. I'm not yet sure about the stacking of lodestone compasses. @kneekoo do you have an opinion on that? [edit: in any case I did revert it anyway.]
Sorry, but it looks like I have to request changes again :(
Lodestone and normal compasses are not supposed to have the same groups
@ -172,0 +217,4 @@
_tt_help = item.tt,
inventory_image = string.format(img_fmt, i),
wield_image = string.format(img_fmt, i),
groups = {compass = i + 1, tool = 1, disable_repair = 1},
This applies these groups to every compass, no matter if it's a normal or lodestone one.
Lodestone Compasses are not supposed to be in the creative inventory, you need to check what kind of compass it is and set
not_in_creative_inventory
to 0 or 1 (0 is default)I think that's what it does? (if not set explicitly to 1, it defaults to 0.)
8ae605165b/mods/ITEMS/mcl_compass/init.lua (L222-L228)
Oh wait, I see what you mean, lodestone compasses are not supposed to be in creative inventory at all..
I'm not sure that's a big problem really.
A lodestone compass in creative inventory will not have an associated lodestone, so it will be like a lodestone compass that has lost its association.
I can easily change the condition into
if i == stereotype_frame and item == "compass" then
but first I'd like to hear some other people's opinion what should be appropriate here.O yeah I wondered about that. But the ls-compass without meta turns back to normal compass which is good anyways
I don't think it does, they have different itemnames.
Try
Indeed. But this is another problem, unrelated to the craftitem definitions. The globalstep code reverts any lodestone compass that has empty meta to a regular compass.
The latest commits should fix this issue. I had to overhaul some logic to not rely on the item meta, but to instead string.find the itemname.
This also required the lodestone on_rightclick to be changed.
But they are still in the creative inventory, and that's the "real" problem in my opinion, since they have no meta and no lodestone to point to... I would suggest doing it like in this commit (based on the current state of your branch)
Personally I don't mind having unset lodestone compasses in creative inventory, as I said before, they behave similarly to lodestone compasses that lost their lodestone. But if the consensus is that they should not be in creative inventory, then that is not a problem for me at all.
personally, I don't like adding commits to other people's PRs, but cora added my commit which removes them from the creative inventory, so we can close this one
Allright, now if you can "approve" the review, it'll look nicer when cora merges..
Works fine now. @chmodsayshello you happy with it now ?
Actually, not 100%, while this PR changes the code in a "good" way, I really think that lodestone compasses shouldn't be in the creative inventory, I made a copy of this branch in my old mcl2 fork, I would suggest doing it like in this commit
Another problem: Once you drop a lodestone compass now, it turns into a normal one
how about this ^^
you can do that too btw.
check out
https://git.minetest.land/MineClone2/MineClone2/wiki/Best-git-tricks
to learn most of my git-fu hehe
mmmh that is indeed a problem with this mod then. metadata transfer to item entities works fine with other stuff like enchanted tools or written books.
There is no longer any logic that uses metadata to determine the type of compass, it is all based on item name now. But that happens only with itemstacks that are in a player's inventory.
I'm a bit stumped about what's going on here (and I also still don't have my head straight atm.)
Uh i dont think it matters a lot but it doesnt really make sense to have lodestone compass in creative imo
No problem. But I don't understand the item change on drop. I added some debug statements to the only place in code (globalstep) where itemname is set, but it doesn't seem to hit that when dropping an item.
@chmodsayshello @kabou
Looks this happens due to the custom item drop code for compasses in 'mcl_item_entity':
https://git.minetest.land/MineClone2/MineClone2/src/branch/get-compass-image-fix/mods/ENTITIES/mcl_item_entity/init.lua#L420-L421
Patching that section with this seems to work:
Ooh thanks a lot for pointing that out.
LOL the meta stays properly it just sets the name to normal compass - this shouldnt be too hard to fix
get this. if i make a normal compass with "pointsto" meta with that method on this branch, then switch back to master and relog it turns back to lodestone compass and works
looks like @chmodsayshello has made a rock solid system hehe
oh didnt see that last commit ... works now <3
1603d0bacd
to85fe5baf7a
85fe5baf7a
tobaf8e0b79c
Sorry, I tweaked the last commit a bit and force pushed the amended commit.
I used a slightly different approach from what @MysticTempest suggested, namely:
lol, I thought obvious, since in the current master code, it checks if there is meta on the item, and then uses it if there is a lodestone
BTW, I tested a bit without the special case code in mcl_item_entity altogether and it works equally well. The difference is that the dropped (lodestone) compass is left in the state (direction) it was when dropped, instead of always pointing in the stereotype direction.
Maybe I even like it better like that.
well i never looked at the code in depth, just thought "wow this reacts in a very sane way to a completely fabricated situation"
it makes 0 practical difference though since it would immediately be updated when in player inv again.
so yeah I think we can merge this now !?
On master, if you drop a lodestone compass, it also becomes a compass item entity, but when you pick it up again, it reverts to the lodestone compass by action of the globalstep code.
One big difference is that we'd get rid of the compass specific case in mcl_item_entity. This could better be discussed in a different issue or pr.
If it doesn't crash anymore and it behaves like it should - okay.
This time my testing was not so intensive (around 7 mins), but I found no issues, and the code is clean and understandable