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 91ffe66 commit cc8ed88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/ldtteam/common/fakelevel/FakeLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public FakeLevel(final SOURCE levelSource,
final boolean overrideBeLevel)
{
// we have to pass null in ctor, so realLevel can be used
super(new FakeLevelData(realLevel.getLevelData(), lightProvider),
super(new FakeLevelData(realLevel::getLevelData, lightProvider),
realLevel.dimension(),
realLevel.registryAccess(),
realLevel.dimensionTypeRegistration(),
Expand All @@ -149,6 +149,7 @@ public FakeLevel(final SOURCE levelSource,
this.lightEngine = new FakeLevelLightEngine(this);

setRealLevel(realLevel); // intentionally due to init
((FakeLevelData) getLevelData()).vanillaLevelData = () -> realLevel().getLevelData();
}

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

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

public Level realLevel()
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/ldtteam/common/fakelevel/FakeLevelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,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 All @@ -35,13 +36,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 @@ -71,7 +72,7 @@ public boolean isHardcore()
@Override
public GameRules getGameRules()
{
return vanillaLevelData.getGameRules();
return vanillaLevelData.get().getGameRules();
}

@Override
Expand Down

0 comments on commit cc8ed88

Please sign in to comment.