Skip to content

Commit

Permalink
better multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jul 16, 2024
1 parent 0590933 commit 1702504
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.polyfrost.overflowparticles.config.MainConfig;
import org.polyfrost.overflowparticles.config.ModConfig;
import org.polyfrost.overflowparticles.config.ParticleConfig;
import org.polyfrost.overflowparticles.utils.UtilKt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand Down Expand Up @@ -46,4 +47,16 @@ private Material fall(Block instance) {

return instance.getMaterial();
}

@ModifyConstant(method = "onDeathUpdate", constant = @Constant(intValue = 20, ordinal = 1))
private int multiplier(int constant) {
ParticleConfig config = OverflowParticles.INSTANCE.getConfigs().get(0);
if (config == null || config.getEntry().getMultiplier() == 1 || config.getId() == 28) return constant;
return (int) (constant * config.getEntry().getMultiplier());
}

@Inject(method = "onDeathUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;DDDDDD[I)V"))
private void cancel(CallbackInfo ci) {
UtilKt.setMultiplied(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class WorldMixin {
@Inject(method = "spawnParticle(IZDDDDDD[I)V", at = @At("HEAD"), cancellable = true)
private void multiplier(int particleID, boolean ignoreRange, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int[] arguments, CallbackInfo ci) {
if (!isRemote) return;
if (UtilKt.getMultiplied()) {
UtilKt.setMultiplied(false);
return;
}
ParticleConfig config = OverflowParticles.INSTANCE.getConfigs().get(particleID);
if (config == null || config.getEntry().getMultiplier() == 1 || config.getId() == 28) return;
UtilKt.spawn(config, worldAccesses, particleID, ignoreRange, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, arguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.polyfrost.overflowparticles.mixin.particles;

import net.minecraft.client.particle.EntityParticleEmitter;
import net.minecraft.util.EnumParticleTypes;
import org.polyfrost.overflowparticles.OverflowParticles;
import org.polyfrost.overflowparticles.config.ParticleConfig;
import org.polyfrost.overflowparticles.utils.UtilKt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityParticleEmitter.class)
public class EntityParticleEmitterMixin {

@Shadow private EnumParticleTypes particleTypes;

@ModifyConstant(method = "onUpdate", constant = @Constant(intValue = 16))
private int multiplier(int constant) {
ParticleConfig config = OverflowParticles.INSTANCE.getConfigs().get(particleTypes.getParticleID());
if (config == null || config.getEntry().getMultiplier() == 1 || config.getId() == 28) return constant;
return (int) (constant * config.getEntry().getMultiplier());
}

@Inject(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnParticle(Lnet/minecraft/util/EnumParticleTypes;ZDDDDDD[I)V"))
private void cancel(CallbackInfo ci) {
UtilKt.setMultiplied(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.polyfrost.overflowparticles.config

import cc.polyfrost.oneconfig.config.Config
import cc.polyfrost.oneconfig.config.data.*
import cc.polyfrost.oneconfig.config.data.Mod
import cc.polyfrost.oneconfig.config.data.ModType
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore
import cc.polyfrost.oneconfig.utils.Notifications
import club.sk1er.patcher.config.OldPatcherConfig
import dev.isxander.particlesenhanced.config.ParticlesEnhancedConfig
import net.minecraft.client.particle.EntityFX
import org.polyfrost.overflowparticles.OverflowParticles
import org.polyfrost.overflowparticles.hook.EntityFXHook
import java.util.ArrayList

object ModConfig : Config(Mod(OverflowParticles.NAME, ModType.PVP, "/overflowparticles.svg"), "${OverflowParticles.MODID}.json") {

Expand Down
55 changes: 10 additions & 45 deletions src/main/kotlin/org/polyfrost/overflowparticles/utils/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.polyfrost.overflowparticles.utils

import net.minecraft.client.particle.EntityFX
import net.minecraft.world.IWorldAccess
import org.polyfrost.overflowparticles.config.MainConfig
import org.polyfrost.overflowparticles.config.ParticleConfig
import org.polyfrost.overflowparticles.hook.EntityFXHook
import kotlin.math.ceil

var multiplied = false

fun setParticleEntityID(entity: EntityFX, id: Int) {
if (entity is EntityFXHook) {
Expand All @@ -17,50 +19,13 @@ fun color(color: Int, targetColor: Float, cfg: ParticleConfig): Float =

fun colorInt(color: Int, targetColor: Float, cfg: ParticleConfig): Int = (color(color, targetColor, cfg) * 255f).toInt()

fun spawn(
config: ParticleConfig,
worldAccesses: List<IWorldAccess>,
particleID: Int,
ignoreRange: Boolean,
x: Double,
y: Double,
z: Double,
xOffset: Double,
yOffset: Double,
zOffset: Double,
vararg arguments: Int
) {
val multiplier = config.entry.multiplier
val integerPart = multiplier.toInt()
val fractionalPart = multiplier - integerPart

repeat(integerPart) {
spawnParticle(worldAccesses, particleID, ignoreRange, x, y, z, xOffset, yOffset, zOffset, *arguments)
}

if (fractionalPart > 0) {
if (Math.random() < fractionalPart) {
spawnParticle(worldAccesses, particleID, ignoreRange, x, y, z, xOffset, yOffset, zOffset, *arguments)
fun spawn(config: ParticleConfig, worldAccesses: List<IWorldAccess>, particleID: Int, ignoreRange: Boolean, x: Double, y: Double, z: Double, xOffset: Double, yOffset: Double, zOffset: Double, vararg arguments: Int) {
repeat(ceil(config.entry.multiplier).toInt()) {
for (worldAccess in worldAccesses) {
val modX = x - 0.5 + Math.random()
val modY = y - 0.5 + Math.random()
val modZ = z - 0.5 + Math.random()
worldAccess.spawnParticle(particleID, ignoreRange, modX, modY, modZ, xOffset, yOffset, zOffset, *arguments);
}
}
}

private fun spawnParticle(
worldAccesses: List<IWorldAccess>,
particleID: Int,
ignoreRange: Boolean,
x: Double,
y: Double,
z: Double,
xOffset: Double,
yOffset: Double,
zOffset: Double,
vararg arguments: Int
) {
for (worldAccess in worldAccesses) {
val modX = x - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0)
val modY = y - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0)
val modZ = z - (if (!MainConfig.settings.cleanerParticles) 0.5 + Math.random() else 0.0)
worldAccess.spawnParticle(particleID, ignoreRange, modX, modY, modZ, xOffset, yOffset, zOffset, *arguments)
}
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.overflowparticles.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"particles.EntityBreakingFXMixin",
"particles.EntityDiggingFXMixin",
"particles.EntityFootStepFXMixin",
"particles.EntityLargeExplodeFXMixin"
"particles.EntityLargeExplodeFXMixin",
"particles.EntityParticleEmitterMixin"
]
}

0 comments on commit 1702504

Please sign in to comment.