use of net.minecraft.network.chat.Component in project SpongeCommon by SpongePowered.
the class SignBlockEntityMixin_API method toContainer.
// @formatter:on
@Override
public DataContainer toContainer() {
DataContainer container = super.toContainer();
List<String> lines = Lists.newArrayList();
for (Component line : this.messages) {
lines.add(Component.Serializer.toJson(line));
}
container.set(Constants.TileEntity.SIGN_LINES, lines);
return container;
}
use of net.minecraft.network.chat.Component in project SpongeCommon by SpongePowered.
the class TranslatableComponentMixin method impl$translateForRendering.
@Inject(method = "visitSelf(Lnet/minecraft/network/chat/FormattedText$StyledContentConsumer;Lnet/minecraft/network/chat/Style;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true)
private <T> void impl$translateForRendering(final FormattedText.StyledContentConsumer<T> visitor, final Style style, final CallbackInfoReturnable<Optional<T>> ci) {
final String currentLocale = Minecraft.getInstance().options.languageCode;
if (!Objects.equals(currentLocale, this.impl$lastLocale)) {
// retranslate
this.impl$lastLocale = currentLocale;
final Locale actualLocale = Locales.of(currentLocale);
// Only do a deep copy if actually necessary
if (GlobalTranslator.get().translate(this.key, actualLocale) != null) {
this.impl$translated = NativeComponentRenderer.apply((Component) this, Locales.of(currentLocale));
} else {
this.impl$translated = (Component) this;
}
}
// If the result is a non-translated component, then Adventure found a translation that we should use
if (!(this.impl$translated instanceof TranslatableComponent)) {
ci.setReturnValue(this.impl$translated.visitSelf(visitor, style));
}
}
use of net.minecraft.network.chat.Component in project MinecraftForge by MinecraftForge.
the class ContainerTypeTest method onRightClick.
private void onRightClick(PlayerInteractEvent.RightClickBlock event) {
if (!event.getWorld().isClientSide && event.getHand() == InteractionHand.MAIN_HAND) {
if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.SPONGE) {
String text = "Hello World!";
NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new MenuProvider() {
@Override
public AbstractContainerMenu createMenu(int p_createMenu_1_, Inventory p_createMenu_2_, Player p_createMenu_3_) {
SimpleContainer inv = new SimpleContainer(9);
for (int i = 0; i < inv.getContainerSize(); i++) {
inv.setItem(i, new ItemStack(Items.DIAMOND));
}
return new TestContainer(p_createMenu_1_, inv, text);
}
@Override
public Component getDisplayName() {
return new TextComponent("Test");
}
}, extraData -> {
extraData.writeUtf(text);
});
}
}
}
use of net.minecraft.network.chat.Component in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showTabListHeaderFooter.
@Override
public void showTabListHeaderFooter(Player player, String header, String footer) {
Component cHeader = Handler.componentToNMS(FormattedTextHelper.parse(header, ChatColor.WHITE));
Component cFooter = Handler.componentToNMS(FormattedTextHelper.parse(footer, ChatColor.WHITE));
ClientboundTabListPacket packet = new ClientboundTabListPacket(cHeader, cFooter);
send(player, packet);
}
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;
}
}
Aggregations