use of net.minecraft.network.chat.Component in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method handleAlteredProfiles.
public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet, DenizenNetworkManagerImpl manager) {
if (ProfileEditor.mirrorUUIDs.isEmpty() && !RenameCommand.hasAnyDynamicRenames()) {
return true;
}
ClientboundPlayerInfoPacket.Action action = packet.getAction();
if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER && action != ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) {
return true;
}
List<ClientboundPlayerInfoPacket.PlayerUpdate> dataList = packet.getEntries();
if (dataList == null) {
return true;
}
try {
boolean any = false;
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) || RenameCommand.customNames.containsKey(data.getProfile().getId())) {
any = true;
}
}
if (!any) {
return true;
}
GameProfile ownProfile = manager.player.getGameProfile();
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (!ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) && !RenameCommand.customNames.containsKey(data.getProfile().getId())) {
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
newPacketDataList.add(data);
manager.oldManager.send(newPacket);
} else {
String rename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), false);
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
GameProfile patchedProfile = new GameProfile(data.getProfile().getId(), rename != null ? (rename.length() > 16 ? rename.substring(0, 16) : rename) : data.getProfile().getName());
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId())) {
patchedProfile.getProperties().putAll(ownProfile.getProperties());
} else {
patchedProfile.getProperties().putAll(data.getProfile().getProperties());
}
String listRename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), true);
Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : data.getDisplayName();
ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName);
newPacketDataList.add(newData);
manager.oldManager.send(newPacket);
}
}
return false;
} catch (Exception e) {
Debug.echoError(e);
return true;
}
}
use of net.minecraft.network.chat.Component in project Tropicraft by Tropicraft.
the class ScubaHUD method drawHUDStrings.
private static void drawHUDStrings(PoseStack matrixStack, Component... components) {
Font fr = Minecraft.getInstance().font;
Window mw = Minecraft.getInstance().getWindow();
int startY = mw.getGuiScaledHeight() - 5 - (fr.lineHeight * components.length);
int startX = mw.getGuiScaledWidth() - 5;
for (Component text : components) {
String s = text.getString();
fr.drawShadow(matrixStack, s, startX - fr.width(s), startY, -1);
startY += fr.lineHeight;
}
}
use of net.minecraft.network.chat.Component in project MC-Prefab by Brian-Wuest.
the class CustomButton method renderButton.
/**
* Draws this button to the screen.
*/
@Override
public void renderButton(PoseStack mStack, int mouseX, int mouseY, float partial) {
if (this.visible) {
Minecraft mc = Minecraft.getInstance();
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
ResourceLocation buttonTexture = this.isHovered ? this.buttonTextureHover : this.buttonTexture;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, buttonTexture);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
GuiUtils.bindAndDrawScaledTexture(mStack, this.x, this.y, this.width, this.height, 90, 20, 90, 20);
int color = 14737632;
Component buttonText = this.getMessage();
int strWidth = mc.font.width(buttonText);
int ellipsisWidth = mc.font.width("...");
if (strWidth > width - 6 && strWidth > ellipsisWidth)
buttonText = Utils.createTextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
GuiComponent.drawCenteredString(mStack, mc.font, buttonText, this.x + this.width / 2, this.y + (this.height - 8) / 2, color);
}
}
use of net.minecraft.network.chat.Component in project MC-Prefab by Brian-Wuest.
the class ExtendedButton method renderButton.
/**
* Draws this button to the screen.
*/
@Override
public void renderButton(PoseStack mStack, int mouseX, int mouseY, float partial) {
if (this.visible) {
Minecraft mc = Minecraft.getInstance();
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
int i = this.getYImage(this.isHoveredOrFocused());
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
this.blit(mStack, this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.blit(mStack, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.renderBg(mStack, mc, mouseX, mouseY);
Component buttonText = this.getMessage();
int strWidth = mc.font.width(buttonText);
int ellipsisWidth = mc.font.width("...");
if (strWidth > width - 6 && strWidth > ellipsisWidth) {
buttonText = Utils.createTextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
}
PoseStack originalStack = new PoseStack();
originalStack.pushPose();
originalStack.scale(this.fontScale, this.fontScale, this.fontScale);
int xPosition = (int) ((this.x + this.width / 2) / this.fontScale);
int yPosition = (int) ((this.y + (this.height - (8 * this.fontScale)) / 2) / this.fontScale);
GuiComponent.drawCenteredString(originalStack, mc.font, buttonText, xPosition, yPosition, this.getFGColor());
originalStack.popPose();
}
}
Aggregations