#I don`t know how to add a note to minecraft 1 20 1.

207 messages · Page 1 of 1 (latest)

sand depot
#

I wanna do item, that shows a picture on the screen, when I click RMB. It must look like on pinned picture.

cunning otter
sand depot
#

Ok, thanks. How I can do background transparent?

cunning otter
#

...you don't draw a background?

sand depot
#

Thnx

sand depot
#

Okay, @cunning otter, I don`t know why it isnt works and how it must works. Maybe you can tell me how works use() event? Sorry if I too dumb, I m just beginner.

cunning otter
#

What doesn't work?

sand depot
#

I have this code

    public StrangeNote (Settings settings) {
        super(settings);
    }

    @Override
    public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
        if (world.isClient) {
            return TypedActionResult.pass(user.getStackInHand(hand));
    }
        MinecraftClient.getInstance().setScreen(
                new NoteInterface(Text.empty())
        );
        return TypedActionResult.success(user.getStackInHand(hand));
    }
}```
#

But "StrangeNote" in class and constructor is grey

cunning otter
#

When you are registrering the item, replace Item with StrangeNote

sand depot
#

There or where?

cunning otter
#

new Item

sand depot
#

new Item where?

cunning otter
#

new Item

sand depot
#

public static final Item STRANGE_NOTE = regItem("strange_note",** new StrangeNote**(new FabricItemSettings().maxCount(1)));

#

Like this?

#

I open menu (cursor been on the screen center), close on ESC, open again and game crashes with this error

#

@cunning otter
I see this
Caused by: java.lang.IllegalStateException: [fabric-screen-api-v1] The current screen (danilon4ig.infcraft.NoteInterface) has not been correctly initialised, please send this crash log to the mod author. This is usually caused by calling setScreen on the wrong thread.
I open menu (cursor been on the screen center), close on ESC, open again and game crashes with this error

cunning otter
#

That is becuase you are opening the screen on the logical server, which is invalid. Only open screens if world.isClient == true

sand depot
#

Ok, i must use this, right?
#1280577890299416730 message

cunning otter
#

yes

#

do you know why?

sand depot
#

No...

cunning otter
#

it's because Screen, MinecraftClient and more classes are only present on the client

#

if you try using them on the server, the server will crash

#

This way, all the code that uses those classes, are running only on the client thread

sand depot
#

Ok, maybe I not that much dumb

#

I understood this

#

But where I must place this
somewhere during client initialization:
NoteOpener.setNoteOpener(() -> MinecraftClient.getInstance().setScreen(...));
then call as NoteOpener.getNoteOpener().openNoteScreen()

#

?

cunning otter
#

Call NoteOpener.setNoteOpener(() -> MinecraftClient.getInstance().setScreen(...)); in ClientModInitializer.
Call NoteOpener.getNoteOpener().openNoteScreen() to open the screen.

sand depot
#

Ok, one minute

#

I have few problems more

cunning otter
#

yeah I posted psuedo code, you should be able to figure out the types

#

I think you will have to make it a class instead of an interface

sand depot
#

I think too

cunning otter
#

The idea is that you write the openNoteScreen code on the client, using MinecraftClient, Screen etc and tell a common class, class that exists on logical server and client, to use that code.

sand depot
#

