net.minecraft.text.Text Java Examples

The following examples show how to use net.minecraft.text.Text. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MachineHandledScreen.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public MachineHandledScreen(C screenHandler, PlayerInventory playerInventory, World world, BlockPos pos, Text textComponent) {
    super(screenHandler, playerInventory, textComponent);
    assert isAllowed();
    this.pos = pos;
    this.world = world;

    if (this.handler.blockEntity != null) {
        ConfigurableElectricMachineBlockEntity entity = this.handler.blockEntity;

        ConfigurableElectricMachineBlockEntity.SecurityInfo security = entity.getSecurity();
        if (!security.hasOwner()) {
            security.setOwner(this.playerInventory.player);
            security.setPublicity(ConfigurableElectricMachineBlockEntity.SecurityInfo.Publicity.PRIVATE);
            sendSecurityUpdate(entity);
        } else if (security.getOwner().equals(playerInventory.player.getUuid())
                && !security.getUsername().equals(playerInventory.player.getEntityName())) {
            security.setUsername(playerInventory.player.getEntityName());
            sendSecurityUpdate(entity);
        }

        for (BlockFace face : BlockFace.values()) {
            sideOptions.put(face, ((ConfigurableElectricMachineBlock) world.getBlockState(pos).getBlock()).getOption(world.getBlockState(pos), face));
        }
    }
}
 
Example #2
Source File: ChatHudMixin.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Inject(at = @At("HEAD"),
	method = "addMessage(Lnet/minecraft/text/Text;I)V",
	cancellable = true)
private void onAddMessage(Text chatText, int chatLineId, CallbackInfo ci)
{
	ChatInputEvent event = new ChatInputEvent(chatText, visibleMessages);
	
	WurstClient.INSTANCE.getEventManager().fire(event);
	if(event.isCancelled())
	{
		ci.cancel();
		return;
	}
	
	chatText = event.getComponent();
	shadow$addMessage(chatText, chatLineId, client.inGameHud.getTicks(),
		false);
	
	LOGGER.info("[CHAT] {}", chatText.getString().replaceAll("\r", "\\\\r")
		.replaceAll("\n", "\\\\n"));
	ci.cancel();
}
 
Example #3
Source File: VRPlatform.java    From ViaFabric with MIT License 6 votes vote down vote up
private boolean kickServer(UUID uuid, String s) {
    MinecraftServer server = getServer();
    if (server == null) return false;
    Supplier<Boolean> kickTask = () -> {
        ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
        if (player == null) return false;
        player.networkHandler.disconnect(Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)));
        return true;
    };
    if (server.isOnThread()) {
        return kickTask.get();
    } else {
        ViaFabric.JLOGGER.log(Level.WARNING, "Weird!? Player kicking was called off-thread", new Throwable());
        runServerSync(kickTask::get);
    }
    return false;  // Can't know if it worked
}
 
Example #4
Source File: PaperBagItem.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public void appendTooltip(ItemStack itemStack, World world, List<Text> list, TooltipContext tooltipContext) {
	String translatedTooltip = new TranslatableText("text.thehallow.paper_bag").asString();
	String[] translatedTooltipWords = translatedTooltip.split(" ");
	
	StringBuilder tooltipBuilder = new StringBuilder();
	for (int i = 1; i <= translatedTooltipWords.length; i++) {
		tooltipBuilder.append(translatedTooltipWords[i - 1]);
		
		if (i % 4 == 0) {
			list.add(new LiteralText(tooltipBuilder.toString()).formatted(Formatting.GRAY));
			tooltipBuilder = new StringBuilder();
		} else {
			tooltipBuilder.append(" ");
		}
	}
	
	super.appendTooltip(itemStack, world, list, tooltipContext);
}
 
