Rendering particle using BatExemple.
Goldocelot opened this issue ยท 1 comments
Description of the issue:
When trying to spawn particles with the BatExemple an issue occurred and only one instance of the entity renders the particle.
Here some picture of the issue, we can see each entity produces particles when they are isolate but when looked at the same time only one produce particles.
Environment information:
- Geckolib: 4.2.2
- Neoforge: 47.14.70
- Minecraft: 1.20.1
How to reproduce:
- Spawn 2 BatEntity one on the left and the other one on the right. The particles should work fine at this moment.
- Leave the world and join it again.
- If you look at each entity one by one it should work fine, but if you look at the two at the same time only one bat does particle.
One easy fix:
An easy fix I have found is to use a HashMap where the keys are the entities' id and the values are their tickCount.
private HashMap<Integer, Integer> currentTickMap = new HashMap<>();
@Override
public void renderFinal(PoseStack poseStack, BatEntity animatable, BakedGeoModel model, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
if (!currentTickMap.containsKey(animatable.getId()) || currentTickMap.get(animatable.getId()) != animatable.tickCount) {
currentTickMap.put(animatable.getId(), animatable.tickCount);
// Find the earbone and use it as the point of reference
this.model.getBone("leftear").ifPresent(ear -> {
RandomSource rand = animatable.getRandom();
Vector3d earPos = ear.getWorldPosition();
animatable.getCommandSenderWorld().addParticle(ParticleTypes.PORTAL,
earPos.x(),
earPos.y(),
earPos.z(),
rand.nextDouble() - 0.5D,
-rand.nextDouble(),
rand.nextDouble() - 0.5D);
});
}
super.renderFinal(poseStack, animatable, model, bufferSource, buffer, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}