updated textures, better logic

This commit is contained in:
2024-07-25 22:15:05 +03:00
parent 73aabb1a43
commit 441d475e6e
4 changed files with 53 additions and 27 deletions

View File

@@ -23,6 +23,7 @@ public class LongRadar extends ItemBase {
public LongRadar() { public LongRadar() {
super("long_radar"); super("long_radar");
setMaxStackSize(1); setMaxStackSize(1);
setMaxDamage(100);
} }
@Override @Override
@@ -41,51 +42,54 @@ public class LongRadar extends ItemBase {
@Override @Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote) { if (!world.isRemote) {
StringBuilder message = new StringBuilder(); player.getHeldItem(hand).damageItem(1, player);
boolean playerNearby = false;
ITextComponent warningMessage = new TextComponentString("WARNING: Cannot detect players less than 500 meters from you!") ITextComponent warningMessage = new TextComponentString("WARNING: Cannot detect players less than 300 meters from you!")
.setStyle(new Style().setColor(TextFormatting.RED)); .setStyle(new Style().setColor(TextFormatting.RED));
player.sendMessage(warningMessage); player.sendMessage(warningMessage);
boolean playerNearby = false;
for (EntityPlayer otherPlayer : world.playerEntities) { for (EntityPlayer otherPlayer : world.playerEntities) {
if (!otherPlayer.equals(player)) { if (!otherPlayer.equals(player)) {
playerNearby = true;
double deltaX = otherPlayer.posX - player.posX; double deltaX = otherPlayer.posX - player.posX;
double deltaZ = otherPlayer.posZ - player.posZ; double deltaZ = otherPlayer.posZ - player.posZ;
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ); double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
if (distance <= 500) continue; if (distance <= 300) continue;
double angle = Math.atan2(deltaZ, deltaX); double angle = Math.atan2(deltaZ, deltaX);
double angleDegrees = Math.toDegrees(angle) - 90; double angleDegrees = Math.toDegrees(angle) - 90;
angleDegrees = (angleDegrees + 360) % 360; angleDegrees = (angleDegrees + 360) % 360;
angleDegrees = (angleDegrees > 180) ? angleDegrees - 360 : angleDegrees;
double margin = RANDOM.nextDouble() * 20; double margin = RANDOM.nextDouble() * 20;
double halfMargin = margin / 2; double halfMargin = margin / 2;
double startAngle = (angleDegrees - halfMargin + 360) % 360; double startAngle = (angleDegrees - halfMargin + 360) % 360;
startAngle = (startAngle > 180) ? startAngle - 360 : startAngle;
double endAngle = (angleDegrees + halfMargin + 360) % 360; double endAngle = (angleDegrees + halfMargin + 360) % 360;
endAngle = (endAngle > 180) ? endAngle - 360 : endAngle;
String distanceMessage = distance > 50000 ? " (very far)" : ""; String distanceMessage = distance > 50000 ? " (very far)" : "";
ITextComponent intervalMessage; ITextComponent intervalMessage;
if (startAngle > endAngle) { if (startAngle > endAngle) {
intervalMessage = new TextComponentString(String.format("Look in the interval (%.1f - %.1f degrees)%s", startAngle, endAngle, distanceMessage)) intervalMessage = new TextComponentString(String.format("Look in the interval of %.1f - %.1f degrees%s", startAngle, endAngle, distanceMessage))
.setStyle(new Style().setColor(TextFormatting.GREEN)); .setStyle(new Style().setColor(TextFormatting.GREEN));
} else { } else {
intervalMessage = new TextComponentString(String.format("Look in the interval (%.1f - %.1f degrees)%s", startAngle, endAngle, distanceMessage)) intervalMessage = new TextComponentString(String.format("Look in the interval of %.1f - %.1f degrees%s", startAngle, endAngle, distanceMessage))
.setStyle(new Style().setColor(TextFormatting.GREEN)); .setStyle(new Style().setColor(TextFormatting.GREEN));
} }
message.append(intervalMessage.getFormattedText()).append("\n"); player.sendMessage(intervalMessage);
playerNearby = true;
} }
} }
if (playerNearby) { if (!playerNearby) {
player.sendMessage(new TextComponentString(message.toString()));
} else {
ITextComponent noPlayersMessage = new TextComponentString("No other players found.") ITextComponent noPlayersMessage = new TextComponentString("No other players found.")
.setStyle(new Style().setColor(TextFormatting.GRAY)); .setStyle(new Style().setColor(TextFormatting.GRAY));
player.sendMessage(noPlayersMessage); player.sendMessage(noPlayersMessage);

View File

@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style; import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
@@ -20,6 +21,7 @@ public class ShortRadar extends ItemBase {
public ShortRadar() { public ShortRadar() {
super("short_radar"); super("short_radar");
setMaxStackSize(1); setMaxStackSize(1);
setMaxDamage(70);
} }
@Override @Override
@@ -34,29 +36,49 @@ public class ShortRadar extends ItemBase {
@Override @Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote) { if (!world.isRemote) {
player.getHeldItem(hand).damageItem(1, player);
boolean playerNearby = false; boolean playerNearby = false;
ITextComponent message; for (EntityPlayer otherPlayer : world.playerEntities) {
if (isPlayerNearby(world, player)) { if (!otherPlayer.equals(player) && player.getDistance(otherPlayer) <= 100) {
message = new TextComponentString("There are players within 200 meters!") playerNearby = true;
String direction = getPlayerDirection(player, otherPlayer);
ITextComponent message = new TextComponentString(otherPlayer.getName() + " to the " + direction + "!")
.setStyle(new Style().setColor(TextFormatting.GREEN)); .setStyle(new Style().setColor(TextFormatting.GREEN));
} else { player.sendMessage(message);
message = new TextComponentString("No players within 200 meters.") }
.setStyle(new Style().setColor(TextFormatting.RED));
} }
player.sendMessage(message); if (!playerNearby) {
player.getCooldownTracker().setCooldown(this, 1200); ITextComponent noPlayersMessage = new TextComponentString("No players within 100 meters.")
.setStyle(new Style().setColor(TextFormatting.RED));
player.sendMessage(noPlayersMessage);
}
player.getCooldownTracker().setCooldown(this, 200);
} }
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
} }
private boolean isPlayerNearby(World world, EntityPlayer player) { private String getPlayerDirection(EntityPlayer player, EntityPlayer otherPlayer) {
for (EntityPlayer otherPlayer : world.playerEntities) { double deltaX = otherPlayer.posX - player.posX;
if (!otherPlayer.equals(player) && player.getDistance(otherPlayer) <= 200) { double deltaZ = otherPlayer.posZ - player.posZ;
return true; double angle = MathHelper.atan2(deltaZ, deltaX) * (180 / Math.PI) - 90;
} if (angle < 0) {
} angle += 360;
return false; }
angle = (angle + 180) % 360;
if (angle >= 337.5 || angle < 22.5) return "north";
if (angle >= 22.5 && angle < 67.5) return "northeast";
if (angle >= 67.5 && angle < 112.5) return "east";
if (angle >= 112.5 && angle < 157.5) return "southeast";
if (angle >= 157.5 && angle < 202.5) return "south";
if (angle >= 202.5 && angle < 247.5) return "southwest";
if (angle >= 247.5 && angle < 292.5) return "west";
if (angle >= 292.5) return "northwest";
return "unknown direction";
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 704 B