-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔖 LambDynamicLights v1.0.0: Initial release.
- Loading branch information
1 parent
8d3b054
commit 6ada0f1
Showing
26 changed files
with
1,707 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/me/lambdaurora/lambdynlights/DynamicLightSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright © 2020 LambdAurora <[email protected]> | ||
* | ||
* This file is part of LambDynamicLights. | ||
* | ||
* Licensed under the MIT license. For more information, | ||
* see the LICENSE file. | ||
*/ | ||
|
||
package me.lambdaurora.lambdynlights; | ||
|
||
import net.minecraft.client.render.WorldRenderer; | ||
import net.minecraft.entity.Entity; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Represents a dynamic light source. | ||
*/ | ||
public interface DynamicLightSource | ||
{ | ||
/** | ||
* Returns the entity the dynamic light source is associated with. | ||
* | ||
* @return The associated entity. | ||
*/ | ||
Entity getDynamicLightEntity(); | ||
|
||
/** | ||
* Returns whether the dynamic light is enabled or not. | ||
* | ||
* @return True if the dynamic light is enabled, else false. | ||
*/ | ||
default boolean isDynamicLightEnabled() | ||
{ | ||
return LambDynLights.get().config.getDynamicLightsMode().isEnabled() && LambDynLights.get().containsLightSource(this); | ||
} | ||
|
||
/** | ||
* Sets whether the dynamic light is enabled or not. | ||
* <p> | ||
* Note: please do not call this function in your mod or you will break things. | ||
* | ||
* @param enabled True if the dynamic light is enabled, else false. | ||
*/ | ||
default void setDynamicLightEnabled(boolean enabled) | ||
{ | ||
if (enabled) | ||
LambDynLights.get().addLightSource(this); | ||
else | ||
LambDynLights.get().removeLightSource(this); | ||
} | ||
|
||
/** | ||
* Returns the luminance of the light source. | ||
* The maximum is 15, below 1 values are ignored. | ||
* | ||
* @return The luminance of the light source. | ||
*/ | ||
default int getLuminance() | ||
{ | ||
return this.getDynamicLightEntity().isOnFire() ? 15 : 0; | ||
} | ||
|
||
/** | ||
* Executed at each tick. | ||
*/ | ||
default void dynamicLightTick() | ||
{ | ||
} | ||
|
||
/** | ||
* Returns whether this dynamic light source should update. | ||
* | ||
* @return True if this dynamic light source should update, else false. | ||
*/ | ||
boolean shouldUpdateDynamicLight(); | ||
|
||
void lambdynlights_updateDynamicLight(@NotNull WorldRenderer renderer); | ||
|
||
void lambdynlights_scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer); | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/me/lambdaurora/lambdynlights/DynamicLightsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright © 2020 LambdAurora <[email protected]> | ||
* | ||
* This file is part of LambDynamicLights. | ||
* | ||
* Licensed under the MIT license. For more information, | ||
* see the LICENSE file. | ||
*/ | ||
|
||
package me.lambdaurora.lambdynlights; | ||
|
||
import com.electronwill.nightconfig.core.file.FileConfig; | ||
import me.lambdaurora.spruceui.option.SpruceCyclingOption; | ||
import net.minecraft.client.options.Option; | ||
import net.minecraft.text.LiteralText; | ||
import net.minecraft.text.TranslatableText; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Represents the mod configuration. | ||
* | ||
* @author LambdAurora | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public class DynamicLightsConfig | ||
{ | ||
private static final DynamicLightsMode DEFAULT_DYNAMIC_LIGHTS_MODE = DynamicLightsMode.OFF; | ||
|
||
protected final FileConfig config = FileConfig.builder("config/lambdynlights.toml").concurrent().defaultResource("/lambdynlights.toml").autosave().build(); | ||
private final LambDynLights mod; | ||
private DynamicLightsMode dynamicLightsMode; | ||
|
||
public final Option dynamicLightsModeOption = new SpruceCyclingOption("lambdynlights.options.mode", | ||
amount -> this.setDynamicLightsMode(this.dynamicLightsMode.next()), | ||
option -> option.getDisplayPrefix().append(this.dynamicLightsMode.getTranslatedText()), | ||
new TranslatableText("lambdynlights.tooltip.mode.1") | ||
.append(new LiteralText("\n")) | ||
.append(new TranslatableText("lambdynlights.tooltip.mode.2", DynamicLightsMode.FASTEST.getTranslatedText(), DynamicLightsMode.FAST.getTranslatedText())) | ||
.append(new LiteralText("\n")) | ||
.append(new TranslatableText("lambdynlights.tooltip.mode.3", DynamicLightsMode.FANCY.getTranslatedText()))); | ||
|
||
public DynamicLightsConfig(@NotNull LambDynLights mod) | ||
{ | ||
this.mod = mod; | ||
} | ||
|
||
/** | ||
* Loads the configuration. | ||
*/ | ||
public void load() | ||
{ | ||
this.config.load(); | ||
|
||
this.dynamicLightsMode = DynamicLightsMode.byId(this.config.getOrElse("mode", DEFAULT_DYNAMIC_LIGHTS_MODE.getName())) | ||
.orElse(DEFAULT_DYNAMIC_LIGHTS_MODE); | ||
|
||
this.mod.log("Configuration loaded."); | ||
} | ||
|
||
/** | ||
* Saves the configuration. | ||
*/ | ||
public void save() | ||
{ | ||
this.config.save(); | ||
} | ||
|
||
/** | ||
* Resets the configuration. | ||
*/ | ||
public void reset() | ||
{ | ||
this.setDynamicLightsMode(DEFAULT_DYNAMIC_LIGHTS_MODE); | ||
} | ||
|
||
/** | ||
* Returns the dynamic lights mode. | ||
* | ||
* @return The dynamic lights mode. | ||
*/ | ||
public DynamicLightsMode getDynamicLightsMode() | ||
{ | ||
return this.dynamicLightsMode; | ||
} | ||
|
||
/** | ||
* Sets the dynamic lights mode. | ||
* | ||
* @param mode The dynamic lights mode. | ||
*/ | ||
public void setDynamicLightsMode(@NotNull DynamicLightsMode mode) | ||
{ | ||
this.dynamicLightsMode = mode; | ||
this.config.set("mode", mode.getName()); | ||
|
||
if (!mode.isEnabled()) { | ||
this.mod.clearLightSources(); | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/me/lambdaurora/lambdynlights/DynamicLightsMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright © 2020 LambdAurora <[email protected]> | ||
* | ||
* This file is part of LambDynamicLights. | ||
* | ||
* Licensed under the MIT license. For more information, | ||
* see the LICENSE file. | ||
*/ | ||
|
||
package me.lambdaurora.lambdynlights; | ||
|
||
import net.minecraft.text.Text; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.Formatting; | ||
import org.aperlambda.lambdacommon.utils.Nameable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the dynamic lights mode. | ||
* | ||
* @author LambdAurora | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public enum DynamicLightsMode implements Nameable | ||
{ | ||
OFF(0, Formatting.RED), | ||
FASTEST(500, Formatting.GOLD), | ||
FAST(250, Formatting.YELLOW), | ||
FANCY(0, Formatting.GREEN); | ||
|
||
private final int delay; | ||
private final Formatting formatting; | ||
|
||
DynamicLightsMode(int delay, @NotNull Formatting formatting) | ||
{ | ||
this.delay = delay; | ||
this.formatting = formatting; | ||
} | ||
|
||
/** | ||
* Returns whether this mode enables dynamic lights. | ||
* | ||
* @return True if the mode enables dynamic lights, else false. | ||
*/ | ||
public boolean isEnabled() | ||
{ | ||
return this != OFF; | ||
} | ||
|
||
/** | ||
* Returns whether this mode has an update delay. | ||
* | ||
* @return True if the mode has an update delay, else false. | ||
*/ | ||
public boolean hasDelay() | ||
{ | ||
return this.delay != 0; | ||
} | ||
|
||
/** | ||
* Returns the update delay of this mode. | ||
* | ||
* @return The mode's update delay. | ||
*/ | ||
public int getDelay() | ||
{ | ||
return this.delay; | ||
} | ||
|
||
/** | ||
* Returns the next dynamic lights mode available. | ||
* | ||
* @return The next available dynamic lights mode. | ||
*/ | ||
public DynamicLightsMode next() | ||
{ | ||
DynamicLightsMode[] v = values(); | ||
if (v.length == this.ordinal() + 1) | ||
return v[0]; | ||
return v[this.ordinal() + 1]; | ||
} | ||
|
||
public @NotNull String getTranslationKey() | ||
{ | ||
return this == OFF ? "options.off" : ("lambdynlights.mode." + this.getName()); | ||
} | ||
|
||
/** | ||
* Returns the translated text of the dynamic lights mode. | ||
* | ||
* @return The translated text of the dynamic lights mode. | ||
*/ | ||
public @NotNull Text getTranslatedText() | ||
{ | ||
return new TranslatableText(this.getTranslationKey()).formatted(this.formatting); | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() | ||
{ | ||
return this.name().toLowerCase(); | ||
} | ||
|
||
/** | ||
* Gets the dynamic lights mode from its identifier. | ||
* | ||
* @param id The identifier of the dynamic lights mode. | ||
* @return The dynamic lights mode if found, else empty. | ||
*/ | ||
public static @NotNull Optional<DynamicLightsMode> byId(@NotNull String id) | ||
{ | ||
return Arrays.stream(values()).filter(mode -> mode.getName().equalsIgnoreCase(id)).findFirst(); | ||
} | ||
} |
Oops, something went wrong.