-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
344 additions
and
41 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
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
org.gradle.jvmargs = -Xmx1G | ||
org.gradle.jvmargs = -Xmx1G | ||
|
||
# fabric properties | ||
minecraft_version = 21w06a | ||
yarn_build = 21 | ||
loader_version = 0.11.1 | ||
minecraft_version = 21w06a | ||
yarn_build = 21 | ||
loader_version = 0.11.1 | ||
|
||
# mod properties | ||
mod_version = 1.0.0 | ||
maven_group = me.andante.undergroundambientlighting | ||
archives_base_name = undergroundambientlighting | ||
mod_version = 1.0.0 | ||
maven_group = me.andante.undergroundambientlighting | ||
archives_base_name = undergroundambientlighting | ||
|
||
# dependencies | ||
fabric_api_version = 0.30.4+1.17 | ||
fabric_api_version = 0.30.4+1.17 | ||
mod_menu_version = 2.0.0-beta.2 | ||
cloth_config_version = 5.0.10 |
30 changes: 0 additions & 30 deletions
30
src/main/java/me/andante/undergroundambientlighting/LightmapTextureManagerMixin.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/main/java/me/andante/undergroundambientlighting/UALModMenu.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,92 @@ | ||
package me.andante.undergroundambientlighting; | ||
|
||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
import me.andante.undergroundambientlighting.config.UALConfig; | ||
import me.andante.undergroundambientlighting.config.UALConfigManager; | ||
import me.shedaniel.clothconfig2.api.ConfigBuilder; | ||
import me.shedaniel.clothconfig2.api.ConfigCategory; | ||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.Identifier; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class UALModMenu implements ModMenuApi { | ||
@Override | ||
public ConfigScreenFactory<?> getModConfigScreenFactory() { | ||
return parentScreen -> { | ||
ConfigBuilder builder = ConfigBuilder.create() | ||
.setParentScreen(parentScreen) | ||
.setDefaultBackgroundTexture(new Identifier("textures/block/stone.png")) | ||
.setTitle(createConfigText("title")) | ||
.setSavingRunnable(UALConfigManager::save); | ||
|
||
builder.setGlobalized(true); | ||
builder.setGlobalizedExpanded(false); | ||
|
||
ConfigEntryBuilder entryBuilder = builder.entryBuilder(); | ||
|
||
// | ||
// MISC CATEGORY | ||
// | ||
|
||
ConfigCategory MISC = builder.getOrCreateCategory(createMiscText()); | ||
|
||
TranslatableText enabled = createMiscText(UALConfig.MISC.enabled.getId()); | ||
TranslatableText startY = createMiscText(UALConfig.MISC.startY.getId()); | ||
TranslatableText endY = createMiscText(UALConfig.MISC.endY.getId()); | ||
TranslatableText intensity = createMiscText(UALConfig.MISC.intensity.getId()); | ||
MISC.addEntry( | ||
entryBuilder.startBooleanToggle(enabled, UALConfig.MISC.enabled.getBoolean()) | ||
.setDefaultValue(UALConfig.MISC.enabled.getDefaultBoolean()) | ||
.setSaveConsumer(value -> UALConfig.MISC.enabled.value = value) | ||
.setTooltip(createTooltip(enabled)) | ||
.build() | ||
).addEntry( | ||
entryBuilder.startIntField(startY, UALConfig.MISC.startY.getInt()) | ||
.setDefaultValue(UALConfig.MISC.startY.getDefaultInt()) | ||
.setMin(UALConfig.MISC.startY.getMinInt()) | ||
.setMax(UALConfig.MISC.startY.getMaxInt()) | ||
.setSaveConsumer(value -> UALConfig.MISC.startY.value = value) | ||
.setTooltip(createTooltip(startY)) | ||
.build() | ||
).addEntry( | ||
entryBuilder.startIntField(endY, UALConfig.MISC.endY.getInt()) | ||
.setDefaultValue(UALConfig.MISC.endY.getDefaultInt()) | ||
.setMin(UALConfig.MISC.endY.getMinInt()) | ||
.setMax(UALConfig.MISC.endY.getMaxInt()) | ||
.setSaveConsumer(value -> UALConfig.MISC.endY.value = value) | ||
.setTooltip(createTooltip(endY)) | ||
.build() | ||
).addEntry( | ||
entryBuilder.startFloatField(intensity, UALConfig.MISC.intensity.getFloat()) | ||
.setDefaultValue(UALConfig.MISC.intensity.getDefaultFloat()) | ||
.setMin(UALConfig.MISC.intensity.getMinFloat()) | ||
.setMax(UALConfig.MISC.intensity.getMaxFloat()) | ||
.setSaveConsumer(value -> UALConfig.MISC.intensity.value = value) | ||
.setTooltip(createTooltip(intensity)) | ||
.build() | ||
); | ||
|
||
return builder.build(); | ||
}; | ||
} | ||
|
||
private TranslatableText createTooltip(TranslatableText text) { | ||
return new TranslatableText(text.getKey() + ".tooltip"); | ||
} | ||
private TranslatableText createMiscText(String label) { | ||
return createCatText("misc" + (label.isEmpty() ? "" : "." + label)); | ||
} | ||
private TranslatableText createMiscText() { | ||
return createMiscText(""); | ||
} | ||
private TranslatableText createCatText(String group) { | ||
return createConfigText("category." + group); | ||
} | ||
private TranslatableText createConfigText(String label) { | ||
return new TranslatableText("config." + UndergroundAmbientLighting.MOD_ID + "." + label); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/me/andante/undergroundambientlighting/UndergroundAmbientLighting.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,13 @@ | ||
package me.andante.undergroundambientlighting; | ||
|
||
import me.andante.undergroundambientlighting.config.UALConfigManager; | ||
import net.fabricmc.api.ClientModInitializer; | ||
|
||
public class UndergroundAmbientLighting implements ClientModInitializer { | ||
public static final String MOD_ID = "undergroundambientlighting"; | ||
|
||
@Override | ||
public void onInitializeClient() { | ||
UALConfigManager.load(); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
src/main/java/me/andante/undergroundambientlighting/config/UALConfig.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,114 @@ | ||
package me.andante.undergroundambientlighting.config; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class UALConfig { | ||
public static MiscGroup MISC = new MiscGroup(); | ||
public static class MiscGroup { | ||
/** | ||
* Enable or disable the entire mod. | ||
*/ | ||
public Option enabled = new Option("enabled", true); | ||
/** | ||
* The Y level at which the effect begins to fade in. | ||
*/ | ||
public RangedOption startY = new RangedOption("start_y", 63, -512, 512); | ||
/** | ||
* The Y level at which the effect becomes strongest. | ||
*/ | ||
public RangedOption endY = new RangedOption("end_y", 32, -512, 512); | ||
/** | ||
* The intensity of the effect by default. | ||
*/ | ||
public RangedOption intensity = new RangedOption("intensity", 0.032F, 0.0F, 1.0F); | ||
} | ||
|
||
/** | ||
* A configuration option. | ||
*/ | ||
public static class Option { | ||
private final String id; | ||
public Object value; | ||
private final Object defaultValue; | ||
|
||
/** | ||
* Instantiates a new configuration option. | ||
* | ||
* @param id The option's identifier. | ||
* @param defaultVal The option's default value. | ||
*/ | ||
private Option(String id, Object defaultVal) { | ||
this.id = id; | ||
this.defaultValue = defaultVal; | ||
this.value = this.defaultValue; | ||
} | ||
|
||
public boolean getBoolean() { | ||
if (value instanceof Boolean) return (Boolean)this.value; | ||
else throw new RuntimeException(); | ||
} | ||
public int getInt() { | ||
if (value instanceof Integer) return (Integer)this.value; | ||
else throw new RuntimeException(); | ||
} | ||
public float getFloat() { | ||
if (value instanceof Float) return (Float)this.value; | ||
else throw new RuntimeException(); | ||
} | ||
|
||
public Boolean getDefaultBoolean() { | ||
if (value instanceof Boolean) return (Boolean)this.defaultValue; | ||
else throw new RuntimeException(); | ||
} | ||
public int getDefaultInt() { | ||
if (value instanceof Integer) return (Integer)this.defaultValue; | ||
else throw new RuntimeException(); | ||
} | ||
public float getDefaultFloat() { | ||
if (value instanceof Float) return (Float)this.defaultValue; | ||
else throw new RuntimeException(); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
} | ||
public static class RangedOption extends Option { | ||
private final Object min; | ||
private final Object max; | ||
|
||
/** | ||
* Instantiates a new ranged configuration option. | ||
* | ||
* @param id The option's identifier. | ||
* @param defaultVal The option's default value. | ||
* @param min The option's minimum value. | ||
* @param max The option's maximum value. | ||
*/ | ||
private RangedOption(String id, Object defaultVal, Object min, Object max) { | ||
super(id, defaultVal); | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public float getMinFloat() { | ||
if (value instanceof Float) return (Float)this.min; | ||
else throw new RuntimeException(); | ||
} | ||
public float getMaxFloat() { | ||
if (value instanceof Float) return (Float)this.max; | ||
else throw new RuntimeException(); | ||
} | ||
|
||
public int getMinInt() { | ||
if (value instanceof Integer) return (Integer)this.min; | ||
else throw new RuntimeException(); | ||
} | ||
public int getMaxInt() { | ||
if (value instanceof Integer) return (Integer)this.max; | ||
else throw new RuntimeException(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/me/andante/undergroundambientlighting/config/UALConfigManager.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,48 @@ | ||
package me.andante.undergroundambientlighting.config; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import me.andante.undergroundambientlighting.UndergroundAmbientLighting; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.nio.file.Files; | ||
|
||
public class UALConfigManager { | ||
private static final File FILE = FabricLoader.getInstance().getConfigDir().toFile().toPath().resolve(UndergroundAmbientLighting.MOD_ID + ".json").toFile(); | ||
|
||
public static void save() { | ||
JsonObject jsonObject = new JsonObject(); | ||
|
||
UALConfig.MiscGroup MISC = UALConfig.MISC; | ||
jsonObject.addProperty(MISC.enabled.getId(), MISC.enabled.getBoolean()); | ||
jsonObject.addProperty(MISC.startY.getId(), MISC.startY.getInt()); | ||
jsonObject.addProperty(MISC.endY.getId(), MISC.endY.getInt()); | ||
jsonObject.addProperty(MISC.intensity.getId(), MISC.intensity.getFloat()); | ||
|
||
try (PrintWriter out = new PrintWriter(FILE)) { | ||
out.println(jsonObject.toString()); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
public static void load() { | ||
try { | ||
String json = new String(Files.readAllBytes(FILE.toPath())); | ||
if (!json.equals("")) { | ||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(json); | ||
|
||
UALConfig.MiscGroup MISC = UALConfig.MISC; | ||
MISC.enabled.value = jsonObject.getAsJsonPrimitive(MISC.enabled.getId()).getAsBoolean(); | ||
MISC.startY.value = jsonObject.getAsJsonPrimitive(MISC.startY.getId()).getAsInt(); | ||
MISC.endY.value = jsonObject.getAsJsonPrimitive(MISC.endY.getId()).getAsInt(); | ||
MISC.intensity.value = jsonObject.getAsJsonPrimitive(MISC.intensity.getId()).getAsFloat(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/me/andante/undergroundambientlighting/mixin/LightmapTextureManagerMixin.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,34 @@ | ||
package me.andante.undergroundambientlighting.mixin; | ||
|
||
import me.andante.undergroundambientlighting.config.UALConfig; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.LightmapTextureManager; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
|
||
@Mixin(LightmapTextureManager.class) | ||
public abstract class LightmapTextureManagerMixin { | ||
@Shadow @Final private MinecraftClient client; | ||
|
||
@ModifyVariable(method = "update", ordinal = 5, at = @At(value = "STORE", ordinal = 0)) | ||
private float applyUndergroundAmbientLight(float l) { | ||
if (UALConfig.MISC.enabled.getBoolean()) { | ||
assert this.client.player != null; | ||
double playerY = this.client.player.getY(); | ||
int startY = UALConfig.MISC.startY.getInt(); | ||
|
||
if (playerY <= startY) { | ||
int endY = UALConfig.MISC.endY.getInt(); | ||
float addedLight = UALConfig.MISC.intensity.getFloat(); | ||
l += playerY >= endY | ||
? addedLight * (float) ((Math.cos((playerY - endY) / (Math.abs(startY - endY) / Math.PI)) + 1) / 2) | ||
: addedLight; | ||
} | ||
} | ||
|
||
return l; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/resources/assets/undergroundambientlighting/lang/en_us.json
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,14 @@ | ||
{ | ||
"mod.undergroundambientlighting.name": "Underground Ambient Lighting", | ||
|
||
"config.undergroundambientlighting.title": "Underground Ambient Lighting", | ||
"config.undergroundambientlighting.category.misc": "Miscellaneous", | ||
"config.undergroundambientlighting.category.misc.enabled": "Enabled", | ||
"config.undergroundambientlighting.category.misc.enabled.tooltip": "Enable or disable the entire mod", | ||
"config.undergroundambientlighting.category.misc.start_y": "Starting Y level", | ||
"config.undergroundambientlighting.category.misc.start_y.tooltip": "The Y level at which the effect begins to fade in", | ||
"config.undergroundambientlighting.category.misc.end_y": "End Y level", | ||
"config.undergroundambientlighting.category.misc.end_y.tooltip": "The Y level at which the effect becomes strongest", | ||
"config.undergroundambientlighting.category.misc.intensity": "Intensity", | ||
"config.undergroundambientlighting.category.misc.intensity.tooltip": "The intensity of the effect" | ||
} |
Oops, something went wrong.