Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Sep 22, 2024
1 parent 987ff80 commit 11dbd44
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 49 deletions.
33 changes: 18 additions & 15 deletions src/main/java/ch/njol/skript/expressions/ExprExperience.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,16 @@ public Class<?>[] acceptChange(ChangeMode mode) {
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
int exp;

switch (event) {
case ExperienceSpawnEvent experienceSpawnEvent -> exp = experienceSpawnEvent.getSpawnedXP();
case BlockBreakEvent blockBreakEvent -> exp = blockBreakEvent.getExpToDrop();
case PlayerExpChangeEvent playerExpChangeEvent -> exp = playerExpChangeEvent.getAmount();
case EntityBreedEvent entityBreedEvent -> exp = entityBreedEvent.getExperience();

default -> {
return;
}
if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) {
exp = experienceSpawnEvent.getSpawnedXP();
} else if (event instanceof BlockBreakEvent blockBreakEvent) {
exp = blockBreakEvent.getExpToDrop();
} else if (event instanceof PlayerExpChangeEvent playerExpChangeEvent) {
exp = playerExpChangeEvent.getAmount();
} else if (event instanceof EntityBreedEvent entityBreedEvent) {
exp = entityBreedEvent.getExperience();
} else {
return;
}

if (delta != null) {
Expand All @@ -108,12 +109,14 @@ public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
}

exp = Math.max(0, exp);
switch (event) {
case ExperienceSpawnEvent experienceSpawnEvent -> experienceSpawnEvent.setSpawnedXP(exp);
case BlockBreakEvent blockBreakEvent -> blockBreakEvent.setExpToDrop(exp);
case PlayerExpChangeEvent playerExpChangeEvent -> playerExpChangeEvent.setAmount(exp);
case EntityBreedEvent entityBreedEvent -> entityBreedEvent.setExperience(exp);
default -> {}
if (event instanceof ExperienceSpawnEvent experienceSpawnEvent) {
experienceSpawnEvent.setSpawnedXP(exp);
} else if (event instanceof BlockBreakEvent blockBreakEvent) {
blockBreakEvent.setExpToDrop(exp);
} else if (event instanceof PlayerExpChangeEvent playerExpChangeEvent) {
playerExpChangeEvent.setAmount(exp);
} else if (event instanceof EntityBreedEvent entityBreedEvent) {
entityBreedEvent.setExperience(exp);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/test/skript/tests/syntaxes/conditions/CondIsInLove.sk
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
test "CondIsInLove - Valid Entity":
test "valid entity is in love":
delete all cows
set {_spawn} to spawn of world "world"
spawn adult cow at {_spawn}
set {_cow} to last spawned cow
assert love time of {_cow} is 0 seconds with "Cow love time was not 0 seconds after spawning"
assert {_cow} is not in love with "Cow is in love after spawning"
assert love time of {_cow} is 0 seconds with "cow love time was not 0 seconds after spawning"
assert {_cow} is not in love with "cow is in love after spawning"
set love time of {_cow} to 10 seconds
assert {_cow} is in love with "Cow is not in love after setting love time"
assert {_cow} is in love with "cow is not in love after setting love time"
add 10 seconds to love time of {_cow}
assert love time of {_cow} > 10 seconds with "Cow love time didn't go up after adding"
assert love time of {_cow} > 10 seconds with "cow love time didn't go up after adding"
remove 1 minute from love time of {_cow}
assert {_cow} is not in love with "Cow is in love after removing more love than possible"
assert {_cow} is not in love with "cow is in love after removing more love than possible"
add 10 minutes to love time of {_cow}
assert {_cow} is in love with "Cow didn't enter love mode after adding love time"
assert {_cow} is in love with "cow didn't enter love mode after adding love time"
reset love time of {_cow}
assert {_cow} is not in love with "Cow was still in love even after resetting love time"
assert {_cow} is not in love with "cow was still in love even after resetting love time"
delete all cows

test "CondIsInLove - Invalid Entity":
test "invalid entity is in love":
delete all zombies
set {_spawn} to spawn of world "world"
spawn adult zombie at {_spawn}
set {_zombie} to last spawned zombie
assert love time of {_zombie} is 0 seconds with "Zombie was in love Test1"
assert love time of {_zombie} is 0 seconds with "zombie was in love on spawn"
set love time of {_zombie} to 10 minutes
assert love time of {_zombie} is 0 seconds with "Zombie was in love Test2"
assert love time of {_zombie} is 0 seconds with "zombie was in love after set"
delete all zombies
11 changes: 11 additions & 0 deletions src/test/skript/tests/syntaxes/effects/EffAllowAging.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test "allow aging":
delete all pigs
set {_spawn} to spawn of world "world"
spawn baby pig at {_spawn}
set {_pig} to last spawned pig
assert {_pig} can age with "baby pig can't age before locking"
lock age of {_pig}
assert {_pig} can't age with "baby pig can still age after locking"
unlock age of {_pig}
assert {_pig} can age with "baby pig can't age after unlocking"
delete all pigs
8 changes: 4 additions & 4 deletions src/test/skript/tests/syntaxes/effects/EffBreedable.sk
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test "breedable" when running minecraft "1.16.5":
test "breedable":
delete all chickens
set {_spawn} to spawn of world "world"
spawn baby chicken at {_spawn}
set {_chicken} to last spawned chicken
assert {_chicken} can't breed with "Chicken could breed before growing up"
assert {_chicken} can't breed with "chicken could breed before growing up"
make {_chicken} breedable
assert {_chicken} can breed with "Chicken can't breed after growing up"
assert {_chicken} can breed with "chicken can't breed after growing up"
make {_chicken} non-breedable
assert {_chicken} can't breed with "Chicken can breed after growing up and preventing"
assert {_chicken} can't breed with "chicken can breed after growing up and preventing"
delete all chickens
11 changes: 0 additions & 11 deletions src/test/skript/tests/syntaxes/effects/EffLockAge.sk

This file was deleted.

16 changes: 8 additions & 8 deletions src/test/skript/tests/syntaxes/effects/EffMakeAdult.sk
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
test "effect make adult 1" when running minecraft "1.16.5":
test "make mob adult":
delete all zombies
set {_spawn} to spawn of world "world"
spawn baby zombie at {_spawn}
set {_zombie} to last spawned zombie
assert {_zombie} is not an adult with "Spawned zombie was an adult"
assert {_zombie} is not an adult with "spawned zombie was an adult"
make {_zombie} an adult
assert {_zombie} is an adult with "Spawned zombie is still a baby zombie"
assert {_zombie} is an adult with "spawned zombie is still a baby zombie"
make {_zombie} a baby
assert {_zombie} is not an adult with "Spawned zombie didn't become a baby zombie"
assert {_zombie} is not an adult with "spawned zombie didn't become a baby zombie"
delete all zombies

test "effect make adult 2":
test "make animal adult":
delete all sheep
set {_spawn} to spawn of world "world"
spawn baby sheep at {_spawn}
set {_sheep} to last spawned sheep
assert {_sheep} is not an adult with "Spawned sheep was an adult"
assert {_sheep} is not an adult with "spawned sheep was an adult"
make {_sheep} an adult
assert {_sheep} is an adult with "Spawned sheep is still a baby sheep"
assert {_sheep} is an adult with "spawned sheep is still a baby sheep"
make {_sheep} a baby
assert {_sheep} is not an adult with "Spawned sheep didn't become a baby sheep"
assert {_sheep} is not an adult with "spawned sheep didn't become a baby sheep"
delete all sheep

0 comments on commit 11dbd44

Please sign in to comment.