And it isn`t broke if I join to dedicated server or join to other peoples with mod?

cunning otter
#

simpler version:

public class NoteOpener {
  public static Runnable openNoteScreen;
}```
then on client:
```java
NoteOpener.openNoteScreen = () -> MinecraftClient.getInstance().openScreen(...);

then to open screen:

NoteOpener.openNoteScreen.run();
cunning otter
sand depot
#

Ok, there is only one problem right now

cunning otter
#

it's probably setScreen

sand depot
#

So my guess was correct. Perfect

#

Oh, and in parameter of setScreen must be NoteInterface, NoteOpener or something else?

cunning otter
#

your screen

sand depot
#

I tried to give parameter to constructor, but it still not work

cunning otter
#

remember new when calling the constructor

sand depot
#

I starting minecraft. Maybe now it was works

#

On 0.11 am

#

Mmm.

#

Crash on first RMB click

cunning otter
#

interesting

sand depot
#

Maybe problem in this&

cunning otter
#

lol

sand depot
#

What is Text.java?

#

In second line on screenshot

cunning otter
#

Any text you see in the game is represented with a Text. It's like a String but with color and such.

#

Text.literal("Your Title") or Text.translatable("title.translation.key")

sand depot
#

translation.key is like en_us, ru_ru?

cunning otter
#

it's the key to look for in en_us.json or ru_ru.json, depending on which language you set in game

#

this way you can translate the text without writing any code

sand depot
#

I understood... Yeah, i think yeah

#

On key I must write new key or key of my item?

#

I got crashes for

second
first
second
first
and more...

Opens of note

cunning otter
#

It can be whatever lowercase letters separated with dot. There are some best-practices tho. I would put "screen.yourmodname.title": "The title"

sand depot
#

I tried with literal(), It`s not help

cunning otter
#

can you post the log file?

sand depot
#

How I can get it from IDEA?

cunning otter
#

run/logs/latest.log

sand depot
cunning otter
#

You are calling the openNoteScreen function from the server thread. Remember, you must check if world.isClient == true before trying to open the screen.

sand depot
#

I do this and note not working now. Not work - no crash

cunning otter
#

you are returning early if world.isClient

sand depot
#

In NoteOpener?

cunning otter
#

in the image you sent

sand depot
cunning otter
#
if (world.isClient) {
  return ...;
}
#

why?

sand depot
#

I dont know

cunning otter
#

don't copy code if you don't know why

sand depot
#

I tried to read this on fabric wiki, but dont understood too

#

maybe we can try tomorrow? Because my timezone is GMT+4. What about ur timezone?

#

Just I wanna sleep in 1:00am

#

And I deleted this strange code

cunning otter
#

no problem, I'll answer when I can

#

Remember, you must check if world.isClient == true before trying to open the screen.

sand depot
#

Ok, thank you very much. Even my teachers couldn't stand me in this situation.

sand depot
#

Hello, @cunning otter, now I try this and minecraft crashes, but it was not Immediately, world save and only after this game crashes (about 3sec)

cunning otter
#

you can't just return null

sand depot
#

But what I gonna return, and where?

cunning otter
#

It looked good before with TypedActionResult.success(...)

sand depot
#

Ok, I add return TypedActionResult.success(user.getStackInHand(hand));

#

It returns completed action&

#

?

#

IT WORKS!!!

#

And I close it on esc

#

Okay, @cunning otter, can you say me how add a picture and text to the note, please?

cunning otter
#

Make a constant in your screen class holding the location of the texture. Then draw it in render

#

the location is in the form of an Identifier("<namepace>", "<location>") which means the texture is in assets/<namespace>/<location>, for example new Identifier(MOD_ID, "textures/gui/note.png")

sand depot
#

new Identifier(MOD_ID, "textures/gui/note.png") must be there? (bottom of screenshot) and what type of constant?

#

@cunning otter or I gonna do two double constants?

cunning otter
#

the constant is the location/identifier

sand depot
#

And I gonna put them into new Identifier path parameter?

#

@cunning otter how I can render picture in render class?

cunning otter
#

DrawContext#drawTexture

sand depot
#

@cunning otter Maybe this?

cunning otter
#

no, is there not a drawTexture?

sand depot
#

Alright, is there

#

@cunning otter But what I gonna give to drawContext?

cunning otter
#

you are given a drawContext in render

sand depot
#
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
    super.render(context, mouseX, mouseY, delta);
    new Identifier(MOD_ID, NOTE_BACKGROUND_CORDS);
    //DrawContext
}

It looks of my render method

sand depot
#

@cunning otter What are you say about my butiful code)

cunning otter
#

what?

cunning otter
#

DrawContext context

sand depot
#

yes, is there

#

But what I can do with this?

cunning otter
#

draw things

sand depot
#

I mean, I began to understand

#

But for now I dont understand

#

@cunning otter how I can realize that? I think in another method, but can`t guess how

cunning otter
#

context.drawTexture?

sand depot
#

Oh Jesus... I`m too dumb for this world

