From 1e252b23b95b3bac96cd6299a7043e3d5429f308 Mon Sep 17 00:00:00 2001 From: PolyacovYury Date: Thu, 15 Oct 2020 13:35:22 +0300 Subject: [PATCH 1/2] Fix #3190: fix mob breeding cooldown --- .../mixin/realtime/entity/EntityAgeableMixin_RealTime.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java index 0f93adeb60e..82746d5a6a1 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java @@ -45,7 +45,10 @@ public abstract class EntityAgeableMixin_RealTime extends EntityMixin_RealTime { } // Subtract the one the original update method added final int diff = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks() - 1; - this.setGrowingAge(Math.min(0, age + diff)); + // age is positive ? subtract : add + final int new_age = age - (int) Math.signum(age) * diff; + // if sign changed - return 0 + this.setGrowingAge((age ^ new_age) < 0 ? 0 : new_age); } From bf05e42411ec342e9f5fe1e2cc0947b992c44fb5 Mon Sep 17 00:00:00 2001 From: PolyacovYury Date: Fri, 16 Oct 2020 11:31:35 +0300 Subject: [PATCH 2/2] This is, indeed, less confusing to read. Thx, @dualspiral --- .../realtime/entity/EntityAgeableMixin_RealTime.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java index 82746d5a6a1..48997d02f6e 100644 --- a/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java +++ b/src/main/java/org/spongepowered/common/mixin/realtime/entity/EntityAgeableMixin_RealTime.java @@ -45,10 +45,13 @@ public abstract class EntityAgeableMixin_RealTime extends EntityMixin_RealTime { } // Subtract the one the original update method added final int diff = (int) ((RealTimeTrackingBridge) this.world).realTimeBridge$getRealTimeTicks() - 1; - // age is positive ? subtract : add - final int new_age = age - (int) Math.signum(age) * diff; - // if sign changed - return 0 - this.setGrowingAge((age ^ new_age) < 0 ? 0 : new_age); + if (diff == 0) { + this.setGrowingAge(age); + } else if (age > 0) { + this.setGrowingAge(Math.max(0, age - diff)); + } else { + this.setGrowingAge(Math.min(0, age + diff)); + } }