Port to 1.17-pre1

This commit is contained in:
Jonas Herzig
2021-06-05 18:05:26 +02:00
parent 5f2dca08d1
commit 1802b1a7d0
35 changed files with 582 additions and 225 deletions

View File

@@ -2,19 +2,31 @@
package com.replaymod.core.gui;
import com.replaymod.core.ReplayMod;
import io.github.prospector.modmenu.api.ModMenuApi;
import net.minecraft.client.gui.screen.Screen;
import java.util.function.Function;
//#if MC>=11700
//$$ import com.terraformersmc.modmenu.api.ConfigScreenFactory;
//$$ import com.terraformersmc.modmenu.api.ModMenuApi;
//#else
import io.github.prospector.modmenu.api.ModMenuApi;
//#endif
public class ModMenuApiImpl implements ModMenuApi {
//#if MC<11700
@Override
public String getModId() {
return ReplayMod.MOD_ID;
}
//#endif
@Override
//#if MC>=11700
//$$ public ConfigScreenFactory<?> getModConfigScreenFactory() {
//#else
public Function<Screen, ? extends Screen> getConfigScreenFactory() {
//#endif
return parent -> new GuiReplaySettings(parent, ReplayMod.instance.getSettingsRegistry()).toMinecraft();
}
}

View File

@@ -2,32 +2,33 @@ package com.replaymod.core.mixin;
import net.minecraft.client.gui.screen.Screen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
//#if MC>=11400
import net.minecraft.client.gui.widget.AbstractButtonWidget;
//#if MC>=11700
//$$ import net.minecraft.client.gui.Drawable;
//$$ import net.minecraft.client.gui.Element;
//$$ import net.minecraft.client.gui.Selectable;
//#else
//$$ import net.minecraft.client.gui.GuiButton;
//#endif
//#if MC>=11400
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import org.spongepowered.asm.mixin.gen.Invoker;
//#else
//$$ import net.minecraft.client.gui.GuiButton;
//$$ import org.spongepowered.asm.mixin.gen.Accessor;
//$$ import java.util.List;
//#endif
@Mixin(Screen.class)
public interface GuiScreenAccessor {
//#if MC>=11400
@Accessor
List<AbstractButtonWidget> getButtons();
//#if MC>=11700
//$$ @Invoker("addDrawableChild")
//$$ <T extends Element & Drawable & Selectable> T invokeAddButton(T drawableElement);
//#elseif MC>=11400
@Invoker
<T extends AbstractButtonWidget> T invokeAddButton(T button);
//#else
//$$ @Accessor("buttonList")
//$$ List<GuiButton> getButtons();
//#endif
//#if MC>=11400
@Accessor
List<Element> getChildren();
//#endif
}

View File

