grounditems/Lootbeam: handle loading models correctly
models are streamed over js5 so loadModel can return null until it is downloaded
This commit is contained in:
@@ -1057,7 +1057,9 @@ public interface Client extends GameEngine
|
||||
* Loads a model from the cache
|
||||
*
|
||||
* @param id the ID of the model
|
||||
* @return the model or null if it is loading or nonexistent
|
||||
*/
|
||||
@Nullable
|
||||
Model loadModel(int id);
|
||||
|
||||
/**
|
||||
@@ -1066,7 +1068,9 @@ public interface Client extends GameEngine
|
||||
* @param id the ID of the model
|
||||
* @param colorToFind array of hsl color values to find in the model to replace
|
||||
* @param colorToReplace array of hsl color values to replace in the model
|
||||
* @return the model or null if it is loading or nonexistent
|
||||
*/
|
||||
@Nullable
|
||||
Model loadModel(int id, short[] colorToFind, short[] colorToReplace);
|
||||
|
||||
/**
|
||||
|
||||
@@ -800,7 +800,7 @@ public class GroundItemsPlugin extends Plugin
|
||||
Lootbeam lootbeam = lootbeams.get(worldPoint);
|
||||
if (lootbeam == null)
|
||||
{
|
||||
lootbeam = new Lootbeam(client, worldPoint, color);
|
||||
lootbeam = new Lootbeam(client, clientThread, worldPoint, color);
|
||||
lootbeams.put(worldPoint, lootbeam);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -27,10 +27,12 @@ package net.runelite.client.plugins.grounditems;
|
||||
import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.JagexColor;
|
||||
import net.runelite.api.Model;
|
||||
import net.runelite.api.RuneLiteObject;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import java.awt.Color;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
|
||||
class Lootbeam
|
||||
{
|
||||
@@ -39,11 +41,13 @@ class Lootbeam
|
||||
|
||||
private final RuneLiteObject runeLiteObject;
|
||||
private final Client client;
|
||||
private final ClientThread clientThread;
|
||||
private Color color;
|
||||
|
||||
public Lootbeam(Client client, WorldPoint worldPoint, Color color)
|
||||
public Lootbeam(Client client, ClientThread clientThread, WorldPoint worldPoint, Color color)
|
||||
{
|
||||
this.client = client;
|
||||
this.clientThread = clientThread;
|
||||
runeLiteObject = client.createRuneLiteObject();
|
||||
|
||||
setColor(color);
|
||||
@@ -64,11 +68,21 @@ class Lootbeam
|
||||
}
|
||||
|
||||
this.color = color;
|
||||
runeLiteObject.setModel(client.loadModel(
|
||||
RAID_LIGHT_MODEL,
|
||||
new short[]{RAID_LIGHT_FIND_COLOR},
|
||||
new short[]{JagexColor.rgbToHSL(color.getRGB(), 1.0d)}
|
||||
));
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
Model m = client.loadModel(
|
||||
RAID_LIGHT_MODEL,
|
||||
new short[]{RAID_LIGHT_FIND_COLOR},
|
||||
new short[]{JagexColor.rgbToHSL(color.getRGB(), 1.0d)}
|
||||
);
|
||||
if (m == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
runeLiteObject.setModel(m);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void remove()
|
||||
|
||||
Reference in New Issue
Block a user