#how can i make the mouse become centered and not able to be moved by the player
223 messages ยท Page 1 of 1 (latest)
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);
}```
i meanlike the cursor ingame
it doesnt work
What exactly do you mean with ingame?
u know that u can look around ingame?
i want to make it so when i pres a button i look at an exact center
there is no exact center.
like 45 degrees up and 0 in the x acis
axis*
the center of the screen
like straight forward
so forward, and straight south
why south
forward in whatever direction trhe player is facing
because 0 x axis is south.
so you want to lock pitch and set yaw to 45ยฐ
yes
how since idk what is the pitch
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
whycant i just inject
because inject is more brittle
!!mixin warpwithcondition
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
do u have the wiki for @wrapwithcondition
what method do i wrap
.
there is no changelook direction in updatemouse
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;
}
}
Lockable Mouse does not exist, you will have to create it
why do i have to make an interface
why dont i just put the methods
beacuse if there is no interface, there is no way to call the methods
you cannot call methods directly on a mixin class
alr
so where do i change the y axis
delta y?
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.
.
i already have smt that locks the movement ;-;
;-;
the mouse movement?
yes
thats what the post title said, so I assumed that was what you needed, in the future, new post for new topic.
that is the function to set y rotation
centered
so set it to the angle in the center
where do i put the bolean that checks if the button is ob
on*
hmm?
what do you mean
marks it as unique, tells mixin that your not trying to modify something that already exists, but create something new
so i just can replace them with the trigger boolean right?
ClientTickEvents.END_CLIENT_TICK.register(() -> {
if (myBool) {
// lock
} else {
// unlock
}
});
.
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...
like thois
I would not do it like that, it might work.
/\
the methods are uknown ioutside the mixin class
yes.
yes
so you cast the targeted class (Mouse) to the interface your mixin implements
what does cast mean ๐
((InterfaceName) object).method()
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?
.
i cant cntrl z back to my old code
since the interface that i craeted interferces with it
you got rid of the other lock thing? cause the mouse.lockCursor is not erroring.
not till 3 hours from now.
dang ok
the one above in this screenshot
the lock cursor is bc i want it to also remove the cursor from the minecraft
ah
so you want unlockCursor?
i think.
((LockableMouse) mouse).auto$lockY();
((LockableMouse) mouse).auto$lock();
this is my old code
also how can i unlock the cursor and make it unable to lock it
unable to lock it?
why do you need to?
ill try that first and tell u
k
so the mouse is locked i cant move it but the cursor doesnt get unlocked and i still have to center it
let me try.
i stand corrected, pitch is up and down
client.mouse.unlockCursor();
client.player.setPitch(0);
worked just fine for me
i doesnt make the cursor appear nor does it go to the center
maybe it is the way that am stopping it?
This is a very confusing thread
@tired orbit your nickname ideally describes what I thought when I saw this thread
there was a reason It became that
๐
can u help me now tho ๐
and at this point, standpoint is one of them
I'm mostly concerned about the way Standpoint formats their code
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...
@cursive wave do you know java
Seconed
yes
he will say yes
to what degree
ik everything abt java
I on the other hand, still have lots to learn about 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
chatgpt failed that... ๐
it's a function I used in a program today btw lol
really?
Yeah
then you have a logic error
I don't exactly remember how it looked, but it did work
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
b < 0 && b < a.size()
lmao
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 .
get or default?
i said that in a more complex way
i was debugging this
not the edited one
I could probably even ask somebody for the error there and they would immediately know what that is and where the mistake was
wkyk.
google.com it maybe?
alr
alr
idk why the unlockcursor doesnt work
and the setpitch does nothing
try entering the pause menu
why?
does that still work?
sec
dw i like calling it function anyway
i have this mixin code as well
so if iam tabbed out it doesnt go to pause screen
idk if that is relavent
idk
when am in the pause menu i cant press any buttons while its triggered
i'll be free in an hour and a half to look at it.
the only way i got back to game is when i pressed esc
alr
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;
}
}
}
}
what does assert do
will that work
Something like that...
so after tweaking it to this now it works fine
BUY
BUT*
nvm ill try to figure it out
i figured the part i needed to figure out
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
why don't you try pressing the attack key programaticlly instead?
.
ill test
how ๐
no
that doesnt work so i believe there is another way
GameOptions#attackKey
what are these #
can u vc now?
it means you call it on an instance of the class.
when i get home yes
how were u even coding outside ur house
how do i register the game options
linkie, yarn wiki, and a text editor
.
you don't