use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.
the class ChatManager method applyUpdatesToServer.
public static Pair<String, Boolean> applyUpdatesToServer(String message) {
String after = message;
boolean cancel = false;
if (ChatConfig.INSTANCE.useBrackets) {
if (message.contains("{") || message.contains("<")) {
StringBuilder newString = new StringBuilder();
WynncraftLanguage language = WynncraftLanguage.NORMAL;
boolean isNumber = false;
boolean invalidNumber = false;
int number = 0;
StringBuilder oldNumber = new StringBuilder();
for (char character : message.toCharArray()) {
if (character == '{') {
language = WynncraftLanguage.WYNNIC;
isNumber = false;
number = 0;
oldNumber = new StringBuilder();
} else if (character == '<') {
language = WynncraftLanguage.GAVELLIAN;
isNumber = false;
number = 0;
oldNumber = new StringBuilder();
} else if ((language == WynncraftLanguage.WYNNIC && character == '}') || (language == WynncraftLanguage.GAVELLIAN && character == '>')) {
language = WynncraftLanguage.NORMAL;
} else if (language == WynncraftLanguage.WYNNIC) {
if (Character.isDigit(character) && !invalidNumber) {
if (oldNumber.toString().endsWith(".")) {
invalidNumber = true;
isNumber = false;
newString.append(oldNumber);
newString.append(character);
oldNumber = new StringBuilder();
number = 0;
continue;
}
number = number * 10 + Integer.parseInt(Character.toString(character));
oldNumber.append(character);
if (number >= 400) {
invalidNumber = true;
isNumber = false;
newString.append(oldNumber);
oldNumber = new StringBuilder();
number = 0;
} else {
isNumber = true;
}
} else if (character == ',' && isNumber) {
oldNumber.append(character);
} else if (character == '.' && isNumber) {
oldNumber.append('.');
} else {
if (isNumber) {
if (1 <= number && number <= 9) {
newString.append((char) (number + 0x2473));
} else if (number == 10 || number == 50 || number == 100) {
switch(number) {
case 10:
newString.append('⑽');
break;
case 50:
newString.append('⑾');
break;
case 100:
newString.append('⑿');
break;
}
} else if (1 <= number && number <= 399) {
int hundreds = number / 100;
for (int hundred = 1; hundred <= hundreds; hundred++) {
newString.append('⑿');
}
int tens = (number % 100) / 10;
if (1 <= tens && tens <= 3) {
for (int ten = 1; ten <= tens; ten++) {
newString.append('⑽');
}
} else if (4 == tens) {
newString.append("⑽⑾");
} else if (5 <= tens && tens <= 8) {
newString.append('⑾');
for (int ten = 1; ten <= tens - 5; ten++) {
newString.append('⑽');
}
} else if (9 == tens) {
newString.append("⑽⑿");
}
int ones = number % 10;
if (1 <= ones) {
newString.append((char) (ones + 0x2473));
}
} else {
newString.append(number);
}
number = 0;
isNumber = false;
if (oldNumber.toString().endsWith(",")) {
newString.append(',');
}
if (oldNumber.toString().endsWith(".")) {
newString.append('0');
}
oldNumber = new StringBuilder();
}
if (invalidNumber && !Character.isDigit(character)) {
invalidNumber = false;
}
if (!Character.toString(character).matches(nonTranslatable)) {
if (Character.toString(character).matches("[a-z]")) {
newString.append((char) ((character) + 0x243B));
} else if (Character.toString(character).matches("[A-Z]")) {
newString.append((char) ((character) + 0x245B));
} else if (character == '.') {
newString.append('0');
} else if (character == '!') {
newString.append('1');
} else if (character == '?') {
newString.append('2');
}
} else {
newString.append(character);
}
}
} else if (language == WynncraftLanguage.GAVELLIAN) {
if ('a' <= character && character <= 'z') {
newString.append((char) (character + 9327));
} else if ('A' <= character && character <= 'Z') {
newString.append((char) (character + 9359));
}
} else {
newString.append(character);
}
}
if (isNumber) {
if (1 <= number && number <= 9) {
newString.append((char) (number + 0x2473));
} else if (number == 10 || number == 50 || number == 100) {
switch(number) {
case 10:
newString.append('⑽');
break;
case 50:
newString.append('⑾');
break;
case 100:
newString.append('⑿');
break;
}
} else if (1 <= number && number <= 399) {
int hundreds = number / 100;
for (int hundred = 1; hundred <= hundreds; hundred++) {
newString.append('⑿');
}
int tens = (number % 100) / 10;
if (1 <= tens && tens <= 3) {
for (int ten = 1; ten <= tens; ten++) {
newString.append('⑽');
}
} else if (4 == tens) {
newString.append("⑽⑾");
} else if (5 <= tens && tens <= 8) {
newString.append('⑾');
for (int ten = 1; ten <= tens - 5; ten++) {
newString.append('⑽');
}
} else if (9 == tens) {
newString.append("⑽⑿");
}
int ones = number % 10;
if (1 <= ones) {
newString.append((char) (ones + 0x2473));
}
} else {
newString.append(number);
}
if (oldNumber.toString().endsWith(",")) {
newString.append(',');
}
if (oldNumber.toString().endsWith(".")) {
newString.append('0');
}
}
after = newString.toString();
}
}
return new Pair<>(after, cancel);
}
use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.
the class FakeInventory method findItem.
public Pair<Integer, ItemStack> findItem(String name, BiPredicate<String, String> filterType) {
if (!isOpen)
return null;
for (int slot = 0; slot < inventory.size(); slot++) {
ItemStack stack = inventory.get(slot);
if (stack.isEmpty() || !stack.hasDisplayName())
continue;
String displayName = TextFormatting.getTextWithoutFormattingCodes(stack.getDisplayName());
if (filterType.test(displayName, name)) {
return new Pair<>(slot, stack);
}
}
return null;
}
use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.
the class FakeInventory method findItems.
public List<Pair<Integer, ItemStack>> findItems(List<String> names, List<? extends BiPredicate<String, String>> filterTypes) {
if (!isOpen)
return null;
int found = 0;
List<Pair<Integer, ItemStack>> result = new ArrayList<>(Collections.nCopies(names.size(), null));
for (int slot = 0, len = inventory.size(); slot < len && found != names.size(); ++slot) {
ItemStack stack = inventory.get(slot);
if (stack.isEmpty() || !stack.hasDisplayName())
continue;
String displayName = TextFormatting.getTextWithoutFormattingCodes(stack.getDisplayName());
for (int i = 0; i < names.size(); ++i) {
if (result.get(i) != null)
continue;
if (filterTypes.get(i).test(displayName, names.get(i))) {
result.set(i, new Pair<>(slot, stack));
}
}
}
return result;
}
use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.
the class PointRenderer method drawTexturedLines.
public static void drawTexturedLines(Texture texture, Long2ObjectMap<List<List<LootRunPath.LootRunPathLocation>>> points, Long2ObjectMap<List<List<Vector3d>>> directions, CustomColor color, float width) {
List<ChunkPos> chunks = new ArrayList<>();
int renderDistance = McIf.mc().gameSettings.renderDistanceChunks;
for (int x = -renderDistance; x <= renderDistance; x++) {
for (int z = -renderDistance; z <= renderDistance; z++) {
int playerChunkX = McIf.player().chunkCoordX;
int playerChunkZ = McIf.player().chunkCoordZ;
ChunkPos chunk = new ChunkPos(x + playerChunkX, z + playerChunkZ);
chunks.add(chunk);
}
}
GlStateManager.disableCull();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
texture.bind();
for (ChunkPos chunk : chunks) {
if (!McIf.world().isChunkGeneratedAt(chunk.x, chunk.z)) {
continue;
}
List<List<LootRunPath.LootRunPathLocation>> pointsInChunk = points.get(ChunkPos.asLong(chunk.x, chunk.z));
List<List<Vector3d>> directionsInChunk = directions.get(ChunkPos.asLong(chunk.x, chunk.z));
if (pointsInChunk != null) {
for (int i = 0; i < pointsInChunk.size(); ++i) {
List<LootRunPath.LootRunPathLocation> pointsInRoute = pointsInChunk.get(i);
List<Vector3d> directionsInRoute = directionsInChunk.get(i);
boolean disable = false;
List<Pair<LootRunPath.LootRunPathLocation, Vector3d>> toRender = new ArrayList<>();
for (int k = 0; k < pointsInRoute.size(); ++k) {
Point3d start = new Point3d(pointsInRoute.get(k).getLocation());
World world = McIf.world();
BlockPos minPos = new BlockPos(start.x - 0.3D, start.y - 1D, start.z - 0.3D);
BlockPos maxPos = new BlockPos(start.x + 0.3D, start.y - 1D, start.z + 0.3D);
Iterable<BlockPos> blocks = BlockPos.getAllInBox(minPos, maxPos);
boolean barrier = false;
boolean validBlock = false;
for (BlockPos blockInArea : blocks) {
IBlockState blockStateInArea = world.getBlockState(blockInArea);
if (blockStateInArea.getBlock() == Blocks.BARRIER) {
barrier = true;
} else if (blockStateInArea.getCollisionBoundingBox(world, blockInArea) != null) {
validBlock = true;
}
}
if (validBlock) {
disable = false;
for (Pair<LootRunPath.LootRunPathLocation, Vector3d> render : toRender) {
Point3d startRender = new Point3d(render.a.getLocation());
Vector3d direction = new Vector3d(render.b);
Point3d end = new Point3d(render.a.getLocation());
CustomColor locationColor = color == CommonColors.RAINBOW ? render.a.getColor() : color;
locationColor.applyColor();
startRender.y -= .24;
direction.normalize();
end.add(direction);
end.y -= .24;
drawTexturedLine(startRender, end, width);
}
toRender.clear();
} else if (barrier) {
disable = true;
toRender.clear();
continue;
} else if (disable) {
continue;
} else {
toRender.add(new Pair<>(pointsInRoute.get(k), directionsInRoute.get(k)));
continue;
}
Vector3d direction = new Vector3d(directionsInRoute.get(k));
Point3d end = new Point3d(pointsInRoute.get(k).getLocation());
CustomColor locationColor = color == CommonColors.RAINBOW ? pointsInRoute.get(k).getColor() : color;
locationColor.applyColor();
start.y -= .24;
direction.normalize();
end.add(direction);
end.y -= .24;
BlockPos startBlockPos = new BlockPos(start.x, start.y, start.z);
Vec3d startVec = new Vec3d(start.x, start.y, start.z);
BlockPos endBlockPos = new BlockPos(end.x, end.y, end.z);
Vec3d endVec = new Vec3d(end.x, end.y, end.z);
AxisAlignedBB startCollisionBox = world.getBlockState(startBlockPos).getCollisionBoundingBox(world, startBlockPos);
if (startCollisionBox != Block.NULL_AABB) {
AxisAlignedBB offsetStartCollisionBox = startCollisionBox.offset(startBlockPos);
if (offsetStartCollisionBox.contains(startVec)) {
if (startCollisionBox.maxY >= 1) {
if (world.getBlockState(startBlockPos.up()).getCollisionBoundingBox(world, startBlockPos) == Block.NULL_AABB) {
start.y = Math.ceil(start.y) + 0.01;
}
} else {
start.y = offsetStartCollisionBox.maxY + 0.01;
}
}
}
AxisAlignedBB endCollisionBox = world.getBlockState(endBlockPos).getCollisionBoundingBox(world, endBlockPos);
if (endCollisionBox != Block.NULL_AABB) {
AxisAlignedBB offsetEndCollisionBox = endCollisionBox.offset(endBlockPos);
if (offsetEndCollisionBox.contains(endVec)) {
if (endCollisionBox.maxY >= 1) {
if (world.getBlockState(endBlockPos.up()).getCollisionBoundingBox(world, endBlockPos) == Block.NULL_AABB) {
end.y = Math.ceil(end.y) + 0.01;
}
} else {
end.y = offsetEndCollisionBox.maxY + 0.01;
}
}
}
drawTexturedLine(start, end, width);
}
for (Pair<LootRunPath.LootRunPathLocation, Vector3d> render : toRender) {
Point3d start = new Point3d(render.a.getLocation());
Vector3d direction = new Vector3d(render.b);
Point3d end = new Point3d(render.a.getLocation());
CustomColor locationColor = color == CommonColors.RAINBOW ? render.a.getColor() : color;
locationColor.applyColor();
start.y -= .24;
direction.normalize();
end.add(direction);
end.y -= .24;
drawTexturedLine(start, end, width);
}
}
}
}
GlStateManager.enableCull();
GlStateManager.disableBlend();
GlStateManager.color(1f, 1f, 1f, 1f);
}
use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.
the class RPCJoinHandler method joinWorld.
/**
* Search for a Wynncraft World.
* only works if the user is on lobby!
*
* @param worldType the world type to join
* @param worldNumber The world to join
*/
private static void joinWorld(String worldType, int worldNumber) {
if (!Reference.onServer || Reference.onWorld)
return;
FakeInventory serverSelector = new FakeInventory(WYNNCRAFT_SERVERS_WINDOW_TITLE_PATTERN, new InventoryOpenByItem(0));
serverSelector.onReceiveItems(inventory -> {
String prefix = "";
if (worldType.equals("WC")) {
// US Servers
prefix = "";
} else if (worldType.equals("HB")) {
prefix = "Beta ";
}
boolean onCorrectCategory = inventory.findItem(prefix + "World ", FilterType.STARTS_WITH) != null;
if (!onCorrectCategory) {
String worldCategory = "";
if (worldType.equals("WC")) {
worldCategory = "US Servers";
} else if (worldType.equals("HB")) {
worldCategory = "Hero Beta";
}
Pair<Integer, ItemStack> categoryItem = inventory.findItem(worldCategory, FilterType.EQUALS_IGNORE_CASE);
if (categoryItem != null) {
inventory.clickItem(categoryItem.a, 1, ClickType.PICKUP);
return;
}
inventory.close();
return;
}
Pair<Integer, ItemStack> world = inventory.findItem(prefix + "World " + worldNumber, FilterType.EQUALS_IGNORE_CASE);
if (world != null) {
inventory.clickItem(world.a, 1, ClickType.PICKUP);
inventory.close();
return;
}
Pair<Integer, ItemStack> nextPage = inventory.findItem("Next Page", FilterType.CONTAINS);
if (nextPage != null) {
serverSelector.clickItem(nextPage.a, 1, ClickType.PICKUP);
return;
}
inventory.close();
}).onClose((inv, result) -> {
if (result != InventoryResult.CLOSED_SUCCESSFULLY)
return;
joinWorld(worldType, worldNumber);
});
serverSelector.open();
}
Aggregations