#

How I don`t guess for this

#

Ooookayy... @cunning otter What`s Identifier texture, int u and int v in this method?

public void drawTexture(Identifier texture, int x, int y, int u, int v, int width, int height) {
this.drawTexture(texture, x, y, 0, (float)u, (float)v, width, height, 256, 256);
}

cunning otter
#

texture is the path of the png, u v is where from the texture to draw from, u=x, v=y

sand depot
#

Like there?

cunning otter
#

the u,v in the image is correct

sand depot
#

Or uv - is point on texture, and x, y - is point on canvas*

cunning otter
#

exactly

sand depot
#

Yey!

#

I dont know... Why is red!?

sand depot
#

@cunning otter What format of pass I gonna use?

#

Oh

#

It looks like something not too bad?

#

It`s not work(

cunning otter
#

width, height 1???

#

it's 1 px wide

sand depot
#

It`s in px?

#

Oh...

#

I think it`s in % like 0.95 it 95%

#

And I understand now, its integer

#

If I press f3+T I reload mod?

cunning otter
#

no

#

press build

sand depot
#

This build?

#

@cunning otter and I can no restart the game, right?

cunning otter
#

or right click in the file you edited

sand depot
cunning otter
#

are you debugging and not running?

sand depot
#

Whats wrong with my IDE?

cunning otter
#

I think you must be debugging

sand depot
#

I think too now

#

No

#

It isnt works

cunning otter
#

🤷‍♂️

sand depot
#

Maybe this is my problem?

#

@cunning otter What do u think?

cunning otter
#

idk, just restart the game, no big deal

sand depot
#

Its true

#

mixin make possible no restart game? If yes - problem with mixin

#

Today I found this interesting thing, look. I think you like it

#

@cunning otter It works, And I need only setting up resolution

#

Ok

#

@cunning otter resolution is 3840, 1080

cunning otter
#

there is a method with x, y, u, v, width, height, i, j, where x y width height is where on the screen to draw, u v i j is where to sample the texture, i j = width height

sand depot
#

ok, one minute

#

now there not texture

#

context.drawTexture(new Identifier(MOD_ID, "textures/gui/notebg.png"), 1, 1, 1, 1, 1920, 1080, 1920, 1080);

#

@cunning otter Or it`s not in px?

#

@cunning otter Are u here?

cunning otter
#

no

sand depot
#

: (

sand depot
cunning otter
#

stop pinging me

sand depot
#

Ok, sorry. I wasn`t ping you anymore

sand depot
#

I have one good news and one bad
good - I found what I gonna do to no restart mincraft client
bad - message.txt

#

when i tried to start vm

#

Vm options:

-Dfabric.dli.config=D:\InfCraft@@0020b@@0020f4nS.gradle\loom-cache\launch.cfg
-Dfabric.dli.env=client
-Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient
-javaagent:"C:\Users\Админ.gradle\caches\modules-2\files-2.1\net.fabricmc\dev-launch-injector\0.2.1+build.8\da8bef7e6e2f952da707f282bdb46882a0fce5e3\dev-launch-injector-0.2.1+build.8.jar!\net\fabricmc\devlaunchinjector\Main.class"

#

I got this error

sand depot
#

Hello, Nate, can u help me? I can’t setting my drawTexture, because i see texture, but always it’s not resolution, what I need

#

I use drawTexture with u, v parameters

#

And I tried big count of combinations of parameters

sand depot
#

yes

cunning otter
#

What did you pass in?

sand depot
#

I tried big count of params

#

I made my texture resolution 703, 861

#

context.drawTexture(new Identifier(MOD_ID, "textures/gui/notebg.png"), 1, 1, 1, 1, 703, 861, 50, 50);

cunning otter
#

lemme draw in paint

cunning otter
sand depot
#

Hello again, I take small rest from small project and I can do this now

#

But it`s not enough, because it still looks rough

sand depot
#

@cunning otter I have the next idea! I wanna make fog from alpha minecraft event. Do you have ideas how to make it?
P.s. Sorry for pinging👉 👈