#how can i make the mouse become centered and not able to be moved by the player

223 messages ยท Page 1 of 1 (latest)

cursive wave
#

title

torn frigate
# cursive wave title

If you mean inside a Screen, I think calling this method inside renderBackground or something that ticks should work...

    double x = client.getWindow().getWidth() / 2;
    double y = client.getWindow().getHeight() / 2;
    InputUtil.setCursorParameters(client.getWindow().getHandle(), InputUtil.GLFW_CURSOR_NORMAL, x, y);
}```
molten stream
cursive wave
#

i want to make it so when i pres a button i look at an exact center

tired orbit
#

there is no exact center.

cursive wave
#

axis*

#

the center of the screen

#

like straight forward

tired orbit
#

so forward, and straight south

cursive wave
#

forward in whatever direction trhe player is facing

tired orbit
#

because 0 x axis is south.

cursive wave
#

how tho

tired orbit
#

so you want to lock pitch and set yaw to 45ยฐ

cursive wave
#

how since idk what is the pitch

tired orbit
#

so you probably want to @WrapWithCondition Mouse#updateMouse at changeLookDirection

#

so you can cancel the players rotation changing with mouse move

#

and use Entity#setYaw

#

to set the yaw

tired orbit
#

because inject is more brittle

cursive wave
#

!!mixin warpwithcondition

jade plumeBOT
#

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM written by Mumfrey, primarily used in Fabric mods for modifying existing game code.

Mixin Wiki: https://github.com/SpongePowered/Mixin/wiki
Javadoc: http://jenkins.liteloader.com/view/Other/job/Mixin/javadoc/index.html
Fabric Wiki tutorial: https://fabricmc.net/wiki/tutorial:mixin_introduction
Cheatsheet: https://github.com/2xsaiko/mixin-cheatsheet/blob/master/README.md

See also:
!!mcdev - An IntelliJ plugin which adds useful helpers and inspections for using mixin
!!spongecord - The Sponge Discord server, with official support for Mixin in the #mixin channel

cursive wave
tired orbit
cursive wave
cursive wave
tired orbit
#

send picture

#

what version are you on?

cursive wave
tired orbit
#

it's right there.

#

this.client.player.changeLookDirection

#

3rd line up

#

you could do something like this if you wanted to lock each direction independantly

#
@Mixin(Mouse.class)
public class MouseMixin implements LockableMouse {
    @Unique
    boolean isYLocked = false;
    @Unique
    boolean isXLocked = false;
    @WrapOperation(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;changeLookDirection(DD)V"))
    private void updateMouse(ClientPlayerEntity instance, double deltaX, double deltaY, Operation<Void> original) {
        if (isYLocked) {
            deltaY = 0;
        }
        if (isXLocked) {
            deltaX = 0;
        }
        original.call(instance, deltaX, deltaY);
    }

    @Override
    public void yourModId$lockX() {
        isXLocked = true;
    }

    @Override
    public void yourModId$unlockX() {
        isXLocked = false;
    }

    @Override
    public void yourModId$lockY() {
        isYLocked = true;
    }

    @Override
    public void yourModId$unlockY() {
        isYLocked = false;
    }
}
tired orbit
#

Lockable Mouse does not exist, you will have to create it

cursive wave
#

why dont i just put the methods

tired orbit
#

beacuse if there is no interface, there is no way to call the methods

#

you cannot call methods directly on a mixin class

cursive wave
#

so where do i change the y axis

#

delta y?

tired orbit
#

no.

#

you don't need a mixin for that.

#

the mixin just locks the movement

#

then you call the lock and unlock whereever you need to ie when your keybind is pressed.

tired orbit
cursive wave
#

;-;

tired orbit
#

the mouse movement?

cursive wave
tired orbit
#

thats what the post title said, so I assumed that was what you needed, in the future, new post for new topic.

tired orbit
tired orbit
#

so set it to the angle in the center

cursive wave
#

on*

tired orbit
#

hmm?

cursive wave
#

what does @Unique do

tired orbit
tired orbit
cursive wave
tired orbit
#
ClientTickEvents.END_CLIENT_TICK.register(() -> {
 if (myBool) {
  // lock
} else {
  // unlock
}
}); 
tired orbit
#

seperation of concerns

#

In computer science, separation of concerns (sometimes abbreviated as SoC) is a design principle for separating a computer program into distinct sections.
...
Separation of concerns results in more degrees of freedom for some aspect of the program's design, deployment, or usage. Common among these is increased freedom for simplification and maintenance of code.
...
Wikipedia

In computer science, separation of concerns (sometimes abbreviated as SoC) is a design principle for separating a computer program into distinct sections. Each section addresses a separate concern, a set of information that affects the code of a computer program. A concern can be as general as "the details of the hardware for an application", or...

cursive wave
tired orbit
#

I would not do it like that, it might work.

cursive wave
tired orbit
#

yes.

cursive wave
#

yes

tired orbit
#

so you cast the targeted class (Mouse) to the interface your mixin implements

cursive wave
tired orbit
#

((InterfaceName) object).method()

cursive wave
tired orbit
#

what is Stop?

#

if you allready have a way to lock the mouse, you don;t need to use my mixin.

#

just use the Entity#setYaw method to set the yaw of the entity to whatever you want?

tired orbit
cursive wave
#

since the interface that i craeted interferces with it

tired orbit
#

you got rid of the other lock thing? cause the mouse.lockCursor is not erroring.

cursive wave
#

what other lockt hing

#

wanna get on vc so i can ss?

tired orbit
#

not till 3 hours from now.

cursive wave
#

dang ok

tired orbit
cursive wave
tired orbit
#

ah

cursive wave
#

like u know when u press t ur cursor aappears

#

i want that to happen

tired orbit
#

so you want unlockCursor?

#

i think.

#
((LockableMouse) mouse).auto$lockY();
((LockableMouse) mouse).auto$lock();
cursive wave
#

also how can i unlock the cursor and make it unable to lock it

tired orbit
#

unable to lock it?

cursive wave
tired orbit
#

why do you need to?

cursive wave
#

ill try that first and tell u

tired orbit
#

k

cursive wave
# tired orbit k

so the mouse is locked i cant move it but the cursor doesnt get unlocked and i still have to center it

tired orbit
#

let me try.

#

i stand corrected, pitch is up and down

#
                    client.mouse.unlockCursor();
                    client.player.setPitch(0);
#

worked just fine for me

cursive wave
#

maybe it is the way that am stopping it?

forest lily
#

This is a very confusing thread

#

@tired orbit your nickname ideally describes what I thought when I saw this thread

tired orbit
#

there was a reason It became that

cursive wave
tired orbit
#

and at this point, standpoint is one of them

forest lily
#

I'm mostly concerned about the way Standpoint formats their code

tired orbit
#

without seeing and running all of your code, or writting the whole thing from scratch myself, not really, because all of your code is very Hectic...

forest lily
#

@cursive wave do you know java

cursive wave
tired orbit
#

he will say yes

forest lily
cursive wave
#

ik everything abt java

tired orbit
#

I on the other hand, still have lots to learn about java...

forest lily
# cursive wave ik everything abt java

okay, can you explain what this does? It's a little test, very simple function

public static <T> T unknown(List<T> a, int b, T c) {
    if(a.size() > b && b > 0) {
        return a.get(b);
    }
    return c;
}```
#

