Compare commits

...

13 Commits
Crog2 ... test

Author SHA1 Message Date
Liz Graham
f26764f5c9 add build-release.yml 2022-03-25 14:57:57 +00:00
Liz Graham
d5f549c417 update fabric json and change config code 2022-03-20 16:56:58 +00:00
Liz Graham
044e78b6fd add underwater check 2 2022-03-17 22:08:28 +00:00
Liz Graham
0437022254 do underwater check 2022-03-17 22:07:07 +00:00
Liz Graham
1e595e23c1 remove debug mixin 2022-03-17 21:48:57 +00:00
Liz Graham
8b14d89369 add basic config 2022-03-17 21:48:46 +00:00
Liz Graham
88b58f137b Update README.md 2022-03-03 03:36:38 +00:00
Liz Graham
dbab825f90 Update README.md 2022-03-03 03:34:53 +00:00
Liz Graham
87fb6b94f6 change modid to dust 2022-03-03 03:26:30 +00:00
Liz Graham
197a115673 update mod version 2022-03-03 03:20:14 +00:00
Liz Graham
3bf86d170c Add config 2022-03-03 03:13:12 +00:00
Liz Graham
25c3ab29b0 Fixed dust build up in pause menu, fixed crash on leave and rejoin singleplayer, added github actions 2022-03-03 01:51:23 +00:00
Liz Graham
3f34718284 based 2022-03-03 01:12:52 +00:00
21 changed files with 782 additions and 81 deletions

60
.github/workflows/build-release.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: build-release
on:
release:
types:
- published
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Set up JDK 16
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 17
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/loom-cache
~/.gradle/wrapper
~/.m2/repository
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle
- run: chmod +x gradlew
- name: Build Release
run: ./gradlew build --stacktrace
- name: Upload artifacts to Modrinth, Curseforge and GitHub
uses: Kir-Antipov/mc-publish@v2.0
with:
modrinth-id: jawg7zT1
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
curseforge-id: 594750
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
files: build/libs/!(*-@(dev|sources|all)).jar
version-type: release
loaders: fabric
java: 17
dependencies: |
fabric-api | depends | 0.46.0
kirin | includes | 1.10.0-beta.2
modmenu | recommends | *
version-resolver: latest # Defaults to selecting the latest compatible version of Minecraft, using the tag from the fabric.mod.json

View File

