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:
@@ -10,6 +10,7 @@ import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector3f;
|
||||
import lombok.SneakyThrows;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
import java.io.IOException;
|
||||
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
|
||||
// renderer translate there again.
|
||||
// Instead of actually translating, we just add the translation on the current model-view-matrix.
|
||||
Matrix4f modelView = getGlModelViewMatrix();
|
||||
Matrix4f.translate(new Vector3f((float) dx, (float) dy, (float) dz), modelView, modelView);
|
||||
renderState.pushModelView(modelView);
|
||||
renderState.applyLastModelViewTransformToObject();
|
||||
if (!(entity instanceof EntityLivingBase)) { // except for EntityLivingBase which get special (better) treatment
|
||||
Matrix4f modelView = getGlModelViewMatrix();
|
||||
Matrix4f.translate(new Vector3f((float) dx, (float) dy, (float) dz), modelView, modelView);
|
||||
renderState.pushModelView(modelView);
|
||||
renderState.applyLastModelViewTransformToObject();
|
||||
|
||||
entityObject.keyframeLocRotScale(renderState.getFrame());
|
||||
entityObject.keyframeLocRotScale(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) {
|
||||
renderState.pop();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -10,6 +10,7 @@
|
||||
"MixinModelRenderer",
|
||||
"MixinRenderGlobal",
|
||||
"MixinRenderItem",
|
||||
"MixinRenderLivingBase",
|
||||
"MixinRenderManager",
|
||||
"MixinTileEntityRendererDispatcher"
|
||||
//#endif
|
||||
|
||||
Reference in New Issue
Block a user