updated textures, better logic
This commit is contained in:
@@ -23,6 +23,7 @@ public class LongRadar extends ItemBase {
|
||||
public LongRadar() {
|
||||
super("long_radar");
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,51 +42,54 @@ public class LongRadar extends ItemBase {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
boolean playerNearby = false;
|
||||
player.getHeldItem(hand).damageItem(1, player);
|
||||
|
||||
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));
|
||||
player.sendMessage(warningMessage);
|
||||
|
||||
boolean playerNearby = false;
|
||||
|
||||
for (EntityPlayer otherPlayer : world.playerEntities) {
|
||||
if (!otherPlayer.equals(player)) {
|
||||
playerNearby = true;
|
||||
|
||||
double deltaX = otherPlayer.posX - player.posX;
|
||||
double deltaZ = otherPlayer.posZ - player.posZ;
|
||||
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
||||
|
||||
if (distance <= 500) continue;
|
||||
if (distance <= 300) continue;
|
||||
|
||||
double angle = Math.atan2(deltaZ, deltaX);
|
||||
double angleDegrees = Math.toDegrees(angle) - 90;
|
||||
angleDegrees = (angleDegrees + 360) % 360;
|
||||
|
||||
angleDegrees = (angleDegrees > 180) ? angleDegrees - 360 : angleDegrees;
|
||||
|
||||
double margin = RANDOM.nextDouble() * 20;
|
||||
double halfMargin = margin / 2;
|
||||
|
||||
double startAngle = (angleDegrees - halfMargin + 360) % 360;
|
||||
startAngle = (startAngle > 180) ? startAngle - 360 : startAngle;
|
||||
|
||||
double endAngle = (angleDegrees + halfMargin + 360) % 360;
|
||||
endAngle = (endAngle > 180) ? endAngle - 360 : endAngle;
|
||||
|
||||
String distanceMessage = distance > 50000 ? " (very far)" : "";
|
||||
|
||||
ITextComponent intervalMessage;
|
||||
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));
|
||||
} 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));
|
||||
}
|
||||
|
||||
message.append(intervalMessage.getFormattedText()).append("\n");
|
||||
player.sendMessage(intervalMessage);
|
||||
playerNearby = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerNearby) {
|
||||
player.sendMessage(new TextComponentString(message.toString()));
|
||||
} else {
|
||||
if (!playerNearby) {
|
||||
ITextComponent noPlayersMessage = new TextComponentString("No other players found.")
|
||||
.setStyle(new Style().setColor(TextFormatting.GRAY));
|
||||
player.sendMessage(noPlayersMessage);
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
@@ -20,6 +21,7 @@ public class ShortRadar extends ItemBase {
|
||||
public ShortRadar() {
|
||||
super("short_radar");
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(70);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,29 +36,49 @@ public class ShortRadar extends ItemBase {
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote) {
|
||||
player.getHeldItem(hand).damageItem(1, player);
|
||||
|
||||
boolean playerNearby = false;
|
||||
|
||||
ITextComponent message;
|
||||
if (isPlayerNearby(world, player)) {
|
||||
message = new TextComponentString("There are players within 200 meters!")
|
||||
for (EntityPlayer otherPlayer : world.playerEntities) {
|
||||
if (!otherPlayer.equals(player) && player.getDistance(otherPlayer) <= 100) {
|
||||
playerNearby = true;
|
||||
String direction = getPlayerDirection(player, otherPlayer);
|
||||
ITextComponent message = new TextComponentString(otherPlayer.getName() + " to the " + direction + "!")
|
||||
.setStyle(new Style().setColor(TextFormatting.GREEN));
|
||||
} else {
|
||||
message = new TextComponentString("No players within 200 meters.")
|
||||
.setStyle(new Style().setColor(TextFormatting.RED));
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(message);
|
||||
player.getCooldownTracker().setCooldown(this, 1200);
|
||||
if (!playerNearby) {
|
||||
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));
|
||||
}
|
||||
|
||||
private boolean isPlayerNearby(World world, EntityPlayer player) {
|
||||
for (EntityPlayer otherPlayer : world.playerEntities) {
|
||||
if (!otherPlayer.equals(player) && player.getDistance(otherPlayer) <= 200) {
|
||||
return true;
|
||||
private String getPlayerDirection(EntityPlayer player, EntityPlayer otherPlayer) {
|
||||
double deltaX = otherPlayer.posX - player.posX;
|
||||
double deltaZ = otherPlayer.posZ - player.posZ;
|
||||
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 |
Reference in New Issue
Block a user