Apply rotation and scale to entity (livingbase), not its parts

Reduces amount of keyframes per entity and makes it easier to work with.
This commit is contained in:
Jonas Herzig
2019-03-14 11:30:40 +01:00
parent cd16e014d1
commit dc6de5bd5f
3 changed files with 45 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector3f;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import java.io.IOException; import java.io.IOException;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
@@ -74,15 +75,26 @@ public class EntityExporter implements Exporter {
// So, we translate there, then store the model-view-matrix and then translate back to let the // So, we translate there, then store the model-view-matrix and then translate back to let the
// renderer translate there again. // renderer translate there again.
// Instead of actually translating, we just add the translation on the current model-view-matrix. // Instead of actually translating, we just add the translation on the current model-view-matrix.
Matrix4f modelView = getGlModelViewMatrix(); if (!(entity instanceof EntityLivingBase)) { // except for EntityLivingBase which get special (better) treatment
Matrix4f.translate(new Vector3f((float) dx, (float) dy, (float) dz), modelView, modelView); Matrix4f modelView = getGlModelViewMatrix();
renderState.pushModelView(modelView); Matrix4f.translate(new Vector3f((float) dx, (float) dy, (float) dz), modelView, modelView);
renderState.applyLastModelViewTransformToObject(); renderState.pushModelView(modelView);
renderState.applyLastModelViewTransformToObject();
entityObject.keyframeLocRotScale(renderState.getFrame()); entityObject.keyframeLocRotScale(renderState.getFrame());
}
entityObject.setVisible(renderState.getFrame()); entityObject.setVisible(renderState.getFrame());
} }
public void postEntityLivingSetup() {
// For any entity which extends EntityLivingBase, we capture its rotation and scale after it has been setup
// in addition to its position (which we capture in preRender for other entities).
// We could add custom hooks for various other entities types as well but it's probably not worth it.
renderState.pushModelView();
renderState.applyLastModelViewTransformToObject();
renderState.peekObject().keyframeLocRotScale(renderState.getFrame());
}
public void postRender(Entity entity, double dx, double dy, double dz, float yaw, float renderPartialTicks) { public void postRender(Entity entity, double dx, double dy, double dz, float yaw, float renderPartialTicks) {
renderState.pop(); renderState.pop();
} }

View File

@@ -0,0 +1,27 @@
//#if MC>=10800
package com.replaymod.render.blend.mixin;
import com.replaymod.render.blend.BlendState;
import com.replaymod.render.blend.exporters.EntityExporter;
import net.minecraft.client.renderer.entity.RenderLivingBase;
import net.minecraft.entity.EntityLivingBase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RenderLivingBase.class)
public abstract class MixinRenderLivingBase {
@Inject(method = "doRender", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/entity/RenderLivingBase;prepareScale(Lnet/minecraft/entity/EntityLivingBase;F)F",
shift = At.Shift.AFTER
))
private void recordModelMatrix(EntityLivingBase entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
BlendState blendState = BlendState.getState();
if (blendState != null) {
blendState.get(EntityExporter.class).postEntityLivingSetup();
}
}
}
//#endif

View File

@@ -10,6 +10,7 @@
"MixinModelRenderer", "MixinModelRenderer",
"MixinRenderGlobal", "MixinRenderGlobal",
"MixinRenderItem", "MixinRenderItem",
"MixinRenderLivingBase",
"MixinRenderManager", "MixinRenderManager",
"MixinTileEntityRendererDispatcher" "MixinTileEntityRendererDispatcher"
//#endif //#endif