Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
use more shares
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 committed Jan 3, 2024
1 parent ad05058 commit 13d33c5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import com.prupe.mcpatcher.cc.ColorizeBlock;
import com.prupe.mcpatcher.cc.Colorizer;
import com.prupe.mcpatcher.mal.block.RenderBlocksUtils;
Expand Down Expand Up @@ -64,20 +67,6 @@ public abstract class MixinRenderBlocks {
@Shadow
public abstract boolean hasOverrideBlockTexture();

// Compute values once and reuse later

@Unique
private boolean mcpatcherforge$computeRedstoneWireColor;

@Unique
private float mcpatcherforge$redstoneWireColorRed;

@Unique
private float mcpatcherforge$redstoneWireColorGreen;

@Unique
private float mcpatcherforge$redstoneWireColorBlue;

@Unique
private void mcpatcherforge$setColorAndVertex(Tessellator tessellator, float red, float green, float blue, double x,
double y, double z, double u, double v) {
Expand Down Expand Up @@ -112,12 +101,14 @@ private void modifyRenderBlockCauldron2(BlockCauldron block, int x, int y, int z

@Inject(method = "renderBlockRedstoneWire(Lnet/minecraft/block/Block;III)Z", at = @At("HEAD"))
private void calculateComputeRedstoneWireColor(Block block, int x, int y, int z,
CallbackInfoReturnable<Boolean> cir) {
this.mcpatcherforge$computeRedstoneWireColor = ColorizeBlock
.computeRedstoneWireColor(this.blockAccess.getBlockMetadata(x, y, z));
this.mcpatcherforge$redstoneWireColorRed = Math.max(Colorizer.setColor[0], 0.0f);
this.mcpatcherforge$redstoneWireColorGreen = Math.max(Colorizer.setColor[1], 0.0f);
this.mcpatcherforge$redstoneWireColorBlue = Math.max(Colorizer.setColor[2], 0.0f);
CallbackInfoReturnable<Boolean> cir,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
computeRedstoneWireColor
.set(ColorizeBlock.computeRedstoneWireColor(this.blockAccess.getBlockMetadata(x, y, z)));
red.set(Math.max(Colorizer.setColor[0], 0.0f));
green.set(Math.max(Colorizer.setColor[1], 0.0f));
blue.set(Math.max(Colorizer.setColor[2], 0.0f));
}

@ModifyArgs(
Expand All @@ -126,11 +117,13 @@ private void calculateComputeRedstoneWireColor(Block block, int x, int y, int z,
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/Tessellator;setColorOpaque_F(FFF)V",
ordinal = 0))
private void modifyColorRedstoneWire1(Args args) {
if (this.mcpatcherforge$computeRedstoneWireColor) {
args.set(0, this.mcpatcherforge$redstoneWireColorRed);
args.set(1, this.mcpatcherforge$redstoneWireColorGreen);
args.set(2, this.mcpatcherforge$redstoneWireColorBlue);
private void modifyColorRedstoneWire1(Args args,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
if (computeRedstoneWireColor.get()) {
args.set(0, red.get());
args.set(1, green.get());
args.set(2, blue.get());
}
}

Expand All @@ -140,11 +133,13 @@ private void modifyColorRedstoneWire1(Args args) {
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/Tessellator;setColorOpaque_F(FFF)V",
ordinal = 4))
private void modifyColorRedstoneWire2(Args args) {
if (this.mcpatcherforge$computeRedstoneWireColor) {
args.set(0, this.mcpatcherforge$redstoneWireColorRed);
args.set(1, this.mcpatcherforge$redstoneWireColorGreen);
args.set(2, this.mcpatcherforge$redstoneWireColorBlue);
private void modifyColorRedstoneWire2(Args args,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
if (computeRedstoneWireColor.get()) {
args.set(0, red.get());
args.set(1, green.get());
args.set(2, blue.get());
}
}

Expand All @@ -154,11 +149,13 @@ private void modifyColorRedstoneWire2(Args args) {
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/Tessellator;setColorOpaque_F(FFF)V",
ordinal = 6))
private void modifyColorRedstoneWire3(Args args) {
if (this.mcpatcherforge$computeRedstoneWireColor) {
args.set(0, this.mcpatcherforge$redstoneWireColorRed);
args.set(1, this.mcpatcherforge$redstoneWireColorGreen);
args.set(2, this.mcpatcherforge$redstoneWireColorBlue);
private void modifyColorRedstoneWire3(Args args,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
if (computeRedstoneWireColor.get()) {
args.set(0, red.get());
args.set(1, green.get());
args.set(2, blue.get());
}
}

Expand All @@ -168,11 +165,13 @@ private void modifyColorRedstoneWire3(Args args) {
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/Tessellator;setColorOpaque_F(FFF)V",
ordinal = 8))
private void modifyColorRedstoneWire4(Args args) {
if (this.mcpatcherforge$computeRedstoneWireColor) {
args.set(0, this.mcpatcherforge$redstoneWireColorRed);
args.set(1, this.mcpatcherforge$redstoneWireColorGreen);
args.set(2, this.mcpatcherforge$redstoneWireColorBlue);
private void modifyColorRedstoneWire4(Args args,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
if (computeRedstoneWireColor.get()) {
args.set(0, red.get());
args.set(1, green.get());
args.set(2, blue.get());
}
}

Expand All @@ -182,11 +181,13 @@ private void modifyColorRedstoneWire4(Args args) {
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/Tessellator;setColorOpaque_F(FFF)V",
ordinal = 10))
private void modifyColorRedstoneWire5(Args args) {
if (this.mcpatcherforge$computeRedstoneWireColor) {
args.set(0, this.mcpatcherforge$redstoneWireColorRed);
args.set(1, this.mcpatcherforge$redstoneWireColorGreen);
args.set(2, this.mcpatcherforge$redstoneWireColorBlue);
private void modifyColorRedstoneWire5(Args args,
@Share("computeRedstoneWireColor") LocalBooleanRef computeRedstoneWireColor, @Share("red") LocalFloatRef red,
@Share("green") LocalFloatRef green, @Share("blue") LocalFloatRef blue) {
if (computeRedstoneWireColor.get()) {
args.set(0, red.get());
args.set(1, green.get());
args.set(2, blue.get());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
import net.minecraft.world.World;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.prupe.mcpatcher.cc.ColorizeWorld;
import com.prupe.mcpatcher.cc.Colorizer;

@Mixin(World.class)
public abstract class MixinWorld {

@Unique
private boolean mcpatcher_forge$computeSkyColor;

@Inject(
method = "getSkyColorBody(Lnet/minecraft/entity/Entity;F)Lnet/minecraft/util/Vec3;",
at = @At("HEAD"),
remap = false)
private void modifyGetSkyColorBody1(Entity entity, float p_72833_2_, CallbackInfoReturnable<Vec3> cir) {
this.mcpatcher_forge$computeSkyColor = ColorizeWorld.computeSkyColor((World) (Object) this, p_72833_2_);
private void modifyGetSkyColorBody1(Entity entity, float p_72833_2_, CallbackInfoReturnable<Vec3> cir,
@Share("computeSkyColor") LocalBooleanRef computeSkyColor) {
computeSkyColor.set(ColorizeWorld.computeSkyColor((World) (Object) this, p_72833_2_));
}

@Inject(
Expand All @@ -45,8 +44,8 @@ private void modifyGetSkyColorBody2(Entity entity, float p_72833_2_, CallbackInf
at = @At(value = "STORE", ordinal = 0),
ordinal = 3,
remap = false)
private float modifyGetSkyColorBody3(float input) {
if (this.mcpatcher_forge$computeSkyColor) {
private float modifyGetSkyColorBody3(float input, @Share("computeSkyColor") LocalBooleanRef computeSkyColor) {
if (computeSkyColor.get()) {
return Colorizer.setColor[0];
}
return input;
Expand All @@ -58,8 +57,8 @@ private float modifyGetSkyColorBody3(float input) {
at = @At(value = "STORE", ordinal = 0),
ordinal = 4,
remap = false)
private float modifyGetSkyColorBody4(float input) {
if (this.mcpatcher_forge$computeSkyColor) {
private float modifyGetSkyColorBody4(float input, @Share("computeSkyColor") LocalBooleanRef computeSkyColor) {
if (computeSkyColor.get()) {
return Colorizer.setColor[1];
}
return input;
Expand All @@ -71,8 +70,8 @@ private float modifyGetSkyColorBody4(float input) {
at = @At(value = "STORE", ordinal = 0),
ordinal = 5,
remap = false)
private float modifyGetSkyColorBody5(float input) {
if (this.mcpatcher_forge$computeSkyColor) {
private float modifyGetSkyColorBody5(float input, @Share("computeSkyColor") LocalBooleanRef computeSkyColor) {
if (computeSkyColor.get()) {
return Colorizer.setColor[2];
}
return input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
import net.minecraft.world.WorldProvider;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.prupe.mcpatcher.cc.ColorizeWorld;
import com.prupe.mcpatcher.cc.Colorizer;

@Mixin(WorldProvider.class)
public abstract class MixinWorldProvider {

@Unique
private boolean mcpatcher_forge$computeFogColor;

@Inject(method = "getFogColor(FF)Lnet/minecraft/util/Vec3;", at = @At("HEAD"))
private void modifyGetFogColor1(float celestialAngle, float renderPartialTicks, CallbackInfoReturnable<Vec3> cir) {
this.mcpatcher_forge$computeFogColor = ColorizeWorld
.computeFogColor((WorldProvider) (Object) this, celestialAngle);
private void modifyGetFogColor1(float celestialAngle, float renderPartialTicks, CallbackInfoReturnable<Vec3> cir,
@Share("computeFogColor") LocalBooleanRef computeFogColor) {
computeFogColor.set(ColorizeWorld.computeFogColor((WorldProvider) (Object) this, celestialAngle));
}

@ModifyConstant(method = "getFogColor(FF)Lnet/minecraft/util/Vec3;", constant = @Constant(floatValue = 0.7529412F))
private float modifyGetFogColor1(float constant) {
if (this.mcpatcher_forge$computeFogColor) {
private float modifyGetFogColor1(float constant, @Share("computeFogColor") LocalBooleanRef computeFogColor) {
if (computeFogColor.get()) {
return Colorizer.setColor[0];
}
return constant;
}

@ModifyConstant(method = "getFogColor(FF)Lnet/minecraft/util/Vec3;", constant = @Constant(floatValue = 0.84705883F))
private float modifyGetFogColor2(float constant) {
if (this.mcpatcher_forge$computeFogColor) {
private float modifyGetFogColor2(float constant, @Share("computeFogColor") LocalBooleanRef computeFogColor) {
if (computeFogColor.get()) {
return Colorizer.setColor[1];
}
return constant;
Expand All @@ -45,8 +43,8 @@ private float modifyGetFogColor2(float constant) {
@ModifyConstant(
method = "getFogColor(FF)Lnet/minecraft/util/Vec3;",
constant = @Constant(floatValue = 1.0F, ordinal = 2))
private float modifyGetFogColor3(float constant) {
if (this.mcpatcher_forge$computeFogColor) {
private float modifyGetFogColor3(float constant, @Share("computeFogColor") LocalBooleanRef computeFogColor) {
if (computeFogColor.get()) {
return Colorizer.setColor[2];
}
return constant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.prupe.mcpatcher.cc.ColorizeWorld;
import com.prupe.mcpatcher.hd.FontUtils;

Expand Down Expand Up @@ -61,13 +63,6 @@ public abstract class MixinFontRenderer implements FontRendererExpansion {
@Unique
private float mcpatcher_forge$fontAdj;

/**
* for custom text colors the index is required when drawing
* unfortunately capturing locals doesn't work with modifyVariable
*/
@Unique
private int mcpatcher_forge$renderStringAtPosIndex;

public float[] getCharWidthf() {
return mcpatcher_forge$charWidthf;
}
Expand Down Expand Up @@ -153,8 +148,9 @@ private void modifyGetUnicodePageLocation(int index, CallbackInfoReturnable<Reso
method = "renderStringAtPos(Ljava/lang/String;Z)V",
locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/FontRenderer;colorCode:[I"))
private void modifyRenderStringAtPos1(String string, boolean bool, CallbackInfo ci, int i, char c0, int j) {
this.mcpatcher_forge$renderStringAtPosIndex = j;
private void modifyRenderStringAtPos1(String string, boolean bool, CallbackInfo ci, int i, char c0, int j,
@Share("renderStringAtPosIndex") LocalIntRef renderStringAtPosIndex) {
renderStringAtPosIndex.set(j);
}

// IDEA plugin really struggles with this for some reason
Expand All @@ -163,8 +159,9 @@ private void modifyRenderStringAtPos1(String string, boolean bool, CallbackInfo
method = "renderStringAtPos(Ljava/lang/String;Z)V",
at = @At(value = "STORE", ordinal = 0),
ordinal = 2)
private int modifyRenderStringAtPos2(int color) {
return ColorizeWorld.colorizeText(color, this.mcpatcher_forge$renderStringAtPosIndex);
private int modifyRenderStringAtPos2(int color,
@Share("renderStringAtPosIndex") LocalIntRef renderStringAtPosIndex) {
return ColorizeWorld.colorizeText(color, renderStringAtPosIndex.get());
}

@ModifyVariable(method = "renderString(Ljava/lang/String;IIIZ)I", at = @At("HEAD"), ordinal = 2, argsOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -20,6 +19,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.prupe.mcpatcher.sky.FireworksHelper;

@SuppressWarnings({ "rawtypes" })
Expand All @@ -29,9 +30,6 @@ public abstract class MixinEffectRenderer {
@Shadow
private List[] fxLayers;

@Unique
private int mcpatcher_forge$renderParticlesIndex;

@Inject(
method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/client/renderer/texture/TextureManager;)V",
at = @At("RETURN"))
Expand Down Expand Up @@ -66,23 +64,24 @@ private int modifyRenderParticles1(int constant) {
at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"),
locals = LocalCapture.CAPTURE_FAILHARD)
private void modifyRenderParticles2(Entity player, float partialTickTime, CallbackInfo ci, float f1, float f2,
float f3, float f4, float f5, int k, int i) {
this.mcpatcher_forge$renderParticlesIndex = i;
float f3, float f4, float f5, int k, int i, @Share("renderParticlesIndex") LocalIntRef renderParticlesIndex) {
renderParticlesIndex.set(i);
}

@Redirect(
method = "renderParticles(Lnet/minecraft/entity/Entity;F)V",
at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"))
private boolean modifyRenderParticles3(List layer) {
return FireworksHelper.skipThisLayer(
this.fxLayers[mcpatcher_forge$renderParticlesIndex].isEmpty(),
this.mcpatcher_forge$renderParticlesIndex);
private boolean modifyRenderParticles3(List layer,
@Share("renderParticlesIndex") LocalIntRef renderParticlesIndex) {
return FireworksHelper
.skipThisLayer(this.fxLayers[renderParticlesIndex.get()].isEmpty(), renderParticlesIndex.get());
}

@Redirect(
method = "renderParticles(Lnet/minecraft/entity/Entity;F)V",
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glBlendFunc(II)V", remap = false))
private void modifyRenderParticles4(int sfactor, int dfactor) {
FireworksHelper.setParticleBlendMethod(this.mcpatcher_forge$renderParticlesIndex, 0, true);
private void modifyRenderParticles4(int sfactor, int dfactor,
@Share("renderParticlesIndex") LocalIntRef renderParticlesIndex) {
FireworksHelper.setParticleBlendMethod(renderParticlesIndex.get(), 0, true);
}
}

0 comments on commit 13d33c5

Please sign in to comment.