Skip to content

Commit

Permalink
🔖 LambDynamicLights v1.0.0: Initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Jul 4, 2020
1 parent 8d3b054 commit 6ada0f1
Show file tree
Hide file tree
Showing 26 changed files with 1,707 additions and 10 deletions.
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ repositories {
name = "AperLambda"
url = 'https://aperlambda.github.io/maven'
}
//maven { url = "https://jitpack.io" }
flatDir {
dirs "lib"
}
maven { url = "https://jitpack.io" }
}

configurations {
Expand All @@ -36,19 +33,20 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "me.lambdaurora:spruceui:${project.spruceui_version}"
modImplementation "com.github.lambdaurora:spruceui:${project.spruceui_version}"
include "com.github.lambdaurora:spruceui:${project.spruceui_version}"

modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
// modImplementation ":phosphor-fabric-mc${project.minecraft_version}-0.6.0+build.7-dev"
// One day, Sodium compatibility.
//modImplementation "com.github.jellysquid3:sodium:1.16.x~dev-SNAPSHOT"
//modImplementation ":sodium-fabric-mc1.16.1-0.1.0-SNAPSHOT-dev"

shadow "com.electronwill.night-config:core:3.6.3"
shadow "com.electronwill.night-config:toml:3.6.3"

shadow "org.aperlambda:lambdajcommon:1.8.0"
shadow ("org.aperlambda:lambdajcommon:1.8.0") {
// Minecraft already has all that google crap.
exclude group: 'com.google.code.gson'
exclude group: 'com.google.guava'
}
}

tasks.withType(JavaCompile) {
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/me/lambdaurora/lambdynlights/DynamicLightSource.java
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 src/main/java/me/lambdaurora/lambdynlights/DynamicLightsConfig.java
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 src/main/java/me/lambdaurora/lambdynlights/DynamicLightsMode.java
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();
}
}
Loading

0 comments on commit 6ada0f1

Please sign in to comment.