-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added notify function to pocket api #2047
Added notify function to pocket api #2047
Conversation
665ebfb
to
840da67
Compare
… then return to previous color, and beeps 3 times, only to the player that is holding it and broadcast if no player is holding it
840da67
to
c10f8cf
Compare
I do believe that pockets not in player inventory are supposed to shut down, is no-player logic supposed to be some kind of future proofing? |
I forgot about that haha. That is completely true, it's fun to make it notify and throw it, but kinda useless yeah, I can remove it |
for (int i = 0; i < 3; i++) { | ||
beep(); | ||
pocket.setLight(0x00CC00); | ||
Thread.sleep(250); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of block the thread, can you use timer/ticker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just do this at client side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I know the PR is closed, but I'm curious on how to do this, can you give me some help, or forward me to some documentation/tutorial? I'm completely new to minecraft modding, though I have some years of experience with java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basiclly what I mean is async programming. You should register a listener when tick executes, and do actions at specific time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know how to do that with java standard timers, I'm asking about the forge standard way, both for async and the clientside, how can I make it run client side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I'd normally do instead is you have some state on the pocket computer (either client-side or server side) which counts the number of ticks since the last "notify" call, and then drive the light colour based on that.
So something like this:
class PocketComputer { // PocketServerComputer on the server, or PocketComputerData on the client.
private int notifyTimer = 0;
public void notify() {
notifyTimer = 60;
}
public void update() {
if(notifyTimer > 0) notifyTimer--;
}
public int getLightColour() {
var timer = notifyTimer / 12;
return timer % 2 == 0 ? lightColour : 0x00CC00;
}
}
The update()
then would get called every tick (via Forge's TickEvent.ServerTickEvent
/TickEvent.ClientTickEvent
).
In order to do this on the client, you'd need to send a custom packet from the server to the client. This is a bit of a faff, so I probably wouldn't bother, and just do this server-side.
This would require making the original pocket.notify()
method non-blocking, but I think that's fine.
Thank you for looking into this! The main thing stalling #1148 right now is that I'm not sure whether I actually want this feature (and if so, what the interface/functionality should be). I suspect the answer here is to go the #1406 route and add multiple upgrade slots, though that's blocked on a new Minecraft version. Given the whole uncertainty around this, I'm afraid I'm going to close this. |
Out of curiosity, why is it blocked on a new mc version? Breaking change? |
Yep! This'll require some changes to the Java API. |
pocket.notify() makes the led blink green and then return to previous color, and beeps 3 times, only to the player that is holding it and broadcast if no player is holding it
Possible solution for #1148