better logic, more tooltips

This commit is contained in:
2024-07-28 18:47:34 +03:00
parent 4b372ed557
commit 9a12b0f2fc
4 changed files with 33 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package com.lumijiez.lumiscope.items.radars;
import com.lumijiez.lumiscope.items.ItemBase;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
@@ -36,6 +37,10 @@ public class LongRadar extends ItemBase {
.setStyle(new Style().setColor(TextFormatting.RED));
tooltip.add(warning.getFormattedText());
tooltip.add(new TextComponentString("Does not detect invisible players!")
.setStyle(new Style().setColor(TextFormatting.DARK_RED).setBold(true).setItalic(true)).getFormattedText());
super.addInformation(stack, worldIn, tooltip, flagIn);
}
@@ -51,7 +56,10 @@ public class LongRadar extends ItemBase {
boolean playerNearby = false;
for (EntityPlayer otherPlayer : world.playerEntities) {
if (!otherPlayer.equals(player)) {
if (!otherPlayer.equals(player)
&& otherPlayer.getActivePotionEffects().stream()
.noneMatch(potionEffect -> potionEffect.getPotion() == MobEffects.INVISIBILITY)) {
double deltaX = otherPlayer.posX - player.posX;
double deltaZ = otherPlayer.posZ - player.posZ;
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
@@ -73,16 +81,15 @@ public class LongRadar extends ItemBase {
double endAngle = (angleDegrees + halfMargin + 360) % 360;
endAngle = (endAngle > 180) ? endAngle - 360 : endAngle;
String distanceMessage = distance > 50000 ? " (very far)" : "";
String distanceMessage = distance > 500000 ? " (extremely far)" :
distance > 50000 ? " (very far)" :
distance > 5000 ? " (far)" : "";
ITextComponent intervalMessage;
if (startAngle > endAngle) {
intervalMessage = new TextComponentString(String.format("Look in the interval of %.1f - %.1f degrees%s", startAngle, endAngle, distanceMessage))
.setStyle(new Style().setColor(TextFormatting.GREEN));
} else {
intervalMessage = new TextComponentString(String.format("Look in the interval of %.1f - %.1f degrees%s", startAngle, endAngle, distanceMessage))
.setStyle(new Style().setColor(TextFormatting.GREEN));
}
intervalMessage = new TextComponentString(String.format("Look in the interval of %.1f - %.1f degrees%s", startAngle, endAngle, distanceMessage))
.setStyle(new Style().setColor(TextFormatting.GREEN));
player.sendMessage(intervalMessage);
playerNearby = true;
@@ -90,7 +97,7 @@ public class LongRadar extends ItemBase {
}
if (!playerNearby) {
ITextComponent noPlayersMessage = new TextComponentString("No other players found.")
ITextComponent noPlayersMessage = new TextComponentString("No players found.")
.setStyle(new Style().setColor(TextFormatting.GRAY));
player.sendMessage(noPlayersMessage);
}

View File

@@ -3,7 +3,9 @@ package com.lumijiez.lumiscope.items.radars;
import com.lumijiez.lumiscope.items.ItemBase;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
@@ -26,10 +28,12 @@ public class ShortRadar extends ItemBase {
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
ITextComponent info = new TextComponentString("Checks for nearby players.")
.setStyle(new Style().setColor(TextFormatting.AQUA));
tooltip.add(info.getFormattedText());
tooltip.add(new TextComponentString("Checks for nearby players.")
.setStyle(new Style().setColor(TextFormatting.AQUA)).getFormattedText());
tooltip.add(new TextComponentString("Does not detect invisible players!")
.setStyle(new Style().setColor(TextFormatting.DARK_RED).setBold(true).setItalic(true)).getFormattedText());
super.addInformation(stack, worldIn, tooltip, flagIn);
}
@@ -41,7 +45,12 @@ public class ShortRadar extends ItemBase {
boolean playerNearby = false;
for (EntityPlayer otherPlayer : world.playerEntities) {
if (!otherPlayer.equals(player) && player.getDistance(otherPlayer) <= 100) {
if (!otherPlayer.equals(player)
&& player.getDistance(otherPlayer) <= 100
&& otherPlayer.getActivePotionEffects().stream()
.noneMatch(potionEffect -> potionEffect.getPotion() == MobEffects.INVISIBILITY)) {
playerNearby = true;
String direction = getPlayerDirection(player, otherPlayer);
ITextComponent message = new TextComponentString(otherPlayer.getName() + " to the " + direction + "!")
@@ -51,7 +60,7 @@ public class ShortRadar extends ItemBase {
}
if (!playerNearby) {
ITextComponent noPlayersMessage = new TextComponentString("No players within 100 meters.")
ITextComponent noPlayersMessage = new TextComponentString("Could not detect players within 100 meters.")
.setStyle(new Style().setColor(TextFormatting.RED));
player.sendMessage(noPlayersMessage);
}

View File

@@ -6,7 +6,7 @@ import org.apache.logging.log4j.Logger;
public class Ref {
public static final String MODID = "lumiscope";
public static final String NAME = "Lumiscope";
public static final String VERSION = "1.0";
public static final String VERSION = "1.1.0";
public static final String CLIENT_PROXY_CLASS = "com.lumijiez.lumiscope.proxy.ClientProxy";
public static final String COMMON_PROXY_CLASS = "com.lumijiez.lumiscope.proxy.CommonProxy";
public static final Logger logger = LogManager.getLogger();