Skip to content

Commit

Permalink
Add option to hide invisible players (#20)
Browse files Browse the repository at this point in the history
* add option to hide invisible players

* fix some warnings
  • Loading branch information
mist475 authored Apr 17, 2024
1 parent 8329a4f commit 2f738bc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/main/java/mcp/mobius/waila/Waila.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mcp.mobius.waila;

import java.lang.reflect.Field;
import java.util.Map;

import net.minecraftforge.common.MinecraftForge;

Expand All @@ -23,6 +24,9 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
import cpw.mods.fml.relauncher.Side;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
Expand Down Expand Up @@ -52,6 +56,7 @@ public class Waila {
public static ProxyServer proxy;
public static Logger log = LogManager.getLogger("Waila");
public boolean serverPresent = false;
private final ArtifactVersion minimumClientJoinVersion = new DefaultArtifactVersion("1.7.3");

/* INIT SEQUENCE */
@EventHandler
Expand Down Expand Up @@ -130,4 +135,16 @@ public void processIMC(FMLInterModComms.IMCEvent event) {
public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandDumpHandlers());
}

/**
* Block any clients older than 1.7.3 to ensure the vanilla.show_invisible_players property is respected
*/
@SuppressWarnings("unused")
@NetworkCheckHandler
public boolean checkModList(Map<String, String> versions, Side side) {
if (side == Side.CLIENT && versions.containsKey("Waila")) {
return minimumClientJoinVersion.compareTo(new DefaultArtifactVersion(versions.get("Waila"))) <= 0;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public static void register() {
ModuleRegistrar.instance().addConfig("VanillaMC", "vanilla.redstone");
ModuleRegistrar.instance().addConfig("VanillaMC", "vanilla.silverfish");
ModuleRegistrar.instance().addConfigRemote("VanillaMC", "vanilla.jukebox");
ModuleRegistrar.instance().addConfigRemote("VanillaMC", "vanilla.show_invisible_players");

IWailaDataProvider provider = new HUDHandlerVanilla();

Expand Down
23 changes: 16 additions & 7 deletions src/main/java/mcp/mobius/waila/overlay/RayTracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -38,8 +39,8 @@ public static RayTracing instance() {
private final Minecraft mc = Minecraft.getMinecraft();

public void fire() {
if (mc.objectMouseOver != null
&& mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY
&& !shouldHidePlayer(mc.objectMouseOver.entityHit)) {
this.target = mc.objectMouseOver;
return;
}
Expand All @@ -50,6 +51,15 @@ public void fire() {
this.target = this.rayTrace(viewpoint, mc.playerController.getBlockReachDistance(), 0);
}

private static boolean shouldHidePlayer(Entity targetEnt) {
// Check if entity is player with invisibility effect
if (targetEnt instanceof EntityPlayer thePlayer) {
boolean shouldHidePlayerSetting = !ConfigHandler.instance().getConfig("vanilla.show_invisible_players");
return shouldHidePlayerSetting && thePlayer.isInvisible();
}
return false;
}

public MovingObjectPosition getTarget() {
return this.target;
}
Expand Down Expand Up @@ -124,7 +134,7 @@ public ArrayList<ItemStack> getIdentifierItems() {
.getWailaStack(DataAccessorCommon.instance, ConfigHandler.instance());
if (providerStack != null) {

if (providerStack.getItem() == null) return new ArrayList<ItemStack>();
if (providerStack.getItem() == null) return new ArrayList<>();

items.add(providerStack);
}
Expand All @@ -141,7 +151,7 @@ public ArrayList<ItemStack> getIdentifierItems() {
.getWailaStack(DataAccessorCommon.instance, ConfigHandler.instance());
if (providerStack != null) {

if (providerStack.getItem() == null) return new ArrayList<ItemStack>();
if (providerStack.getItem() == null) return new ArrayList<>();

items.add(providerStack);
}
Expand All @@ -165,12 +175,11 @@ public ArrayList<ItemStack> getIdentifierItems() {
try {
ItemStack pick = mouseoverBlock.getPickBlock(this.target, world, x, y, z);
if (pick != null) items.add(pick);
} catch (Exception e) {}
} catch (Exception ignored) {}

if (!items.isEmpty()) return items;

if (mouseoverBlock instanceof IShearable) {
IShearable shearable = (IShearable) mouseoverBlock;
if (mouseoverBlock instanceof IShearable shearable) {
if (shearable.isShearable(new ItemStack(Items.shears), world, x, y, z)) {
items.addAll(shearable.onSheared(new ItemStack(Items.shears), world, x, y, z, 0));
}
Expand Down

0 comments on commit 2f738bc

Please sign in to comment.