Skip to content

Commit d639f06

Browse files
Atilistcalmilamsy
authored andcommitted
Improved Object Creation and more Tests
CelestialEvent now has 1 Constructor and Methods for changing other Values. Fixed Falling Dimando being impossible to happen. Added Spinning Dimando and Burning Dimando.
1 parent c798dd1 commit d639f06

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/test/java/net/modificationstation/sltest/celestial/CelestialListener.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ public class CelestialListener {
1212

1313
public static CelestialEvent flyingDimando;
1414
public static CelestialEvent fallingDimando;
15+
public static CelestialEvent spinningDimando;
16+
public static CelestialEvent burningDimando;
1517

1618
@EventListener
1719
public void registerCelestialEvents(CelestialRegisterEvent event) {
1820
if (hasRegistered) return;
1921
hasRegistered = true;
2022
SLTest.LOGGER.info("Register celestial events for testing");
21-
flyingDimando = new CelestialEvent(2, "Flying Dimando");
22-
fallingDimando = new CelestialEvent(4, "Falling Dimando");
23+
flyingDimando = new CelestialEvent(4, "Flying Dimando");
24+
fallingDimando = new CelestialEvent(2, "Falling Dimando");
25+
spinningDimando = new CelestialEvent(4, "Spinning Dimando").setDayOffset(1);
26+
burningDimando = new CelestialEvent(2, "Burning Dimando").setDayOffset(1);
2327
flyingDimando.addIncompatibleEvent(fallingDimando);
2428
CelestialTimeManager.addMorningEvent(flyingDimando);
2529
CelestialTimeManager.addNoonEvent(fallingDimando);
30+
CelestialTimeManager.addEveningEvent(spinningDimando);
31+
CelestialTimeManager.addMidnightEvent(burningDimando);
2632
}
2733
}

station-world-events-v0/src/main/java/net/modificationstation/stationapi/api/celestial/CelestialEvent.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,33 @@
77
public class CelestialEvent {
88
private final String name;
99
private final int frequency;
10-
private final float chance;
11-
private final int dayLength;
12-
private final int dayOffset;
10+
private float chance = 1;
11+
private int dayLength = 24000;
12+
private int dayOffset = 0;
1313
private boolean active;
1414
private final List<CelestialEvent> incompatibleEvents = new LinkedList<>();
1515

16-
public CelestialEvent(int frequency, float chance, int dayLength, int dayOffset, String name) {
16+
public CelestialEvent(int frequency, String name) {
1717
this.frequency = frequency;
18-
this.chance = chance;
19-
this.dayLength = dayLength;
20-
this.dayOffset = dayOffset;
2118
this.name = name;
2219
}
2320

24-
public CelestialEvent(int frequency, float chance, int dayLength, String name) {
25-
this(frequency, chance, dayLength, 0, name);
21+
public CelestialEvent setChance(float chance) {
22+
this.chance = chance;
23+
return this;
2624
}
2725

28-
public CelestialEvent(int frequency, float chance, String name) {
29-
this(frequency, chance, 24000, name);
26+
public CelestialEvent setDayLength(int dayLength) {
27+
this.dayLength = dayLength;
28+
return this;
3029
}
3130

32-
public CelestialEvent(int frequency, String name) {
33-
this(frequency, 1, name);
31+
public CelestialEvent setDayOffset(int dayOffset) {
32+
this.dayOffset = dayOffset;
33+
return this;
3434
}
3535

3636
public boolean activateEvent(long worldTime, Random random) {
37-
System.out.println("Attempt activation for event " + name);
3837
if (active) {
3938
return true;
4039
}
@@ -47,11 +46,12 @@ public boolean activateEvent(long worldTime, Random random) {
4746
}
4847
long days = worldTime / dayLength + dayOffset;
4948
active = days % frequency == 0 && random.nextFloat() <= chance;
49+
if (active) System.out.println("Starting event " + name);
5050
return active;
5151
}
5252

5353
public void stopEvent() {
54-
System.out.println("Stopping event " + name);
54+
if (active) System.out.println("Stopping event " + name);
5555
active = false;
5656
}
5757

0 commit comments

Comments
 (0)