diff --git a/gradle.properties b/gradle.properties index 784f5ea..ef3dba3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,45 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G +#1.21.9 # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.21.8 - yarn_mappings=1.21.8+build.1 - loader_version=0.17.2 - loom_version=1.11-SNAPSHOT - -# Mod Properties - mod_version=3.0.1 - maven_group=com.lizistired - archives_base_name=cave_dust + #minecraft_version=1.21.9 + #yarn_mappings=1.21.9+build.1 + #loader_version=0.18.4 + #loom_version=1.14-SNAPSHOT # Dependencies - fabric_version=0.133.0+1.21.8 - clothconfig_version=19.0.147 - modmenu_version=15.0.0 - kirin_version=1.21.0-beta.5+1.21.7 + #fabric_version=0.134.1+1.21.9 + #modmenu_version=16.0.0-rc.2 + #kirin_version=1.21.1+1.21.7 + +#1.21.10 +# Fabric Properties + #minecraft_version=1.21.10 + #yarn_mappings=1.21.10+build.3 + #loader_version=0.18.4 + #loom_version=1.14-SNAPSHOT + +# Dependencies + #fabric_version=0.138.4+1.21.10 + #modmenu_version=16.0.0-rc.2 + #kirin_version=1.21.3+1.21.10 + +#1.21.11 +# Fabric Properties + minecraft_version=1.21.11 + yarn_mappings=1.21.11+build.3 + loader_version=0.18.4 + loom_version=1.14-SNAPSHOT + +# Mod Properties + mod_version=1.0.0 + maven_group=com.straice + archives_base_name=cave_dust_reforged + +# Dependencies + fabric_version=0.140.2+1.21.11 + modmenu_version=17.0.0-beta.1 + kirin_version=1.21.4+1.21.11 \ No newline at end of file diff --git a/src/main/java/net/lizistired/cavedust/CaveDust.java b/src/main/java/net/lizistired/cavedust/CaveDust.java index 57d26f2..d54b223 100644 --- a/src/main/java/net/lizistired/cavedust/CaveDust.java +++ b/src/main/java/net/lizistired/cavedust/CaveDust.java @@ -1,101 +1,129 @@ package net.lizistired.cavedust; -//minecraft imports +// minecraft imports +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.minecraft.client.MinecraftClient; import net.minecraft.particle.ParticleEffect; import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -//other imports + +// 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.*; -import static net.lizistired.cavedust.utils.MathHelper.generateRandomDouble; -import static net.lizistired.cavedust.utils.ParticleSpawnUtil.shouldParticlesSpawn; -import static net.lizistired.cavedust.utils.KeybindingHelper.*; +// java imports +import java.nio.file.Path; + +// static imports +import static net.lizistired.cavedust.utils.KeybindingHelper.*; +import static net.lizistired.cavedust.utils.MathHelper.generateRandomDouble; +import static net.lizistired.cavedust.utils.MathHelper.normalize; +import static net.lizistired.cavedust.utils.ParticleSpawnUtil.shouldParticlesSpawn; 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 net.lizistired.cavedust.CaveDustConfig config; - public net.lizistired.cavedust.CaveDustConfig getConfig() { - return config; - } + // logger + public static final Logger LOGGER = LoggerFactory.getLogger("cavedust"); - public static ParticleEffect WHITE_ASH_ID = (ParticleEffect) Registries.PARTICLE_TYPE.get(Identifier.of("cavedust", "cave_dust")); - public static int PARTICLE_AMOUNT = 0; + // make class static + private static CaveDust instance; + public static CaveDust getInstance() { + return instance; + } + public CaveDust() { + instance = this; + } + // config assignment + private static CaveDustConfig 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(); - registerKeyBindings(); - ParticleFactoryRegistry.getInstance().register(CaveDustServer.CAVE_DUST, CaveDustParticleFactory.Factory::new); + public CaveDustConfig getConfig() { + return config; + } - //register end client tick to create cave dust function, using end client tick for async - ClientTickEvents.END_CLIENT_TICK.register(this::createCaveDust); - } + public static ParticleEffect WHITE_ASH_ID = + (ParticleEffect) Registries.PARTICLE_TYPE.get(Identifier.of("cavedust", "cave_dust")); - private void createCaveDust(MinecraftClient client) { - if (keyBinding1.wasPressed()){ - getConfig().toggleCaveDust(); - LOGGER.info("Toggled dust"); - client.player.sendMessage(Text.translatable("debug.cavedust.toggle." + config.getCaveDustEnabled()), false); - } - if (keyBinding2.wasPressed()){ - getConfig().load(); - LOGGER.info("Reloaded config"); - client.player.sendMessage(Text.translatable("debug.cavedust.reload"), false); - } + public static int PARTICLE_AMOUNT = 0; - //ensure world is not null - if (client.world == null) return; - World world = client.world; + @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(); - //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()); + registerKeyBindings(); - for (int i = 0; i < PARTICLE_AMOUNT; i++) { - 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); + ParticleFactoryRegistry.getInstance().register(CaveDustServer.CAVE_DUST, CaveDustParticleFactory.Factory::new); - if (shouldParticlesSpawn(client, config, particlePos)) { - if (client.world.getBlockState(particlePos).isAir()) { - world.addParticleClient(getConfig().getParticle(), miniX, miniY, miniZ, config.getVelocityRandomnessRandom() * 0.01, config.getVelocityRandomnessRandom() * 0.01, config.getVelocityRandomnessRandom() * 0.01); - } - } - } - } - } + // 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.player == null) return; + + if (keyBinding1.wasPressed()) { + getConfig().toggleCaveDust(); + LOGGER.info("Toggled dust"); + client.player.sendMessage( + Text.translatable("debug.cavedust.toggle." + config.getCaveDustEnabled()), + false + ); + } + + if (keyBinding2.wasPressed()) { + getConfig().load(); + LOGGER.info("Reloaded config"); + client.player.sendMessage(Text.translatable("debug.cavedust.reload"), false); + } + + // ensure world is not null + if (client.world == null) return; + World world = client.world; + + double probabilityNormalized = + normalize(config.getLowerLimit(), config.getUpperLimit(), client.player.getBlockY()); + + PARTICLE_AMOUNT = (int) (probabilityNormalized + * config.getParticleMultiplier() + * config.getParticleMultiplierMultiplier()); + + for (int i = 0; i < PARTICLE_AMOUNT; i++) { + int x = (int) (client.player.getX() + + generateRandomDouble(-config.getDimensionWidth(), config.getDimensionWidth())); + + int y = (int) (client.player.getEyeY() + + generateRandomDouble(-config.getDimensionHeight(), config.getDimensionHeight())); + + int z = (int) (client.player.getZ() + + generateRandomDouble(-config.getDimensionWidth(), 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.addParticleClient( + getConfig().getParticle(), + miniX, miniY, miniZ, + config.getVelocityRandomnessRandom() * 0.01, + config.getVelocityRandomnessRandom() * 0.01, + config.getVelocityRandomnessRandom() * 0.01 + ); + } + } + } + } +} diff --git a/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java b/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java index 50e7a4e..59c0781 100644 --- a/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java +++ b/src/main/java/net/lizistired/cavedust/CaveDustParticleFactory.java @@ -2,40 +2,63 @@ package net.lizistired.cavedust; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.*; +import net.minecraft.client.particle.BillboardParticle; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleFactory; +import net.minecraft.client.particle.SpriteProvider; import net.minecraft.client.world.ClientWorld; import net.minecraft.particle.SimpleParticleType; +import net.minecraft.util.math.random.Random; -public class CaveDustParticleFactory extends SpriteBillboardParticle { +@Environment(EnvType.CLIENT) +public class CaveDustParticleFactory extends BillboardParticle { 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 + + CaveDustParticleFactory( + ClientWorld world, + double x, double y, double z, + double velocityX, double velocityY, double velocityZ, + SpriteProvider spriteProvider + ) { + // En 1.21.9+ BillboardParticle puede recibir sprite inicial + super(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider.getFirst()); + + this.spriteProvider = spriteProvider; + + this.maxAge = 200; // 20 ticks = 1s this.scale = 0.1f; - this.velocityX = velocityX; //The velX from the constructor parameters - this.velocityY = -0.007f; //Allows the particle to slowly fall + + this.velocityX = velocityX; + this.velocityY = -0.007f; 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 + this.alpha = 1.0f; + + // Selecciona el sprite correcto segĂșn edad/maxAge (equivalente a setSpriteForAge) + this.updateSprite(spriteProvider); + } + + @Override + protected BillboardParticle.RenderType getRenderType() { + return BillboardParticle.RenderType.PARTICLE_ATLAS_TRANSLUCENT; } @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; + if (!this.isAlive()) { + return; + } + + this.alpha -= 0.005f; + if (this.alpha <= 0.0f) { + this.markDead(); + return; + } + + this.updateSprite(this.spriteProvider); } @Environment(EnvType.CLIENT) @@ -46,8 +69,14 @@ public class CaveDustParticleFactory extends SpriteBillboardParticle { this.spriteProvider = spriteProvider; } - - public Particle createParticle(SimpleParticleType type, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { + @Override + public Particle createParticle( + SimpleParticleType type, + ClientWorld world, + double x, double y, double z, + double velocityX, double velocityY, double velocityZ, + Random random + ) { return new CaveDustParticleFactory(world, x, y, z, velocityX, velocityY, velocityZ, this.spriteProvider); } } diff --git a/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java b/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java index 4cd4d28..03b6290 100644 --- a/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java +++ b/src/main/java/net/lizistired/cavedust/mixin/MixinDebugScreenOverlay.java @@ -6,19 +6,31 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.ArrayList; import java.util.List; import static net.lizistired.cavedust.CaveDust.PARTICLE_AMOUNT; -import static net.lizistired.cavedust.utils.ParticleSpawnUtil.shouldParticlesSpawn; @Mixin(DebugHud.class) public abstract class MixinDebugScreenOverlay { - @Inject(method = "getRightText", at = @At("RETURN")) + + @Inject( + method = "getRightText()Ljava/util/List;", + at = @At("RETURN"), + cancellable = true, + require = 0 + ) private void appendDebugText(CallbackInfoReturnable> cir) { List messages = cir.getReturnValue(); + if (messages == null) return; - messages.add(""); - messages.add("Particle amount evaluated: " + PARTICLE_AMOUNT); - messages.add(""); + // Evita modificar una lista inmutable/compartida + List out = new ArrayList<>(messages); + + out.add(""); + out.add("Particle amount evaluated: " + PARTICLE_AMOUNT); + out.add(""); + + cir.setReturnValue(out); } -} +} \ No newline at end of file diff --git a/src/main/java/net/lizistired/cavedust/utils/KeybindingHelper.java b/src/main/java/net/lizistired/cavedust/utils/KeybindingHelper.java index 254f3ce..59c1b4b 100644 --- a/src/main/java/net/lizistired/cavedust/utils/KeybindingHelper.java +++ b/src/main/java/net/lizistired/cavedust/utils/KeybindingHelper.java @@ -3,6 +3,7 @@ package net.lizistired.cavedust.utils; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; +import net.minecraft.util.Identifier; import org.lwjgl.glfw.GLFW; public class KeybindingHelper { @@ -10,19 +11,23 @@ public class KeybindingHelper { public static KeyBinding keyBinding1; public static KeyBinding keyBinding2; + // 1.21.9+ requiere Category (no String) + private static final KeyBinding.Category CATEGORY = + KeyBinding.Category.create(Identifier.of("cavedust", "spook")); - public static void registerKeyBindings(){ + public static void registerKeyBindings() { keyBinding1 = KeyBindingHelper.registerKeyBinding(new KeyBinding( "key.cavedust.toggle", - InputUtil.Type.KEYSYM,// The translation key of the keybinding's name // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse. - GLFW.GLFW_KEY_KP_ADD, // The keycode of the key - "category.cavedust.spook" // The translation key of the keybinding's category. + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_KP_ADD, + CATEGORY )); + keyBinding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.cavedust.reload", // The translation key of the keybinding's name - InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse. - GLFW.GLFW_KEY_KP_ENTER, // The keycode of the key - "category.cavedust.spook" // The translation key of the keybinding's category. + "key.cavedust.reload", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_KP_ENTER, + CATEGORY )); } } diff --git a/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java b/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java index fcd19c4..5402222 100644 --- a/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java +++ b/src/main/java/net/lizistired/cavedust/utils/ParticleSpawnUtil.java @@ -14,7 +14,6 @@ public class ParticleSpawnUtil { private static float timer; public static boolean shouldParticlesSpawn; - /** * Returns true if particles should spawn. * @param client MinecraftClient @@ -23,14 +22,21 @@ public class ParticleSpawnUtil { */ 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 (client.player == null) { + timer = 0; + shouldParticlesSpawn = false; + return false; + } + + // checks if the config is enabled, if the game isn't paused, if the world is valid, + // if the dimension is valid and if the player isn't in a lush caves biome if (!config.getCaveDustEnabled() || client.isPaused() || client.world == null || !client.world.getDimension().bedWorks() - || Objects.requireNonNull(client.player).isSubmergedInWater() - || client.world.getBiome(Objects.requireNonNull(client.player.getBlockPos())).matchesKey(LUSH_CAVES)) - { + || client.player.isSubmergedInWater() + || client.world.getBiome(client.player.getBlockPos()).matchesKey(LUSH_CAVES)) { + timer = 0; shouldParticlesSpawn = false; return false; @@ -39,16 +45,18 @@ public class ParticleSpawnUtil { World world = client.world; int seaLevel = world.getSeaLevel(); - if (!client.player.clientWorld.isSkyVisible(client.player.getBlockPos())) { - if (client.player.getBlockPos().getY() + 2 < seaLevel){ + // 1.21.10: usar world directamente + if (!world.isSkyVisible(client.player.getBlockPos())) { + if (client.player.getBlockPos().getY() + 2 < seaLevel) { timer = timer + 1; - if (timer > 10){ + if (timer > 10) { timer = 10; shouldParticlesSpawn = true; return true; } } } + shouldParticlesSpawn = false; return false; } @@ -62,21 +70,27 @@ public class ParticleSpawnUtil { */ public static boolean shouldParticlesSpawn(MinecraftClient client, CaveDustConfig config, BlockPos pos) { - //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 + // checks if the config is enabled, if the game isn't paused, if the world is valid, + // if the dimension is valid and if the particle position isn't in lush caves if (!config.getCaveDustEnabled() || client.isPaused() || 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)) + || client.world.getBiome(Objects.requireNonNull(pos)).matchesKey(LUSH_CAVES)) { - { timer = 0; shouldParticlesSpawn = false; return false; } - if(!config.getSuperFlatStatus()) { + + if (client.player == null) { + timer = 0; + shouldParticlesSpawn = false; + return false; + } + + if (!config.getSuperFlatStatus()) { if (((ClientWorldAccessor) client.world.getLevelProperties()).getFlatWorld()) { return false; } @@ -85,16 +99,18 @@ public class ParticleSpawnUtil { World world = client.world; int seaLevel = world.getSeaLevel(); - if (!client.player.clientWorld.isSkyVisible(pos)) { - if (pos.getY() + 2 < seaLevel){ + // 1.21.10: usar world directamente + if (!world.isSkyVisible(pos)) { + if (pos.getY() + 2 < seaLevel) { timer = timer + 1; - if (timer > 10){ + if (timer > 10) { timer = 10; shouldParticlesSpawn = true; return true; } } } + shouldParticlesSpawn = false; return false; } diff --git a/src/main/resources/assets/cavedust/icon.png b/src/main/resources/assets/cavedust/icon.png index 32eb0f8..7c256af 100644 Binary files a/src/main/resources/assets/cavedust/icon.png and b/src/main/resources/assets/cavedust/icon.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b2615d3..57f0909 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,15 +1,19 @@ { "schemaVersion": 1, - "id": "cavedust", + "id": "cavedustreforged", "version": "${version}", - "name": "Cave Dust", + "name": "Cave Dust Reforged", "description": "Makes dust underground that scales with depth!", "authors": [ - "LizIsTired" + "DekinDev" + ], + "contributors": [ + "LizIsTired (Original mod)" ], "contact": { - "issues": "https://github.com/LizIsTired/dust/issues", - "sources": "https://github.com/LizIsTired/dust" + "issues": "https://git.straice.com/DekinDev/cave_dust_reforged/issues", + "sources": "https://git.straice.com/DekinDev/cave_dust_reforged", + "homepage": "https://modrinth.com/project/cave-dust-reforged" }, "license": "MPL-2.0", "icon": "assets/cavedust/icon.png", @@ -28,19 +32,12 @@ "cavedust.mixins.json" ], "depends": { - "fabricloader": ">=0.14.5", + "fabricloader": ">=0.17.2", "fabric": "*", - "minecraft": "1.21.8", + "minecraft": "1.21.11", "java": ">=17" }, "suggests": { "modmenu": ">=3.0.1" - }, - "custom": { - "modmenu": { - "links": { - "modmenu.discord": "https://discord.gg/4m6kQSX6bx" - } - } } }