@@ -12,28 +12,39 @@ jobs:
matrix: matrix:
# Use these Java versions # Use these Java versions
java: [ java: [
17, # Current Java LTS & minimum supported by Minecraft 17 # Minimum supported by Minecraft 1.18
] ]
# and run on both Linux and Windows os: [ubuntu-20.04] # and run on Linux
os: [ubuntu-20.04, windows-2022]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- name: checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: validate gradle wrapper
- name: Extract current branch name
shell: bash
# bash pattern expansion to grab branch name without slashes
run: ref="${GITHUB_REF#refs/heads/}" && echo "::set-output name=branch::${ref////-}"
id: ref
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1 uses: gradle/wrapper-validation-action@v1
- name: setup jdk ${{ matrix.java }}
- name: Setup JDK${{ matrix.java }}
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: ${{ matrix.java }} java-version: ${{ matrix.java }}
- name: make gradle wrapper executable
- name: Make gradle wrapper executable
if: ${{ runner.os != 'Windows' }} if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew run: chmod +x gradlew
- name: build
- name: Build
run: ./gradlew build run: ./gradlew build
- name: capture build artifacts
- name: Capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: Artifacts name: dust-fabric-${{ github.sha }}
path: build/libs/ path: build/libs/*[0-9].jar

3
.gitignore vendored
View File

@@ -31,3 +31,6 @@ bin/
# fabric # fabric
run/ run/
# github
.github/secret.json

View File

@@ -1,9 +1,13 @@
# Fabric Example Mod # Cave Dust
## Setup ## What...what is "Cave Dust"?
For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. I'm glad you asked! It's just a mod that adds the white ash particle from the Basalt Deltas biome to the underground to simulate dust! After all, the air wouldn't be 100% clear in a real mineshaft :p
## License Now to the nitty gritty:
It works by checking if the player has the sky above them while being below sea level and then scales the amount of particles based on depth.
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. <br><br>It has a config system that you can access using Mod Menu, most things you can change in-game, but to change the particle you'll need to open the config file manually :)
<br>
## Dependencies
Cave Dust requires the [Fabric API](https://www.curseforge.com/minecraft/mc-mods/fabric-api) but everything else Cave Dust *needs* is included.
***HOWEVER***, I recommend [Mod Menu](https://www.curseforge.com/minecraft/mc-mods/modmenu) to be able to use the config screen :p

View File

@@ -11,6 +11,24 @@ version = project.mod_version
group = project.maven_group group = project.maven_group
repositories { repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
maven {
url = "https://maven.terraformersmc.com"
}
maven {
name = 'minelp'
url = 'https://repo.minelittlepony-mod.com/maven/snapshot'
}
maven {
name = 'minelp-release'
url = 'https://repo.minelittlepony-mod.com/maven/release'
}
// Add repositories to retrieve artifacts from in here. // Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because // You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
@@ -26,6 +44,11 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modApi "com.minelittlepony:kirin:${project.kirin_version}"
include "com.minelittlepony:kirin:${project.kirin_version}"
modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
} }
processResources { processResources {

View File

@@ -3,14 +3,18 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
minecraft_version=1.18.2 minecraft_version=1.18.1
yarn_mappings=1.18.2+build.1 yarn_mappings=1.18.1+build.22
loader_version=0.13.3 loader_version=0.12.11
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.1.1
maven_group = com.example maven_group = com.lizistired
archives_base_name = fabric-example-mod archives_base_name = cave_dust
# Dependencies # Dependencies
fabric_version=0.47.8+1.18.2 fabric_version=0.46.4+1.18
clothconfig_version = 6.1.48
modmenu_version = 3.0.1
minelp_version=4.4.0-beta.2
kirin_version=1.10.0-beta.2

View File

@@ -1,21 +0,0 @@
package net.fabricmc.example;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExampleMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("modid");
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
}
}

View File

@@ -1,16 +0,0 @@
package net.fabricmc.example.mixin;
import net.fabricmc.example.ExampleMod;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TitleScreen.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
ExampleMod.LOGGER.info("This line is printed by an example mod mixin!");
}
}

View File

@@ -0,0 +1,68 @@
package net.lizistired.cavedust;
//minecraft imports
import net.minecraft.client.MinecraftClient;
import net.minecraft.world.World;
//other imports
import com.minelittlepony.common.util.GamePaths;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//java imports
import java.nio.file.Path;
//static imports
import static net.lizistired.cavedust.utils.MathHelper.*;
public class CaveDust implements ClientModInitializer {
//logger
public static final Logger LOGGER = LoggerFactory.getLogger("caveDust");
//make class static
private static CaveDust instance;
public static CaveDust getInstance() {
return instance;
}
public CaveDust() {
instance = this;
}
//config assignment
private static CaveDustConfig config;
public CaveDustConfig getConfig() {
return config;
}
@Override
public void onInitializeClient() {
//config path and loading
Path CaveDustFolder = GamePaths.getConfigDirectory().resolve("cavedust");
config = new CaveDustConfig(CaveDustFolder.getParent().resolve("cavedust.json"), this);
config.load();
//register end client tick to create cave dust function, using end client tick for async
ClientTickEvents.END_CLIENT_TICK.register(this::createCaveDust);
}
private void createCaveDust(MinecraftClient client) {
if (client.world == null) return;
World world = client.world;
if (shouldParticlesSpawn(client, config)) {
double probabilityNormalized = normalize(config.getLowerLimit(), config.getUpperLimit(), client.player.getBlockY());
for (int i = 0; i < probabilityNormalized * config.getParticleMultiplier(); i++) {
try {
double x = client.player.getPos().getX() + generateRandomDouble(config.getDimensionsMinX(), config.getDimensionsMaxX());
double y = client.player.getPos().getY() + generateRandomDouble(config.getDimensionsMinX(), config.getDimensionsMaxY());
double z = client.player.getPos().getZ() + generateRandomDouble(config.getDimensionsMinX(), config.getDimensionsMaxZ());
world.addParticle(config.getParticle(), x, y, z, 0, 0, 0);}
catch (NullPointerException e) {
LOGGER.error(String.valueOf(e));
getConfig().setParticle("minecraft:white_ash");
}
}
}
}
}

View File

@@ -0,0 +1,205 @@
package net.lizistired.cavedust;
import net.lizistired.cavedust.utils.JsonFile;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import static net.lizistired.cavedust.CaveDust.*;
import java.nio.file.Path;
public class CaveDustConfig extends JsonFile {
private transient final CaveDust CaveDust;
private int dimensionMaxX = 5;
private int dimensionMaxY = 5;
private int dimensionMaxZ = 5;
private int dimensionMinX = -5;
private int dimensionMinY = -5;
private int dimensionMinZ = -5;
private boolean caveDustEnabled = true;
private String particleName = "white_ash";
private boolean seaLevelCheck = true;
private float upperLimit = 64;
private float lowerLimit = -64;
private float particleMultiplier = 1;
public CaveDustConfig(Path file, CaveDust caveDust) {
super(file);
this.CaveDust = caveDust;
}
public float setDimensionsMinX(float size){
if (this.dimensionMinX != size) {
this.dimensionMinX = (int)size;
save();
}
return getDimensionsMinX();
}
public float setDimensionsMinY(float size){
if (this.dimensionMinY != size) {
this.dimensionMinY = (int)size;
save();
}
return getDimensionsMinY();
}
public float setDimensionsMinZ(float size){
if (this.dimensionMinZ != size) {
this.dimensionMinZ = (int)size;
save();
}
return getDimensionsMinZ();
}
public float getDimensionsMinX(){
return dimensionMinX;
}
public float getDimensionsMinY(){
return dimensionMinY;
}
public float getDimensionsMinZ(){
return dimensionMinZ;
}
public float setDimensionsMaxX(float size){
if (this.dimensionMaxX != size) {
this.dimensionMaxX = (int)size;
save();
}
return getDimensionsMaxX();
}
public float setDimensionsMaxY(float size){
if (this.dimensionMaxY != size) {
this.dimensionMaxY = (int)size;
save();
}
return getDimensionsMaxY();
}
public float setDimensionsMaxZ(float size){
if (this.dimensionMaxZ != size) {
this.dimensionMaxZ = (int)size;
save();
}
return getDimensionsMaxZ();
}
public float getDimensionsMaxX(){
return dimensionMaxX;
}
public float getDimensionsMaxY(){
return dimensionMaxY;
}
public float getDimensionsMaxZ(){
return dimensionMaxZ;
}
public float setUpperLimit(float upperLimit){
if (this.upperLimit - 1 < getLowerLimit())
{
return getUpperLimit();
}
if (this.upperLimit != upperLimit) {
this.upperLimit = (int)upperLimit;
save();
}
return getUpperLimit();
}
public float getUpperLimit(){
return upperLimit;
}
public float setLowerLimit(float lowerLimit){
if (this.lowerLimit + 1 > getUpperLimit())
{
return getLowerLimit();
}
if (this.lowerLimit != lowerLimit) {
this.lowerLimit = (int)lowerLimit;
save();
}
return getLowerLimit();
}
public float getLowerLimit(){
return lowerLimit;
}
public float getParticleMultiplier(){
return particleMultiplier;
}
public float setParticleMultiplier(float particleMultiplier){
this.particleMultiplier = particleMultiplier;
save();
return getParticleMultiplier();
}
public boolean toggleCaveDust(){
caveDustEnabled = !caveDustEnabled;
save();
return caveDustEnabled;
}
public boolean getCaveDustEnabled(){
return caveDustEnabled;
}
public ParticleEffect setParticle(String particleType){
particleName = particleType;
save();
return getParticle();
}
public ParticleEffect getParticle(){
try {
return (ParticleEffect) Registry.PARTICLE_TYPE.get(new Identifier(particleName.toLowerCase()));
} catch (ClassCastException e) {
LOGGER.error(e + "\nThere was an error loading the specified particle from the config, make sure a valid particle name is specified. Falling back to \"minecraft:white_ash\".");
particleName = "minecraft:white_ash";
save();
return ParticleTypes.WHITE_ASH;
}
}
public boolean getSeaLevelCheck() {
return seaLevelCheck;
}
public boolean setSeaLevelCheck() {
seaLevelCheck = !seaLevelCheck;
save();
return getSeaLevelCheck();
}
public void resetConfig(){
dimensionMinX = -5;
dimensionMinY = -5;
dimensionMinZ = -5;
dimensionMaxX = 5;
dimensionMaxY = 5;
dimensionMaxZ = 5;
upperLimit = 64;
lowerLimit = -64;
particleMultiplier = 1;
seaLevelCheck = true;
caveDustEnabled = true;
particleName = "minecraft:white_ash";
save();
}
}

View File

@@ -0,0 +1,11 @@
package net.lizistired.cavedust;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
public class CaveDustModMenuFactory implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return net.lizistired.cavedust.ModMenuScreen::new;
}
}

View File

@@ -0,0 +1,97 @@
package net.lizistired.cavedust;
import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.common.client.gui.element.*;
import net.lizistired.cavedust.utils.TranslatableTextHelper;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import javax.annotation.Nullable;
public class ModMenuScreen extends GameGui {
public ModMenuScreen(@Nullable Screen parent) {
super(new TranslatableText("menu.cavedust.title"), parent);
}
@Override
public void init() {
int left = width / 2 - 100;
int row = height / 4 + 14;
CaveDustConfig config = CaveDust.getInstance().getConfig();
TranslatableTextHelper transText = new TranslatableTextHelper();
config.load();
addButton(new Label(width / 2, 30)).setCentered().getStyle()
.setText(getTitle());
addButton(new Button(left, row += -60).onClick(sender -> {
sender.getStyle().setText("menu.cavedust.global." + config.toggleCaveDust()).setTooltip(new TranslatableText("menu.cavedust.global.tooltip." + config.getCaveDustEnabled()));
})).getStyle()
.setText("menu.cavedust.global." + config.getCaveDustEnabled())
.setTooltip(new TranslatableText("menu.cavedust.global.tooltip." + config.getCaveDustEnabled()));
addButton(new Slider(left += -110, row += 24, -50, 0, config.getDimensionsMinX()))
.onChange(config::setDimensionsMinX)
.setTextFormat(transText::formatMinX)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.minX.tooltip"));
addButton(new Slider(left, row += 24, -50, 0, config.getDimensionsMinY()))
.onChange(config::setDimensionsMinY)
.setTextFormat(transText::formatMinY)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.minY.tooltip"));
addButton(new Slider(left, row += 24, -50, 0, config.getDimensionsMinZ()))
.onChange(config::setDimensionsMinZ)
.setTextFormat(transText::formatMinZ)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.minZ.tooltip"));
addButton(new Slider(left += 220, row += -48, 0, 50, config.getDimensionsMaxX()))
.onChange(config::setDimensionsMaxX)
.setTextFormat(transText::formatMaxX)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.maxX.tooltip"));
addButton(new Slider(left, row += 24, 0, 50, config.getDimensionsMaxY()))
.onChange(config::setDimensionsMaxY)
.setTextFormat(transText::formatMaxY)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.maxY.tooltip"));
addButton(new Slider(left, row += 24, 0, 50, config.getDimensionsMaxZ()))
.onChange(config::setDimensionsMaxZ)
.setTextFormat(transText::formatMaxZ)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.maxZ.tooltip"));
addButton(new Slider(left += -110, row += 24, -64, 319, config.getUpperLimit()))
.onChange(config::setUpperLimit)
.setTextFormat(transText::formatUpperLimit)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.upperlimit.tooltip"));
addButton(new Slider(left, row += 24, -64, 319, config.getLowerLimit()))
.onChange(config::setLowerLimit)
.setTextFormat(transText::formatLowerLimit)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.lowerlimit.tooltip"));
addButton(new Slider(left, row += 24, 0, 10, config.getParticleMultiplier()))
.onChange(config::setParticleMultiplier)
.setTextFormat(transText::formatParticleMultiplier)
.getStyle().setTooltip(new TranslatableText("menu.cavedust.particlemultiplier.tooltip"));
addButton(new Button(left, row += 24).onClick(sender -> {
config.resetConfig();
finish();
})).getStyle().setText(new TranslatableText("menu.cavedust.reset")).setTooltip(new TranslatableText("menu.cavedust.reset.tooltip"));
addButton(new Button(left, row += 180)
.onClick(sender -> finish())).getStyle()
.setText("gui.done");
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
renderBackground(matrices);
super.render(matrices, mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,45 @@
package net.lizistired.cavedust.mixin;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.Objects;
import static net.lizistired.cavedust.utils.MathHelper.*;
@Mixin(DebugHud.class)
public abstract class MixinDebugScreenOverlay {
@Unique
private static final List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
@Unique
private static final BufferPoolMXBean directPool;
static {
BufferPoolMXBean found = null;
for (BufferPoolMXBean pool : pools) {
if (pool.getName().equals("direct")) {
found = pool;
break;
}
}
directPool = Objects.requireNonNull(found);
}
@Inject(method = "getRightText", at = @At("RETURN"))
private void appendShaderPackText(CallbackInfoReturnable<List<String>> cir) {
List<String> messages = cir.getReturnValue();
messages.add("");
messages.add("Should particles spawn: " + shouldParticlesSpawn);
messages.add("");
}
}

View File

@@ -0,0 +1,54 @@
package net.lizistired.cavedust.utils;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import net.lizistired.cavedust.CaveDust;
public class JsonFile {
protected transient final Gson gson = new GsonBuilder()
.registerTypeAdapter(getClass(), (InstanceCreator<JsonFile>)t -> this)
.setPrettyPrinting()
.create();
private transient Path file;
JsonFile() { }
public JsonFile(Path file) {
this.file = file;
}
public final void load() {
if (Files.isReadable(file)) {
try (Reader reader = Files.newBufferedReader(file)) {
load(reader);
} catch (Exception e) {
CaveDust.LOGGER.error("Invalid config", e);
}
}
save();
}
public final void load(Reader reader) {
gson.fromJson(reader, getClass());
}
public final void save() {
try {
Files.createDirectories(file.getParent());
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
gson.toJson(this, writer);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,74 @@
package net.lizistired.cavedust.utils;
import net.lizistired.cavedust.CaveDustConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.DimensionEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.OverworldBiomeCreator;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.feature.OceanRuinFeature;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import static net.minecraft.world.biome.BiomeKeys.LUSH_CAVES;
public class MathHelper {
private static float timer;
public static boolean shouldParticlesSpawn;
public static double normalize(double min, double max, double val) {
return 1 - ((val - min) / (max - min));
}
public static int getRandomNumberUsingInts(int min, int max) {
Random random = new Random();
return random.ints(min, max)
.findFirst()
.getAsInt();
}
public static double generateRandomDouble(double min, double max) {
return ThreadLocalRandom.current().nextDouble(min, max);
}
public static boolean shouldParticlesSpawn(MinecraftClient client, CaveDustConfig config) {
//checks if the config is enabled, if the game isn't paused, if the world is valid, if the particle is valid and if the player isn't in a lush caves biome
if (!config.getCaveDustEnabled()
|| client.isPaused()
|| client.world == null
|| !client.world.getDimension().isBedWorking()
|| Objects.equals(client.world.getBiomeKey(Objects.requireNonNull(client.player).getBlockPos()), Optional.of(LUSH_CAVES))
|| Objects.requireNonNull(client.player).isSubmergedInWater())
{
timer = 0;
shouldParticlesSpawn = false;
return false;
}
World world = client.world;
int seaLevel = world.getSeaLevel();
if (!client.player.clientWorld.isSkyVisible(client.player.getBlockPos())) {
if (client.player.getBlockPos().getY() < seaLevel){
timer = timer + 1;
if (timer > 10){
timer = 10;
shouldParticlesSpawn = true;
return true;
}
}
}
shouldParticlesSpawn = false;
return false;
}
}

View File

@@ -0,0 +1,35 @@
package net.lizistired.cavedust.utils;
import com.minelittlepony.common.client.gui.element.AbstractSlider;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
public class TranslatableTextHelper {
public Text formatMinX(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.minX", (int)Math.floor(slider.getValue()));
}
public Text formatMinY(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.minY", (int)Math.floor(slider.getValue()));
}
public Text formatMinZ(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.minZ", (int)Math.floor(slider.getValue()));
}
public Text formatMaxX(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.maxX", (int)Math.floor(slider.getValue()));
}
public Text formatMaxY(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.maxY", (int)Math.floor(slider.getValue()));
}
public Text formatMaxZ(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.maxZ", (int)Math.floor(slider.getValue()));
}
public Text formatUpperLimit(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.upperlimit", (int)Math.floor(slider.getValue()));
}
public Text formatLowerLimit(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.lowerlimit", (int)Math.floor(slider.getValue()));
}
public Text formatParticleMultiplier(AbstractSlider<Float> slider) {
return new TranslatableText("menu.cavedust.particlemultiplier", (int)Math.floor(slider.getValue()));
}
}

View File

@@ -0,0 +1,10 @@
package net.lizistired.caveDust.utils;
import net.minecraft.client.MinecraftClient;
public class WindowFocusHelper {
private static boolean unpaused;
public boolean unpausedMenu(MinecraftClient client){
return unpaused;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 227 KiB

View File

@@ -0,0 +1,27 @@
{
"menu.cavedust.title": "Cave Dust",
"menu.cavedust.global.false": "Cave Dust: Disabled",
"menu.cavedust.global.true": "Cave Dust: Enabled",
"menu.cavedust.global.tooltip.false": "Enable cave dust particles?",
"menu.cavedust.global.tooltip.true": "Disable cave dust particles?",
"menu.cavedust.minX": "Minimum X: %s",
"menu.cavedust.minY": "Minimum Y: %s",
"menu.cavedust.minZ": "Minimum Z: %s",
"menu.cavedust.maxX": "Maximum X: %s",
"menu.cavedust.maxY": "Maximum Y: %s",
"menu.cavedust.maxZ": "Maximum Z: %s",
"menu.cavedust.minX.tooltip": "Minimum X: %s",
"menu.cavedust.minY.tooltip": "Minimum Y: %s",
"menu.cavedust.minZ.tooltip": "Minimum Z: %s",
"menu.cavedust.maxX.tooltip": "Maximum X: %s",
"menu.cavedust.maxY.tooltip": "Maximum Y: %s",
"menu.cavedust.maxZ.tooltip": "Maximum Z: %s",
"menu.cavedust.upperlimit": "Upper limit: %s",
"menu.cavedust.lowerlimit": "Lower limit: %s",
"menu.cavedust.upperlimit.tooltip": "The height where particles will fade out and stop spawning (uses player y).",
"menu.cavedust.lowerlimit.tooltip": "The height where particles spawn the most (uses player y).",
"menu.cavedust.reset": "Reset settings",
"menu.cavedust.reset.tooltip": "Are you sure you want to reset all settings?",
"menu.cavedust.particlemultiplier": "Particle multiplier: %s",
"menu.cavedust.particlemultiplier.tooltip": "Multiplies the amount of particles at any given depth."
}

View File

@@ -1,12 +1,13 @@
{ {
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "net.fabricmc.example.mixin", "package": "net.lizistired.cavedust.mixin",
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_16",
"mixins": [ "mixins": [
], ],
"client": [ "client": [
"ExampleMixin" ],
"server": [
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

View File

@@ -1,38 +1,44 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "modid", "id": "cavedust",
"version": "${version}", "version": "${version}",
"name": "Cave Dust",
"name": "Example Mod", "description": "Makes dust underground that scales with depth!",
"description": "This is an example description! Tell everyone what your mod is about!",
"authors": [ "authors": [
"Me!" "LizIsTired"
], ],
"contact": { "contact": {
"homepage": "https://fabricmc.net/", "issues": "https://github.com/LizIsTired/dust/issues",
"sources": "https://github.com/FabricMC/fabric-example-mod" "sources": "https://github.com/LizIsTired/dust"
}, },
"license": "CC0-1.0", "license": "CC0-1.0",
"icon": "assets/modid/icon.png", "icon": "assets/modid/icon.png",
"environment": "*", "environment": "*",
"entrypoints": { "entrypoints": {
"main": [ "client": [
"net.fabricmc.example.ExampleMod" "net.lizistired.cavedust.CaveDust"
],
"modmenu": [
"net.lizistired.cavedust.CaveDustModMenuFactory"
] ]
}, },
"mixins": [ "mixins": [
"modid.mixins.json" "dust.mixins.json"
], ],
"depends": { "depends": {
"fabricloader": ">=0.13.3", "fabricloader": ">=0.12.11",
"fabric": "*", "fabric": "*",
"minecraft": "1.18.x", "minecraft": "<=1.18.1",
"java": ">=17" "java": ">=17"
}, },
"suggests": { "suggests": {
"another-mod": "*" "modmenu": ">=3.0.1"
},
"custom": {
"modmenu": {
"links": {
"modmenu.discord": "https://discord.gg/4m6kQSX6bx"
}
}
} }
} }