Schedule things by minecraft days

So I’m trying to create a method that’ll permit for specific things to occure on specific days in minecraft.

The logic i’m thinking is a way to take the end of the day 24000, and add the new time from the next day (exp: 01000 = 25000)

And just keep adding to this tick number till it reaches a certain point like say 60000 then set it back to 0.

then taking the tick variable adding in different class calls to activate certain events on certain days…

right now i’m using the WorldProperties.GetTime() event within a EntitySpawnEvent…however when ever I set the time…say to the next day at 0 the counter in this class
doesn’t add it to the existing tick counter but rather sets it back to 0…please help.

There are several things wrong with this code.
int a = 0000; - One zero does the same thing (and prevents you from mistakenly entering an octal literal).
long b = Sponge.getGame().getServer().getWorld("world").get().getProperties().getWorldTime(); - There is not always a world named world. There’s yet another method in Server called getDefaultWorld() for this very reason.
if(a < b){ - The world time cannot be less than zero. Therefore, this code will always return true and is thus unnecessary.
long c =+ b; I… legitimately did not know that this was compilable code. It’s also completely pointless, as c is now equal to b and therefore isn’t needed, replaceable just by b.

And finally, as the answer to your problem,
int a = 0000;
Every time the event is run, you set this counter to 0. It’s never persisted outside the single method call. The ‘counter’ itself is a local variable, i.e. not any sort of storage lasting longer than the call.

I’ve said it before and I’ll say it again. You should endeavor to learn more basic Java before attempting to learn a high-level API like Sponge, because exactly one of your questions so far has been a Sponge API question, and the rest, including this one, is a question about Java syntax, the Java standard library, and, in fact, the basic concepts of programming flow.

3 Likes

Thank you for the info on the Default world. I’ve fixed that. If anyone has some suggestions besides learning Java…because that’s not the point. One is always constantly learning Java as Java is constantly being updated. Please let me know. I’ve tried For loops and While loops. I just need to be able to grab a continous tick counter. from there I would be able to make events. that’s the simplest Meaning. @pie_flavor thank you for your advise so far. Please let me know if you figure a way to keep a continuous counter. thank you. Anyone else please help.

This is not a question of Java being updated. I would not push this point strongly if you were, say, unfamiliar with a truly new feature and its interactions with the Sponge API, such as streams or lambdas. But there is a general cut-off point between where you can struggle through it and where you need to go back and learn more, and you’re well below that line. If you have a method, and the first line sets a local variable to 0, and you are asking why each call to the method sets the variable to 0, then you would benefit greatly from a programming class.

meh, thank you for your honest oppinon. However I will not make you answer any of my questions as you feel they are below you. I admit that there are things I can learn. And I’m not to obstinate to admit that. But a forum is a place to ask questions/ideas. If you feel that my questions are below you please do not waste your time by bashing me. Just simply move on, thank you and I hope someone will help me with figuring some of this out.

Sorry I am not sure if I understand what you want to do… so I’m sorry if I misunderstood.

So you need the scheduler and a scheduled task. You may want to read this: https://docs.spongepowered.org/master/en/plugin/scheduler.html

Add a new listener for the GameStartedServerEvent event. That event is called after the server has been completely loaded. On that, check what’s the current world time and how many ticks left until your your custom things have to happen, and then schedule your code. This is an example:

Sponge.getScheduler().createTaskBuilder().execute(task -> {
   // insert code here for your custom things to happen
}).delayTicks(numberOfTicksUntilYourCustomThings).intervalTicks(24000).submit(this);

That is being called every Minecraft day at the same day. If you want it to be every 60000 ticks, then change 24000 to 60000

I hope this helps

K…so here’s what i’ve come up with so far.

  public static int days = 6;
public static int getCustDays(){
  return days;
}

@Listener
public void test(GenerateChunkEvent event){
  long currentTime = Sponge.getGame().getServer().getDefaultWorld().get().getWorldTime();
  long base = 0100;
  if (currentTime == base){
	  HOB.days = HOB.days + 1;
	  Sponge.getGame().getServer().getBroadcastChannel().send(Text.of(days));
  }else{
	  return;
  }
 }

the problem…is it’s not firing when the if statement is true…which means it’s not adding days to it…

Like I told you before, don’t use extra zeros. 0100 is an octal literal. What you’re saying is long base = 64. Remove the leading 0 from 0100 to make it a literal 100.
And as I told you in the other question about world time, world time is not a 0-2399 number - it doesn’t reset to 0 at the end of a day, it just keeps going. So use Sponge.getGame().getServer().getDefaultWorld().get().getWorldTime() % 24000.
Props to you for figuring out fields.

5 Likes