diff --git a/src/main/java/net/lizistired/cavedust/CaveDust.java b/src/main/java/net/lizistired/cavedust/CaveDust.java index 2dfd336..83435d9 100644 --- a/src/main/java/net/lizistired/cavedust/CaveDust.java +++ b/src/main/java/net/lizistired/cavedust/CaveDust.java @@ -1,9 +1,8 @@ package net.lizistired.cavedust; //minecraft imports -import net.minecraft.block.Blocks; +import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.minecraft.client.MinecraftClient; -import net.minecraft.particle.ParticleTypes; import net.minecraft.registry.Registries; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; @@ -40,10 +39,12 @@ public net.lizistired.cavedust.CaveDustConfig getConfig() { return config; } - public static int WHITE_ASH_ID = Registries.PARTICLE_TYPE.getRawId(ParticleTypes.WHITE_ASH); + public static int WHITE_ASH_ID = Registries.PARTICLE_TYPE.getRawId(CaveDustServer.CAVE_DUST); public static int PARTICLE_AMOUNT = 0; + + @Override public void onInitializeClient() { //config path and loading @@ -51,6 +52,7 @@ public void onInitializeClient() { config = new CaveDustConfig(CaveDustFolder.getParent().resolve("cavedust.json"), this); config.load(); registerKeyBindings(); + ParticleFactoryRegistry.getInstance().register(CaveDustServer.CAVE_DUST, CaveDustParticleFactory.Factory::new); //register end client tick to create cave dust function, using end client tick for async ClientTickEvents.END_CLIENT_TICK.register(this::createCaveDust); @@ -78,20 +80,23 @@ private void createCaveDust(MinecraftClient client) { for (int i = 0; i < PARTICLE_AMOUNT; i++) { try { - int x = (int) (client.player.getPos().getX() + (int) generateRandomDouble(config.getDimensionsX() * -1, config.getDimensionsX())); - int y = (int) (client.player.getPos().getY() + (int) generateRandomDouble(config.getDimensionsY() * -1, config.getDimensionsY())); - int z = (int) (client.player.getPos().getZ() + (int) generateRandomDouble(config.getDimensionsZ() * -1, config.getDimensionsZ())); + int x = (int) (client.player.getPos().getX() + (int) generateRandomDouble(config.getDimensionWidth() *-1, config.getDimensionWidth())); + int y = (int) (client.player.getEyePos().getY() + (int) generateRandomDouble(config.getDimensionHeight() *-1, config.getDimensionHeight())); + int z = (int) (client.player.getPos().getZ() + (int) generateRandomDouble(config.getDimensionWidth() *-1, config.getDimensionWidth())); + double miniX = (x + Math.random()); + double miniY = (y + Math.random()); + double miniZ = (z + Math.random()); BlockPos particlePos = new BlockPos(x, y, z); if (shouldParticlesSpawn(client, config, particlePos)) { if (client.world.getBlockState(particlePos).isAir()) { - world.addParticle(config.getParticle(), x, y, z, config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom(), config.getVelocityRandomnessRandom()); + world.addParticle(config.getParticle(), miniX, miniY, miniZ, config.getVelocityRandomnessRandom() * 0.01, config.getVelocityRandomnessRandom() * 0.01, config.getVelocityRandomnessRandom() * 0.01); } } } catch (NullPointerException e) { LOGGER.error(String.valueOf(e)); - getConfig().setParticleID(WHITE_ASH_ID); + //getConfig().setParticleID(WHITE_ASH_ID); } } } diff --git a/src/main/java/net/lizistired/cavedust/CaveDustConfig.java b/src/main/java/net/lizistired/cavedust/CaveDustConfig.java index 9043df2..ca698ef 100644 --- a/src/main/java/net/lizistired/cavedust/CaveDustConfig.java +++ b/src/main/java/net/lizistired/cavedust/CaveDustConfig.java @@ -16,10 +16,9 @@ public class CaveDustConfig extends JsonFile { private transient final net.lizistired.cavedust.CaveDust CaveDust; - private int dimensionX = 5; - private int dimensionY = 5; - private int dimensionZ = 5; - private int velocityRandomness = 1; + private int width = 10; + private int height = 10; + private int velocityRandomness = 0; private boolean caveDustEnabled = true; private boolean seaLevelCheck = true; @@ -37,40 +36,28 @@ public CaveDustConfig(Path file, net.lizistired.cavedust.CaveDust caveDust) { this.CaveDust = caveDust; } - public float setDimensionsX(float size){ - if (this.dimensionX != size) { - this.dimensionX = (int)size; + public float setDimensionWidth(float size){ + if (this.width != size) { + this.width = (int)size; save(); } - return getDimensionsX(); + return getDimensionWidth(); } - public float setDimensionsY(float size){ - if (this.dimensionY != size) { - this.dimensionY = (int)size; + public float setDimensionHeight(float size){ + if (this.height != size) { + this.height = (int)size; save(); } - return getDimensionsY(); + return getDimensionHeight(); } - public float setDimensionsZ(float size){ - if (this.dimensionZ != size) { - this.dimensionZ = (int)size; - save(); - } - return getDimensionsZ(); - } - - public float getDimensionsX(){ - return dimensionX; + public float getDimensionWidth(){ + return width; } - public float getDimensionsY(){ - return dimensionY; - } - - public float getDimensionsZ(){ - return dimensionZ; + public float getDimensionHeight(){ + return height; } public float setUpperLimit(float upperLimit){ @@ -145,10 +132,11 @@ public ParticleEffect getParticle(){ try { return (ParticleEffect) Registries.PARTICLE_TYPE.get(new Identifier(Registries.PARTICLE_TYPE.getEntry(getParticleID()).get().getKey().get().getValue().toString().toLowerCase())); } catch (ClassCastException e) { - MinecraftClient.getInstance().player.sendMessage(Text.literal("Issue loading particle, defaulting to white ash particle!"), false); - setParticleID(WHITE_ASH_ID); + MinecraftClient.getInstance().player.sendMessage(Text.translatable("debug.cavedust.particleerror"), true); + LOGGER.error("Cannot spawn particle, check config."); + iterateParticle(); save(); - return ParticleTypes.WHITE_ASH; + return getParticle(); } } @@ -210,15 +198,15 @@ public int getParticleID(){ } public void resetConfig(){ - dimensionX = 5; - dimensionY = 5; - dimensionZ = 5; + width = 10; + height = 10; upperLimit = 64; lowerLimit = -64; particleMultiplier = 1; particleMultiplierMultiplier = 10; + velocityRandomness = 0; seaLevelCheck = true; caveDustEnabled = true; diff --git a/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java b/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java new file mode 100644 index 0000000..abd5442 --- /dev/null +++ b/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java @@ -0,0 +1,54 @@ +package net.lizistired.cavedust; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.particle.*; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.particle.DefaultParticleType; + +public class CaveDustParticleFactory extends SpriteBillboardParticle { + private final SpriteProvider spriteProvider; + CaveDustParticleFactory(ClientWorld clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ, SpriteProvider spriteProvider) { + super(clientWorld, x, y, z); + this.spriteProvider = spriteProvider; //Sets the sprite provider from above to the sprite provider in the constructor method + this.maxAge = 200; //20 ticks = 1 second + this.scale = 0.1f; + this.velocityX = velocityX; //The velX from the constructor parameters + this.velocityY = -0.007f; //Allows the particle to slowly fall + this.velocityZ = velocityZ; + this.x = x; //The x from the constructor parameters + this.y = y; + this.z = z; + this.collidesWithWorld = true; + this.alpha = 1.0f; //Setting the alpha to 1.0f means there will be no opacity change until the alpha value is changed + this.setSpriteForAge(spriteProvider); //Required + } + + @Override + public void tick() { + super.tick(); + if(this.alpha < 0.0f){ + this.markDead(); + } + this.alpha -= 0.005f; + } + + @Override + public ParticleTextureSheet getType() { + return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + } + + @Environment(EnvType.CLIENT) + public static class Factory implements ParticleFactory { + private final SpriteProvider spriteProvider; + + public Factory(SpriteProvider spriteProvider) { + this.spriteProvider = spriteProvider; + } + + + public Particle createParticle(DefaultParticleType type, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + return new CaveDustParticleFactory(world, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider); + } + } +} diff --git a/src/main/java/net/lizistired/cavedust/CaveDustServer.java b/src/main/java/net/lizistired/cavedust/CaveDustServer.java new file mode 100644 index 0000000..49cf0bd --- /dev/null +++ b/src/main/java/net/lizistired/cavedust/CaveDustServer.java @@ -0,0 +1,19 @@ +package net.lizistired.cavedust; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; +import net.minecraft.particle.DefaultParticleType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class CaveDustServer implements ModInitializer { + public static final DefaultParticleType CAVE_DUST = FabricParticleTypes.simple(); + /** + * Runs the mod initializer. + */ + @Override + public void onInitialize() { + Registry.register(Registries.PARTICLE_TYPE, new Identifier("cavedust", "cave_dust"), CAVE_DUST); + } +} diff --git a/src/main/java/net/lizistired/cavedust/ModMenuConfigScreen.java b/src/main/java/net/lizistired/cavedust/ModMenuConfigScreen.java index 25ec6e1..516d047 100644 --- a/src/main/java/net/lizistired/cavedust/ModMenuConfigScreen.java +++ b/src/main/java/net/lizistired/cavedust/ModMenuConfigScreen.java @@ -5,12 +5,12 @@ import net.lizistired.cavedust.utils.TranslatableTextHelper; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.particle.ParticleEffect; import net.minecraft.registry.Registries; import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; +import java.util.NoSuchElementException; + public class ModMenuConfigScreen extends GameGui { public ModMenuConfigScreen(@Nullable Screen parent) { super(Text.translatable("menu.cavedust.title"), parent); @@ -73,20 +73,15 @@ public void init() { })).getStyle().setText("Particle: " + (getNameOfParticle())) .setTooltip(Text.translatable("menu.cavedust.particle.tooltip")); - addButton(new Slider(left += 220, row -= 96, 1, 50, config.getDimensionsX())) - .onChange(config::setDimensionsX) - .setTextFormat(transText::formatMaxX) - .getStyle().setTooltip(Text.translatable("menu.cavedust.X.tooltip")); - - addButton(new Slider(left, row += 24, 1, 50, config.getDimensionsY())) - .onChange(config::setDimensionsY) - .setTextFormat(transText::formatMaxY) - .getStyle().setTooltip(Text.translatable("menu.cavedust.Y.tooltip")); + addButton(new Slider(left += 220, row -= 96, 1, 50, config.getDimensionWidth())) + .onChange(config::setDimensionWidth) + .setTextFormat(transText::formatMaxWidth) + .getStyle().setTooltip(Text.translatable("menu.cavedust.width.tooltip")); - addButton(new Slider(left, row += 24, 1, 50, config.getDimensionsZ())) - .onChange(config::setDimensionsZ) - .setTextFormat(transText::formatMaxZ) - .getStyle().setTooltip(Text.translatable("menu.cavedust.Z.tooltip")); + addButton(new Slider(left, row += 24, 1, 50, config.getDimensionHeight())) + .onChange(config::setDimensionHeight) + .setTextFormat(transText::formatMaxHeight) + .getStyle().setTooltip(Text.translatable("menu.cavedust.height.tooltip")); addButton(new Slider(left, row += 24, 0, 10, config.getVelocityRandomness())) .onChange(config::setVelocityRandomness) @@ -94,9 +89,10 @@ public void init() { .getStyle().setTooltip(Text.translatable("menu.cavedust.velocityrandomness.tooltip")); - addButton(new Button(left -= 110, row += 60).onClick(sender -> { + addButton(new Button(left -= 110, row += 120).onClick(sender -> { config.resetConfig(); finish(); + client.setScreen(new ModMenuConfigScreen(parent)); })).getStyle().setText(Text.translatable("menu.cavedust.reset")).setTooltip(Text.translatable("menu.cavedust.reset.tooltip")); addButton(new Button(left, row += 24) @@ -114,6 +110,10 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTic private String getNameOfParticle(){ CaveDustConfig config = CaveDust.getInstance().getConfig(); config.load(); - return Registries.PARTICLE_TYPE.getEntry(config.getParticleID()).get().getKey().get().getValue().toString(); + try { + return Registries.PARTICLE_TYPE.getEntry(config.getParticleID()).get().getKey().get().getValue().toString(); + } catch (NoSuchElementException e){ + return "null"; + } } } diff --git a/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java b/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java index 30cedad..4cd4d28 100644 --- a/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java +++ b/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java @@ -14,7 +14,7 @@ @Mixin(DebugHud.class) public abstract class MixinDebugScreenOverlay { @Inject(method = "getRightText", at = @At("RETURN")) - private void appendShaderPackText(CallbackInfoReturnable> cir) { + private void appendDebugText(CallbackInfoReturnable> cir) { List messages = cir.getReturnValue(); messages.add(""); diff --git a/src/main/java/net/lizistired/cavedust/utils/MathHelper.java b/src/main/java/net/lizistired/cavedust/utils/MathHelper.java index f9670d0..f13696d 100644 --- a/src/main/java/net/lizistired/cavedust/utils/MathHelper.java +++ b/src/main/java/net/lizistired/cavedust/utils/MathHelper.java @@ -35,6 +35,10 @@ public static int generateRandomInt(int min, int max) { * @return Random number (double) */ public static double generateRandomDouble(double min, double max) { - return ThreadLocalRandom.current().nextDouble(min, max); + try { + return ThreadLocalRandom.current().nextDouble(min, max); + } catch (IllegalArgumentException e) { + return 0; + } } } diff --git a/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java b/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java index 0b81484..fcd19c4 100644 --- a/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java +++ b/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java @@ -14,6 +14,7 @@ public class ParticleSpawnUtil { private static float timer; public static boolean shouldParticlesSpawn; + /** * Returns true if particles should spawn. * @param client MinecraftClient @@ -67,6 +68,7 @@ public static boolean shouldParticlesSpawn(MinecraftClient client, CaveDustConfi || client.world == null || !client.world.getDimension().bedWorks() || (client.world.getBottomY() > pos.getY()) + //|| client.world.getBiome(Objects.requireNonNull(pos)).matchesKey(LUSH_CAVES)) || client.world.getBiome(Objects.requireNonNull(pos)).matchesKey(LUSH_CAVES)) { diff --git a/src/main/java/net/lizistired/cavedust/utils/TranslatableTextHelper.java b/src/main/java/net/lizistired/cavedust/utils/TranslatableTextHelper.java index c07ccd4..9d24951 100644 --- a/src/main/java/net/lizistired/cavedust/utils/TranslatableTextHelper.java +++ b/src/main/java/net/lizistired/cavedust/utils/TranslatableTextHelper.java @@ -6,14 +6,11 @@ import javax.swing.*; public class TranslatableTextHelper { - public Text formatMaxX(AbstractSlider slider) { - return Text.translatable("menu.cavedust.X", (int)Math.floor(slider.getValue())); + public Text formatMaxWidth(AbstractSlider slider) { + return Text.translatable("menu.cavedust.width", (int)Math.floor(slider.getValue())); } - public Text formatMaxY(AbstractSlider slider) { - return Text.translatable("menu.cavedust.Y", (int)Math.floor(slider.getValue())); - } - public Text formatMaxZ(AbstractSlider slider) { - return Text.translatable("menu.cavedust.Z", (int)Math.floor(slider.getValue())); + public Text formatMaxHeight(AbstractSlider slider) { + return Text.translatable("menu.cavedust.height", (int)Math.floor(slider.getValue())); } public Text formatUpperLimit(AbstractSlider slider) { return Text.translatable("menu.cavedust.upperlimit", (int)Math.floor(slider.getValue())); diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/cavedust/icon.png similarity index 100% rename from src/main/resources/assets/modid/icon.png rename to src/main/resources/assets/cavedust/icon.png diff --git a/src/main/resources/assets/modid/lang/en_us.json b/src/main/resources/assets/cavedust/lang/en_us.json similarity index 84% rename from src/main/resources/assets/modid/lang/en_us.json rename to src/main/resources/assets/cavedust/lang/en_us.json index e053ad4..5bb13ce 100644 --- a/src/main/resources/assets/modid/lang/en_us.json +++ b/src/main/resources/assets/cavedust/lang/en_us.json @@ -4,12 +4,10 @@ "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.X": "X bounds: %s", - "menu.cavedust.Y": "Y bounds: %s", - "menu.cavedust.Z": "Z bounds: %s", - "menu.cavedust.X.tooltip": "X axis bounds for particle spawning.", - "menu.cavedust.Y.tooltip": "Y axis bounds for particle spawning.", - "menu.cavedust.Z.tooltip": "Z axis bounds for particle spawning.", + "menu.cavedust.width": "Width bounds: %s", + "menu.cavedust.height": "Height bounds: %s", + "menu.cavedust.width.tooltip": "Maximum width to spawn particle.", + "menu.cavedust.height.tooltip": "Maximum height to spawn particle.", "menu.cavedust.upperlimit": "Upper limit height: %s", "menu.cavedust.lowerlimit": "Lower limit height: %s", "menu.cavedust.upperlimit.tooltip": "The height where particles will fade out and stop spawning (uses player y).", @@ -37,6 +35,7 @@ "debug.cavedust.toggle.true": "(Cave Dust) Enabled particles", "debug.cavedust.toggle.false": "(Cave Dust) Disabled particles", - "debug.cavedust.reload": "(Cave Dust) Reloaded config" + "debug.cavedust.reload": "(Cave Dust) Reloaded config", + "debug.cavedust.particleerror": "(Cave Dust) Error setting particle, skipping to next particle!" } \ No newline at end of file diff --git a/src/main/resources/assets/cavedust/particles/cave_dust.json b/src/main/resources/assets/cavedust/particles/cave_dust.json new file mode 100644 index 0000000..ca698ca --- /dev/null +++ b/src/main/resources/assets/cavedust/particles/cave_dust.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "minecraft:generic_0" + ] +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 585bc25..361379f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,12 +12,14 @@ "sources": "https://github.com/LizIsTired/dust" }, "license": "MPL-2.0", - "icon": "assets/modid/icon.png", + "icon": "assets/cavedust/icon.png", "environment": "*", "entrypoints": { "client": [ "net.lizistired.cavedust.CaveDust" ], + "main": [ + "net.lizistired.cavedust.CaveDustServer"], "modmenu": [ "net.lizistired.cavedust.CaveDustModMenuFactory" ]