Skip to content

Commit

Permalink
Merge pull request #41 from doc-bok/lifetime-fix
Browse files Browse the repository at this point in the history
[FIX] Fixed caterpillar and chrysalis lifespan.
  • Loading branch information
doc-bok committed Nov 22, 2023
2 parents f5ffef7 + 62aa466 commit 77b92b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,9 @@ cats away from them!

## Changelog

### 1.0.3 (2023-11-22)
- Fixed caterpillar and chrysalis aging.

### 1.0.2 (2023-11-06)
- Added names to the entities to better support modpacks.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -48,7 +48,7 @@ mod_name=Butterfly Mod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=1.0.2
mod_version=1.0.3
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Expand Up @@ -305,6 +305,7 @@ public static void spawn(ServerLevel level,
caterpillar.moveTo(x, y, z, 0.0F, 0.0F);
caterpillar.setSurfaceDirection(direction);
caterpillar.setSurfaceBlock(spawnPosition);
caterpillar.setAge(-24000);

caterpillar.finalizeSpawn(level,
level.getCurrentDifficultyAt(position),
Expand Down Expand Up @@ -355,13 +356,12 @@ public boolean isPushable() {
}

/**
* The main update loop for the entity.
* Override so that the bounding box isn't recalculated for "babies".
* @param age The age of the entity.
*/
@Override
public void tick() {
super.tick();

// TODO: ?
public void setAge(int age) {
this.age = age;
}

/**
Expand Down Expand Up @@ -505,7 +505,7 @@ protected void customServerAiStep() {
this.setYRot(this.getYRot() + (float) rotationDelta);

// Spawn Chrysalis.
if (this.getAge() > 24000 && this.random.nextInt(0, 15) == 0) {
if (this.getAge() >= 0 && this.random.nextInt(0, 15) == 0) {
String encodeId = this.getEncodeId();
if (encodeId != null) {
String[] splitEncodeId = encodeId.split("_");
Expand Down
Expand Up @@ -269,6 +269,7 @@ public static void spawn(ServerLevel level,
chrysalis.setYRot(yRotation);
chrysalis.setSurfaceDirection(surfaceDirection);
chrysalis.setSurfaceBlock(spawnBlock);
chrysalis.setAge(-24000);

chrysalis.finalizeSpawn(level,
level.getCurrentDifficultyAt(spawnBlock),
Expand Down Expand Up @@ -311,6 +312,15 @@ public boolean isPushable() {
return false;
}

/**
* Override so that the bounding box isn't recalculated for "babies".
* @param age The age of the entity.
*/
@Override
public void setAge(int age) {
this.age = age;
}

/**
* Construction
*
Expand All @@ -337,7 +347,7 @@ protected void customServerAiStep() {
}

// Spawn Butterfly.
if (this.getAge() > 24000 && this.random.nextInt(0, 15) == 0) {
if (this.getAge() >= 0 && this.random.nextInt(0, 15) == 0) {
String encodeId = this.getEncodeId();
if (encodeId != null) {
String[] splitEncodeId = encodeId.split("_");
Expand Down

0 comments on commit 77b92b1

Please sign in to comment.