moler Posted September 14, 2015 Posted September 14, 2015 hi guys, iv got a - DefaultModelList myLoot; I'm kinda stuck converting this list into a working looting method. any help is appreciated.
FrostBug Posted September 14, 2015 Posted September 14, 2015 I'd say convert your model to an array by copying contents over while iterating the model, using the enumeration returned by the DefaultListModel#elements method. Then pass that array using getGroundItems().closest(array) to get the closest desired item on the ground; or getGroundItems().filter(array) to get them all.
FrostBug Posted September 14, 2015 Posted September 14, 2015 toArray? toArray doesn't make use of generics, and will always return Object[], so he'd have to convert it regardless to use it with the EntityAPI 1
Joseph Posted September 14, 2015 Posted September 14, 2015 I'd say convert your model to an array by copying contents over while iterating the model, using the enumeration returned by the DefaultListModel#elements method. Then pass that array using getGroundItems().closest(array) to get the closest desired item on the ground; or getGroundItems().filter(array) to get them all.
fixthissite Posted September 14, 2015 Posted September 14, 2015 (edited) toArray doesn't make use of generics, and will always return Object[], so he'd have to convert it regardless to use it with the EntityAPI He could actually use copyInto, which is backed by System.arraycopy. But seeing how DefaultListModel is backed by Vector, it would be wiser to use your own ListModel implementation, allowing you to add this support while potentionally increasing performance. Edited September 14, 2015 by fixthissite 1