use of net.minecraft.text.MutableText in project Client by MatHax.
the class ClientConnectionMixin method disconnect.
@Inject(method = "disconnect", at = @At("HEAD"))
private void disconnect(Text disconnectReason, CallbackInfo info) {
if (Modules.get().get(HighwayBuilder.class).isActive()) {
MutableText text = new LiteralText(String.format("\n\n%s[%sHighway Builder%s] Statistics:", Formatting.GRAY, Formatting.BLUE, Formatting.GRAY)).append("\n");
text.append(Modules.get().get(HighwayBuilder.class).getStatsText());
((MutableText) disconnectReason).append(text);
}
}
use of net.minecraft.text.MutableText in project Client by MatHax.
the class BookBot method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
// Check if there is a book to write
if (!writableBook.found()) {
toggle();
return;
}
// Move the book into hand
if (!writableBook.isMainHand()) {
InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
return;
}
// If somehow it failed, just dont do anything until it tries again
FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
if (!finalBook.isMainHand())
return;
// Check delay
if (delayTimer > 0) {
delayTimer--;
return;
}
// Reset delay
delayTimer = delay.get();
if (mode.get() == Mode.Random) {
int origin = onlyAscii.get() ? 0x21 : 0x0800;
int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
writeBook(// Generate a random load of ints to use as random characters
random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
} else if (mode.get() == Mode.File) {
// Ignore if somehow the file got deleted
if ((file == null || !file.exists()) && mode.get() == Mode.File) {
info("No file selected, please select a file in the GUI.");
toggle();
return;
}
// Handle the file being empty
if (file.length() == 0) {
MutableText message = new LiteralText("");
message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
info(message);
toggle();
return;
}
// Read each line of the file and construct a string with the needed line breaks
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
StringBuilder file = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
file.append(line).append('\n');
}
reader.close();
// Write the file string to a book
writeBook(file.toString().chars().iterator());
} catch (IOException ignored) {
error("Failed to read the file.");
}
}
}
use of net.minecraft.text.MutableText in project Client by MatHax.
the class SoundLocator method printSound.
private void printSound(SoundInstance sound) {
WeightedSoundSet soundSet = mc.getSoundManager().get(sound.getId());
MutableText text = soundSet.getSubtitle().copy();
text.append(String.format("%s at ", Formatting.GRAY));
Vec3d pos = new Vec3d(sound.getX(), sound.getY(), sound.getZ());
text.append(ChatUtils.formatCoords(pos));
text.append(String.format("%s.", Formatting.GRAY));
info(text);
}
use of net.minecraft.text.MutableText in project Client by MatHax.
the class BindsCommand method getTooltip.
private MutableText getTooltip(Module module) {
MutableText tooltip = new LiteralText(module.description).formatted(Formatting.BLUE, Formatting.BOLD).append("\n\n");
tooltip.append(new LiteralText(module.description).formatted(Formatting.WHITE));
return tooltip;
}
use of net.minecraft.text.MutableText in project factions by ickerio.
the class MapCommand method show.
public static int show(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
ServerPlayerEntity player = source.getPlayer();
ServerWorld world = player.getWorld();
ChunkPos chunkPos = world.getChunk(player.getBlockPos()).getPos();
String dimension = world.getRegistryKey().getValue().toString();
Member member = Member.get(player.getUuid());
Faction faction = member == null ? null : member.getFaction();
// Print the header of the faction map.
new Message("---------------[").format(Formatting.GRAY).add(new Message(" F MAP ").format(Formatting.AQUA)).add(new Message("]---------------").format(Formatting.GRAY)).send(player, false);
Map<String, Formatting> factions = new HashMap<>();
// Create and fill an array with the faction map.
MutableText[] rows = new MutableText[11];
for (int z = -5; z <= 5; z++) {
MutableText row = new LiteralText("");
for (int x = -6; x <= 6; x++) {
Claim claim = Claim.get(chunkPos.x + x, chunkPos.z + z, dimension);
if (x == 0 && z == 0) {
row.append(new LiteralText(" ■").formatted(Formatting.YELLOW));
} else if (claim == null) {
row.append(new LiteralText(" ■").formatted(Formatting.GRAY));
} else if (faction != null && claim.getFaction().name.equals(faction.name)) {
row.append(new LiteralText(" ■").formatted(Formatting.GREEN));
} else {
Faction owner = claim.getFaction();
factions.put(owner.name, owner.color);
row.append(new LiteralText(" ■").formatted(owner.color).styled((style) -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(owner.name)))));
}
}
rows[z + 5] = row;
}
// Attach the legend to the rows and send them to the player.
player.sendMessage(rows[0].append(new LiteralText(" ■").formatted(Formatting.GRAY)).append(" Wilderness"), false);
player.sendMessage(rows[1].append(new LiteralText(" ■").formatted(Formatting.GREEN)).append(" Your faction"), false);
player.sendMessage(rows[2].append(new LiteralText(" ■").formatted(Formatting.YELLOW)).append(" Your position"), false);
int i = 3;
for (Map.Entry<String, Formatting> entry : factions.entrySet()) {
if (i >= rows.length)
break;
player.sendMessage(rows[i].append(new LiteralText(" ■").formatted(entry.getValue())).append(" " + entry.getKey()), false);
i++;
}
// Send remaining rows.
for (; i < rows.length; i++) {
player.sendMessage(rows[i], false);
}
// Print the footer of the faction map.
new Message("---------------------------------------").format(Formatting.GRAY).send(player, false);
return 1;
}
Aggregations