Skip to content

Commit

Permalink
Add comments to RuntimeWorldConfig (#45)
Browse files Browse the repository at this point in the history
* chore: Port to 1.20.5 and probably break something important

* chore: Fix commented line

Signed-off-by: Awakened-Redstone <[email protected]>

* chore: Remove try catch

Signed-off-by: Awakened-Redstone <[email protected]>

* chore: Better handle test command errors

Signed-off-by: Awakened-Redstone <[email protected]>

* chore: Comment RuntimeWorldConfig.java

Signed-off-by: Awakened-Redstone <[email protected]>

* Delete src/main/java/xyz/nucleoid/fantasy/mixin/registry/DimensionOptionsRegistryHolderMixin.java

---------

Signed-off-by: Awakened-Redstone <[email protected]>
Co-authored-by: Patbox <[email protected]>
  • Loading branch information
Awakened-Redstone and Patbox authored May 12, 2024
1 parent 7fe6963 commit db45eaf
Showing 1 changed file with 159 additions and 0 deletions.
159 changes: 159 additions & 0 deletions src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,105 +39,254 @@ public final class RuntimeWorldConfig {
private int thunderTime;
private TriState flat = TriState.DEFAULT;

/**
* Sets the world seed
*
* @param seed The world seed to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setSeed(long seed) {
this.seed = seed;
return this;
}

/**
* Sets the world constructor
*
* @param constructor The world constructor to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setWorldConstructor(RuntimeWorld.Constructor constructor) {
this.worldConstructor = constructor;
return this;
}

/**
* Sets the world dimension type
*
* @param dimensionType The dimension type to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setDimensionType(RegistryEntry<DimensionType> dimensionType) {
this.dimensionType = dimensionType;
this.dimensionTypeKey = null;
return this;
}

/**
* Sets the world dimension type
*
* @param dimensionType The dimension type to use
*
* @deprecated Pleas use {@link RuntimeWorldConfig#setDimensionType(RegistryKey)}
* or {@link RuntimeWorldConfig#setDimensionType(RegistryEntry)} instead
*
* @return The same instance of RuntimeWorldConfig
*/
@Deprecated
public RuntimeWorldConfig setDimensionType(DimensionType dimensionType) {
this.dimensionType = RegistryEntry.of(dimensionType);
this.dimensionTypeKey = null;
return this;
}

/**
* Sets the world dimension type
*
* @param dimensionType The dimension type to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setDimensionType(RegistryKey<DimensionType> dimensionType) {
this.dimensionTypeKey = dimensionType;
this.dimensionType = null;
return this;
}

/**
* Sets the world chunk generator
*
* @param generator The chunk generator to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setGenerator(ChunkGenerator generator) {
this.generator = generator;
return this;
}

/**
* Defines whenever the world should tick time.
* <br/>
* Setting this set's the {@link GameRules#DO_DAYLIGHT_CYCLE}
* gamerule for the world to avoid jitter
* <br/>
* <br/>
* <i>The gamerule does not have effect if {@link RuntimeWorldConfig#mirrorOverworldGameRules} is set to true</i>
*
* @param shouldTickTime Whenever the world should tick the time
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setShouldTickTime(boolean shouldTickTime) {
this.shouldTickTime = shouldTickTime;
this.gameRules.set(GameRules.DO_DAYLIGHT_CYCLE, shouldTickTime);
return this;
}

/**
* Sets the world's day time
*
* @param timeOfDay The new time of the day
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setTimeOfDay(long timeOfDay) {
this.timeOfDay = timeOfDay;
return this;
}

/**
* Sets the world difficulty
*
* @param difficulty The difficulty to use
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setDifficulty(Difficulty difficulty) {
this.difficulty = difficulty;
return this;
}

/**
* Modifies a gamerule
* <br/>
* <b>Does nothing if {@link RuntimeWorldConfig#mirrorOverworldGameRules} is true</b>
*
* @param key The gamerule to modify
* @param value The value of the gamerule
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setGameRule(GameRules.Key<GameRules.BooleanRule> key, boolean value) {
this.gameRules.set(key, value);
return this;
}

/**
* Modifies a gamerule
* <br/>
* <b>Does nothing if {@link RuntimeWorldConfig#mirrorOverworldGameRules} is true</b>
*
* @param key The gamerule to modify
* @param value The value of the gamerule
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setGameRule(GameRules.Key<GameRules.IntRule> key, int value) {
this.gameRules.set(key, value);
return this;
}

/**
* Defines if the world should follow the overworld gamurules or not
*
* @param mirror Whenever it should mirror or not
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setMirrorOverworldGameRules(boolean mirror) {
this.mirrorOverworldGameRules = mirror;
return this;
}

/**
* Modifies the weather to sunny
*
* @param sunnyTime For how many ticks it should be sunny
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setSunny(int sunnyTime) {
this.sunnyTime = sunnyTime;
this.raining = false;
this.thundering = false;
return this;
}

/**
* Modifies the weather to rainy
*
* @param rainTime For how many ticks it should be raining
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setRaining(int rainTime) {
this.raining = rainTime > 0;
this.rainTime = rainTime;
return this;
}

/**
* Toggles the rain in the world
*
* @param raining Whenever it should be raining or not
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setRaining(boolean raining) {
this.raining = raining;
return this;
}


/**
* Modifies the weather to thundering
*
* @param thunderTime For how many ticks it should be thundering
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setThundering(int thunderTime) {
this.thundering = thunderTime > 0;
this.thunderTime = thunderTime;
return this;
}

/**
* Toggles the thunder in the world
*
* @param thundering Whenever it should be thundering or not
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setThundering(boolean thundering) {
this.thundering = thundering;
return this;
}

/**
* Defines if the world is a flat world or not
*
* @param state If the world should be flat, not flat or use the default value
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setFlat(TriState state) {
this.flat = state;
return this;
}

/**
* Defines if the world is a flat world or not
*
* @param state If the world should be flat or not
*
* @return The same instance of RuntimeWorldConfig
*/
public RuntimeWorldConfig setFlat(boolean state) {
return this.setFlat(TriState.of(state));
}
Expand All @@ -146,11 +295,21 @@ public long getSeed() {
return this.seed;
}

/**
* Creates new dimension options from the server
*
* @return The new dimension options
*/
public DimensionOptions createDimensionOptions(MinecraftServer server) {
var dimensionType = this.resolveDimensionType(server);
return new DimensionOptions(dimensionType, this.generator);
}

/**
* Resolves the dimension type from the server
*
* @return The dimension type
*/
private RegistryEntry<DimensionType> resolveDimensionType(MinecraftServer server) {
var dimensionType = this.dimensionType;
if (dimensionType == null) {
Expand Down

0 comments on commit db45eaf

Please sign in to comment.