Skip to content

Commit

Permalink
feat(acid): add dripping acid particle
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Dec 11, 2023
1 parent dc17391 commit dd32f9d
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraftforge.common.data.ExistingFileHelper;

public class ModParticleSpriteProvider extends ParticleSpriteProvider {

public ModParticleSpriteProvider(DataGenerator generator, ExistingFileHelper fileHelper) {
super(generator, BiomancyMod.MOD_ID, fileHelper);
}
Expand All @@ -16,6 +17,9 @@ public void registerParticles() {
addParticle(ModParticleTypes.FALLING_BLOOD, "minecraft:drip_fall");
addParticle(ModParticleTypes.LANDING_BLOOD, "minecraft:drip_land");
addParticle(ModParticleTypes.CORROSIVE_SWIPE_ATTACK, 8, 1);
addParticle(ModParticleTypes.DRIPPING_ACID, "minecraft:drip_hang");
addParticle(ModParticleTypes.FALLING_ACID, "minecraft:drip_fall");
addParticle(ModParticleTypes.LANDING_ACID, "minecraft:drip_land");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
double x = direction.getStepX() == 0 ? random.nextDouble() : 0.5d + direction.getStepX() * 0.6d;
double y = direction.getStepY() == 0 ? random.nextDouble() : 0.5d + direction.getStepY() * 0.6d;
double z = direction.getStepZ() == 0 ? random.nextDouble() : 0.5d + direction.getStepZ() * 0.6d;
// TODO: implement acid particle
level.addParticle(ModParticleTypes.FALLING_BLOOD.get(), pos.getX() + x, pos.getY() + y, pos.getZ() + z, 0, 0, 0);
level.addParticle(ModParticleTypes.DRIPPING_ACID.get(), pos.getX() + x, pos.getY() + y, pos.getZ() + z, 0, 0, 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.github.elenterius.biomancy.client.particle;

import com.github.elenterius.biomancy.init.ModFluids;
import com.github.elenterius.biomancy.init.ModMobEffects;
import com.github.elenterius.biomancy.init.ModParticleTypes;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public final class ParticleProviders {
private ParticleProviders() {}

@OnlyIn(Dist.CLIENT)
public static class AcidLandProvider implements ParticleProvider<SimpleParticleType> {
protected final SpriteSet sprite;

public AcidLandProvider(SpriteSet pSprites) {
this.sprite = pSprites;
}

public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
VanillaDripParticle particle = new VanillaDripParticle.DripLandParticle(level, x, y, z, ModFluids.ACID.get());
particle.setColorRGB(ModMobEffects.CORROSIVE.get().getColor());
particle.pickSprite(sprite);
return particle;
}
}

@OnlyIn(Dist.CLIENT)
public static class AcidHangProvider implements ParticleProvider<SimpleParticleType> {
protected final SpriteSet sprite;

public AcidHangProvider(SpriteSet pSprites) {
this.sprite = pSprites;
}

public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
VanillaDripParticle particle = new VanillaDripParticle.DripHangParticle(level, x, y, z, ModFluids.ACID.get(), ModParticleTypes.FALLING_ACID.get());
particle.setColorRGB(ModMobEffects.CORROSIVE.get().getColor());
particle.pickSprite(sprite);
return particle;
}
}

@OnlyIn(Dist.CLIENT)
public static class AcidFallProvider implements ParticleProvider<SimpleParticleType> {
protected final SpriteSet sprite;

public AcidFallProvider(SpriteSet pSprites) {
this.sprite = pSprites;
}

public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
VanillaDripParticle particle = new VanillaDripParticle.AcidFallAndLandParticle(level, x, y, z, ModFluids.ACID.get(), ModParticleTypes.LANDING_ACID.get());
particle.setColorRGB(ModMobEffects.CORROSIVE.get().getColor());
particle.pickSprite(sprite);
return particle;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package com.github.elenterius.biomancy.client.particle;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.particle.TextureSheetParticle;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
* Almost exact copy of vanilla code because DripParticle class can't be extended
*/
@OnlyIn(Dist.CLIENT)
public class VanillaDripParticle extends TextureSheetParticle {

protected final Fluid type;
private boolean isGlowing;

protected VanillaDripParticle(ClientLevel level, double x, double y, double z, Fluid fluid) {
super(level, x, y, z);
this.setSize(0.01F, 0.01F);
this.gravity = 0.06F;
this.type = fluid;
}

public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
}

protected void setGlowing(boolean glowing) {
isGlowing = glowing;
}

@Override
public int getLightColor(float partialTick) {
return isGlowing ? 240 : super.getLightColor(partialTick);
}

@Override
public void tick() {
xo = x;
yo = y;
zo = z;

preMoveUpdate();

if (!removed) {
yd -= gravity;
move(xd, yd, zd);

postMoveUpdate();

if (!removed) {
xd *= 0.9800000190734863;
yd *= 0.9800000190734863;
zd *= 0.9800000190734863;
BlockPos blockPos = new BlockPos(x, y, z);
FluidState fluidState = level.getFluidState(blockPos);
if (fluidState.getType() == type && y < (blockPos.getY() + fluidState.getHeight(level, blockPos))) {
remove();
}
}
}
}

protected void preMoveUpdate() {
if (lifetime-- <= 0) {
remove();
}
}

protected void postMoveUpdate() { /* placeholder */ }

protected void setColorRGB(int color) {
rCol = FastColor.ARGB32.red(color) / 255f;
gCol = FastColor.ARGB32.green(color) / 255f;
bCol = FastColor.ARGB32.blue(color) / 255f;
}

protected void setColorARGB(int color) {
rCol = FastColor.ARGB32.red(color) / 255f;
gCol = FastColor.ARGB32.green(color) / 255f;
bCol = FastColor.ARGB32.blue(color) / 255f;
alpha = FastColor.ARGB32.alpha(color) / 255f;
}

@OnlyIn(Dist.CLIENT)
protected static class DripLandParticle extends VanillaDripParticle {
protected DripLandParticle(ClientLevel level, double x, double y, double z, Fluid fluid) {
super(level, x, y, z, fluid);
this.lifetime = (int) (16.0f / (Math.random() * 0.8f + 0.2f));
}
}

@OnlyIn(Dist.CLIENT)
protected static class DripHangParticle extends VanillaDripParticle {
protected final ParticleOptions fallingParticle;

protected DripHangParticle(ClientLevel level, double x, double y, double z, Fluid fluid, ParticleOptions fallingParticle) {
super(level, x, y, z, fluid);
this.fallingParticle = fallingParticle;
this.gravity *= 0.02F;
this.lifetime = 40;
}

@Override
protected void preMoveUpdate() {
if (lifetime-- <= 0) {
remove();
level.addParticle(fallingParticle, x, y, z, xd, yd, zd);
}
}

@Override
protected void postMoveUpdate() {
xd *= 0.02;
yd *= 0.02;
zd *= 0.02;
}
}

@OnlyIn(Dist.CLIENT)
protected static class FallingParticle extends VanillaDripParticle {
protected FallingParticle(ClientLevel level, double x, double y, double z, Fluid fluid) {
this(level, x, y, z, fluid, (int) (64.0f / (Math.random() * 0.8f + 0.2f)));
}

protected FallingParticle(ClientLevel level, double x, double y, double z, Fluid fluid, int lifetime) {
super(level, x, y, z, fluid);
this.lifetime = lifetime;
}

@Override
protected void postMoveUpdate() {
if (onGround) {
remove();
}
}
}

@OnlyIn(Dist.CLIENT)
protected static class FallAndLandParticle extends FallingParticle {
protected final ParticleOptions landParticle;

protected FallAndLandParticle(ClientLevel level, double x, double y, double z, Fluid fluid, ParticleOptions landParticle) {
super(level, x, y, z, fluid);
this.landParticle = landParticle;
}

@Override
protected void postMoveUpdate() {
if (onGround) {
remove();
level.addParticle(landParticle, x, y, z, 0, 0, 0);
}
}
}

@OnlyIn(Dist.CLIENT)
protected static class AcidFallAndLandParticle extends FallAndLandParticle {
protected AcidFallAndLandParticle(ClientLevel level, double x, double y, double z, Fluid fluid, ParticleOptions landParticle) {
super(level, x, y, z, fluid, landParticle);
}

@Override
protected void postMoveUpdate() {
if (onGround) {
remove();
level.addParticle(landParticle, x, y, z, 0, 0, 0);

float volume = Mth.randomBetween(random, 0.3f, 0.5f);
float pitch = Mth.randomBetween(random, 1.8f, 3.4f);
level.playLocalSound(x, y, z, SoundEvents.LAVA_EXTINGUISH, SoundSource.BLOCKS, volume, pitch, false);
for (int i = 0; i < 4; i++) {
level.addParticle(ParticleTypes.LARGE_SMOKE, x + random.nextDouble(), y + 1.2d, z + random.nextDouble(), 0, 0, 0);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public final class ModParticleTypes {
public static final RegistryObject<SimpleParticleType> FALLING_BLOOD = register("falling_blood", false);
public static final RegistryObject<SimpleParticleType> LANDING_BLOOD = register("landing_blood", false);
public static final RegistryObject<SimpleParticleType> CORROSIVE_SWIPE_ATTACK = register("corrosive_swipe", true);
public static final RegistryObject<SimpleParticleType> DRIPPING_ACID = register("dripping_acid", false);
public static final RegistryObject<SimpleParticleType> FALLING_ACID = register("falling_acid", false);
public static final RegistryObject<SimpleParticleType> LANDING_ACID = register("landing_acid", false);

private ModParticleTypes() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.elenterius.biomancy.client.gui.tooltip.HrTooltipClientComponent;
import com.github.elenterius.biomancy.client.gui.tooltip.StorageSacTooltipClientComponent;
import com.github.elenterius.biomancy.client.particle.BloodDripParticle;
import com.github.elenterius.biomancy.client.particle.ParticleProviders;
import com.github.elenterius.biomancy.client.render.block.bioforge.BioForgeRenderer;
import com.github.elenterius.biomancy.client.render.block.biolab.BioLabRenderer;
import com.github.elenterius.biomancy.client.render.block.cradle.PrimordialCradleRenderer;
Expand Down Expand Up @@ -132,6 +133,9 @@ public static void registerParticles(final RegisterParticleProvidersEvent event)
event.register(ModParticleTypes.FALLING_BLOOD.get(), BloodDripParticle.FallingBloodFactory::new);
event.register(ModParticleTypes.LANDING_BLOOD.get(), BloodDripParticle.LandingBloodFactory::new);
event.register(ModParticleTypes.CORROSIVE_SWIPE_ATTACK.get(), AttackSweepParticle.Provider::new);
event.register(ModParticleTypes.DRIPPING_ACID.get(), ParticleProviders.AcidHangProvider::new);
event.register(ModParticleTypes.FALLING_ACID.get(), ParticleProviders.AcidFallProvider::new);
event.register(ModParticleTypes.LANDING_ACID.get(), ParticleProviders.AcidLandProvider::new);
}

@SubscribeEvent
Expand Down

0 comments on commit dd32f9d

Please sign in to comment.