Skip to content

Commit

Permalink
Fix leaky FakeLevelData
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom committed Oct 4, 2024
1 parent a2614df commit a083802
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public FakeLevel(final IFakeLevelBlockGetter levelSource,
@Nullable final Scoreboard scoreboard,
final boolean overrideBeLevel)
{
super(new FakeLevelData(clientLevel().getLevelData(), lightProvider),
super(new FakeLevelData(clientLevel()::getLevelData, lightProvider),
clientLevel().dimension(),
clientLevel().registryAccess(),
clientLevel().dimensionTypeRegistration(),
Expand All @@ -145,6 +145,7 @@ public FakeLevel(final IFakeLevelBlockGetter levelSource,
this.lightEngine = new FakeLevelLightEngine(this);

setRealLevel(clientLevel());
((FakeLevelData) getLevelData()).vanillaLevelData = realLevel()::getLevelData;
}

// ========================================
Expand All @@ -170,7 +171,6 @@ public void setRealLevel(final Level realLevel)
}

this.realLevel = realLevel;
((FakeLevelData) this.getLevelData()).vanillaLevelData = realLevel == null ? null : realLevel.getLevelData();
}

public Level realLevel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.WritableLevelData;
import java.util.function.Supplier;

/**
* Porting: class is relatively small, just check super class manually (all of missing methods are/were just aliases)
*/
public class FakeLevelData implements WritableLevelData
{
protected LevelData vanillaLevelData;
protected Supplier<LevelData> vanillaLevelData;
protected final IFakeLevelLightProvider lightProvider;

protected FakeLevelData(final LevelData vanillaLevelData, final IFakeLevelLightProvider lightProvider)
protected FakeLevelData(final Supplier<LevelData> vanillaLevelData, final IFakeLevelLightProvider lightProvider)
{
this.vanillaLevelData = vanillaLevelData;
this.lightProvider = lightProvider;
Expand Down Expand Up @@ -46,13 +47,13 @@ public float getSpawnAngle()
@Override
public long getGameTime()
{
return vanillaLevelData.getGameTime();
return vanillaLevelData.get().getGameTime();
}

@Override
public long getDayTime()
{
return lightProvider.forceOwnLightLevel() ? lightProvider.getDayTime() : vanillaLevelData.getDayTime();
return lightProvider.forceOwnLightLevel() ? lightProvider.getDayTime() : vanillaLevelData.get().getDayTime();
}

@Override
Expand Down Expand Up @@ -82,7 +83,7 @@ public boolean isHardcore()
@Override
public GameRules getGameRules()
{
return vanillaLevelData.getGameRules();
return vanillaLevelData.get().getGameRules();
}

@Override
Expand Down

0 comments on commit a083802

Please sign in to comment.