Example #5
Source File: Contributors.java    From the-hallow with MIT License 6 votes vote down vote up
private static Text makeDesc(Person person, Formatting formatting) {
	ContactInformation contact = person.getContact();
	Text ret = new LiteralText(person.getName()).formatted(formatting);
	contact.get("github").ifPresent(gh ->
		ret.append(Texts.bracketed(new TranslatableText("social.thehallow.github")
			.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, gh))))
			.formatted(Formatting.BLACK)
		)
	);
	
	contact.get("minecraft").ifPresent(mc ->
		ret.append(Texts.bracketed(new TranslatableText("social.thehallow.minecraft")
			.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://mcuuid.net/?q=" + mc))))
			.formatted(Formatting.GREEN)
		)
	);
	
	return ret;
}
 
Example #6
Source File: GlowstoneTorchBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void buildTooltip(ItemStack itemStack, BlockView blockView, List<Text> list, TooltipContext tooltipContext) {
    if (Screen.hasShiftDown()) {
        list.add(new TranslatableText("tooltip.galacticraft-rewoven.glowstone_torch").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
    } else {
        list.add(new TranslatableText("tooltip.galacticraft-rewoven.press_shift").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
    }
}
 
Example #7
Source File: MixinEntityType.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = SPAWN, at = @At(value = "INVOKE", target = "net/minecraft/world/World.spawnEntity(Lnet/minecraft/entity/Entity;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void hookMobSpawns(World world, @Nullable CompoundTag itemTag, @Nullable Text name, @Nullable PlayerEntity player, BlockPos pos, SpawnType type, boolean alignPosition, boolean bl, CallbackInfoReturnable<Entity> callback, Entity entity) {
	if (!(entity instanceof MobEntity)) {
		return;
	}

	MobEntity mob = (MobEntity) entity;

	if (EntityEvents.doSpecialSpawn(mob, world, pos.getX(), pos.getY(), pos.getZ(), null, type)) {
		callback.setReturnValue(null);
	}
}
 
Example #8
Source File: VRPlatform.java    From ViaFabric with MIT License 5 votes vote down vote up
private void sendMessageServer(UUID uuid, String s) {
    MinecraftServer server = getServer();
    if (server == null) return;
    runServerSync(() -> {
        ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
        if (player == null) return;
        player.sendMessage(Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)), false);
    });
}
 
Example #9
Source File: GetProtocolPacketListener.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void onDisconnected(Text reason) {
    if (!completed) {
        completed = true;
        failed = true;
    }
}
 
Example #10
Source File: MachineHandledScreen.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
protected void drawEnergyTooltip(MatrixStack stack, int mouseX, int mouseY, int energyX, int energyY) {
    if (check(mouseX, mouseY, energyX, energyY, Constants.TextureCoordinates.OVERLAY_WIDTH, Constants.TextureCoordinates.OVERLAY_HEIGHT)) {
        List<Text> lines = new ArrayList<>();
        if (handler.blockEntity.getStatusForTooltip() != null) {
            lines.add(new TranslatableText("ui.galacticraft-rewoven.machine.status").setStyle(Style.EMPTY.withColor(Formatting.GRAY)).append(this.handler.blockEntity.getStatusForTooltip().getText()));
        }

        lines.add(new TranslatableText("ui.galacticraft-rewoven.machine.current_energy").setStyle(Style.EMPTY.withColor(Formatting.GOLD)).append(GalacticraftEnergy.GALACTICRAFT_JOULES.getDisplayAmount(this.handler.energy.get()).setStyle(Style.EMPTY.withColor(Formatting.BLUE))));
        lines.add(new TranslatableText("ui.galacticraft-rewoven.machine.max_energy").setStyle(Style.EMPTY.withColor(Formatting.RED)).append(GalacticraftEnergy.GALACTICRAFT_JOULES.getDisplayAmount(this.handler.getMaxEnergy()).setStyle(Style.EMPTY.withColor(Formatting.BLUE))));
        lines.addAll(getEnergyTooltipLines());

        this.renderTooltip(stack, lines, mouseX, mouseY);
    }
}
 
