use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.
the class ServerPlayNetworkHandlerMixin method onGetDisplayName.
@Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getDisplayName()Lnet/minecraft/text/Text;"))
private Text onGetDisplayName(ServerPlayerEntity instance) {
MutableText name = (MutableText) instance.getDisplayName();
if (BadgeExtension.isExtensionEnabled) {
List<BadgeInstance> badges = BadgeExtension.playerBadges.get(instance.getUuidAsString());
if (badges.size() != 0) {
name.append(new LiteralText(" "));
}
for (int i = badges.size() - 1; i >= 0; i--) {
int finalI = i;
name.append(new LiteralText(badges.get(i).getBadge()).styled(style -> style.withColor(Formatting.byColorIndex(badges.get(finalI).getColorIndex()))));
if (i < badges.size() - 2) {
break;
}
}
}
return name;
}
use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.
the class BlockInfoExtension method getInfo.
public void getInfo(ServerCommandSource source, BlockPos pos, int page) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
List<MutableText> msg = getBlockInfo(x, y, z, DimUtils.getWorldID(DimUtils.getDim(source.getWorld())), page);
Collections.reverse(msg);
source.sendFeedback(new LiteralText("======BlockInfo======"), false);
int nLine = getLines(x, y, z, DimUtils.getWorldID(DimUtils.getDim(source.getWorld())));
for (MutableText line : msg) {
source.sendFeedback(line, false);
}
if (page > nLine) {
// No pages.
return;
} else if (page == nLine && page == 1) {
// There is only 1 page.
source.sendFeedback(new LiteralText(String.format("%d/%d.", page, nLine)), false);
} else if (page == 1) {
// First page but there are more
MutableText pages = BlockInfoUtils.getPages(page, nLine);
MutableText next = BlockInfoUtils.getNext(x, y, z, page);
source.sendFeedback(new LiteralText("").append(pages).append(next).append(BlockInfoUtils.getHelp(x, y, z)), false);
} else if (page == nLine) {
// The last page.
MutableText prev = BlockInfoUtils.getPrev(x, y, z, page);
MutableText pages = BlockInfoUtils.getPages(page, nLine);
source.sendFeedback(new LiteralText("").append(prev).append(pages).append(BlockInfoUtils.getHelp(x, y, z)), false);
} else {
// Have pages before and after the one you are in.
MutableText prev = BlockInfoUtils.getPrev(x, y, z, page);
MutableText pages = BlockInfoUtils.getPages(page, nLine);
MutableText next = BlockInfoUtils.getNext(x, y, z, page);
source.sendFeedback(new LiteralText("").append(prev).append(pages).append(next).append(BlockInfoUtils.getHelp(x, y, z)), false);
}
}
use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.
the class BlockInfoExtension method getBlockInfo.
public List<MutableText> getBlockInfo(int x, int y, int z, int dim, int page) {
List<MutableText> msg = new ArrayList<>();
try {
String q = "SELECT amount, action, date, playerName, block FROM `action_logger` " + "WHERE posX = ? AND posY = ? AND posZ = ? AND dim = ? ORDER BY id DESC LIMIT 10 OFFSET ?;";
PreparedStatement ps = this.conn.prepareStatement(q);
ps.setInt(1, x);
ps.setInt(2, y);
ps.setInt(3, z);
ps.setInt(4, dim);
ps.setInt(5, (page - 1) * 10);
ResultSet rs = ps.executeQuery();
int i = 0;
while (rs.next() && i <= 10) {
MutableText line = BlockInfoUtils.buildLine(rs);
msg.add(line);
i++;
}
if (msg.isEmpty()) {
msg.add(new LiteralText("No logs :("));
}
rs.close();
ps.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
msg.clear();
msg.add(new LiteralText("Error."));
}
return msg;
}
use of net.minecraft.text.MutableText in project meteor-client by MeteorDevelopment.
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 FZMM-Mod by Zailer43.
the class GradientLogic method getGradient.
public static MutableText getGradient(String message, byte red, byte green, byte blue, byte red2, byte green2, byte blue2, Style style) {
List<String> messageList = splitString(message);
int gradientLength = messageList.size();
byte[] gradientRed = getByteGradient(red, red2, gradientLength);
byte[] gradientGreen = getByteGradient(green, green2, gradientLength);
byte[] gradientBlue = getByteGradient(blue, blue2, gradientLength);
MutableText gradientText = LiteralText.EMPTY.copy();
for (int i = 0; i != gradientLength; i++) {
int rgb = rgbToInt(gradientRed[i], gradientGreen[i], gradientBlue[i]);
gradientText.append(new LiteralText(String.valueOf(messageList.get(i))).setStyle(style.withColor(TextColor.fromRgb(rgb))));
}
return gradientText;
}
Aggregations