Skip to content

Commit

Permalink
Add details on method and make overlay progressive
Browse files Browse the repository at this point in the history
  • Loading branch information
Alluysl committed Jun 1, 2021
1 parent 2072844 commit dde6eeb
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/main/java/alluysl/alluyslorigins/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public abstract class GameRendererMixin {
private static Identifier field_26730;

// Code from Mojang, mapping from Yarn, few edits from me, essentially a modified method_31136
private void drawBurrowOverlayOnScreen(float strength, float r, float g, float b) {
private void drawBurrowOverlayOnScreen(float ratio, float r, float g, float b) {
int w = this.client.getWindow().getScaledWidth();
int h = this.client.getWindow().getScaledHeight();
double d = MathHelper.lerp((double)strength, 2.0D, 1.0D);
r *= strength;
g *= strength;
b *= strength;
double d = MathHelper.lerp((double)ratio, 2.0D, 1.0D);
r *= ratio;
g *= ratio;
b *= ratio;
double wA = (double)w * d;
double hA = (double)h * d;
double wB = ((double)w - wA) / 2.0D;
Expand All @@ -43,10 +43,11 @@ private void drawBurrowOverlayOnScreen(float strength, float r, float g, float b
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(wB, hB + hA, -90.0D).texture(0.0F, 1.0F).next();
bufferBuilder.vertex(wB + wA, hB + hA, -90.0D).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(wB + wA, hB, -90.0D).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(wB, hB, -90.0D).texture(0.0F, 0.0F).next();
// A goes from 2x to x, B goes from -0.5x to 0, A+B goes from 1.5x to x for x the width or height
bufferBuilder.vertex(wB, hB + hA, -90.0D).texture(0.0F, 1.0F).next(); // bottom left
bufferBuilder.vertex(wB + wA, hB + hA, -90.0D).texture(1.0F, 1.0F).next(); // bottom right
bufferBuilder.vertex(wB + wA, hB, -90.0D).texture(1.0F, 0.0F).next(); // top right
bufferBuilder.vertex(wB, hB, -90.0D).texture(0.0F, 0.0F).next(); // top left
tessellator.draw();
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.defaultBlendFunc();
Expand All @@ -55,6 +56,8 @@ private void drawBurrowOverlayOnScreen(float strength, float r, float g, float b
RenderSystem.enableDepthTest();
}

private int ticksSinceStart = -1;

// Heavily based on Origin's game renderer phantomzied overlay mixin

@Shadow
Expand All @@ -63,8 +66,15 @@ private void drawBurrowOverlayOnScreen(float strength, float r, float g, float b

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F"))
private void drawBurrowOverlay(CallbackInfo ci) {
if(AlluyslOriginsPowers.BURROW_OVERLAY.isActive(this.client.player) && !this.client.player.hasStatusEffect(StatusEffects.NAUSEA)) {
this.drawBurrowOverlayOnScreen(1.0F, 0.2F, 0.1F, 0.05F);
}
if(!this.client.player.hasStatusEffect(StatusEffects.NAUSEA)) {
if (AlluyslOriginsPowers.BURROW_OVERLAY.isActive(this.client.player)){
if (ticksSinceStart < 30)
++ticksSinceStart;
} else if (ticksSinceStart > 0)
--ticksSinceStart;
if (ticksSinceStart > 0)
this.drawBurrowOverlayOnScreen(MathHelper.sqrt(ticksSinceStart / 30.0F), 0.2F, 0.1F, 0.05F);
} else
ticksSinceStart = 0;
}
}

0 comments on commit dde6eeb

Please # to comment.