(Fabric/1.19.3) Gecko4 Entity rotations not reflecting in game
awitkowski0 opened this issue ยท 1 comments
Hi, I recently updated from Geckolib3.0 -> Geckolib4.0 and I have been having some trouble with Entity rotations.
Here's a little gif of it before updating to Geckolib4.0
https://cdn.discordapp.com/attachments/1052397100211634256/1054852011985735761/Dec-20-2022_15-04-18.gif
Here's what happens when you throw it from the wrong rotation in Gecko4.0
The code actually in charge of setting the velocity is quite similar to shooting out from a bow:
public void useGadget(ThematicArmor armor, ItemStack armorStack, PlayerEntity player, ItemStack itemStack) {
if (type.equals(Type.THROW)) {
PersistentProjectileEntity thrown = item.createThrowable(player.getWorld(), itemStack, player);
thrown.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, 3.0F, 1.0F);
thrown.setPosition(player.getX(), player.getEyeY() - 0.1D, player.getZ());
player.world.spawnEntity(thrown);
}
if (type.equals(Type.USE)) {
use(armor, armorStack, player, itemStack);
}
}
My renderer for these entities:
public abstract class ThematicEntityGadgetRenderer extends GeoEntityRenderer<ThematicThrowableEntity> {
public ThematicEntityGadgetRenderer(EntityRendererFactory.Context renderManager, ThematicGadgetEntityModel model) {
super(renderManager, model);
}
/**
* Sets a scale override for this renderer, telling GeckoLib to pre-scale the model
*/
public GeoEntityRenderer<ThematicThrowableEntity> withScale(float scaleWidth, float scaleHeight) {
this.scaleWidth = scaleWidth * 0.75f;
this.scaleHeight = scaleHeight * 0.75f;
return this;
}
}
My model for these entities:
public class ThematicGadgetEntityModel extends DefaultedEntityGeoModel<ThematicThrowableEntity> {
public ThematicGadgetEntityModel(String gadgetName) {
super(new Identifier(Mod.MOD_ID, gadgetName));
}
@Override
protected String subtype() {
return "gadget";
}
}
Entity code
public class ThematicThrowableEntity extends PersistentProjectileEntity implements GeoEntity {
private final AnimatableInstanceCache animatableInstanceCache = GeckoLibUtil.createInstanceCache(this);
private String id = "default";
private ItemStack itemStack;
@Nullable
private ThematicGadget gadget;
public ThematicThrowableEntity(EntityType<? extends ThematicThrowableEntity> entityType, World world) {
super(entityType, world);
}
public ThematicThrowableEntity(EntityType<? extends ThematicThrowableEntity> entityType, World world, LivingEntity shooter) {
super(entityType, world);
this.setOwner(shooter);
}
public ThematicThrowableEntity(EntityType<ThematicThrowableEntity> entity, World world, LivingEntity shooter, ThematicGadget gadget) {
super(entity, world);
this.gadget = gadget;
this.setOwner(shooter);
}
public String getID() {
return this.id;
}
public void setID(String id) {
this.id = id;
}
protected void onEntityHit(EntityHitResult entityHitResult) { // called on entity hit.
super.onEntityHit(entityHitResult);
if (gadget != null && !this.world.isClient) {
gadget.onEntityHit(this, this.getOwner(), entityHitResult);
}
}
public void setItem(ItemStack itemStack) {
this.itemStack = itemStack;
}
@Override
protected ItemStack asItemStack() {
return itemStack;
}
protected void onCollision(HitResult hitResult) {
super.onCollision(hitResult);
if (gadget != null && !this.world.isClient) {
gadget.onCollision(this, hitResult);
}
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(DefaultAnimations.genericLivingController(this));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.animatableInstanceCache;
}
}
Here's the actual .geo model and animation:
batarang.zip
Originally asked in the geckolib discord and @Tslat requested I create an issue for it.
If this is something on my end (very possible) just let me know.
Thanks!
Added
@Override
public void preRender(MatrixStack poseStack, ThematicThrowableEntity animatable, BakedGeoModel model, VertexConsumerProvider bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue,
float alpha) {
RenderUtils.faceRotation(poseStack, animatable, partialTick);
super.preRender(poseStack, animatable, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}
To my renderer and it works fine.