Example #11
Source File: MixinKeyboard.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/ScreenshotUtils;saveScreenshot(Ljava/io/File;IILnet/minecraft/client/gl/Framebuffer;Ljava/util/function/Consumer;)V"))
public void takeScreenshot(File file_1, int int_1, int int_2, Framebuffer glFramebuffer_1, Consumer<Text> consumer_1) {
    if (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_P)) {
        PanoramaHandler.takeScreenshot(consumer_1);
    } else {
        ScreenshotUtils.saveScreenshot(file_1, int_1, int_2, glFramebuffer_1, consumer_1);
    }
}
 
Example #12
Source File: CarpetClient.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void onClientCommand(Tag t)
{
    CarpetSettings.LOG.info("Server Response:");
    CompoundTag tag = (CompoundTag)t;
    CarpetSettings.LOG.info(" - id: "+tag.getString("id"));
    CarpetSettings.LOG.info(" - code: "+tag.getInt("code"));
    if (tag.contains("error")) CarpetSettings.LOG.warn(" - error: "+tag.getString("error"));
    if (tag.contains("output"))
    {
        ListTag outputTag = (ListTag) tag.get("output");
        for (int i = 0; i < outputTag.size(); i++)
            CarpetSettings.LOG.info(" - response: " + Text.Serializer.fromJson(outputTag.getString(i)).getString());
    }
}
 
Example #13
Source File: CompressorBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public final void buildTooltip(ItemStack itemStack_1, BlockView blockView_1, List<Text> list_1, TooltipContext tooltipContext_1) {
    if (Screen.hasShiftDown()) {
        list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.compressor").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
    } else {
        list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.press_shift").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
    }
}
 
Example #14
Source File: Contributors.java    From the-hallow with MIT License 5 votes vote down vote up
public static void sendContributorsMessage(ServerCommandSource source) {
	source.sendFeedback(Texts.bracketed(new TranslatableText("thehallow.contrib.title").formatted(Formatting.GOLD)), false);
	
	Text root = new LiteralText("");
	
	for (Text entry : USER_INFO) {
		root.append(new TranslatableText("thehallow.contrib.entry", entry.copy()));
	}
	
	source.sendFeedback(root, false);
}
 
Example #15
Source File: OxygenCollectorScreen.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public void drawMouseoverTooltip(MatrixStack stack, int mouseX, int mouseY) {
    super.drawMouseoverTooltip(stack, mouseX, mouseY);
    this.drawEnergyTooltip(stack, mouseX, mouseY, this.x + 11, this.y + 18);
    if (mouseX >= oxygenDisplayX && mouseX <= oxygenDisplayX + OVERLAY_WIDTH && mouseY >= oxygenDisplayY && mouseY <= oxygenDisplayY + OVERLAY_HEIGHT) {
        List<Text> toolTipLines = new ArrayList<>();
        toolTipLines.add(new TranslatableText("ui.galacticraft-rewoven.machine.current_oxygen", GalacticraftEnergy.GALACTICRAFT_JOULES.getDisplayAmount(this.handler.energy.get()).setStyle(Style.EMPTY.withColor(Formatting.BLUE))).setStyle(Style.EMPTY.withColor(Formatting.GOLD)));
        toolTipLines.add(new TranslatableText("ui.galacticraft-rewoven.machine.max_oxygen", GalacticraftEnergy.GALACTICRAFT_JOULES.getDisplayAmount(this.handler.getMaxEnergy())).setStyle(Style.EMPTY.withColor(Formatting.RED)));
        this.renderTooltip(stack, toolTipLines, mouseX, mouseY);
    }
}
 
Example #16
Source File: VRPlatform.java    From ViaFabric with MIT License 5 votes vote down vote up
@Environment(EnvType.CLIENT)
private boolean kickClient(String msg) {
    ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
    if (handler != null) {
        try {
            handler.onDisconnect(new DisconnectS2CPacket(
                    Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(msg))
            ));
        } catch (OffThreadException ignored) {
        }
        return true;
    }
    return false;
}
 
Example #17
Source File: SignEditScreenMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")}, method = {"init()V"})
private void onInit(CallbackInfo ci)
{
	AutoSignHack autoSignHack = WurstClient.INSTANCE.getHax().autoSignHack;
	
	Text[] autoSignText = autoSignHack.getSignText();
	if(autoSignText == null)
		return;
	
	for(int i = 0; i < 4; i++)
		sign.setTextOnRow(i, autoSignText[i]);
	
	finishEditing();
}
 
