Open DarthSharkie opened 1 month ago
Yup, specifically the cricles render half-way
What position are you at when trying this? I think what's happening is the detection to determine whether to send the instructions to the client is using a radius of 32 blocks to determine whether to send the payload or not. Since this code is rendering at the origin, that's the value being checked for distance from the player. If you're around 32 blocks from the origin, then there's a good chance you'll see part of the circular animation. If the point (as computed by the CircularAnimator) moves more than 32 blocks from you, the instructions will no longer send, and therefore you won't see the spheres render.
That value can be modified, and it's probably a value that should become a configuration.
It would also be good to figure out if the pattern in this code (render at origin, position with offset) is a pattern that should be supported, or if the guidance and docs should describe a better way to compute an origin. For example, use the animator interceptor to get the player's position and update the center of the circular animator's path. That would be ideal, I think, since the path is really supposed to be relevant to the player, and the offset (0, 0.3, 0)
is not really used to do more than raise the sphere a little bit.
I changed some of the code to the following to try to set the center of the circular path to the user's position (everything not seen here is still the same):
ParticleSphere particleSphere = ParticleSphere.builder().particleEffect(ParticleTypes.FLAME).radius(1.0f)
.amount(80).offset(new Vector3f(0, 0.3f, 0))
.beforeDraw((data, obj) -> obj.setRotation(obj.getRotation().add(0.001f, 0.001f, 0.001f)))
.build();
circularAnimator.setDuringRenderingSteps(((data, obj) -> {
obj.setCenter(user.getPos().toVector3f());
obj.setRadius((3.0f * (float) Math.sin(0.05f * obj.getRadius())) + 3.2f);
}));
What I found is that the center doesn't move. The reason for this is the animation frames are all computed near-instantly instead of being run on the tick they should be. I think the animator code should run on the correct tick, not be front-loaded like it is now. That will change the scheduler a bit, but it will also (I believe) solve the lag problem we've discussed. I'm going to explore that change and see how big it is.
Coming back to this one. Here's updated code that uses builders to construct objects and animators:
Vector3f userPos = user.getPos().toVector3f();
user.sendMessage(Text.of("User at " + userPos));
ParticleSphere particleSphere = ParticleSphere.builder().particleEffect( ParticleTypes.FLAME).radius(1.0f)
.amount(80).beforeDraw((data, obj) -> {
obj.setOffset(user.getPos().toVector3f().add(0, 0.3f, 0));
obj.setRotation(obj.getRotation().add(0.001f, 0.001f, 0.001f));
}).build();
ParticleSphere particleSphere2 = new ParticleSphere(particleSphere);
particleSphere2.setParticleEffect(ParticleTypes.SOUL_FIRE_FLAME);
particleSphere2.setBeforeDraw(((data, obj) -> {
obj.setOffset(user.getPos().toVector3f().add(0, 0.3f, 0));
obj.setRotation(obj.getRotation().add(-0.001f, -0.001f, -0.001f));
}));
ParticleCuboid particleCuboid = ParticleCuboid.builder().particleEffect(ParticleTypes.END_ROD).amount(50)
.size(new Vector3f(1f)).afterDraw((data, obj) -> {
obj.setOffset(user.getPos().toVector3f().add(0, 1f, 0));
obj.setSize((0.8f * (float) Math.sin(0.01f * obj.getSize().x)) + 1.8f);
}).build();
PointAnimator pointAnimator = PointAnimator.builder().delay(1).particleObject(particleCuboid)
.renderingSteps(2400).build();
CircularAnimator circularAnimator = CircularAnimator.builder().delay(1).center(new Vector3f()).radius(3.0f)
.rotation(new Vector3f((float) Math.PI / 2, 0, 0)).particleObject(particleSphere).renderingSteps(600)
.revolutions(4).build();
circularAnimator.setDuringRenderingSteps(((data, obj) -> {
obj.setRadius((3.0f * (float) Math.sin(0.05f * obj.getRadius())) + 3.2f);
}));
CircularAnimator circularAnimator2 = new CircularAnimator(circularAnimator);
circularAnimator2.setParticleObject(particleSphere2);
circularAnimator2.rotate(3 * (float) Math.PI / 2, (float) Math.PI, 0);
ParallelAnimator parallelAnimator = ParallelAnimator.builder().delay(0).animator(circularAnimator)
.animator(circularAnimator2).animator(pointAnimator).build();
parallelAnimator.beginAnimation(ApelServerRenderer.create(world));
Summarizing the issues:
beforeDraw
or afterDraw
method, but this leads to (2).Fixing the issues:
The following code, when using
ApelServerRenderer.client
, does not behave the same as when usingApelServerRenderer.create
(server-side rendering).