Skip to content

Commit

Permalink
Small bug fixes and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCymaera committed Aug 3, 2024
1 parent 10e403d commit 67cd57e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
1. Download a 1.21 server JAR from [Paper](https://papermc.io/downloads) or [Spigot](https://getbukkit.org/download/spigot).
2. Run the following command `java -Xmx1024M -Xms1024M -jar server.jar nogui`.
3. I typically use the Java runtime bundled with my Minecraft installation so as to avoid version conflicts.
- Windows: `C:\Users\%USERNAME%\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe`
- MacOS: `~/Library/Application\ Support/minecraft/runtime/java-runtime-gamma/mac-os/java-runtime-gamma/jre.bundle/Contents/Home/bin/java`
- In Modrinth, you can find the Java runtime location inside the profile options menu.
4. Accept the EULA by changing `eula=false` to `eula=true` in the `eula.txt` file.
5. Join the server with `localhost` as the IP address.
Expand All @@ -26,10 +24,10 @@ Autocomplete will show available options.
# Reset options
/options gait reset
# Get option (Version 2 Beta only)
# Get option
/options gait <option:string>
# Change body plan (Version 2 Beta only)
# Change body plan (quadruped, hexapod, octopod)
/body_plan <plan:string> <scale:double?> <segment_length:double?> <segment_count:int?>
```

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/heledron/spideranimation/components/Body.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class Leg(


private fun triggerDistance(): Double {
// if (spider.isWalking || spider.isRotatingPitch || spider.isRotatingYaw) return spider.gait.legWalkingTriggerDistance
// return spider.gait.legStationaryTriggerDistance
val maxSpeed = spider.gait.walkSpeed * spider.gait.gallopBreakpoint.coerceAtMost(1.0)
val walkFraction = min(spider.velocity.length() / maxSpeed, 1.0)
val fraction = if (spider.isRotatingYaw || spider.isRotatingPitch) 1.0 else walkFraction
Expand Down Expand Up @@ -269,7 +267,6 @@ class Leg(

val best = candidates
.filterNotNull()
// .filter { comfortZone.contains(SplitDistance.distance(it.position, restPosition)) }
.minByOrNull { it.position.distanceSquared(preferredPosition) }

if (best != null && !comfortZone.contains(restPosition, best.position)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class SymmetricalBodyPlan(override val legs: List<LegPlan>): SpiderBodyPlan {

val wantsToMove = leg.isOutsideTriggerZone || !leg.touchingGround
val alreadyAtTarget = leg.endEffector.distanceSquared(leg.target.position) < 0.01
val atLeastOneLegOnGround = spider.body.legs.any { it.isGrounded() }
val onGround = spider.body.legs.any { it.isGrounded() } || spider.body.onGround

return wantsToMove && !alreadyAtTarget && atLeastOneLegOnGround
return wantsToMove && !alreadyAtTarget && onGround
}

// x .
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/com/heledron/spideranimation/components/Cloak.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class Cloak(var spider: Spider) : SpiderComponent {


fun getCloakPalette(material: Material): List<Material> {

fun weighted(vararg pairs: Pair<Material, Int>): List<Material> {
val list = mutableListOf<Material>()
for ((option, weight) in pairs) {
for (i in 0 until weight) list.add(option)
}
return list
}

val mossLike = listOf(
Material.GRASS_BLOCK,
Material.OAK_LEAVES,
Expand All @@ -45,14 +54,14 @@ fun getCloakPalette(material: Material): List<Material> {
)

if (mossLike.contains(material)) {
return listOf(Material.MOSS_BLOCK, Material.MOSS_BLOCK, Material.MOSS_BLOCK, Material.MOSS_BLOCK, Material.GREEN_SHULKER_BOX)
return weighted(Material.MOSS_BLOCK to 4, Material.GREEN_SHULKER_BOX to 1)
}
if (material == Material.DIRT || material == Material.COARSE_DIRT || material == Material.ROOTED_DIRT) {
return listOf(Material.COARSE_DIRT, Material.ROOTED_DIRT)
}

if (material == Material.STONE_BRICKS || material == Material.STONE_BRICK_SLAB || material == Material.STONE_BRICK_STAIRS) {
return listOf(Material.STONE_BRICKS, Material.STONE_BRICKS, Material.STONE_BRICKS, Material.CRACKED_STONE_BRICKS, Material.LIGHT_GRAY_SHULKER_BOX)
return weighted(Material.STONE_BRICKS to 3, Material.CRACKED_STONE_BRICKS to 1, Material.LIGHT_GRAY_SHULKER_BOX to 1)
}

if (material == Material.OAK_LOG) {
Expand All @@ -66,14 +75,9 @@ fun getCloakPalette(material: Material): List<Material> {
)

if (spruceLike.contains(material)) {
return listOf(Material.SPRUCE_PLANKS, Material.SPRUCE_PLANKS, Material.SPRUCE_PLANKS, Material.STRIPPED_SPRUCE_WOOD)
return weighted(Material.SPRUCE_PLANKS to 3, Material.STRIPPED_SPRUCE_WOOD to 1)
}


// if (material == Material.DARK_OAK_FENCE) {
// return listOf(Material.DARK_OAK_PLANKS)
// }

if (material === Material.DIRT_PATH) {
return listOf(Material.STRIPPED_OAK_WOOD)
}
Expand All @@ -83,7 +87,7 @@ fun getCloakPalette(material: Material): List<Material> {
}

if (material === Material.SAND) {
return listOf(Material.SAND, Material.SAND, Material.SAND, Material.SAND, Material.SANDSTONE)
return weighted(Material.SAND to 4, Material.SANDSTONE to 1)
}

val deepSlateLike = listOf(
Expand All @@ -95,7 +99,7 @@ fun getCloakPalette(material: Material): List<Material> {
)

if (deepSlateLike.contains(material)) {
return listOf(Material.POLISHED_DEEPSLATE, Material.POLISHED_DEEPSLATE, Material.POLISHED_DEEPSLATE, Material.DEEPSLATE_TILES)
return weighted(Material.POLISHED_DEEPSLATE to 3, Material.DEEPSLATE_TILES to 1)
}

val stoneLike = listOf(
Expand Down Expand Up @@ -148,7 +152,7 @@ fun getCloakPalette(material: Material): List<Material> {
);

if (tuffLike.contains(material)) {
return listOf(Material.POLISHED_TUFF, Material.POLISHED_TUFF, Material.GRAY_SHULKER_BOX)
return weighted(Material.POLISHED_TUFF to 2, Material.GRAY_SHULKER_BOX to 1)
}

return listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import org.bukkit.entity.Display
import org.bukkit.util.Vector

class DebugRendererOptions {
@KVElement var showScanBars = true
@KVElement var showTriggerZones = true
@KVElement var showEndEffectors = true
@KVElement var showTargetPositions = true
@KVElement var showLegPolygons = true
@KVElement var showCentreOfMass = true
@KVElement var showBodyAcceleration = true
@KVElement var showDirection = true
@KVElement var scanBars = true
@KVElement var triggerZones = true
@KVElement var endEffectors = true
@KVElement var targetPositions = true
@KVElement var legPolygons = true
@KVElement var centreOfMass = true
@KVElement var bodyAcceleration = true
@KVElement var direction = true
}

class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): SpiderComponent {
Expand All @@ -34,7 +34,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid

for ((legIndex, leg) in spider.body.legs.withIndex()) {
// Render scan bars
if (options.showScanBars) renderer.render(Pair("scanBar", legIndex), lineTemplate(
if (options.scanBars) renderer.render(Pair("scanBar", legIndex), lineTemplate(
location = leg.scanStartPosition.toLocation(spider.location.world!!),
vector = leg.scanVector,
thickness = .05f * scale,
Expand All @@ -49,7 +49,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid

// Render trigger zone
val vector = Vector(0,1,0).multiply(leg.triggerZone.vertical)
if (options.showTriggerZones) renderer.render(Pair("triggerZoneVertical", legIndex), lineTemplate(
if (options.triggerZones) renderer.render(Pair("triggerZoneVertical", legIndex), lineTemplate(
location = leg.restPosition.toLocation(spider.location.world!!).subtract(vector.clone().multiply(.5)),
vector = vector,
thickness = .07f * scale,
Expand All @@ -61,7 +61,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid
))

// Render trigger zone
if (options.showTriggerZones) renderer.render(Pair("triggerZoneHorizontal", legIndex), blockTemplate(
if (options.triggerZones) renderer.render(Pair("triggerZoneHorizontal", legIndex), blockTemplate(
location = run {
val location = leg.restPosition.toLocation(leg.spider.location.world!!)
location.y = leg.target.position.y.coerceIn(location.y - leg.triggerZone.vertical, location.y + leg.triggerZone.vertical)
Expand All @@ -83,7 +83,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid
))

// Render end effector
if (options.showEndEffectors) renderer.render(Pair("endEffector", legIndex), blockTemplate(
if (options.endEffectors) renderer.render(Pair("endEffector", legIndex), blockTemplate(
location = leg.endEffector.toLocation(spider.location.world!!),
init = {
it.teleportDuration = 1
Expand All @@ -102,7 +102,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid
))

// Render target position
if (options.showTargetPositions) renderer.render(Pair("targetPosition", legIndex), blockTemplate(
if (options.targetPositions) renderer.render(Pair("targetPosition", legIndex), blockTemplate(
location = leg.target.position.toLocation(spider.location.world!!),
init = {
it.teleportDuration = 1
Expand All @@ -121,7 +121,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid


// Render spider direction
if (options.showDirection) renderer.render("direction", blockTemplate(
if (options.direction) renderer.render("direction", blockTemplate(
location = spider.location.clone().add(spider.location.direction.clone().multiply(scale)),
init = {
it.teleportDuration = 1
Expand All @@ -137,13 +137,13 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid


val normal = spider.body.normal ?: return
if (options.showLegPolygons && normal.contactPolygon != null) {
if (options.legPolygons && normal.contactPolygon != null) {
val points = normal.contactPolygon.map { it.toLocation(spider.location.world!!)}
for (i in points.indices) {
val a = points[i]
val b = points[(i + 1) % points.size]

if (options.showLegPolygons) renderer.render(Pair("polygon",i), lineTemplate(
if (options.legPolygons) renderer.render(Pair("polygon",i), lineTemplate(
location = a,
vector = b.toVector().subtract(a.toVector()),
thickness = .05f * scale,
Expand All @@ -154,7 +154,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid
}
}

if (options.showCentreOfMass && normal.centreOfMass != null) renderer.render("centreOfMass", blockTemplate(
if (options.centreOfMass && normal.centreOfMass != null) renderer.render("centreOfMass", blockTemplate(
location = normal.centreOfMass.toLocation(spider.location.world!!),
init = {
it.teleportDuration = 1
Expand All @@ -170,7 +170,7 @@ class DebugRenderer(val spider: Spider, val options: DebugRendererOptions): Spid
))


if (options.showBodyAcceleration && normal.centreOfMass != null && normal.origin !== null) renderer.render("acceleration", lineTemplate(
if (options.bodyAcceleration && normal.centreOfMass != null && normal.origin !== null) renderer.render("acceleration", lineTemplate(
location = normal.origin.toLocation(spider.location.world!!),
vector = normal.centreOfMass.clone().subtract(normal.origin),
thickness = .02f * scale,
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ api-version: '1.20'
commands:
options:
description: Set gait options
usage: /options <gait|galloping_gait|debug_renderer> <option:string> <value:double>
usage: /options <gait|galloping_gait|debug_renderer> <option:string> <value:double?>
fall:
description: Teleport the spider up by the specified height
usage: /fall <height:double>
body_plan:
description: Set the body plan of the spider
usage: /body_plan <plan:string>
usage: /body_plan <quadruped|hexapod|octopod> <scale:double?> <segment_length:double?> <segment_count:int?>

0 comments on commit 67cd57e

Please sign in to comment.