How to draw particles from BlockPos A to BlockPos B #2161
-
Hello! I want to make an item that draws particles to nearby, living entities every inventory tick. This is the code that I have tried: public class OreFinderItem extends Item {
public OreFinderItem(Settings settings) {
super(settings);
}
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
if (stack.getItem() == ModItems.ORE_FINDER && entity instanceof PlayerEntity)
{
drawParticles(world, (PlayerEntity) entity);
}
super.inventoryTick(stack, world, entity, slot, selected);
}
public void drawParticles(World world, PlayerEntity user) {
if (world.isClient)
{
BlockPos playerPos = user.getBlockPos();
int x = playerPos.getX();
int y = playerPos.getY();
int z = playerPos.getZ();
List<LivingEntity> livingEntities = world.getEntitiesByClass(LivingEntity.class,
new Box(x - 10, y - 10, z - 10, x + 10, y + 10, z + 10),
EntityPredicates.VALID_ENTITY);
for (LivingEntity entity : livingEntities)
{
if (entity != user)
{
Vec3d entityVector = new Vec3d(entity.getX(), entity.getY(), entity.getZ());
Vec3d playerVector = new Vec3d(x, y, z);
Vec3d velocity = entityVector.subtract(playerVector);
world.addParticle(ParticleTypes.CLOUD,
x, y, z,
velocity.x, velocity.y, velocity.z);
}
}
}
}
} drawParticles() is called as expected, and does draw particles from the player to the entity. The problem is that the particles go directly through the entity, and go past it indefinitely... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 83 replies
-
The cloud particle effect hardwires its To get entity collisions you are going to have to write your own Particle (e.g. copy |
Beta Was this translation helpful? Give feedback.
The cloud particle effect hardwires its
Particle.collidesWithWorld
to false in its constructor.But even then, I believe setting it to true just checks block collisions and the world border, not entity collision.
To get entity collisions you are going to have to write your own Particle (e.g. copy
CloudParticle
) then override theParticle.move()
method to also check entity collision.Again, you have to do this yourself, normaly entity collision requires an entity to check against other entities, e.g. see
ProjectileUtil.getEntityCollision
.