Example #18
Source File: ItemWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void appendTooltip(net.minecraft.item.ItemStack itemStack_1, @Nullable net.minecraft.world.World world_1, List<Text> list_1, TooltipContext tooltipContext_1) {
    List<org.sandboxpowered.sandbox.api.util.text.Text> tooltip = new LinkedList<>();
    item.appendTooltipText(
            WrappingUtil.cast(itemStack_1, ItemStack.class),
            world_1 == null ? null : (World) world_1,
            tooltip,
            tooltipContext_1.isAdvanced()
    );
    tooltip.forEach(text -> list_1.add(WrappingUtil.convert(text)));
    super.appendTooltip(itemStack_1, world_1, list_1, tooltipContext_1);
}
 
Example #19
Source File: ItemStackMixin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@SuppressWarnings("RedundantSuppression")
@Inject(method = "getName", at = @At("RETURN"), cancellable = true)
private void getName(CallbackInfoReturnable<Text> returnable) {
    Identifier id = Registry.ITEM.getId(getItem());
    //noinspection ConstantConditions,PointlessBooleanExpression
    if (false && id.getNamespace().equals(Constants.MOD_ID)) {
        Text returnVal = returnable.getReturnValue();
        if (returnVal.getStyle().getColor() == null) {
            returnable.setReturnValue(returnVal.shallowCopy().setStyle(returnVal.getStyle().withColor(Formatting.BLUE)));
        }
    }
}
 
Example #20
Source File: VRPlatform.java    From ViaFabric with MIT License 5 votes vote down vote up
@Environment(EnvType.CLIENT)
private void sendMessageClient(String s) {
    ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
    if (handler != null) {
        try {
            handler.onGameMessage(new GameMessageS2CPacket(
                    Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)), MessageType.SYSTEM, Util.NIL_UUID
            ));
        } catch (OffThreadException ignored) {
        }
    }
}
 
Example #21
Source File: BatteryItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack stack, World world, List<Text> lines, TooltipContext context) {
    int charge = stack.getOrCreateTag().getInt("Energy");
    if (stack.getMaxDamage() - stack.getDamage() < 3334) {
        lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.DARK_RED)));
    } else if (stack.getMaxDamage() - stack.getDamage() < 6667) {
        lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GOLD)));
    } else {
        lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GREEN)));
    }
    super.appendTooltip(stack, world, lines, context);
}
 
Example #22
Source File: MixinDisconnectedScreen.java    From multiconnect with MIT License 4 votes vote down vote up
protected MixinDisconnectedScreen(Text title) {
    super(title);
}
 
Example #23
Source File: GuiBlockEntity.java    From LibGui with MIT License 4 votes vote down vote up
@Override
public Text getDisplayName() {
	return new LiteralText(""); // no title
}
 
Example #24
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Text getName() {
	return name;
}
 
Example #25
Source File: NetHandlerPlayServerFake.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Override
public void disconnect(Text message)
{
}
 
Example #26
Source File: MixinDownloadingTerrainScreen.java    From multiconnect with MIT License 4 votes vote down vote up
protected MixinDownloadingTerrainScreen(Text title) {
    super(title);
}
 
Example #27
Source File: ChatInputListener.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
public ChatInputEvent(Text component, List<ChatHudLine> chatLines)
{
	this.component = component;
	this.chatLines = chatLines;
}
 
Example #28
Source File: MixinJigsawBlockScreen.java    From multiconnect with MIT License 4 votes vote down vote up
protected MixinJigsawBlockScreen(Text title) {
    super(title);
}
 
Example #29
Source File: ChatInputListener.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
public Text getComponent()
{
	return component;
}
 
Example #30
Source File: ISignBlockEntity.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
public default Text[] getTextOnAllRows()
{
	return new Text[]{getTextOnRow(0), getTextOnRow(1), getTextOnRow(2),
		getTextOnRow(3)};
}