Move remaining mixins to replay module
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.replaymod.replay.mixin;
|
||||
|
||||
import com.replaymod.replay.camera.CameraEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiSpectator;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(GuiSpectator.class)
|
||||
public abstract class MixinGuiSpectator {
|
||||
@Shadow
|
||||
private Minecraft field_175268_g;
|
||||
|
||||
@Inject(method = "func_175260_a", at = @At("HEAD"), cancellable = true)
|
||||
public void isInReplay(int i, CallbackInfo ci) {
|
||||
// Prevent spectator gui from opening while in a replay
|
||||
if (field_175268_g.thePlayer instanceof CameraEntity) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.replaymod.replay.mixin;
|
||||
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import net.minecraft.client.renderer.culling.ICamera;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderArrow;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(RenderArrow.class)
|
||||
public abstract class MixinRenderArrow extends Render {
|
||||
protected MixinRenderArrow(RenderManager renderManager) {
|
||||
super(renderManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(Entity entity, ICamera camera, double camX, double camY, double camZ) {
|
||||
// Force arrows to always render, otherwise they stop rendering when you get close to them
|
||||
return ReplayModReplay.instance.getReplayHandler() != null || super.shouldRender(entity, camera, camX, camY, camZ);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.replaymod.replay.mixin;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RenderManager.class)
|
||||
public class MixinRenderManager {
|
||||
@Shadow
|
||||
private float playerViewY;
|
||||
|
||||
@Inject(method = "cacheActiveRenderInfo", at = @At("RETURN"))
|
||||
public void fixHeadRotationForAnimals(World world, FontRenderer font, Entity view, Entity target, GameSettings settings, float partialRenderTick, CallbackInfo ci) {
|
||||
if (view instanceof EntityAnimal && !((EntityAnimal) view).isPlayerSleeping()) {
|
||||
EntityAnimal e = (EntityAnimal) view;
|
||||
this.playerViewY = e.prevRotationYawHead + (e.rotationYawHead - e.prevRotationYawHead) * partialRenderTick;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.replaymod.replay.mixin;
|
||||
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.ViewFrustum;
|
||||
import net.minecraft.client.renderer.chunk.IRenderChunkFactory;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ViewFrustum.class)
|
||||
public abstract class MixinViewFrustum {
|
||||
private IRenderChunkFactory renderChunkFactory;
|
||||
|
||||
@Shadow protected RenderGlobal renderGlobal;
|
||||
@Shadow protected World world;
|
||||
@Shadow protected int countChunksY;
|
||||
@Shadow protected int countChunksX;
|
||||
@Shadow protected int countChunksZ;
|
||||
@Shadow public RenderChunk[] renderChunks;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void setRenderChunkFactory(World a1, int a2, RenderGlobal a3, IRenderChunkFactory rcf, CallbackInfo ci) {
|
||||
this.renderChunkFactory = rcf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instead of calling {@link RenderChunk#setPosition(BlockPos)} we recreate the render chunk
|
||||
* which seems to solve the problem that chunks are invisible when you leave an area and return
|
||||
* to it.
|
||||
* Any better fixes are welcome.
|
||||
* Note: Most of this code is copied from {@link ViewFrustum#updateChunkPositions(double, double)}
|
||||
*/
|
||||
@Inject(method = "updateChunkPositions", at = @At("HEAD"), cancellable = true)
|
||||
public void fixedUpdateChunkPositions(double viewEntityX, double viewEntityZ, CallbackInfo ci) {
|
||||
if (ReplayModReplay.instance.getReplayHandler() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = MathHelper.floor_double(viewEntityX) - 8;
|
||||
int j = MathHelper.floor_double(viewEntityZ) - 8;
|
||||
int k = this.countChunksX * 16;
|
||||
|
||||
for (int l = 0; l < this.countChunksX; ++l) {
|
||||
int i1 = this.func_178157_a(i, k, l);
|
||||
for (int j1 = 0; j1 < this.countChunksZ; ++j1) {
|
||||
int k1 = this.func_178157_a(j, k, j1);
|
||||
for (int l1 = 0; l1 < this.countChunksY; ++l1) {
|
||||
int i2 = l1 * 16;
|
||||
RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l];
|
||||
BlockPos blockpos = new BlockPos(i1, i2, k1);
|
||||
if (!blockpos.equals(renderchunk.getPosition())) {
|
||||
// Recreate render chunk instead of setting its position
|
||||
renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l] =
|
||||
renderChunkFactory.makeRenderChunk(world, renderGlobal, blockpos, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
@Shadow abstract int func_178157_a(int p_178157_1_, int p_178157_2_, int p_178157_3_);
|
||||
}
|
||||
Reference in New Issue
Block a user