generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7293fe
commit 86db12a
Showing
8 changed files
with
310 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/direwolf20/justdirethings/client/particles/ModParticles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.direwolf20.justdirethings.client.particles; | ||
|
||
|
||
import com.direwolf20.justdirethings.JustDireThings; | ||
import com.direwolf20.justdirethings.client.particles.itemparticle.ItemFlowParticleData; | ||
import com.direwolf20.justdirethings.client.particles.itemparticle.ItemFlowParticleType; | ||
import net.minecraft.core.particles.ParticleType; | ||
import net.minecraft.core.registries.Registries; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ModParticles { | ||
public static final DeferredRegister<ParticleType<?>> PARTICLE_TYPES = DeferredRegister.create(Registries.PARTICLE_TYPE, JustDireThings.MODID); | ||
public static final Supplier<ParticleType<ItemFlowParticleData>> ITEMFLOWPARTICLE = PARTICLE_TYPES.register("itemflowparticle", ItemFlowParticleType::new); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/direwolf20/justdirethings/client/particles/ParticleRenderDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.direwolf20.justdirethings.client.particles; | ||
|
||
|
||
import com.direwolf20.justdirethings.JustDireThings; | ||
import com.direwolf20.justdirethings.client.particles.itemparticle.ItemFlowParticle; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; | ||
|
||
@Mod.EventBusSubscriber(modid = JustDireThings.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) | ||
public class ParticleRenderDispatcher { | ||
|
||
@SubscribeEvent | ||
public static void registerProviders(RegisterParticleProvidersEvent evt) { | ||
evt.registerSpecial(ModParticles.ITEMFLOWPARTICLE.get(), ItemFlowParticle.FACTORY); | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
...in/java/com/direwolf20/justdirethings/client/particles/itemparticle/ItemFlowParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.direwolf20.justdirethings.client.particles.itemparticle; | ||
|
||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.particle.BreakingItemParticle; | ||
import net.minecraft.client.particle.ParticleProvider; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.Blocks; | ||
|
||
import java.util.Random; | ||
|
||
public class ItemFlowParticle extends BreakingItemParticle { | ||
|
||
private double targetX, targetY, targetZ; | ||
Random random = new Random(); | ||
private float partSize; | ||
private boolean doGravity; | ||
private boolean shrinking; | ||
|
||
public ItemFlowParticle(ClientLevel world, double x, double y, double z, ItemStack itemStack, boolean gravity, boolean shrinking) { | ||
super(world, x, y, z, itemStack); | ||
this.doGravity = gravity; | ||
this.shrinking = shrinking; | ||
float minSize = 0.25f; | ||
float maxSize = 0.5f; | ||
this.partSize = minSize + random.nextFloat() * (maxSize - minSize); | ||
this.lifetime = 30; | ||
int longLifeChance = random.nextInt(20); | ||
if (longLifeChance == 0) | ||
this.lifetime = 120; | ||
|
||
this.scale(partSize); | ||
this.partSize = quadSize; | ||
if (this.sprite == null) { | ||
this.setSprite(Minecraft.getInstance().getItemRenderer().getModel(new ItemStack(Blocks.COBBLESTONE), world, (LivingEntity) null, 0).getParticleIcon()); | ||
} | ||
//this.xd = 0; | ||
//this.yd = 0; | ||
//this.zd = 0; | ||
/*if (shrinking) { | ||
this.targetX = x + 1.75f; | ||
this.targetY = y + 1.75f; | ||
this.targetZ = z + 1.75f; | ||
} else { | ||
if (!gravity) { | ||
double randomX = random.nextFloat(); | ||
double randomY = random.nextFloat(); | ||
double randomZ = random.nextFloat(); | ||
this.xo = x + randomX; | ||
this.yo = y + randomY; | ||
this.zo = z + randomZ; | ||
this.setPos(xo, yo, zo); | ||
this.targetX = x; | ||
this.targetY = y; | ||
this.targetZ = z; | ||
} | ||
}*/ | ||
|
||
/*Vec3 target = new Vec3(targetX, targetY, targetZ); | ||
Vec3 source = new Vec3(this.x, this.y, this.z); | ||
Vec3 path = target.subtract(source).normalize().multiply(1, 1, 1); | ||
float speedModifier = (1f - 0.5f) * (partSize - minSize) / (maxSize - minSize) + 0.25f; | ||
int ticksPerBlock = 15; | ||
float speedAdjust = ticksPerBlock * (1 / speedModifier); | ||
this.xd += path.x / speedAdjust; | ||
this.yd += path.y / speedAdjust; | ||
this.zd += path.z / speedAdjust; | ||
if (gravity) { | ||
this.xd = 0; | ||
this.yd = 0; | ||
this.zd = 0; | ||
this.gravity = 0.0625f; | ||
this.hasPhysics = true; | ||
this.age = this.lifetime / 2; | ||
this.scale(2f); | ||
this.partSize = quadSize; | ||
updateColorAndGravity(); | ||
} else { | ||
this.gravity = 0.0f; | ||
this.hasPhysics = false; | ||
} | ||
if (!shrinking) | ||
updateColorAndGravity();*/ | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
super.tick(); | ||
/*this.xo = this.x; | ||
this.yo = this.y; | ||
this.zo = this.z; | ||
if (this.age++ >= this.lifetime) { | ||
this.remove(); | ||
} else { | ||
this.yd -= 0.04D * (double) this.gravity; | ||
this.move(this.xd, this.yd, this.zd); | ||
} | ||
if (!shrinking && this.y <= targetY) | ||
this.remove();*/ | ||
updateColorAndGravity(); | ||
} | ||
|
||
public void updateColorAndGravity() { | ||
float relativeAge = (float) ((this.lifetime - this.age)) / this.lifetime; //1.0 -> 0.0 | ||
//float shrink = Mth.lerp(relativeAge, 0.1f, 1); | ||
//this.quadSize = partSize * shrink; | ||
|
||
float adjustedAge = (float) Math.pow(relativeAge, 2); | ||
/*float darkness; | ||
if (shrinking) | ||
darkness = Mth.lerp(adjustedAge, 0, 1); | ||
else | ||
darkness = Mth.lerp(adjustedAge, 1, 0.15f); | ||
this.rCol = darkness; | ||
this.gCol = darkness; | ||
this.bCol = darkness;*/ | ||
|
||
if (relativeAge < 0.5f) { | ||
adjustedAge = (float) Math.pow(relativeAge / 0.5f, 2); | ||
//if (shrinking) | ||
this.alpha = Mth.lerp(adjustedAge, 0.25f, 1); | ||
//else | ||
// this.alpha = Mth.lerp(adjustedAge, 1f, 0.2f); | ||
} | ||
/*if (!doGravity) { | ||
int gravityChance = random.nextInt(2); | ||
if (relativeAge < 0.75f && gravityChance == 0) { | ||
this.gravity = 0.05f; | ||
} | ||
}*/ | ||
} | ||
|
||
@Override //Performance Reasons | ||
protected int getLightColor(float pPartialTick) { | ||
return 0xF00080; | ||
} | ||
|
||
public static ParticleProvider<ItemFlowParticleData> FACTORY = | ||
(data, world, x, y, z, xSpeed, ySpeed, zSpeed) -> | ||
new ItemFlowParticle(world, x, y, z, data.getItemStack(), data.doGravity, data.shrinking); | ||
} | ||
|
75 changes: 75 additions & 0 deletions
75
...ava/com/direwolf20/justdirethings/client/particles/itemparticle/ItemFlowParticleData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.direwolf20.justdirethings.client.particles.itemparticle; | ||
|
||
import com.direwolf20.justdirethings.client.particles.ModParticles; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.commands.arguments.item.ItemInput; | ||
import net.minecraft.commands.arguments.item.ItemParser; | ||
import net.minecraft.core.particles.ParticleOptions; | ||
import net.minecraft.core.particles.ParticleType; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.api.distmarker.OnlyIn; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Locale; | ||
|
||
public class ItemFlowParticleData implements ParticleOptions { | ||
private final ItemStack itemStack; | ||
public final boolean doGravity; | ||
public final boolean shrinking; | ||
|
||
public ItemFlowParticleData(ItemStack itemStack, boolean doGravity, boolean shrinking) { | ||
this.itemStack = itemStack.copy(); //Forge: Fix stack updating after the fact causing particle changes. | ||
this.doGravity = doGravity; | ||
this.shrinking = shrinking; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ParticleType<ItemFlowParticleData> getType() { | ||
return ModParticles.ITEMFLOWPARTICLE.get(); | ||
} | ||
|
||
@Override | ||
public void writeToNetwork(FriendlyByteBuf buffer) { | ||
buffer.writeItem(this.itemStack); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String writeToString() { | ||
return String.format(Locale.ROOT, "%s %b %b", | ||
this.getType(), this.doGravity, this.shrinking); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public ItemStack getItemStack() { | ||
return this.itemStack; | ||
} | ||
|
||
public static final Deserializer<ItemFlowParticleData> DESERIALIZER = new Deserializer<ItemFlowParticleData>() { | ||
@Nonnull | ||
@Override | ||
public ItemFlowParticleData fromCommand(ParticleType<ItemFlowParticleData> particleTypeIn, StringReader reader) throws CommandSyntaxException { | ||
reader.expect(' '); | ||
ItemParser.ItemResult itemparser$itemresult = ItemParser.parseForItem(BuiltInRegistries.ITEM.asLookup(), reader); | ||
ItemStack itemstack = (new ItemInput(itemparser$itemresult.item(), itemparser$itemresult.nbt())).createItemStack(1, false); | ||
|
||
reader.expect(' '); | ||
boolean doGravity = reader.readBoolean(); | ||
reader.expect(' '); | ||
boolean building = reader.readBoolean(); | ||
|
||
return new ItemFlowParticleData(itemstack, doGravity, building); | ||
} | ||
|
||
@Override | ||
public ItemFlowParticleData fromNetwork(ParticleType<ItemFlowParticleData> particleTypeIn, FriendlyByteBuf buffer) { | ||
return new ItemFlowParticleData(buffer.readItem(), buffer.readBoolean(), buffer.readBoolean()); | ||
} | ||
}; | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
...ava/com/direwolf20/justdirethings/client/particles/itemparticle/ItemFlowParticleType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.direwolf20.justdirethings.client.particles.itemparticle; | ||
|
||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.particles.ParticleType; | ||
|
||
public class ItemFlowParticleType extends ParticleType<ItemFlowParticleData> { | ||
public ItemFlowParticleType() { | ||
super(false, ItemFlowParticleData.DESERIALIZER); | ||
} | ||
|
||
@Override | ||
public Codec<ItemFlowParticleData> codec() { | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.