Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.4] Remove getters and setters from Level.java.patch #1809

Open
wants to merge 1 commit into
base: 1.21.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
53 changes: 7 additions & 46 deletions patches/net/minecraft/world/level/Level.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@
this.neighborChanged(blockstate, blockpos, p_46719_, null, false);
}
}
@@ -1026,6 +_,18 @@
@@ -1024,6 +_,18 @@
@Override
public BiomeManager getBiomeManager() {
return this.biomeManager;
}
+ }
+
+ private double maxEntityRadius = 2.0D;
+ @Override
+ public double getMaxEntityRadius() {
Expand All @@ -211,47 +213,6 @@
+ if (value > maxEntityRadius)
+ maxEntityRadius = value;
+ return maxEntityRadius;
+ }
+
public final boolean isDebug() {
return this.isDebug;
}
@@ -1068,5 +_,38 @@
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) {
+ return 1L; // avoid doing math (and rounding errors) if no speed has been set
+ }
+ float dayTimeStep = getDayTimeFraction() + getDayTimePerTick();
+ long result = (long)dayTimeStep;
+ setDayTimeFraction(dayTimeStep - result);
+ return result;
}
}

public final boolean isDebug() {
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();
}
}
Loading