Skip to content

Commit

Permalink
Add server player spawn helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Dec 5, 2021
1 parent e97e843 commit 17519a4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
------------------------------------------------------
Version 0.1.1
------------------------------------------------------
**Additions**
- Added a helper method for spawning server players

------------------------------------------------------
Version 0.1.0
------------------------------------------------------
Initial release

**Additions**
- Fix for test cases that are run multiple times
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.12.6

# Mod Properties
mod_version = 0.1.0
mod_version = 0.1.1
maven_group = io.github.ladysnake
archives_base_name = elmendorf

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/github/ladysnake/elmendorf/GameTestUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.ladysnake.elmendorf;

import com.mojang.authlib.GameProfile;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.test.GameTestException;
import net.minecraft.test.TestContext;
import net.minecraft.util.math.Vec3d;

import java.util.UUID;

public final class GameTestUtil {
public static void assertTrue(boolean b, String errorMessage) {
if (!b) throw new GameTestException(errorMessage);
}

public static ServerPlayerEntity spawnPlayer(TestContext ctx, double x, double y, double z) {
ServerPlayerEntity mockPlayer = new ServerPlayerEntity(ctx.getWorld().getServer(), ctx.getWorld(), new GameProfile(UUID.randomUUID(), "test-mock-player"));
Vec3d vec3d = ctx.getAbsolute(new Vec3d(x, y, z));
mockPlayer.refreshPositionAndAngles(vec3d.x, vec3d.y, vec3d.z, mockPlayer.getYaw(), mockPlayer.getPitch());
ctx.getWorld().spawnEntity(mockPlayer);
return mockPlayer;
}
}

0 comments on commit 17519a4

Please sign in to comment.