@@ -5,6 +5,7 @@ import net.minecraft.network.ClientConnection;
import net.minecraft.util.crash.CrashReport;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Queue;
@@ -27,6 +28,9 @@ public interface MinecraftAccessor {
@Accessor("renderTickCounter")
RenderTickCounter getTimer();
@Accessor("renderTickCounter")
//#if MC>=11200
@Mutable
//#endif
void setTimer(RenderTickCounter value);
//#if MC>=11400

View File

@@ -2,6 +2,7 @@ package com.replaymod.core.mixin;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(RenderTickCounter.class)
@@ -15,6 +16,7 @@ public interface TimerAccessor {
@Accessor("tickTime")
float getTickLength();
@Accessor("tickTime")
@Mutable
void setTickLength(float value);
//#else
//$$ @Accessor

View File

@@ -1,11 +1,17 @@
package com.replaymod.core.versions;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.core.mixin.GuiScreenAccessor;
import com.replaymod.replaystudio.protocol.PacketTypeRegistry;
import com.replaymod.replaystudio.us.myles.ViaVersion.api.protocol.ProtocolVersion;
import com.replaymod.replaystudio.us.myles.ViaVersion.packets.State;
import de.johni0702.minecraft.gui.MinecraftGuiRenderer;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector2f;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector3f;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
//#if MC>=11600
@@ -206,14 +212,15 @@ public class MCVer {
//#endif
) {
GuiScreenAccessor acc = (GuiScreenAccessor) screen;
acc.getButtons().add(button);
//#if MC>=11400
acc.getChildren().add(button);
acc.invokeAddButton(button);
//#else
//$$ acc.getButtons().add(button);
//#endif
}
//#if MC>=11400
public static Optional<AbstractButtonWidget> findButton(List<AbstractButtonWidget> buttonList, @SuppressWarnings("unused") String text, @SuppressWarnings("unused") int id) {
public static Optional<AbstractButtonWidget> findButton(Iterable<AbstractButtonWidget> buttonList, @SuppressWarnings("unused") String text, @SuppressWarnings("unused") int id) {
//#if MC>=11600
final TranslatableText message = new TranslatableText(text);
//#else
@@ -233,7 +240,7 @@ public class MCVer {
return Optional.empty();
}
//#else
//$$ public static Optional<GuiButton> findButton(List<GuiButton> buttonList, @SuppressWarnings("unused") String text, int id) {
//$$ public static Optional<GuiButton> findButton(Iterable<GuiButton> buttonList, @SuppressWarnings("unused") String text, int id) {
//$$ for (GuiButton b : buttonList) {
//$$ if (b.id == id) {
//$$ return Optional.of(b);
@@ -332,6 +339,53 @@ public class MCVer {
//#endif
}
public static void pushMatrix() {
//#if MC>=11700
//$$ RenderSystem.getModelViewStack().push();
//#else
GlStateManager.pushMatrix();
//#endif
}
public static void popMatrix() {
//#if MC>=11700
//$$ RenderSystem.getModelViewStack().pop();
//$$ RenderSystem.applyModelViewMatrix();
//#else
GlStateManager.popMatrix();
//#endif
}
public static void emitLine(BufferBuilder buffer, Vector2f p1, Vector2f p2, int color) {
emitLine(buffer, new Vector3f(p1.x, p1.y, 0), new Vector3f(p2.x, p2.y, 0), color);
}
public static void emitLine(BufferBuilder buffer, Vector3f p1, Vector3f p2, int color) {
int r = color >> 24 & 0xff;
int g = color >> 16 & 0xff;
int b = color >> 8 & 0xff;
int a = color & 0xff;
//#if MC>=11700
//$$ Vector3f n = Vector3f.sub(p2, p1, null);
//#endif
buffer.vertex(p1.x, p1.y, p1.z)
.color(r, g, b, a)
//#if MC>=11700
//$$ .normal(n.x, n.y, n.z)
//#endif
.next();
buffer.vertex(p2.x, p2.y, p2.z)
.color(r, g, b, a)
//#if MC>=11700
//$$ .normal(n.x, n.y, n.z)
//#endif
.next();
}
public static void bindTexture(Identifier id) {
new MinecraftGuiRenderer(null).bindTexture(id);
}
//#if MC<10900
//$$ public static class SoundEvent {}
//#endif

View File

@@ -3,6 +3,7 @@ package com.replaymod.core.versions;
import com.replaymod.gradle.remap.Pattern;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.render.Tessellator;
@@ -16,6 +17,11 @@ import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraft.world.chunk.WorldChunk;
//#if MC>=11700
//#else
import org.lwjgl.opengl.GL11;
//#endif
//#if MC>=11400
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.Window;
@@ -88,6 +94,42 @@ class Patterns {
//#endif
}
@Pattern
private static void Entity_setYaw(Entity entity, float value) {
//#if MC>=11700
//$$ entity.setYaw(value);
//#else
entity.yaw = value;
//#endif
}
@Pattern
private static float Entity_getYaw(Entity entity) {
//#if MC>=11700
//$$ return entity.getYaw();
//#else
return entity.yaw;
//#endif
}
@Pattern
private static void Entity_setPitch(Entity entity, float value) {
//#if MC>=11700
//$$ entity.setPitch(value);
//#else
entity.pitch = value;
//#endif
}
@Pattern
private static float Entity_getPitch(Entity entity) {
//#if MC>=11700
//$$ return entity.getPitch();
//#else
return entity.pitch;
//#endif
}
@Pattern
private static void Entity_setPos(Entity entity, double x, double y, double z) {
//#if MC>=11500
@@ -187,13 +229,19 @@ class Patterns {
}
@Pattern
//#if MC>=11700
//$$ private static void getEntitySectionArray() {}
//#else
private static Collection<Entity>[] getEntitySectionArray(WorldChunk chunk) {
//#if MC>=10800
//#if MC>=11700
//$$ return obsolete(chunk);
//#elseif MC>=10800
return chunk.getEntitySectionArray();
//#else
//$$ return chunk.entityLists;
//#endif
}
//#endif
@Pattern
private static List<? extends PlayerEntity> playerEntities(World world) {
@@ -244,6 +292,7 @@ class Patterns {
//#endif
}
//#if MC<11700
@Pattern
private static void BufferBuilder_beginPosCol(BufferBuilder buffer, int mode) {
//#if MC>=10809
@@ -297,6 +346,14 @@ class Patterns {
//$$ { WorldRenderer $buffer = buffer; double $x = x; double $y = y; double $z = z; float $u = u; float $v = v; $buffer.setColorRGBA(r, g, b, a); $buffer.addVertexWithUV($x, $y, $z, $u, $v); }
//#endif
}
//#else
@Pattern private static void BufferBuilder_beginPosCol() {}
@Pattern private static void BufferBuilder_addPosCol() {}
@Pattern private static void BufferBuilder_beginPosTex() {}
@Pattern private static void BufferBuilder_addPosTex() {}
@Pattern private static void BufferBuilder_beginPosTexCol() {}
@Pattern private static void BufferBuilder_addPosTexCol() {}
//#endif
@Pattern
private static Tessellator Tessellator_getInstance() {
@@ -382,4 +439,64 @@ class Patterns {
//$$ return (a.getKeyCode() == b.getKeyCode());
//#endif
}
//#if MC>=11600
@Pattern
private static void BufferBuilder_beginLineStrip(BufferBuilder buffer, VertexFormat vertexFormat) {
//#if MC>=11700
//$$ buffer.begin(net.minecraft.client.render.VertexFormat.DrawMode.LINE_STRIP, VertexFormats.LINES);
//#else
buffer.begin(GL11.GL_LINE_STRIP, VertexFormats.POSITION_COLOR);
//#endif
}
@Pattern
private static void BufferBuilder_beginLines(BufferBuilder buffer) {
//#if MC>=11700
//$$ buffer.begin(net.minecraft.client.render.VertexFormat.DrawMode.LINES, VertexFormats.LINES);
//#else
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
//#endif
}
@Pattern
private static void BufferBuilder_beginQuads(BufferBuilder buffer, VertexFormat vertexFormat) {
//#if MC>=11700
//$$ buffer.begin(net.minecraft.client.render.VertexFormat.DrawMode.QUADS, vertexFormat);
//#else
buffer.begin(GL11.GL_QUADS, vertexFormat);
//#endif
}
//#else
//$$ @Pattern private static void BufferBuilder_beginLineStrip() {}
//$$ @Pattern private static void BufferBuilder_beginLines() {}
//$$ @Pattern private static void BufferBuilder_beginQuads() {}
//#endif
@Pattern
private static void GL11_glLineWidth(float width) {
//#if MC>=11700
//$$ com.mojang.blaze3d.systems.RenderSystem.lineWidth(width);
//#else
GL11.glLineWidth(width);
//#endif
}
@Pattern
private static void GL11_glTranslatef(float x, float y, float z) {
//#if MC>=11700
//$$ com.mojang.blaze3d.systems.RenderSystem.getModelViewStack().translate(x, y, z);
//#else
GL11.glTranslatef(x, y, z);
//#endif
}
@Pattern
private static void GL11_glRotatef(float angle, float x, float y, float z) {
//#if MC>=11700
//$$ { float $angle = angle; com.mojang.blaze3d.systems.RenderSystem.getModelViewStack().multiply(new net.minecraft.util.math.Quaternion(new net.minecraft.util.math.Vec3f(x, y, z), $angle, true)); }
//#else
GL11.glRotatef(angle, x, y, z);
//#endif
}
}

View File

@@ -29,7 +29,7 @@ public class SchedulerImpl implements Scheduler {
runLater(new Runnable() {
@Override
public void run() {
if (mc.overlay != null) {
if (mc.getOverlay() != null) {
// delay until after resources have been loaded
runLater(this);
return;

View File

@@ -19,6 +19,7 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
//#endif
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@@ -78,9 +79,9 @@ public class GuiRecordingControls extends EventRegistrations {
{ on(InitScreenCallback.EVENT, this::injectIntoIngameMenu); }
private void injectIntoIngameMenu(Screen guiScreen,
//#if MC>=11400
List<AbstractButtonWidget> buttonList
Collection<AbstractButtonWidget> buttonList
//#else
//$$ List<net.minecraft.client.gui.GuiButton> buttonList
//$$ Collection<net.minecraft.client.gui.GuiButton> buttonList
//#endif
) {
if (!(guiScreen instanceof GameMenuScreen)) {

View File

@@ -38,14 +38,12 @@ public class GuiRecordingOverlay extends EventRegistrations {
if (settingsRegistry.get(Setting.INDICATOR)) {
TextRenderer fontRenderer = mc.textRenderer;
String text = guiControls.isPaused() ? I18n.translate("replaymod.gui.paused") : I18n.translate("replaymod.gui.recording");
fontRenderer.draw(
//#if MC>=11600
stack,
//#endif
text.toUpperCase(), 30, 18 - (fontRenderer.fontHeight / 2), 0xffffffff);
mc.getTextureManager().bindTexture(TEXTURE);
MinecraftGuiRenderer renderer = new MinecraftGuiRenderer(stack);
renderer.drawString(30, 18 - (fontRenderer.fontHeight / 2), 0xffffffff, text.toUpperCase());
renderer.bindTexture(TEXTURE);
//#if MC<11700
enableAlphaTest();
GuiRenderer renderer = new MinecraftGuiRenderer(stack);
//#endif
renderer.drawTexturedRect(10, 10, 58, 20, 16, 16, 16, 16, TEXTURE_SIZE, TEXTURE_SIZE);
}
}

View File

@@ -172,7 +172,12 @@ public class ResourcePackRecorder {
}
}
return new ResourcePackSendS2CPacket("replay://" + requestId, "");
return new ResourcePackSendS2CPacket(
"replay://" + requestId, ""
//#if MC>=11700
//$$ , packet.isRequired(), packet.getPrompt()
//#endif
);
}
private void downloadResourcePackFuture(int requestId, String url, final String hash) {
@@ -190,7 +195,11 @@ public class ResourcePackRecorder {
downloadResourcePack(final int requestId, String url, String hash) {
ClientBuiltinResourcePackProvider packFinder = mc.getResourcePackDownloader();
((IDownloadingPackFinder) packFinder).setRequestCallback(file -> recordResourcePack(file, requestId));
//#if MC>=11700
//$$ return packFinder.download(url, hash, true);
//#else
return packFinder.download(url, hash);
//#endif
}
public interface IDownloadingPackFinder {

View File

@@ -63,7 +63,9 @@ public class BlendMeshBuilder
}
@Override
//#if MC>=10809
//#if MC>=11700
//$$ public void begin(VertexFormat.DrawMode mode, VertexFormat vertexFormat) {
//#elseif MC>=10809
public void begin(int mode, VertexFormat vertexFormat) {
//#else
//$$ public void startDrawing(int mode) {
@@ -148,7 +150,17 @@ public class BlendMeshBuilder
//#endif
}
public static DMesh addBufferToMesh(ByteBuffer buffer, int mode, VertexFormat vertexFormat, DMesh mesh, ReadableVector3f vertOffset) {
public static DMesh addBufferToMesh(
ByteBuffer buffer,
//#if MC>=11700
//$$ VertexFormat.DrawMode mode,
//#else
int mode,
//#endif
VertexFormat vertexFormat,
DMesh mesh,
ReadableVector3f vertOffset
) {
//#if MC>=11400
int vertexCount = buffer.remaining() / vertexFormat.getVertexSize();
//#else
@@ -157,7 +169,18 @@ public class BlendMeshBuilder
return addBufferToMesh(buffer, vertexCount, mode, vertexFormat, mesh, vertOffset);
}
public static DMesh addBufferToMesh(ByteBuffer buffer, int vertexCount, int mode, VertexFormat vertexFormat, DMesh mesh, ReadableVector3f vertOffset) {
public static DMesh addBufferToMesh(
ByteBuffer buffer,
int vertexCount,
//#if MC>=11700
//$$ VertexFormat.DrawMode mode,
//#else
int mode,
//#endif
VertexFormat vertexFormat,
DMesh mesh,
ReadableVector3f vertOffset
) {
if (mesh == null) {
mesh = new DMesh();
}
@@ -261,7 +284,11 @@ public class BlendMeshBuilder
// Bundle vertices into shapes and add them to the mesh
switch (mode) {
//#if MC>=11700
//$$ case TRIANGLES:
//#else
case GL11.GL_TRIANGLES:
//#endif
for (int i = 0; i < vertices.size(); i+=3) {
mesh.addTriangle(
vertices.get(i ),
@@ -277,7 +304,11 @@ public class BlendMeshBuilder
);
}
break;
//#if MC>=11700
//$$ case QUADS:
//#else
case GL11.GL_QUADS:
//#endif
for (int i = 0; i < vertices.size(); i+=4) {
mesh.addQuad(
vertices.get(i ),

View File

@@ -11,6 +11,7 @@ import com.replaymod.render.blend.mixin.ParticleAccessor;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Matrix4f;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector3f;
import net.minecraft.client.MinecraftClient;
import org.lwjgl.opengl.GL11;
//#if MC>=11400
import net.minecraft.util.math.Vec3d;
@@ -169,7 +170,7 @@ public class ParticlesExporter implements Exporter {
builder.setReverseOffset(offset);
builder.setWellBehaved(true);
//#if MC>=10809
builder.begin(7, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT);
builder.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT);
//#else
//$$ builder.startDrawingQuads();
//#endif

View File

@@ -1,5 +1,6 @@
package com.replaymod.render.capturer;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.render.rendering.Channel;
import de.johni0702.minecraft.gui.utils.EventRegistrations;
import com.replaymod.render.RenderSettings;
@@ -15,12 +16,12 @@ import net.minecraft.util.crash.CrashReport;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.Identifier;
import static com.mojang.blaze3d.platform.GlStateManager.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static com.replaymod.core.versions.MCVer.popMatrix;
import static com.replaymod.core.versions.MCVer.pushMatrix;
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@@ -170,12 +171,12 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
pushMatrix();
frameBuffer().beginWrite(true);
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
//#if MC>=11400
, false
//#endif
);
enableTexture();
GlStateManager.enableTexture();
directionVariable.set(captureData.ordinal());
worldRenderer.renderWorld(partialTicks, null);

View File

@@ -1,5 +1,6 @@
package com.replaymod.render.capturer;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.core.versions.MCVer;
import com.replaymod.render.frame.OpenGlFrame;
import com.replaymod.render.rendering.Frame;
@@ -16,12 +17,8 @@ import org.lwjgl.opengl.GL12;
import java.io.IOException;
import java.nio.ByteBuffer;
//#if MC>=10800
import static com.mojang.blaze3d.platform.GlStateManager.*;
//#else
//$$ import static com.replaymod.core.versions.MCVer.GlStateManager.*;
//#endif
import static com.replaymod.core.versions.MCVer.popMatrix;
import static com.replaymod.core.versions.MCVer.pushMatrix;
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@@ -86,12 +83,12 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
pushMatrix();
frameBuffer().beginWrite(true);
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
//#if MC>=11400
, false
//#endif
);
enableTexture();
GlStateManager.enableTexture();
worldRenderer.renderWorld(partialTicks, captureData);

View File

@@ -1,4 +1,4 @@
//#if MC>=10800
//#if MC>=10800 && MC<11700
package com.replaymod.render.mixin;
import com.replaymod.render.hooks.FogStateCallback;

View File

@@ -83,13 +83,15 @@ public abstract class Mixin_StabilizeCamera {
//#endif
RenderSettings settings = getHandler().getSettings();
if (settings.isStabilizeYaw()) {
entity.prevYaw = entity.yaw = 0;
entity.prevYaw = 0;
entity.yaw = 0;
if (entity instanceof LivingEntity) {
((LivingEntity) entity).prevHeadYaw = ((LivingEntity) entity).headYaw = 0;
}
}
if (settings.isStabilizePitch()) {
entity.prevPitch = entity.pitch = 0;
entity.prevPitch = 0;
entity.pitch = 0;
}
if (settings.isStabilizeRoll() && entity instanceof CameraEntity) {
((CameraEntity) entity).roll = 0;

View File

@@ -1,5 +1,6 @@
package com.replaymod.render.rendering;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.core.mixin.TimerAccessor;
import com.replaymod.core.utils.WrappedTimer;
@@ -40,6 +41,12 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.client.render.RenderTickCounter;
import org.lwjgl.glfw.GLFW;
//#if MC>=11700
//$$ import net.minecraft.client.gl.WindowFramebuffer;
//$$ import net.minecraft.client.render.DiffuseLighting;
//$$ import net.minecraft.util.math.Matrix4f;
//#endif
//#if MC>=11600
import net.minecraft.client.util.math.MatrixStack;
//#endif
@@ -59,10 +66,8 @@ import java.util.concurrent.CompletableFuture;
//#endif
//#if MC>=10800
import static com.mojang.blaze3d.platform.GlStateManager.*;
//#else
//$$ import com.replaymod.replay.gui.screen.GuiOpeningReplay;
//$$ import static com.replaymod.core.versions.MCVer.GlStateManager.*;
//#endif
import java.io.IOException;
@@ -360,11 +365,15 @@ public class VideoRenderer implements RenderInfo {
forceChunkLoadingHook = new ForceChunkLoadingHook(mc.worldRenderer);
// Set up our own framebuffer to render the GUI to
//#if MC>=11700
//$$ guiFramebuffer = new WindowFramebuffer(displayWidth, displayHeight);
//#else
guiFramebuffer = new Framebuffer(displayWidth, displayHeight, true
//#if MC>=11400
, false
//#endif
);
//#endif
}
private void finish() {
@@ -419,7 +428,7 @@ public class VideoRenderer implements RenderInfo {
private void executeTaskQueue() {
//#if MC>=11400
while (true) {
while (mc.overlay != null) {
while (mc.getOverlay() != null) {
drawGui();
((MinecraftMethodAccessor) mc).replayModExecuteTaskQueue();
}
@@ -486,22 +495,38 @@ public class VideoRenderer implements RenderInfo {
}
pushMatrix();
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
//#if MC>=11400
, false
//#endif
);
enableTexture();
GlStateManager.enableTexture();
guiFramebuffer.beginWrite(true);
//#if MC>=11500
RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC);
//#if MC>=11700
//$$ RenderSystem.setProjectionMatrix(Matrix4f.projectionMatrix(
//$$ 0,
//$$ (float) (window.getFramebufferWidth() / window.getScaleFactor()),
//$$ 0,
//$$ (float) (window.getFramebufferHeight() / window.getScaleFactor()),
//$$ 1000,
//$$ 3000
//$$ ));
//$$ MatrixStack matrixStack = RenderSystem.getModelViewStack();
//$$ matrixStack.loadIdentity();
//$$ matrixStack.translate(0, 0, -2000);
//$$ RenderSystem.applyModelViewMatrix();
//$$ DiffuseLighting.enableGuiDepthLighting();
//#else
RenderSystem.matrixMode(GL11.GL_PROJECTION);
RenderSystem.loadIdentity();
RenderSystem.ortho(0, window.getFramebufferWidth() / window.getScaleFactor(), window.getFramebufferHeight() / window.getScaleFactor(), 0, 1000, 3000);
RenderSystem.matrixMode(GL11.GL_MODELVIEW);
RenderSystem.loadIdentity();
RenderSystem.translatef(0, 0, -2000);
//#endif
//#else
//#if MC>=11400
//$$ window.method_4493(
@@ -535,11 +560,11 @@ public class VideoRenderer implements RenderInfo {
int mouseX = (int) mc.mouse.getX() * window.getScaledWidth() / displayWidth;
int mouseY = (int) mc.mouse.getY() * window.getScaledHeight() / displayHeight;
if (mc.overlay != null) {
if (mc.getOverlay() != null) {
Screen orgScreen = mc.currentScreen;
try {
mc.currentScreen = gui.toMinecraft();
mc.overlay.render(
mc.getOverlay().render(
//#if MC>=11600
new MatrixStack(),
//#endif

View File

@@ -366,6 +366,8 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
// Entity#addedToChunk is not set and it is therefore not updated every tick.
// To counteract this, we need to manually update it's position if it hasn't been added
// to any chunk yet.
// The `updateNeeded` flag appears to have been removed in 1.17, so this should no longer be an issue.
//#if MC<11700
if (mc.world != null) {
for (PlayerEntity playerEntity : mc.world.getPlayers()) {
if (!playerEntity.updateNeeded && playerEntity instanceof OtherClientPlayerEntity) {
@@ -373,6 +375,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
}
}
}
//#endif
}
}
@@ -413,7 +416,9 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
|| p instanceof ExperienceOrbSpawnS2CPacket
|| p instanceof EntitiesDestroyS2CPacket) {
ClientWorld world = mc.world;
//#if MC>=11400
//#if MC>=11700
//$$ // From the looks of it, this has now been resolved (thanks to EntityChangeListener)
//#elseif MC>=11400
// Note: Not sure if it's still required but there's this really handy method anyway
world.finishRemovingEntities();
//#else
@@ -478,12 +483,16 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
int i = pb.readVarInt();
NetworkState state = loginPhase ? NetworkState.LOGIN : NetworkState.PLAY;
//#if MC>=11700
//$$ Packet p = state.getPacketHandler(NetworkSide.CLIENTBOUND, i, pb);
//#else
//#if MC>=10800
Packet p = state.getPacketHandler(NetworkSide.CLIENTBOUND, i);
//#else
//$$ Packet p = Packet.generatePacket(state.func_150755_b(), i);
//#endif
p.read(pb);
//#endif
return p;
}
@@ -1154,6 +1163,9 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
// 1.14+: The update issue remains but only for non-players and the unloading list bug appears to have been
// fixed (chunk unloading no longer removes the entities).
// Get the chunk that will be unloaded
//#if MC>=11700
//$$ // From the looks of it, this may be fixed now (thanks to EntityChangeListener), guess we'll see
//#else
//#if MC>=11400
ClientWorld world = mc.world;
ChunkManager chunkProvider = world.getChunkManager();
@@ -1250,6 +1262,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
//#endif
}
}
//#endif
}
return p; // During synchronous playback everything is sent normally
}

View File

@@ -8,6 +8,9 @@ import net.minecraft.client.MinecraftClient;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.util.ScreenshotUtils;
import static com.replaymod.core.versions.MCVer.popMatrix;
import static com.replaymod.core.versions.MCVer.pushMatrix;
//#if MC>=11500
import net.minecraft.client.util.math.MatrixStack;
//#endif
@@ -58,7 +61,7 @@ public class NoGuiScreenshot {
mc.options.hudHidden = true;
// Render frame without GUI
GlStateManager.pushMatrix();
pushMatrix();
GlStateManager.clear(
16640
//#if MC>=11400
@@ -84,10 +87,10 @@ public class NoGuiScreenshot {
//#endif
mc.getFramebuffer().endWrite();
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
popMatrix();
pushMatrix();
mc.getFramebuffer().draw(frameWidth, frameHeight);
GlStateManager.popMatrix();
popMatrix();
} catch (Throwable t) {
future.setException(t);
return;

View File

@@ -99,6 +99,18 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
@Override
protected Packet<?> decode(com.github.steveice10.netty.buffer.ByteBuf byteBuf) throws IOException {
int packetId = new ByteBufNetInput(byteBuf).readVarInt();
int size = byteBuf.readableBytes();
if (buf.length < size) {
buf = new byte[size];
}
byteBuf.readBytes(buf, 0, size);
ByteBuf wrappedBuf = Unpooled.wrappedBuffer(buf);
wrappedBuf.writerIndex(size);
PacketByteBuf packetByteBuf = new PacketByteBuf(wrappedBuf);
//#if MC>=11700
//$$ return NetworkState.PLAY.getPacketHandler(NetworkSide.CLIENTBOUND, packetId, packetByteBuf);
//#else
//#if MC>=11500
Packet<?> mcPacket = NetworkState.PLAY.getPacketHandler(NetworkSide.CLIENTBOUND, packetId);
//#else
@@ -110,16 +122,10 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
//$$ }
//#endif
if (mcPacket != null) {
int size = byteBuf.readableBytes();
if (buf.length < size) {
buf = new byte[size];
}
byteBuf.readBytes(buf, 0, size);
ByteBuf wrappedBuf = Unpooled.wrappedBuffer(buf);
wrappedBuf.writerIndex(size);
mcPacket.read(new PacketByteBuf(wrappedBuf));
mcPacket.read(packetByteBuf);
}
return mcPacket;
//#endif
}
@Override
@@ -220,7 +226,12 @@ public class QuickReplaySender extends ChannelHandlerAdapter implements ReplaySe
//$$ GameMode.SPECTATOR
//#endif
));
ctx.fireChannelRead(new PlayerPositionLookS2CPacket(0, 0, 0, 0, 0, Collections.emptySet(), 0));
ctx.fireChannelRead(new PlayerPositionLookS2CPacket(
0, 0, 0, 0, 0, Collections.emptySet(), 0
//#if MC>=11700
//$$ , true
//#endif
));
}
@Override

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.mojang.blaze3d.platform.GlStateManager;
import com.replaymod.core.ReplayMod;
import com.replaymod.core.mixin.MinecraftAccessor;
import com.replaymod.core.mixin.TimerAccessor;
@@ -40,6 +41,11 @@ import net.minecraft.network.ClientConnection;
import java.io.IOException;
import java.util.*;
//#if MC>=11700
//$$ import net.minecraft.client.render.DiffuseLighting;
//$$ import net.minecraft.util.math.Matrix4f;
//#endif
//#if MC>=11600
import net.minecraft.client.util.math.MatrixStack;
//#endif
@@ -97,7 +103,6 @@ import javax.annotation.Nullable;
import static com.replaymod.core.versions.MCVer.*;
import static com.replaymod.replay.ReplayModReplay.LOGGER;
import static com.mojang.blaze3d.platform.GlStateManager.*;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
@@ -213,11 +218,13 @@ public class ReplayHandler {
channel.close().awaitUninterruptibly();
if (mc.player instanceof CameraEntity) {
//#if MC<11700
//#if MC>=11400
mc.player.remove();
//#else
//$$ mc.player.setDead();
//#endif
//#endif
}
if (mc.world != null) {
@@ -604,22 +611,38 @@ public class ReplayHandler {
// Perform the rendering using OpenGL
pushMatrix();
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
GlStateManager.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
//#if MC>=11400
, true
//#endif
);
enableTexture();
GlStateManager.enableTexture();
mc.getFramebuffer().beginWrite(true);
Window window = mc.getWindow();
//#if MC>=11500
RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC);
//#if MC>=11700
//$$ RenderSystem.setProjectionMatrix(Matrix4f.projectionMatrix(
//$$ 0,
//$$ (float) (window.getFramebufferWidth() / window.getScaleFactor()),
//$$ 0,
//$$ (float) (window.getFramebufferHeight() / window.getScaleFactor()),
//$$ 1000,
//$$ 3000
//$$ ));
//$$ MatrixStack matrixStack = RenderSystem.getModelViewStack();
//$$ matrixStack.loadIdentity();
//$$ matrixStack.translate(0, 0, -2000);
//$$ RenderSystem.applyModelViewMatrix();
//$$ DiffuseLighting.enableGuiDepthLighting();
//#else
RenderSystem.matrixMode(GL11.GL_PROJECTION);
RenderSystem.loadIdentity();
RenderSystem.ortho(0, window.getFramebufferWidth() / window.getScaleFactor(), window.getFramebufferHeight() / window.getScaleFactor(), 0, 1000, 3000);
RenderSystem.matrixMode(GL11.GL_MODELVIEW);
RenderSystem.loadIdentity();
RenderSystem.translatef(0, 0, -2000);
//#endif
//#else
//#if MC>=11400
//$$ window.method_4493(true);

View File

@@ -208,8 +208,10 @@ public class CameraEntity
* @param roll Roll in degrees
*/
public void setCameraRotation(float yaw, float pitch, float roll) {
this.prevYaw = this.yaw = yaw;
this.prevPitch = this.pitch = pitch;
this.prevYaw = yaw;
this.prevPitch = pitch;
this.yaw = yaw;
this.pitch = pitch;
this.roll = roll;
}
@@ -575,8 +577,13 @@ public class CameraEntity
//#endif
@Override
//#if MC>=11700
//$$ public void remove(RemovalReason reason) {
//$$ super.remove(reason);
//#else
public void remove() {
super.remove();
//#endif
if (eventHandler != null) {
eventHandler.unregister();
eventHandler = null;

View File

@@ -34,8 +34,8 @@ import net.minecraft.client.gui.widget.ButtonWidget;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -54,7 +54,7 @@ public class GuiHandler extends EventRegistrations {
}
{ on(InitScreenCallback.EVENT, this::injectIntoIngameMenu); }
private void injectIntoIngameMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
private void injectIntoIngameMenu(Screen guiScreen, Collection<AbstractButtonWidget> buttonList) {
if (!(guiScreen instanceof GameMenuScreen)) {
return;
}
@@ -182,9 +182,9 @@ public class GuiHandler extends EventRegistrations {
*/
private void moveAllButtonsInRect(
//#if MC>=11400
List<AbstractButtonWidget> buttons,
Collection<AbstractButtonWidget> buttons,
//#else
//$$ List<GuiButton> buttons,
//$$ Collection<GuiButton> buttons,
//#endif
int xStart,
int xEnd,
@@ -198,8 +198,8 @@ public class GuiHandler extends EventRegistrations {
.forEach(button -> button.y += moveBy);
}
{ on(InitScreenCallback.EVENT, this::ensureReplayStopped); }
private void ensureReplayStopped(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
{ on(InitScreenCallback.EVENT, (screen, buttons) -> ensureReplayStopped(screen)); }
private void ensureReplayStopped(Screen guiScreen) {
if (!(guiScreen instanceof TitleScreen || guiScreen instanceof MultiplayerScreen)) {
return;
}
@@ -220,7 +220,7 @@ public class GuiHandler extends EventRegistrations {
}
{ on(InitScreenCallback.EVENT, this::injectIntoMainMenu); }
private void injectIntoMainMenu(Screen guiScreen, List<AbstractButtonWidget> buttonList) {
private void injectIntoMainMenu(Screen guiScreen, Collection<AbstractButtonWidget> buttonList) {
if (!(guiScreen instanceof TitleScreen)) {
return;
}
@@ -291,7 +291,7 @@ public class GuiHandler extends EventRegistrations {
addButton(guiScreen, button);
}
private Point determineButtonPos(MainMenuButtonPosition buttonPosition, Screen guiScreen, List<AbstractButtonWidget> buttonList) {
private Point determineButtonPos(MainMenuButtonPosition buttonPosition, Screen guiScreen, Collection<AbstractButtonWidget> buttonList) {
Point topRight = new Point(guiScreen.width - 20 - 5, 5);
if (buttonPosition == MainMenuButtonPosition.TOP_LEFT) {

View File

@@ -4,10 +4,15 @@ package com.replaymod.replay.mixin;
import com.replaymod.replay.ReplayModReplay;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.ArrowEntityRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
//#if MC>=11700
//$$ import net.minecraft.client.render.entity.EntityRendererFactory.Context;
//#else
import net.minecraft.client.render.entity.EntityRenderDispatcher;
//#endif
//#if MC>=11500
import net.minecraft.client.render.Frustum;
//#else
@@ -16,9 +21,15 @@ import net.minecraft.client.render.Frustum;
@Mixin(ArrowEntityRenderer.class)
public abstract class MixinRenderArrow extends EntityRenderer {
//#if MC>=11700
//$$ protected MixinRenderArrow(Context context) {
//$$ super(context);
//$$ }
//#else
protected MixinRenderArrow(EntityRenderDispatcher renderManager) {
super(renderManager);
}
//#endif
@SuppressWarnings("unchecked")
@Override

View File

@@ -40,7 +40,7 @@ public class MixinTileEntityEndPortalRenderer {
//#endif
//#endif
//#endif
private long replayModReplay_getEnchantmentTime() {
private long replayModReplay_getPortalTime() {
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
if (replayHandler != null) {
return replayHandler.getReplaySender().currentTimeStamp();

View File

@@ -18,6 +18,7 @@ import com.replaymod.simplepathing.SPTimeline.SPPath;
import de.johni0702.minecraft.gui.GuiRenderer;
import de.johni0702.minecraft.gui.element.advanced.AbstractGuiTimeline;
import de.johni0702.minecraft.gui.function.Draggable;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector2f;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
@@ -30,6 +31,16 @@ import org.lwjgl.opengl.GL11;
import java.util.Comparator;
import java.util.Optional;
import static com.replaymod.core.versions.MCVer.emitLine;
import static de.johni0702.minecraft.gui.versions.MCVer.popScissorState;
import static de.johni0702.minecraft.gui.versions.MCVer.pushScissorState;
import static de.johni0702.minecraft.gui.versions.MCVer.setScissorState;
//#if MC>=11700
//$$ import com.mojang.blaze3d.systems.RenderSystem;
//$$ import net.minecraft.client.render.GameRenderer;
//#endif
public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline> implements Draggable {
protected static final int KEYFRAME_SIZE = 5;
protected static final int KEYFRAME_TEXTURE_X = 74;
@@ -146,59 +157,33 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
buffer.begin(GL11.GL_LINE_STRIP, VertexFormats.POSITION_COLOR);
// Start just below the top border of the replay timeline
buffer.vertex(
replayTimelineLeft + positionXReplayTimeline,
replayTimelineTop + BORDER_TOP,
0
).color(
color >> 24 & 0xff,
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff
).next();
Vector2f p1 = new Vector2f(replayTimelineLeft + positionXReplayTimeline, replayTimelineTop + BORDER_TOP);
// Draw vertically over the replay timeline, including its bottom border
buffer.vertex(
replayTimelineLeft + positionXReplayTimeline,
replayTimelineBottom,
0
).color(
color >> 24 & 0xff,
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff
).next();
Vector2f p2 = new Vector2f(replayTimelineLeft + positionXReplayTimeline, replayTimelineBottom);
// Now for the important part: connecting to the keyframe timeline
buffer.vertex(
keyframeTimelineLeft + positionXKeyframeTimeline,
keyframeTimelineTop,
0
).color(
color >> 24 & 0xff,
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff
).next();
Vector2f p3 = new Vector2f(keyframeTimelineLeft + positionXKeyframeTimeline, keyframeTimelineTop);
// And finally another vertical bit (the timeline is already crammed enough, so only the border)
buffer.vertex(
keyframeTimelineLeft + positionXKeyframeTimeline,
keyframeTimelineTop + BORDER_TOP,
0
).color(
color >> 24 & 0xff,
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff
).next();
Vector2f p4 = new Vector2f(keyframeTimelineLeft + positionXKeyframeTimeline, keyframeTimelineTop + BORDER_TOP);
emitLine(buffer, p1, p2, color);
emitLine(buffer, p2, p3, color);
emitLine(buffer, p3, p4, color);
//#if MC>=11700
//$$ RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
//#else
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glPushAttrib(GL11.GL_SCISSOR_BIT);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL11.glLineWidth(1);
//#endif
pushScissorState();
setScissorState(false);
GL11.glLineWidth(2);
tessellator.draw();
GL11.glPopAttrib();
popScissorState();
//#if MC<11700
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
//#endif
}
}
});

View File

@@ -18,6 +18,7 @@ import com.replaymod.simplepathing.ReplayModSimplePathing;
import com.replaymod.simplepathing.SPTimeline;
import com.replaymod.simplepathing.gui.GuiPathing;
import de.johni0702.minecraft.gui.utils.EventRegistrations;
import de.johni0702.minecraft.gui.utils.lwjgl.vector.Vector3f;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
@@ -29,6 +30,10 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.lwjgl.opengl.GL11;
//#if MC>=11700
//$$ import net.minecraft.client.render.GameRenderer;
//#endif
//#if MC>=11500
import com.mojang.blaze3d.systems.RenderSystem;
//#endif
@@ -37,6 +42,10 @@ import java.util.Comparator;
import java.util.Optional;
import static com.replaymod.core.ReplayMod.TEXTURE;
import static com.replaymod.core.versions.MCVer.bindTexture;
import static com.replaymod.core.versions.MCVer.emitLine;
import static com.replaymod.core.versions.MCVer.popMatrix;
import static com.replaymod.core.versions.MCVer.pushMatrix;
public class PathPreviewRenderer extends EventRegistrations {
private static final Identifier CAMERA_HEAD = new Identifier("replaymod", "camera_head.png");
@@ -76,25 +85,32 @@ public class PathPreviewRenderer extends EventRegistrations {
int renderDistance = mc.options.viewDistance * 16;
int renderDistanceSquared = renderDistance * renderDistance;
Triple<Double, Double, Double> viewPos = Triple.of(
view.getX(),
view.getY()
Vector3f viewPos = new Vector3f(
(float) view.getX(),
(float) view.getY()
//#if MC>=10800 && MC<11500
//$$ // Eye height is subtracted to make path appear higher (at eye height) than it actually is (at foot height)
//$$ - view.getStandingEyeHeight(),
//#else
,
//#endif
view.getZ()
(float) view.getZ()
);
//#if MC<11700
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushMatrix();
//#endif
pushMatrix();
try {
//#if MC<11700
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_TEXTURE_2D);
//#endif
//#if MC>=11500
//#if MC>=11700
//$$ RenderSystem.getModelViewStack().method_34425(matrixStack.peek().getModel());
//$$ RenderSystem.applyModelViewMatrix();
//#elseif MC>=11500
RenderSystem.multMatrix(matrixStack.peek().getModel());
//#endif
@@ -110,7 +126,7 @@ public class PathPreviewRenderer extends EventRegistrations {
}
// Spectator segments have 20 lines per second (at least 10) whereas normal segments have a fixed 100
long steps = spectator ? Math.max(diff / 50, 10) : 100;
Triple<Double, Double, Double> prevPos = null;
Vector3f prevPos = null;
for (int i = 0; i <= steps; i++) {
long time = start.getTime() + diff * i / steps;
if (spectator) {
@@ -119,24 +135,24 @@ public class PathPreviewRenderer extends EventRegistrations {
if (entityId.isPresent() && replayTime.isPresent()) {
Location loc = entityTracker.getEntityPositionAtTimestamp(entityId.get(), replayTime.get());
if (loc != null) {
Triple<Double, Double, Double> pos = Triple.of(loc.getX(), loc.getY(), loc.getZ());
Vector3f pos = loc2Vec(loc);
if (prevPos != null) {
drawConnection(viewPos, prevPos, pos, 0x0000ff, renderDistanceSquared);
drawConnection(viewPos, prevPos, pos, 0x0000ffff, renderDistanceSquared);
}
prevPos = pos;
continue;
}
}
} else {
Optional<Triple<Double, Double, Double>> optPos = path.getValue(CameraProperties.POSITION, time);
Optional<Vector3f> optPos = path.getValue(CameraProperties.POSITION, time).map(this::tripleD2Vec);
if (optPos.isPresent()) {
Triple<Double, Double, Double> pos = optPos.get();
Vector3f pos = optPos.get();
if (prevPos != null) {
double distance = Math.sqrt(distanceSquared(prevPos, pos));
double speed = Math.min(distance / (diff / steps), FASTEST_PATH_SPEED);
double speedFraction = speed / FASTEST_PATH_SPEED;
int color = interpolateColor(SLOW_PATH_COLOR, FAST_PATH_COLOR, speedFraction);
drawConnection(viewPos, prevPos, pos, color, renderDistanceSquared);
drawConnection(viewPos, prevPos, pos, (color << 8) | 0xff, renderDistanceSquared);
}
prevPos = pos;
continue;
@@ -147,12 +163,14 @@ public class PathPreviewRenderer extends EventRegistrations {
}
GL11.glEnable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_SRC_COLOR);
GL11.glDisable(GL11.GL_DEPTH_TEST);
//#if MC<11700
GL11.glEnable(GL11.GL_TEXTURE_2D);
//#endif
path.getKeyframes().stream()
.map(k -> Pair.of(k, k.getValue(CameraProperties.POSITION)))
.map(k -> Pair.of(k, k.getValue(CameraProperties.POSITION).map(this::tripleD2Vec)))
.filter(p -> p.getRight().isPresent())
.map(p -> Pair.of(p.getLeft(), p.getRight().get()))
.filter(p -> distanceSquared(p.getRight(), viewPos) < renderDistanceSquared)
@@ -171,26 +189,40 @@ public class PathPreviewRenderer extends EventRegistrations {
if (replayTime.isPresent()) {
Location loc = entityTracker.getEntityPositionAtTimestamp(entityId.get(), replayTime.get());
if (loc != null) {
drawCamera(viewPos,
Triple.of(loc.getX(), loc.getY(), loc.getZ()),
Triple.of(loc.getYaw(), loc.getPitch(), 0f));
drawCamera(viewPos, loc2Vec(loc), new Vector3f(loc.getYaw(), loc.getPitch(), 0f));
}
}
}
} else {
// Normal camera path
Optional<Triple<Double, Double, Double>> cameraPos = path.getValue(CameraProperties.POSITION, time);
Optional<Triple<Float, Float, Float>> cameraRot = path.getValue(CameraProperties.ROTATION, time);
Optional<Vector3f> cameraPos = path.getValue(CameraProperties.POSITION, time).map(this::tripleD2Vec);
Optional<Vector3f> cameraRot = path.getValue(CameraProperties.ROTATION, time).map(this::tripleF2Vec);
if (cameraPos.isPresent() && cameraRot.isPresent()) {
drawCamera(viewPos, cameraPos.get(), cameraRot.get());
}
}
} finally {
GL11.glPopMatrix();
GlStateManager.popAttributes();
popMatrix();
//#if MC>=11700
GL11.glDisable(GL11.GL_BLEND);
//#else
GL11.glPopAttrib();
//#endif
}
}
private Vector3f loc2Vec(Location loc) {
return new Vector3f((float) loc.getX(), (float) loc.getY(), (float) loc.getZ());
}
private Vector3f tripleD2Vec(Triple<Double, Double, Double> loc) {
return new Vector3f(loc.getLeft().floatValue(), loc.getMiddle().floatValue(), loc.getRight().floatValue());
}
private Vector3f tripleF2Vec(Triple<Float, Float, Float> loc) {
return new Vector3f(loc.getLeft(), loc.getMiddle(), loc.getRight());
}
private static int interpolateColor(int c1, int c2, double weight) {
return (interpolateColorComponent((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, weight) << 16)
| (interpolateColorComponent((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, weight) << 8)
@@ -201,17 +233,11 @@ public class PathPreviewRenderer extends EventRegistrations {
return (int) (c1 + (1 - Math.pow(Math.E, -4 * weight)) * (c2 - c1)) & 0xff;
}
private static double distanceSquared(Triple<Double, Double, Double> p1, Triple<Double, Double, Double> p2) {
double dx = p1.getLeft() - p2.getLeft();
double dy = p1.getMiddle() - p2.getMiddle();
double dz = p1.getRight() - p2.getRight();
return dx * dx + dy * dy + dz * dz;
private static double distanceSquared(Vector3f p1, Vector3f p2) {
return Vector3f.sub(p1, p2, null).lengthSquared();
}
private void drawConnection(Triple<Double, Double, Double> view,
Triple<Double, Double, Double> pos1,
Triple<Double, Double, Double> pos2,
int color, int renderDistanceSquared) {
private void drawConnection(Vector3f view, Vector3f pos1, Vector3f pos2, int color, int renderDistanceSquared) {
if (distanceSquared(view, pos1) > renderDistanceSquared) return;
if (distanceSquared(view, pos2) > renderDistanceSquared) return;
@@ -219,36 +245,22 @@ public class PathPreviewRenderer extends EventRegistrations {
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
buffer.vertex(
pos1.getLeft() - view.getLeft(),
pos1.getMiddle() - view.getMiddle(),
pos1.getRight() - view.getRight()
).color(
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff,
255
).next();
buffer.vertex(
pos2.getLeft() - view.getLeft(),
pos2.getMiddle() - view.getMiddle(),
pos2.getRight() - view.getRight()
).color(
color >> 16 & 0xff,
color >> 8 & 0xff,
color & 0xff,
255
).next();
emitLine(buffer, Vector3f.sub(pos1, view, null), Vector3f.sub(pos2, view, null), color);
//#if MC>=11700
//$$ RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
//$$ RenderSystem.disableCull();
//#endif
GL11.glLineWidth(3);
tessellator.draw();
//#if MC>=11700
//$$ RenderSystem.enableCull();
//#endif
}
private void drawPoint(Triple<Double, Double, Double> view,
Triple<Double, Double, Double> pos,
Keyframe keyframe) {
private void drawPoint(Vector3f view, Vector3f pos, Keyframe keyframe) {
mc.getTextureManager().bindTexture(TEXTURE);
bindTexture(TEXTURE);
float posX = 80f / ReplayMod.TEXTURE_SIZE;
float posY = 0f;
@@ -276,53 +288,55 @@ public class PathPreviewRenderer extends EventRegistrations {
buffer.vertex(maxX, maxY, 0).texture(posX, posY).next();
buffer.vertex(maxX, minY, 0).texture(posX, posY + size).next();
GL11.glPushMatrix();
pushMatrix();
GL11.glTranslated(
pos.getLeft() - view.getLeft(),
pos.getMiddle() - view.getMiddle(),
pos.getRight() - view.getRight()
);
GL11.glNormal3f(0, 1, 0);
Vector3f t = Vector3f.sub(pos, view, null);
GL11.glTranslatef(t.x, t.y, t.z);
GL11.glRotatef(-mc.getEntityRenderDispatcher().camera.getYaw(), 0, 1, 0);
GL11.glRotatef(mc.getEntityRenderDispatcher().camera.getPitch(), 1, 0, 0);
//#if MC>=11700
//$$ RenderSystem.applyModelViewMatrix();
//$$ RenderSystem.setShader(GameRenderer::getPositionTexShader);
//#endif
tessellator.draw();
GL11.glPopMatrix();
popMatrix();
}
private void drawCamera(Triple<Double, Double, Double> view,
Triple<Double, Double, Double> pos,
Triple<Float, Float, Float> rot) {
private void drawCamera(Vector3f view, Vector3f pos, Vector3f rot) {
mc.getTextureManager().bindTexture(CAMERA_HEAD);
bindTexture(CAMERA_HEAD);
GL11.glPushMatrix();
pushMatrix();
GL11.glTranslated(
pos.getLeft() - view.getLeft(),
pos.getMiddle() - view.getMiddle(),
pos.getRight() - view.getRight()
);
GL11.glRotated(-rot.getLeft(), 0, 1, 0); // Yaw
GL11.glRotated(rot.getMiddle(), 1, 0, 0); // Pitch
GL11.glRotated(rot.getRight(), 0, 0, 1); // Roll
GL11.glNormal3f(0, 1, 0);
Vector3f t = Vector3f.sub(pos, view, null);
GL11.glTranslatef(t.x, t.y, t.z);
GL11.glRotatef(-rot.x, 0, 1, 0); // Yaw
GL11.glRotatef(rot.y, 1, 0, 0); // Pitch
GL11.glRotatef(rot.z, 0, 0, 1); // Roll
//draw the position line
GL11.glDisable(GL11.GL_TEXTURE_2D);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR);
buffer.vertex(0, 0, 0).color(0, 255, 0, 170).next();
buffer.vertex(0, 0, 2).color(0, 255, 0, 170).next();
emitLine(buffer, new Vector3f(0, 0, 0), new Vector3f(0, 0, 2), 0x00ff00aa);
//#if MC>=11700
//$$ RenderSystem.applyModelViewMatrix();
//$$ RenderSystem.setShader(GameRenderer::getRenderTypeLinesShader);
//#else
GL11.glDisable(GL11.GL_TEXTURE_2D);
//#endif
tessellator.draw();
// draw camera cube
//#if MC<11700
GL11.glEnable(GL11.GL_TEXTURE_2D);
//#endif
// draw camera cube
float cubeSize = 0.5f;
@@ -366,21 +380,24 @@ public class PathPreviewRenderer extends EventRegistrations {
buffer.vertex(r + cubeSize, r + cubeSize, r + cubeSize).texture(2*8/64f, 8/64f).color(255, 255, 255, 200).next();
buffer.vertex(r + cubeSize, r + cubeSize, r).texture(2 * 8 / 64f, 0).color(255, 255, 255, 200).next();
//#if MC>=11700
//$$ RenderSystem.applyModelViewMatrix();
//$$ RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
//#endif
tessellator.draw();
GL11.glPopMatrix();
popMatrix();
}
private class KeyframeComparator implements Comparator<Pair<Keyframe, Triple<Double, Double, Double>>> {
private final Triple<Double, Double, Double> viewPos;
private class KeyframeComparator implements Comparator<Pair<Keyframe, Vector3f>> {
private final Vector3f viewPos;
public KeyframeComparator(Triple<Double, Double, Double> viewPos) {
public KeyframeComparator(Vector3f viewPos) {
this.viewPos = viewPos;
}
@Override
public int compare(Pair<Keyframe, Triple<Double, Double, Double>> o1,
Pair<Keyframe, Triple<Double, Double, Double>> o2) {
public int compare(Pair<Keyframe, Vector3f> o1, Pair<Keyframe, Vector3f> o2) {
return -Double.compare(distanceSquared(o1.getRight(), viewPos), distanceSquared(o2.getRight(), viewPos));
}
}

View File

@@ -38,7 +38,7 @@
//$$ "MixinEffectRenderer",
//#endif
"MixinEntityRenderer",
//#if MC>=10800
//#if MC>=10800 && MC<11700
"MixinGlStateManager",
//#endif
//#if MC>=10800