add cave dust particle
calculate position inside blocks changed menu changed modid to cavedust change some default values fix bug where user got softlocked in the particle cycle in multiplayer
This commit is contained in:
@@ -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 class CaveDust implements ClientModInitializer {
|
||||
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 class CaveDust implements ClientModInitializer {
|
||||
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 @@ public class CaveDust implements ClientModInitializer {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 class CaveDustConfig extends JsonFile {
|
||||
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 getDimensionWidth(){
|
||||
return width;
|
||||
}
|
||||
|
||||
public float getDimensionsX(){
|
||||
return dimensionX;
|
||||
}
|
||||
|
||||
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 class CaveDustConfig extends JsonFile {
|
||||
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 class CaveDustConfig extends JsonFile {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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<DefaultParticleType> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/main/java/net/lizistired/cavedust/CaveDustServer.java
Normal file
19
src/main/java/net/lizistired/cavedust/CaveDustServer.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ import com.minelittlepony.common.client.gui.element.*;
|
||||
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 class ModMenuConfigScreen extends GameGui {
|
||||
})).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 += 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.getDimensionsY()))
|
||||
.onChange(config::setDimensionsY)
|
||||
.setTextFormat(transText::formatMaxY)
|
||||
.getStyle().setTooltip(Text.translatable("menu.cavedust.Y.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 class ModMenuConfigScreen extends GameGui {
|
||||
.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 class ModMenuConfigScreen extends GameGui {
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import static net.lizistired.cavedust.utils.ParticleSpawnUtil.shouldParticlesSpa
|
||||
@Mixin(DebugHud.class)
|
||||
public abstract class MixinDebugScreenOverlay {
|
||||
@Inject(method = "getRightText", at = @At("RETURN"))
|
||||
private void appendShaderPackText(CallbackInfoReturnable<List<String>> cir) {
|
||||
private void appendDebugText(CallbackInfoReturnable<List<String>> cir) {
|
||||
List<String> messages = cir.getReturnValue();
|
||||
|
||||
messages.add("");
|
||||
|
||||
@@ -35,6 +35,10 @@ public class MathHelper {
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 class ParticleSpawnUtil {
|
||||
|| 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))
|
||||
|
||||
{
|
||||
|
||||
@@ -6,14 +6,11 @@ import net.minecraft.text.Text;
|
||||
import javax.swing.*;
|
||||
|
||||
public class TranslatableTextHelper {
|
||||
public Text formatMaxX(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.X", (int)Math.floor(slider.getValue()));
|
||||
public Text formatMaxWidth(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.width", (int)Math.floor(slider.getValue()));
|
||||
}
|
||||
public Text formatMaxY(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.Y", (int)Math.floor(slider.getValue()));
|
||||
}
|
||||
public Text formatMaxZ(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.Z", (int)Math.floor(slider.getValue()));
|
||||
public Text formatMaxHeight(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.height", (int)Math.floor(slider.getValue()));
|
||||
}
|
||||
public Text formatUpperLimit(AbstractSlider<Float> slider) {
|
||||
return Text.translatable("menu.cavedust.upperlimit", (int)Math.floor(slider.getValue()));
|
||||
|
||||
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
@@ -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!"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"textures": [
|
||||
"minecraft:generic_0"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user