It can be described in 3 words btw

tired orbit
#

chatgpt failed that... ๐Ÿ’€

forest lily
#

it's a function I used in a program today btw lol

tired orbit
#

really?

forest lily
#

Yeah

tired orbit
#

then you have a logic error

forest lily
#

I don't exactly remember how it looked, but it did work

cursive wave
# forest lily okay, can you explain what this does? It's a little test, very simple function `...

your creating a method that has a generic and it is called unknown and u made a list of a that can take pretty much any generic and u have a b which is a number and c which is a generic and ur telling it if the size of the amount of things inside of a is larger than whatever b is worth say a has 5 things and b is worth 6 and also b needs to be small than 0 so it won't be possibe it will return the generic c which is currently undefinded

tired orbit
#

b < 0 && b < a.size()

forest lily
#

lmao

tired orbit
#

oops

#

!!learnjava

jade plumeBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .

forest lily
#

I always struggle at brain logic

#

@tired orbit but could you describe it in 3 words?

tired orbit
#

get or default?

forest lily
#

Exactly

#

It was what I was aiming for but my poor brain failed with logic, as usual

tired orbit
#

/\ that

#

anyway,

cursive wave
#

i was debugging this

#

not the edited one

forest lily
#

I could probably even ask somebody for the error there and they would immediately know what that is and where the mistake was

tired orbit
#

i was going to say (it returns c)

#

then i saw what he was going for

cursive wave
tired orbit
#

wkyk.

cursive wave
#

am not a native

forest lily
tired orbit
#

it's just bad code organization that makes us think you don't

#

we know you know

cursive wave
tired orbit
#

and you're new

#

so thats alright for now.

cursive wave
#

idk why the unlockcursor doesnt work

#

and the setpitch does nothing

tired orbit
#

try entering the pause menu

cursive wave
tired orbit
#

does that still work?

cursive wave
tired orbit
#

because that uses the same method

#

i'm from rust forgive me

cursive wave
#

i have this mixin code as well

#

so if iam tabbed out it doesnt go to pause screen

#

idk if that is relavent

tired orbit
#

idk

cursive wave
#

when am in the pause menu i cant press any buttons while its triggered

tired orbit
#

i'll be free in an hour and a half to look at it.

cursive wave
#

the only way i got back to game is when i pressed esc

tired orbit
#
public class YourModClient implements ClientModInitializer {
    boolean isLocked = true;
    KeyBinding keyBinding = new KeyBinding("key.utilcommands.example_key", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_G, "category.utilcommands.example_category");
    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
        // This entrypoint is suitable for setting up client-specific logic, such as rendering.
    }
    private void onTick(MinecraftClient client) {
        while (keyBinding.wasPressed()) {
            if (isLocked)  {
                assert client.player != null;
                client.player.sendMessage(Text.literal("Unlocking Mouse"), true);
                client.player.setPitch(0);
                ((LockableMouse) client.mouse).yourModId$lock();
                client.mouse.unlockCursor();
                isLocked = false;
            } else {
                assert client.player != null;
                client.player.sendMessage(Text.literal("Locking Mouse"), true);
                ((LockableMouse) client.mouse).yourModId$unlock();
                client.mouse.lockCursor();
                isLocked = true;
            }
        }
    }
}
tired orbit
#

Something like that...

cursive wave
#

so after tweaking it to this now it works fine

#

BUY

#

BUT*

#

nvm ill try to figure it out

cursive wave
#

but is there a way to make the player keep on just kinda attacking without having a target enity

#

cuz tht just crashes the game

tired orbit
#

why don't you try pressing the attack key programaticlly instead?

tired orbit
tired orbit
#

no

cursive wave
#

that doesnt work so i believe there is another way

tired orbit
#

GameOptions#attackKey

cursive wave
#

what are these #

cursive wave
tired orbit
#

it means you call it on an instance of the class.

tired orbit
cursive wave
cursive wave
tired orbit
tired orbit