#I don`t know how to add a note to minecraft 1 20 1.
207 messages · Page 1 of 1 (latest)
Ok, thanks. How I can do background transparent?
...you don't draw a background?
Thnx
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.
What doesn't work?
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
When you are registrering the item, replace Item with StrangeNote
There or where?
new Item
new Item where?
new Item
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
That is becuase you are opening the screen on the logical server, which is invalid. Only open screens if world.isClient == true
Why simply calling setScreen in use is not allowed: https://discord.com/channels/507304429255393322/1280577890299416730
Ok, i must use this, right?
#1280577890299416730 message
No...
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
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()
?
Call NoteOpener.setNoteOpener(() -> MinecraftClient.getInstance().setScreen(...)); in ClientModInitializer.
Call NoteOpener.getNoteOpener().openNoteScreen() to open the screen.
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
I think too
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.
And it isn`t broke if I join to dedicated server or join to other peoples with mod?
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();
as long as you don't import client-only classes from non-client-only-classes it will work
Ok, there is only one problem right now
it's probably setScreen
So my guess was correct. Perfect
Oh, and in parameter of setScreen must be NoteInterface, NoteOpener or something else?
your screen
remember new when calling the constructor
I starting minecraft. Maybe now it was works
On 0.11 am
Mmm.
Crash on first RMB click
interesting
Maybe problem in this&
lol
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")
translation.key is like en_us, ru_ru?
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
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
It can be whatever lowercase letters separated with dot. There are some best-practices tho. I would put "screen.yourmodname.title": "The title"
I tried with literal(), It`s not help
can you post the log file?
How I can get it from IDEA?
run/logs/latest.log
You are calling the openNoteScreen function from the server thread. Remember, you must check if world.isClient == true before trying to open the screen.
I do this and note not working now. Not work - no crash
you are returning early if world.isClient
In NoteOpener?
in the image you sent
Upper? yes, when i copy this code from guide it`s been here. bottom - i tested a minute ago
I dont know
don't copy code if you don't know why
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
no problem, I'll answer when I can
Remember, you must check if world.isClient == true before trying to open the screen.
Ok, thank you very much. Even my teachers couldn't stand me in this situation.
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)
you can't just return null
But what I gonna return, and where?
It looked good before with TypedActionResult.success(...)
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?
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")
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?
the constant is the location/identifier
And I gonna put them into new Identifier path parameter?
@cunning otter how I can render picture in render class?
DrawContext#drawTexture
@cunning otter Maybe this?
no, is there not a drawTexture?
you are given a drawContext in render
@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
Because I think, yes
@cunning otter What are you say about my butiful code)
what?
.
DrawContext context
draw things
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
context.drawTexture?
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);
}
texture is the path of the png, u v is where from the texture to draw from, u=x, v=y
Like there?
the u,v in the image is correct
Or uv - is point on texture, and x, y - is point on canvas*
exactly
this
@cunning otter What format of pass I gonna use?
Oh
It looks like something not too bad?
It`s not work(
this, to not instantiate a new Identifier every frame
width, height 1???
it's 1 px wide
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?
are you debugging and not running?
Whats wrong with my IDE?
I think you must be debugging
Oh, yeah
I think too now
No
It isnt works
🤷♂️
idk, just restart the game, no big deal
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
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
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?
no
: (
It was magic discord thelepathy?
stop pinging me
Ok, sorry. I wasn`t ping you anymore
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
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
Do you use this method?
yes
What did you pass in?
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);
lemme draw in paint
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
I have this result. P.s. I know how to fix y-axis
@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👉 👈