Skip to content

Commit

Permalink
Remove getters and setters from Level.java.patch
Browse files Browse the repository at this point in the history
- These getters and setters are not needed, and just make extending Level in a multiloader mod a bit more annoying.
  • Loading branch information
IThundxr committed Dec 31, 2024
1 parent 821e47f commit c65cc7d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 53 deletions.
31 changes: 11 additions & 20 deletions patches/net/minecraft/client/multiplayer/ClientLevel.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
}
}

@@ -1112,10 +_,58 @@
@@ -1112,10 +_,49 @@
ClientLevel.this.dragonParts.removeAll(Arrays.asList(enderdragon.getSubEntities()));
break;
default:
Expand Down Expand Up @@ -173,25 +173,16 @@
+
+ // Neo: Variable day time code
+
+ private float dayTimeFraction = 0.0f;
+ private float dayTimePerTick = -1.0f;
+ public float dayTimeFraction = 0.0f;
+ public float dayTimePerTick = -1.0f;
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public void setDayTimeFraction(float dayTimeFraction) {
+ this.dayTimeFraction = dayTimeFraction;
+ }
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public float getDayTimeFraction() {
+ return dayTimeFraction;
+ }
+
+ public float getDayTimePerTick() {
+ return dayTimePerTick;
+ }
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public void setDayTimePerTick(float dayTimePerTick) {
+ this.dayTimePerTick = dayTimePerTick;
+ protected long advanceDaytime() {
+ if (dayTimePerTick < 0) {
+ return 1L; // avoid doing math (and rounding errors) if no speed has been set
+ }
+ float dayTimeStep = dayTimeFraction + dayTimePerTick;
+ long result = (long)dayTimeStep;
+ dayTimeFraction = dayTimeStep - result;
+ return result;
}
}
14 changes: 11 additions & 3 deletions patches/net/minecraft/server/level/ServerLevel.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
ServerLevel.this.dragonParts.put(enderdragonpart.getId(), enderdragonpart);
}
}
@@ -1783,24 +_,101 @@
@@ -1783,24 +_,109 @@
if (ServerLevel.this.isUpdatingNavigations) {
String s = "onTrackingStart called during navigation iteration";
Util.logAndPauseIfInIde(
Expand Down Expand Up @@ -271,7 +271,7 @@
public void onSectionChange(Entity p_215086_) {
p_215086_.updateDynamicGameEventListener(DynamicGameEventListener::move);
}
}
+ }
+
+ private final net.neoforged.neoforge.capabilities.CapabilityListenerHolder capListenerHolder = new net.neoforged.neoforge.capabilities.CapabilityListenerHolder();
+
Expand Down Expand Up @@ -338,12 +338,20 @@
+ * While this still technically works when vanilla clients are connected, those will desync and
+ * experience a time jump once per second.
+ */
+ @Override
+ public void setDayTimePerTick(float dayTimePerTick) {
+ if (dayTimePerTick != getDayTimePerTick() && dayTimePerTick != 0f) {
+ serverLevelData.setDayTimePerTick(dayTimePerTick);
+ server.forceTimeSynchronization();
+ }
+ }
+
+ protected long advanceDaytime() {
+ if (serverLevelData.getDayTimePerTick() < 0) {
+ return 1L; // avoid doing math (and rounding errors) if no speed has been set
+ }
+ float dayTimeStep = serverLevelData.getDayTimeFraction() + serverLevelData.getDayTimePerTick();
+ long result = (long)dayTimeStep;
+ serverLevelData.setDayTimeFraction(dayTimeStep - result);
+ return result;
}
}
12 changes: 10 additions & 2 deletions patches/net/minecraft/world/entity/player/Player.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,21 @@
this.stopSleepInBed(false, true);
}
} else if (this.sleepCounter > 0) {
@@ -298,7 +_,11 @@
@@ -298,7 +_,19 @@
}

if (!this.isSleeping()) {
- this.awardStat(Stats.TIME_SINCE_REST);
+ float dayTimeFraction;
+
+ if (level().isClientSide) {
+ dayTimeFraction = ((net.minecraft.client.multiplayer.ClientLevel) level()).dayTimeFraction;
+ } else {
+ dayTimeFraction = ((ServerLevel) level()).getDayTimeFraction();
+ }
+
+ // Neo: Advance TIME_SINCE_REST if (a) vanilla daytime handling in effect, or (b) days are shorter, or (c) dayTime has ticked, or (d) dayTime advances are off and we need to ignore day length
+ if (level().getDayTimeFraction() < 0 || level().getDayTimeFraction() >= 1 || lastDayTimeTick != level().getDayTime() || !serverplayer.serverLevel().getGameRules().getRule(GameRules.RULE_DAYLIGHT).get()) {
+ if (dayTimeFraction < 0 || dayTimeFraction >= 1 || lastDayTimeTick != level().getDayTime() || !serverplayer.serverLevel().getGameRules().getRule(GameRules.RULE_DAYLIGHT).get()) {
+ lastDayTimeTick = level().getDayTime();
+ this.awardStat(Stats.TIME_SINCE_REST);
+ }
Expand Down
31 changes: 5 additions & 26 deletions patches/net/minecraft/world/level/Level.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -216,42 +216,21 @@
public final boolean isDebug() {
return this.isDebug;
}
@@ -1068,5 +_,38 @@
@@ -1068,5 +_,17 @@
public String getSerializedName() {
return this.id;
}
+ }
+
+ // Neo: Variable day time code
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public abstract void setDayTimeFraction(float dayTimeFraction);
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public abstract float getDayTimeFraction();
+
+ /**
+ * Returns the current ratio between game ticks and clock ticks. If this value is negative, no
+ * speed has been set and those two are coupled 1:1 (i.e. vanilla mode).
+ */
+ public abstract float getDayTimePerTick();
+
+ /**
+ * DO NOT CALL.
+ * <p>
+ * Use {@link net.minecraft.server.level.ServerLevel#setDayTimePerTick(float)} instead.
+ */
+ public abstract void setDayTimePerTick(float dayTimePerTick);
+
+ // advances the fractional daytime, returns the integer part of it
+ @org.jetbrains.annotations.ApiStatus.Internal
+ protected long advanceDaytime() {
+ if (getDayTimePerTick() < 0) {
+ protected long advanceDaytime(org.apache.commons.lang3.mutable.MutableFloat dayTimeFraction, float dayTimePerTick) {
+ if (dayTimePerTick < 0) {
+ return 1L; // avoid doing math (and rounding errors) if no speed has been set
+ }
+ float dayTimeStep = getDayTimeFraction() + getDayTimePerTick();
+ float dayTimeStep = dayTimeFraction.getValue() + dayTimePerTick;
+ long result = (long)dayTimeStep;
+ setDayTimeFraction(dayTimeStep - result);
+ dayTimeFraction.setValue(dayTimeStep - result);
+ return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static void handle(final ClientboundCustomSetTimePayload payload, final I
@SuppressWarnings("resource")
final ClientLevel level = Minecraft.getInstance().level;
level.setTimeFromServer(payload.gameTime(), payload.dayTime(), payload.gameRule());
level.setDayTimeFraction(payload.dayTimeFraction());
level.setDayTimePerTick(payload.dayTimePerTick());
level.dayTimeFraction = payload.dayTimeFraction();
level.dayTimePerTick = payload.dayTimePerTick();
}
}

0 comments on commit c65cc7d

Please sign in to comment.