Skip to content
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

Closed

Conversation

IvoLeal72
Copy link
Contributor

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

@IvoLeal72 IvoLeal72 force-pushed the feature/pocket-notification branch from 665ebfb to 840da67 Compare January 3, 2025 17:05
… 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
@IvoLeal72 IvoLeal72 force-pushed the feature/pocket-notification branch from 840da67 to c10f8cf Compare January 3, 2025 17:05
@Wojbie
Copy link
Contributor

Wojbie commented Jan 3, 2025

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?

@IvoLeal72
Copy link
Contributor Author

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);
Copy link
Contributor

@zyxkad zyxkad Jan 3, 2025

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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.

@SquidDev SquidDev added enhancement An extension of a feature or a new feature. wontfix A bug which I won't fix or an enhancement which won't be implemented. area-Minecraft This affects CC's Minecraft-specific content. labels Jan 5, 2025
@SquidDev
Copy link
Member

SquidDev commented Jan 5, 2025

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.

@SquidDev SquidDev closed this Jan 5, 2025
@IvoLeal72
Copy link
Contributor Author

Out of curiosity, why is it blocked on a new mc version? Breaking change?

@SquidDev
Copy link
Member

SquidDev commented Jan 6, 2025

Out of curiosity, why is it blocked on a new mc version? Breaking changes?

Yep! This'll require some changes to the Java API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature. wontfix A bug which I won't fix or an enhancement which won't be implemented.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants