baritone icon indicating copy to clipboard operation
baritone copied to clipboard

✨ Add "#set add", "#set remove" and "#set clear"

Open ZacSharp opened this issue 4 years ago • 5 comments

Behaviour for lists and simple maps is simply appending or removing the values, for lists in maps the new value is appended to or removed from the value list.

  • #set add <setting> <value> adds a value to a list setting or merges it into a map setting
  • #set remove <setting> <value> removes the value from the setting, doing the exact opposite of #set add
  • #set clear <setting> removes all entries from list and map settings

This is a draft because there are a few things I'd like to get sorted first (ideas are welcome, that's why this pr exists already):

  • [x] #set remove and #set clear now allow for any list or map or mapped list to be empty, leading to edge cases like having an empty list of throwaways or the builder having to substitute some block for nothing (not air, nothing) EDIT: #set <list setting> , can also set any setting to an empty list
  • [ ] Empty lists/maps serialize to an empty string, which is not a valid value
  • [ ] The way the parsing is done is more of a hack to work around the setting parsers only being able to parse a complete value but not e.g. just a key for a map
  • [ ] I'd like to have #set clear <setting> <key>, #set add <setting> <key> <value> (currently redundant with #set add <setting> <value>), #set remove <setting> <key> and #set <setting> <key> <value> for Map<*,List<*>> type settings
  • [x] The tab completion could be better, but I think that's a problem for settings in general and not specific to this pr. It just continues what is there.
  • [x] ~Map parsing only works when the keys and values have the same type (did it wrong when adding maps, want to fix it now) (EDIT: see #3474)~ Fixed in #4324

closes #2306

ZacSharp avatar Oct 16 '21 22:10 ZacSharp

wow that code looks absolutely disgusting 😻

leijurv avatar Oct 25 '21 22:10 leijurv

would merge this, except it's marked as draft?

leijurv avatar Oct 25 '21 22:10 leijurv

Its better than previous attempts so I made the pr, but I am still not happy with how it is done and was hoping for ideas from others. Also I think we might need to do something to catch edge cases with lists being empty that could not be empty before.

ZacSharp avatar Oct 25 '21 22:10 ZacSharp

#set remove and #set clear now allow for any list or map or mapped list to be empty, leading to edge cases like having an empty list of throwaways or the builder having to substitute some block for nothing (not air, nothing)

I'd say either add an optional argument to map/list settings where you can specify the values that can't actually be removed/cleared, or fix it on the other end when settings are parsed in the various places baritone uses them in code. (the first way might be messier but easier to implement)

wagyourtail avatar Jan 19 '22 22:01 wagyourtail

Unless I overlooked something buildSubstitutes was the only one causing problems and they should all work with empty lists now.

ZacSharp avatar Jan 19 '22 22:01 ZacSharp