use of net.minecraft.text.Text in project FabricWaystones by LordDeatHunter.
the class WaystoneScrollItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
NbtCompound tag = stack.getNbt();
if (tag == null || !tag.contains("waystones")) {
return TypedActionResult.fail(stack);
}
NbtList list = tag.getList("waystones", 8);
int learned = 0;
HashSet<String> toLearn = new HashSet<>();
for (int i = 0; i < list.size(); ++i) {
String hash = list.getString(i);
if (Waystones.WAYSTONE_STORAGE != null && Waystones.WAYSTONE_STORAGE.containsHash(hash) && !((PlayerEntityMixinAccess) user).hasDiscoveredWaystone(hash)) {
var waystone = Waystones.WAYSTONE_STORAGE.getWaystoneEntity(hash);
if (waystone.getOwner() == null) {
waystone.setOwner(user);
}
toLearn.add(hash);
++learned;
}
}
Text text;
if (learned > 0) {
if (learned > 1) {
text = new TranslatableText("waystones.learned.multiple", new LiteralText(String.valueOf(learned)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.learned.multiple.arg_color").getString()))));
} else {
text = new TranslatableText("waystones.learned.single");
}
((PlayerEntityMixinAccess) user).discoverWaystones(toLearn);
if (!user.isCreative()) {
stack.decrement(1);
}
} else {
text = new TranslatableText("waystones.learned.none");
stack.setNbt(null);
}
if (!world.isClient) {
user.sendMessage(text, false);
}
if (stack.isEmpty()) {
user.setStackInHand(hand, ItemStack.EMPTY);
}
stack = user.getStackInHand(hand);
return TypedActionResult.success(stack, world.isClient());
}
use of net.minecraft.text.Text in project BleachHack by BleachDrinker420.
the class CmdCustomSign method onCommand.
@Override
public void onCommand(String alias, String[] args) {
if (args.length == 0) {
throw new CmdSyntaxException();
}
NoRender noRender = ModuleManager.getModule(NoRender.class);
if (args[0].equalsIgnoreCase("list")) {
String s = "Sign Text:";
for (Text text : noRender.signText) {
s += "\n\u00a77" + text.getString();
}
BleachLogger.info(s);
return;
}
String arg = args[0].toLowerCase(Locale.ENGLISH);
boolean all = arg.equals("all");
Text text = new LiteralText(String.join(" ", Arrays.asList(args).subList(1, args.length)));
boolean[] linesToChange = new boolean[] { arg.equals("line1") || all, arg.equals("line2") || all, arg.equals("line3") || all, arg.equals("line4") || all };
JsonArray json = new JsonArray();
for (int i = 0; i < 4; i++) {
if (linesToChange[i]) {
noRender.signText[i] = text;
json.add(noRender.signText[i].getString());
}
}
BleachFileHelper.saveMiscSetting("customSignText", json);
BleachLogger.info("Changed sign text!");
}
use of net.minecraft.text.Text in project BleachHack by BleachDrinker420.
the class CmdNBT method onCommand.
@Override
public void onCommand(String alias, String[] args) throws Exception {
if (args.length == 0) {
throw new CmdSyntaxException();
}
if (args[0].equalsIgnoreCase("get")) {
if (args.length != 2) {
throw new CmdSyntaxException();
}
NbtCompound nbt = getNbt(args[1]);
if (nbt != null) {
String stringNbt = NbtHelper.toPrettyPrintedString(nbt);
Text copy = new LiteralText("\u00a7e\u00a7l<COPY>").styled(s -> s.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stringNbt)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the nbt of this item to your clipboard"))));
BleachLogger.info(new LiteralText("\u00a76\u00a7lNBT: ").append(copy).append("\u00a76\n" + stringNbt));
}
} else if (args[0].equalsIgnoreCase("copy")) {
if (args.length != 2) {
throw new CmdSyntaxException();
}
NbtCompound nbt = getNbt(args[1]);
if (nbt != null) {
mc.keyboard.setClipboard(nbt.toString());
BleachLogger.info("\u00a76Copied\n\u00a7f" + NbtHelper.toPrettyPrintedString(nbt) + "\n\u00a76to clipboard.");
}
} else if (args[0].equalsIgnoreCase("set")) {
if (!mc.interactionManager.getCurrentGameMode().isCreative()) {
BleachLogger.error("You must be in creative mode to set NBT!");
return;
}
if (args.length < 2) {
throw new CmdSyntaxException();
}
ItemStack item = mc.player.getMainHandStack();
item.setNbt(StringNbtReader.parse(StringUtils.join(ArrayUtils.subarray(args, 1, args.length), ' ')));
BleachLogger.info("\u00a76Set NBT of " + item.getItem().getName().getString() + " to\n" + BleachJsonHelper.formatJson(item.getNbt().toString()));
} else if (args[0].equalsIgnoreCase("wipe")) {
if (!mc.interactionManager.getCurrentGameMode().isCreative()) {
BleachLogger.error("You must be in creative mode to wipe NBT!");
return;
}
mc.player.getMainHandStack().setNbt(new NbtCompound());
} else {
throw new CmdSyntaxException();
}
}
use of net.minecraft.text.Text in project Moonfix by Kingdom-of-Moon.
the class InputEntry method render.
@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
// text
TextRenderer textRenderer = client.textRenderer;
int posY = y + entryHeight / 2;
if (this.field.isFocused() && this.inputType == ConfigManager.InputType.HEX_COLOR) {
Text text = new LiteralText("").append(this.title).append(" (").append(this.field.getText()).append(")");
textRenderer.draw(matrices, text, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
} else {
textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
}
// reset button
this.reset.x = x + 260;
this.reset.y = y;
this.reset.active = !this.config.configValue.equals(this.config.defaultValue + "");
this.reset.render(matrices, mouseX, mouseY, tickDelta);
// text field
this.field.y = y + 2;
// focused size
int extraWidth = 0;
if (this.field.isFocused() && !field.getText().isBlank())
extraWidth = MathHelper.clamp(textRenderer.getWidth(field.getText()) - 50, 0, 177);
// set size
this.field.setWidth(76 + extraWidth);
this.field.x = x + 177 - extraWidth;
// set text color
int color = 0xFFFFFF;
if (!this.config.configValue.equals(this.initValue + ""))
if (this.inputType == ConfigManager.InputType.HEX_COLOR)
color = hexToInt(this.field.getText());
else
color = ConfigManager.ACCENT_COLOR.apply(Style.EMPTY).getColor().getRgb();
if (!inputType.validator.test(field.getText())) {
color = 0xFF5555;
}
this.field.setEditableColor(color);
// render
this.field.render(matrices, mouseX, mouseY, tickDelta);
}
use of net.minecraft.text.Text in project Moonfix by Kingdom-of-Moon.
the class SignBlockEntityRendererMixin method renderModel.
// sign scaling
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;II)V", shift = At.Shift.BEFORE), method = "render(Lnet/minecraft/block/entity/SignBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", locals = LocalCapture.CAPTURE_FAILHARD)
private void renderModel(SignBlockEntity signBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci, BlockState blockState, float g, SignType signType, SignBlockEntityRenderer.SignModel signModel, SpriteIdentifier h, VertexConsumer vertexConsumer) {
if (!(boolean) Config.SIGN_SCALE.value)
return;
// text len
float max = 90;
OrderedText[] texts = signBlockEntity.updateSign(MinecraftClient.getInstance().shouldFilterText(), Text::asOrderedText);
for (OrderedText text : texts) max = Math.max(this.textRenderer.getWidth(text), max);
max = (max + 6) / 96f;
if (max <= 1.01f)
return;
// stick
boolean wasStickVisible = signModel.stick.visible;
signModel.stick.visible = false;
// scale
matrixStack.push();
matrixStack.scale(max, 1.01f, 1.01f);
// render
signModel.root.render(matrixStack, vertexConsumer, i, j);
matrixStack.pop();
signModel.stick.visible = wasStickVisible;
}
Aggregations