Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

entityhider: add blacklist for hiding dead npcs. #2231

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,14 @@ public interface Client extends GameShell
*/
void setDeadNPCsHidden(boolean state);

/**
* The provided ids will not be hidden when the
* entity-hider attempts to hide dead {@link NPC}'s.
*
* @param blacklist set of npc ids.
*/
void setBlacklistDeadNpcs(Set<Integer> blacklist);

/**
* Gets an array of tile collision data.
* <p>
Expand Down
2 changes: 1 addition & 1 deletion runelite-api/src/main/java/net/runelite/api/util/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Text
{
private static final StringBuilder SB = new StringBuilder(64);

private static final Splitter COMMA_SPLITTER = Splitter
public static final Splitter COMMA_SPLITTER = Splitter
.on(",")
.omitEmptyStrings()
.trimResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,24 @@ default String hideNPCsOnDeath()
}

@ConfigItem(
position = 18,
keyName = "hidePets",
name = "Hide Pets",
description = "Configures whether or not other player pets are hidden"
position = 18,
keyName = "blacklistDeadNpcs",
name = "Hide on Death Blacklist",
description = "Configures which NPCs NOT to hide when they die",
titleSection = "npcsTitle",
hidden = true,
unhide = "hideDeadNPCs"
)
default String blacklistDeadNpcs()
{
return "";
}

@ConfigItem(
position = 19,
keyName = "hidePets",
name = "Hide Pets",
description = "Configures whether or not other player pets are hidden"
)
default boolean hidePets()
{
Expand All @@ -249,15 +263,15 @@ default boolean hidePets()
keyName = "miscTitle",
name = "Miscellaneous",
description = "",
position = 19
position = 20
)
default Title miscTitle()
{
return new Title();
}

@ConfigItem(
position = 20,
position = 21,
keyName = "hideProjectiles",
name = "Hide Projectiles",
description = "Configures whether or not projectiles are hidden",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

import com.google.inject.Provides;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -83,6 +85,22 @@ public void onConfigChanged(ConfigChanged event)
{
updateConfig();

final Set<Integer> blacklist = new HashSet<>();

for (String s : Text.COMMA_SPLITTER.split(config.blacklistDeadNpcs()))
{
try
{
blacklist.add(Integer.parseInt(s));
}
catch (NumberFormatException ignored)
{
}

}

client.setBlacklistDeadNpcs(blacklist);

if (event.getOldValue() == null || event.getNewValue() == null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.rs.api.RSClient;
Expand Down Expand Up @@ -83,6 +85,9 @@ public abstract class EntityHiderBridgeMixin implements RSClient
@Inject
public static List<String> hideSpecificPlayers = new ArrayList<>();

@Inject
public static Set<Integer> blacklistDeadNpcs = new HashSet<>();

@Inject
@Override
public void setIsHidingEntities(boolean state)
Expand Down Expand Up @@ -225,6 +230,13 @@ public void setHideSpecificPlayers(List<String> players)
hideSpecificPlayers = players;
}

@Inject
@Override
public void setBlacklistDeadNpcs(Set<Integer> blacklist)
{
blacklistDeadNpcs = blacklist;
}

@Inject
@Override
public void setPetsHidden(boolean state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.HashMap;
import java.util.List;
import java.util.Set;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
Expand Down Expand Up @@ -80,6 +81,9 @@ public abstract class EntityHiderMixin implements RSScene
@Shadow("hideSpecificPlayers")
private static List<String> hideSpecificPlayers;

@Shadow("blacklistDeadNpcs")
private static Set<Integer> blacklistDeadNpcs;

@Shadow("hideNPCs2D")
private static boolean hideNPCs2D;

Expand Down Expand Up @@ -199,7 +203,7 @@ else if (entity instanceof RSNPC)
}
}

if (hideDeadNPCs && npc.getHealthRatio() == 0)
if (hideDeadNPCs && npc.getHealthRatio() == 0 && !blacklistDeadNpcs.contains(npc.getId()))
{
return false;
}
Expand Down