Skip to content

Commit

Permalink
Merge v3.1.3 changes into 1.21.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Nov 25, 2024
2 parents 8121943 + 5358741 commit 3a40f39
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@
- Fixed dynamic lighting of various projectiles.
- Fixed water-sensitive items lighting up underwater while they shouldn't.

### 3.1.3

- Fixed item frames and other "block-attached" entities not ticking properly on the integrated server.

## 3.2.0

- Updated to Minecraft 1.21.2.
Expand All @@ -232,6 +236,11 @@
- Fixed dynamic lighting of various projectiles.
- Fixed water-sensitive items lighting up underwater while they shouldn't.

### 3.2.3

- Same changes as v3.1.3 but for 1.21.3.
- Fixed item frames and other "block-attached" entities not ticking properly on the integrated server.

[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
[pridelib]: https://github.com/Queerbric/pridelib "Pridelib page"
[Sodium]: https://modrinth.com/mod/sodium "Sodium Modrinth page"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ GitHub
</div>
<!-- modrinth_exclude.long_end -->

# 📖 Compatibility
## 📖 Compatibility

- [Sodium] is recommended for better performances.
- **OptiFabric is obviously incompatible.**
Expand Down
2 changes: 1 addition & 1 deletion build_logic/src/main/kotlin/lambdynamiclights/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.accessors.dm.LibrariesForLibs
object Constants {
const val GROUP = "dev.lambdaurora"
const val NAME = "lambdynamiclights"
const val VERSION = "3.2.2"
const val VERSION = "3.2.3"
const val JAVA_VERSION = 21

private var minecraftVersion: String? = null
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
minecraft = "1.21.3"
fabric-loader = "0.16.7"
fabric-loader = "0.16.9"
fabric-api = "0.106.1+1.21.3"
mappings-yalmm = "2"
mappings-parchment = "2024.07.28"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

import dev.lambdaurora.spruceui.background.Background;
import dev.lambdaurora.spruceui.background.SimpleColorBackground;
import dev.lambdaurora.spruceui.util.ColorUtil;
import dev.lambdaurora.spruceui.widget.SpruceWidget;
import io.github.queerbric.pride.PrideClient;
import io.github.queerbric.pride.PrideFlag;
import io.github.queerbric.pride.PrideFlagShapes;
import io.github.queerbric.pride.PrideFlags;
import io.github.queerbric.pride.*;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Text;
import net.minecraft.resources.Identifier;

import java.util.Random;
Expand All @@ -27,46 +28,57 @@
* If you have an issue with this, I don't care.
*
* @author LambdAurora
* @version 3.2.0
* @version 3.2.3
* @since 2.1.0
*/
public class RandomPrideFlagBackground implements Background {
private static final Background SECOND_LAYER = new SimpleColorBackground(0xe0101010);
private static final IntList DEFAULT_RAINBOW_COLORS = IntList.of(
0xffff0018, 0xffffa52c, 0xffffff41, 0xff008018, 0xff0000f9, 0xff86007d
);
private static final PrideFlagShape PROGRESS = PrideFlagShapes.get(Identifier.of("pride", "progress"));
private static final Random RANDOM = new Random();

private final PrideFlag flag;
private final boolean nuhUh;

public RandomPrideFlagBackground(PrideFlag flag) {
RandomPrideFlagBackground(PrideFlag flag, boolean nuhUh) {
this.flag = flag;
this.nuhUh = nuhUh;
}

private IntList getColors() {
return this.nuhUh ? DEFAULT_RAINBOW_COLORS : this.flag.getColors();
}

@Override
public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
int x = widget.getX();
int y = widget.getY();
int width = widget.getWidth();
int height = widget.getHeight();

if (this.flag.getShape() == PrideFlagShapes.get(Identifier.of("pride", "horizontal_stripes"))) {
if (this.nuhUh || this.flag.getShape() == PrideFlagShapes.get(Identifier.of("pride", "horizontal_stripes"))) {
graphics.drawSpecial(bufferSource -> {
var buffer = bufferSource.getBuffer(PrideClient.FLAG_SHAPE_TRIANGLE_RENDER_TYPE);

int width = widget.getWidth();
int height = widget.getHeight();
var colors = this.getColors();

float partHeight = height / (this.flag.getColors().size() - 1.f);
float partHeight = height / (colors.size() - 1.f);

// First one
float rightY = y;
float leftY = y;

int color = this.flag.getColors().getInt(0);
int color = colors.getInt(0);
buffer.addVertex(x + width, rightY + partHeight, 0).color(color);
buffer.addVertex(x + width, rightY, 0).color(color);
buffer.addVertex(x, leftY, 0).color(color);

rightY += partHeight;

for (int i = 1; i < this.flag.getColors().size() - 1; i++) {
color = this.flag.getColors().getInt(i);
for (int i = 1; i < colors.size() - 1; i++) {
color = colors.getInt(i);

buffer.addVertex(x + width, rightY + partHeight, 0).color(color);
buffer.addVertex(x + width, rightY, 0).color(color);
Expand All @@ -81,7 +93,7 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
}

// Last one
color = this.flag.getColors().getInt(this.flag.getColors().size() - 1);
color = colors.getInt(colors.size() - 1);
buffer.addVertex(x + width, rightY, 0).color(color);
buffer.addVertex(x, leftY, 0).color(color);
buffer.addVertex(x, y + height, 0).color(color);
Expand All @@ -91,6 +103,19 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
}

SECOND_LAYER.render(graphics, widget, vOffset, mouseX, mouseY, delta);

if (this.nuhUh) {
var text = Text.literal("Nuh uh, you're not going to remove this, try harder :3c");
var font = Minecraft.getInstance().font;
var lines = font.wrapLines(text, width - 8);

int startY = y + height - 24 - lines.size() * (font.lineHeight + 2);

for (var line : lines) {
graphics.drawCenteredShadowedText(font, line, x + width / 2, startY, 0xffff0000);
startY += font.lineHeight + 2;
}
}
}

/**
Expand All @@ -99,6 +124,39 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
* @return the background
*/
public static Background random() {
return new RandomPrideFlagBackground(PrideFlags.getRandomFlag(RANDOM));
var flag = PrideFlags.getRandomFlag(RANDOM);
boolean nuhUh = flag == null || (flag.getShape() != PROGRESS && areColorsSpoofed(flag.getColors()));

return new RandomPrideFlagBackground(flag, nuhUh);
}

private static boolean areColorsSpoofed(IntList colors) {
if (colors.size() < 2) {
return true;
} else {
int maxDist = 0;

for (int colorA : colors) {
for (int colorB : colors) {
int dist = colorDist(colorA, colorB);

if (dist > maxDist) {
maxDist = dist;
}
}
}

return maxDist < 10;
}
}

private static int colorDist(int a, int b) {
// https://en.wikipedia.org/wiki/Color_difference#sRGB
float r = (ColorUtil.argbUnpackRed(a) + ColorUtil.argbUnpackRed(b)) / 2.f;
int deltaR = ColorUtil.argbUnpackRed(a) - ColorUtil.argbUnpackRed(b);
int deltaG = ColorUtil.argbUnpackGreen(a) - ColorUtil.argbUnpackGreen(b);
int deltaB = ColorUtil.argbUnpackBlue(a) - ColorUtil.argbUnpackBlue(b);

return (int) Math.sqrt((2 + r / 256.f) * deltaR * deltaR + 4 * deltaG * deltaG + (2 + (255 - r) / 256) * deltaB * deltaB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
import net.minecraft.world.entity.decoration.BlockAttachedEntity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BlockAttachedEntity.class)
public abstract class BlockAttachedEntityMixin extends Entity implements DynamicLightSource {
public BlockAttachedEntityMixin(EntityType<?> type, Level level) {
super(type, level);
}

@Override
public void tick() {
super.tick();
@Inject(method = "tick", at = @At("RETURN"))
public void lambdynlights$onTick(CallbackInfo ci) {
// We do not want to update the entity on the server.
if (this.level().isClientSide()) {
if (this.isRemoved()) {
Expand Down

0 comments on commit 3a40f39

Please sign in to comment.