Skip to content

Commit

Permalink
Fix bugs and fix #4
Browse files Browse the repository at this point in the history
Particles can no longer spawn under the world.
Particles no longer spawn in blocks, instead spawning in air.
Fixed bug present since 1.2.0, which meant particle amount was dependant on blocks around player.
New particle multiplier allowing greater control of particle amount.
New F3 screen text, allows user to debug particle amount.
Removed upper and lower limit buttons.
  • Loading branch information
LizIsTired committed May 22, 2023
1 parent c345b78 commit 5f48fec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/main/java/net/lizistired/cavedust/CaveDust.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.lizistired.cavedust;

//minecraft imports
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
Expand Down Expand Up @@ -40,6 +41,7 @@ public net.lizistired.cavedust.CaveDustConfig getConfig() {
}

public static int WHITE_ASH_ID = Registries.PARTICLE_TYPE.getRawId(ParticleTypes.WHITE_ASH);
public static int PARTICLE_AMOUNT = 0;


@Override
Expand Down Expand Up @@ -72,18 +74,20 @@ private void createCaveDust(MinecraftClient client) {
//LOGGER.info(String.valueOf(((ClientWorldAccessor) client.world.getLevelProperties()).getFlatWorld()));
// )
double probabilityNormalized = normalize(config.getLowerLimit(), config.getUpperLimit(), client.player.getBlockY());
PARTICLE_AMOUNT = (int) (probabilityNormalized * config.getParticleMultiplier() * config.getParticleMultiplierMultiplier());

for (int i = 0; i < probabilityNormalized * config.getParticleMultiplier() * 10; i++) {
for (int i = 0; i < PARTICLE_AMOUNT; i++) {
try {
double x = client.player.getPos().getX() + generateRandomDouble(config.getDimensionsX() * -1, config.getDimensionsX());
double y = client.player.getPos().getY() + generateRandomDouble(config.getDimensionsY() * -1, config.getDimensionsY());
double z = client.player.getPos().getZ() + generateRandomDouble(config.getDimensionsZ() * -1, config.getDimensionsZ());
BlockPos particlePos = new BlockPos(x, y, z);

if (!shouldParticlesSpawn(client, config, particlePos)){return;}


world.addParticle(config.getParticle(), x, y, z, config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom());
if (shouldParticlesSpawn(client, config, particlePos)) {
if (client.world.getBlockState(particlePos).isAir()) {
world.addParticle(config.getParticle(), x, y, z, config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom());
}
}
}
catch (NullPointerException e) {
LOGGER.error(String.valueOf(e));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/lizistired/cavedust/CaveDustConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class CaveDustConfig extends JsonFile {
private float lowerLimit = -64;
private int particleMultiplier = 1;

private int particleMultiplierMultiplier = 10;

private int particleID = WHITE_ASH_ID;

public CaveDustConfig(Path file, net.lizistired.cavedust.CaveDust caveDust) {
Expand Down Expand Up @@ -111,6 +113,16 @@ public float setParticleMultiplier(float particleMultiplier){
return getParticleMultiplier();
}

public int getParticleMultiplierMultiplier(){
return particleMultiplierMultiplier;
}

public float setParticleMultiplierMultiplier(float particleMultiplierMultiplier){
this.particleMultiplierMultiplier = (int) particleMultiplierMultiplier;
save();
return getParticleMultiplierMultiplier();
}

public boolean toggleCaveDust(){
caveDustEnabled = !caveDustEnabled;
save();
Expand Down Expand Up @@ -197,6 +209,7 @@ public void resetConfig(){
lowerLimit = -64;

particleMultiplier = 1;
particleMultiplierMultiplier = 10;

seaLevelCheck = true;
caveDustEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

import static net.lizistired.cavedust.CaveDust.PARTICLE_AMOUNT;
import static net.lizistired.cavedust.utils.ParticleSpawnUtil.shouldParticlesSpawn;

@Mixin(DebugHud.class)
Expand All @@ -16,7 +18,7 @@ private void appendShaderPackText(CallbackInfoReturnable<List<String>> cir) {
List<String> messages = cir.getReturnValue();

messages.add("");
messages.add("Should particles spawn: " + shouldParticlesSpawn);
messages.add("Particle amount evaluated: " + PARTICLE_AMOUNT);
messages.add("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static boolean shouldParticlesSpawn(MinecraftClient client, CaveDustConfi
|| client.isPaused()
|| client.world == null
|| !client.world.getDimension().bedWorks()
|| Objects.requireNonNull(client.player).isSubmergedInWater()
|| (client.world.getBottomY() > pos.getY())
|| client.world.getBiome(Objects.requireNonNull(pos)).matchesKey(LUSH_CAVES))

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public Text formatLowerLimit(AbstractSlider<Float> slider) {
public Text formatParticleMultiplier(AbstractSlider<Float> slider) {
return Text.translatable("menu.cavedust.particlemultiplier", (int)Math.floor(slider.getValue()));
}

public Text formatParticleMultiplierMultiplier(AbstractSlider<Float> slider) {
return Text.translatable("menu.cavedust.particlemultipliermultiplier", (int)Math.floor(slider.getValue()));
}
public Text formatVelocityRandomness(AbstractSlider<Float> slider) {
return Text.translatable("menu.cavedust.velocityrandomness", (int) Math.floor(slider.getValue()));
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/assets/modid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"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.",
"menu.cavedust.particlemultiplier": "Particle amount: %s",
"menu.cavedust.particlemultiplier.tooltip": "Amount of particles to spawn at any given depth.",
"menu.cavedust.particlemultipliermultiplier": "Particle multiplier: %s",
"menu.cavedust.particlemultipliermultiplier.tooltip": "Multiplies particle amount.",
"menu.cavedust.velocityrandomness": "Velocity randomness: %s",
"menu.cavedust.velocityrandomness.tooltip": "The randomness of the velocity of the particles.",
"menu.cavedust.enhanceddetection.true": "Enhanced detection: Enabled",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/dust.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"package": "net.lizistired.cavedust.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"ClientWorldAccessor"
"ClientWorldAccessor",
"MixinDebugScreenOverlay"
],
"client": [
],
Expand Down

0 comments on commit 5f48fec

Please sign in to comment.