forked from Jorbon/cool_elytra
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug and add momentum based camera movement.
- Loading branch information
Showing
11 changed files
with
216 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
- Added the ability to switch the yaw and roll axes. | ||
- Added sensitivity settings. | ||
- Added controller compat via MidnightControls. | ||
- Fixed camera drifting while game is paused (#5) | ||
- Added momentum based camera movement option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nl.enjarai.doabarrelroll; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public class ModMath { | ||
|
||
public static void forBresenhamLine(int x0, int y0, int x1, int y1, BiConsumer<Integer, Integer> consumer) { | ||
|
||
int dx = Math.abs(x1 - x0); | ||
int dy = Math.abs(y1 - y0); | ||
|
||
int sx = x0 < x1 ? 1 : -1; | ||
int sy = y0 < y1 ? 1 : -1; | ||
|
||
int err = dx - dy; | ||
int e2; | ||
|
||
while (true) { | ||
|
||
consumer.accept(x0, y0); | ||
|
||
if (x0 == x1 && y0 == y1) break; | ||
|
||
e2 = 2 * err; | ||
|
||
if (e2 > -dy) { | ||
err = err - dy; | ||
x0 = x0 + sx; | ||
} | ||
|
||
if (e2 < dx) { | ||
err = err + dx; | ||
y0 = y0 + sy; | ||
} | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/nl/enjarai/doabarrelroll/MomentumCrosshairWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package nl.enjarai.doabarrelroll; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.render.*; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.util.math.Vec2f; | ||
|
||
public class MomentumCrosshairWidget { | ||
|
||
public static void render(MatrixStack matrices, int scaledWidth, int scaledHeight, Vec2f mouseTurnVec) { | ||
int color = 0xffffffff; | ||
int centerX = scaledWidth / 2; | ||
int centerY = scaledHeight / 2 - 1; | ||
var turnVec = mouseTurnVec.multiply(50); | ||
var lineVec = turnVec.add(turnVec.negate().normalize().multiply(Math.min(turnVec.length(), 10f))); | ||
|
||
if (!lineVec.equals(Vec2f.ZERO)) { | ||
|
||
RenderSystem.enableBlend(); | ||
RenderSystem.disableTexture(); | ||
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.ONE_MINUS_DST_COLOR, GlStateManager.DstFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); | ||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
ModMath.forBresenhamLine(centerX, centerY, centerX + (int) lineVec.x, centerY + (int) lineVec.y, (x, y) -> { | ||
|
||
var matrix = matrices.peek().getPositionMatrix(); | ||
var bufferBuilder = Tessellator.getInstance().getBuffer(); | ||
|
||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); | ||
bufferBuilder.vertex(matrix, (float) x, (float) y + 1, 0.0F).color(color).next(); | ||
bufferBuilder.vertex(matrix, (float) x + 1, (float) y + 1, 0.0F).color(color).next(); | ||
bufferBuilder.vertex(matrix, (float) x + 1, (float) y, 0.0F).color(color).next(); | ||
bufferBuilder.vertex(matrix, (float) x, (float) y, 0.0F).color(color).next(); | ||
BufferRenderer.drawWithShader(bufferBuilder.end()); | ||
|
||
}); | ||
RenderSystem.enableTexture(); | ||
} | ||
|
||
// change the position of the crosshair, which is rendered up the stack | ||
matrices.translate((int) turnVec.x, (int) turnVec.y, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/nl/enjarai/doabarrelroll/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nl.enjarai.doabarrelroll.mixin; | ||
|
||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.gui.hud.InGameHud; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import nl.enjarai.doabarrelroll.DoABarrelRollClient; | ||
import nl.enjarai.doabarrelroll.ElytraMath; | ||
import nl.enjarai.doabarrelroll.ModMath; | ||
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.Redirect; | ||
|
||
@Mixin(InGameHud.class) | ||
public abstract class InGameHudMixin extends DrawableHelper { | ||
|
||
@Shadow private int scaledWidth; | ||
@Shadow private int scaledHeight; | ||
|
||
@Shadow abstract void renderCrosshair(MatrixStack matrices); | ||
|
||
@Redirect( | ||
method = "render(Lnet/minecraft/client/util/math/MatrixStack;F)V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/client/gui/hud/InGameHud;renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V" | ||
) | ||
) | ||
private void onRenderCrosshair(InGameHud inGameHud, MatrixStack matrixStack) { | ||
matrixStack.push(); | ||
DoABarrelRollClient.onRenderCrosshair(matrixStack, scaledWidth, scaledHeight); | ||
renderCrosshair(matrixStack); | ||
matrixStack.pop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.