Skip to content

Commit

Permalink
Port to 1.21 (#227)
Browse files Browse the repository at this point in the history
Co-authored-by: LambdAurora <[email protected]>
  • Loading branch information
IMS212 and LambdAurora committed Jul 23, 2024
1 parent ef48189 commit 4286c10
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 98 deletions.
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.4.+"
id "fabric-loom" version "1.7.+"
id "dev.yumi.gradle.licenser" version "1.1.+"
id "java-library"
id "maven-publish"
Expand Down Expand Up @@ -82,10 +82,6 @@ String fetchChangelog() {
repositories {
mavenLocal()
mavenCentral()
maven {
name "Quilt"
url "https://maven.quiltmc.org/repository/release"
}
maven {
name "Terraformers"
url "https://maven.terraformersmc.com/releases/"
Expand Down Expand Up @@ -122,7 +118,7 @@ loom {

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${project.quilt_mappings}:intermediary-v2"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.4
quilt_mappings=2
loader_version=0.15.3
minecraft_version=1.21
yarn_mappings=2
loader_version=0.15.11
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version=0.91.3+1.20.4
fabric_api_version=0.100.4+1.21

# Mod Properties
mod_version = 2.3.4
Expand All @@ -18,7 +18,7 @@ curseforge_id=393442

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
spruceui_version=5.0.3+1.20.2
pridelib_version=1.2.0+1.19.4
modmenu_version=9.0.0
sodium_version=mc1.20.3-0.5.5
spruceui_version=5.1.0+1.21
pridelib_version=1.2.1+1.21
modmenu_version=11.0.1
sodium_version=mc1.21-0.5.9
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.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier(NAMESPACE, "dynamiclights_resources");
return Identifier.of(NAMESPACE, "dynamiclights_resources");
}

@Override
Expand Down Expand Up @@ -450,15 +450,15 @@ private static boolean isEyeSubmergedInFluid(LivingEntity entity) {
return false;
}

var eyePos = BlockPos.create(entity.getX(), entity.getEyeY(), entity.getZ());
var eyePos = BlockPos.ofFloored(entity.getX(), entity.getEyeY(), entity.getZ());
return !entity.getWorld().getFluidState(eyePos).isEmpty();
}

public static int getLivingEntityLuminanceFromItems(LivingEntity entity) {
boolean submergedInFluid = isEyeSubmergedInFluid(entity);
int luminance = 0;

for (var equipped : entity.getItemsEquipped()) {
for (var equipped : entity.getEquippedItems()) {
if (!equipped.isEmpty())
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, submergedInFluid));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean isWaterSensitive(T lightSource) {
static <T extends LivingEntity> @NotNull DynamicLightHandler<T> makeLivingEntityHandler(@NotNull DynamicLightHandler<T> handler) {
return entity -> {
int luminance = 0;
for (var equipped : entity.getItemsEquipped()) {
for (var equipped : entity.getEquippedItems()) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, entity.isSubmergedInWater()));
}
return Math.max(luminance, handler.getLuminance(entity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static <T extends Entity> int getLuminanceFrom(T entity) {
if (!canLightUp(entity))
return 0;
if (handler.isWaterSensitive(entity)
&& !entity.getWorld().getFluidState(BlockPos.create(entity.getX(), entity.getEyeY(), entity.getZ())).isEmpty())
&& !entity.getWorld().getFluidState(BlockPos.ofFloored(entity.getX(), entity.getEyeY(), entity.getZ())).isEmpty())
return 0;
return handler.getLuminance(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import dev.lambdaurora.lambdynlights.LambDynLights;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.BlockStateComponent;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -95,7 +97,7 @@ public String toString() {
return Optional.empty();
}

var affectId = new Identifier(json.get("item").getAsString());
var affectId = Identifier.tryParse(json.get("item").getAsString());
var item = Registries.ITEM.get(affectId);

if (item == Items.AIR)
Expand Down Expand Up @@ -162,19 +164,10 @@ public int getLuminance(ItemStack stack) {
}

static int getLuminance(ItemStack stack, BlockState state) {
var nbt = stack.getNbt();

if (nbt != null) {
var blockStateTag = nbt.getCompound("BlockStateTag");
var stateManager = state.getBlock().getStateManager();

for (var key : blockStateTag.getKeys()) {
var property = stateManager.getProperty(key);
if (property != null) {
var value = blockStateTag.get(key).asString();
state = with(state, property, value);
}
}
var nbt = stack.getComponents().getOrDefault(DataComponentTypes.BLOCK_STATE, BlockStateComponent.DEFAULT);

if (!nbt.isEmpty()) {
state = nbt.applyToState(state);
}

return state.getLuminance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public static void load(ResourceManager resourceManager) {
}

private static void load(Identifier resourceId, Resource resource) {
var id = new Identifier(resourceId.getNamespace(), resourceId.getPath().replace(".json", ""));
try (var reader = new InputStreamReader(resource.open())) {
var id = Identifier.of(resourceId.getNamespace(), resourceId.getPath().replace(".json", ""));
try (var reader = new InputStreamReader(resource.getInputStream())) {
var json = JsonParser.parseReader(reader).getAsJsonObject();

ItemLightSource.fromJson(id, json).ifPresent(data -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.mojang.serialization.Codec;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.button.ButtonWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.Option;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.text.Text;

import java.util.Optional;
Expand All @@ -26,22 +26,22 @@
public final class DynamicLightsOptionsOption {
private static final String KEY = "lambdynlights.menu.title";

public static Option<Unit> getOption(Screen parent) {
return new Option<>(
KEY, Option.emptyTooltip(),
public static SimpleOption<Unit> getOption(Screen parent) {
return new SimpleOption<>(
KEY, SimpleOption.emptyTooltip(),
(title, object) -> title,
new DummyValueSet(parent),
Unit.INSTANCE,
unit -> {});
}

private record DummyValueSet(Screen parent) implements Option.ValueSet<Unit> {
private record DummyValueSet(Screen parent) implements SimpleOption.Callbacks<Unit> {

@Override
public Function<Option<Unit>, ClickableWidget> getButtonCreator(Option.TooltipSupplier<Unit> tooltipSupplier, GameOptions options,
public Function<SimpleOption<Unit>, ClickableWidget> getWidgetCreator(SimpleOption.TooltipFactory<Unit> tooltipSupplier, GameOptions options,
int x, int y, int width, Consumer<Unit> changeCallback) {
return option -> ButtonWidget.builder(Text.translatable(KEY), button -> MinecraftClient.getInstance()
.setScreen(new SettingsScreen(this.parent))).positionAndSize(x, y, width, 20).build();
.setScreen(new SettingsScreen(this.parent))).dimensions(x, y, width, 20).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
import dev.lambdaurora.spruceui.background.DirtTexturedBackground;
import dev.lambdaurora.spruceui.widget.SpruceWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.DrawContext;

public class InnerBackground implements Background {

@Override
public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
public void render(DrawContext drawContext, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
if (MinecraftClient.getInstance().world != null) {
graphics.fillGradient(widget.getX(), widget.getY(),
drawContext.fillGradient(widget.getX(), widget.getY(),
widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight(),
0xc0060606, 0xd0060606);
} else {
DirtTexturedBackground.DARKENED.render(graphics, widget, vOffset, mouseX, mouseY, delta);
DirtTexturedBackground.DARKENED.render(drawContext, widget, vOffset, mouseX, mouseY, delta);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import dev.lambdaurora.spruceui.widget.WithBackground;
import dev.lambdaurora.spruceui.widget.container.SpruceEntryListWidget;
import dev.lambdaurora.spruceui.widget.container.SpruceParentWidget;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -203,12 +203,12 @@ protected boolean onCharTyped(char chr, int keyCode) {

/* Rendering */

protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.forEach(widget -> widget.render(graphics, mouseX, mouseY, delta));
protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, float delta) {
this.forEach(widget -> widget.render(drawContext, mouseX, mouseY, delta));
}

protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.background.render(graphics, this, 0, mouseX, mouseY, delta);
protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
this.background.render(drawContext, this, 0, mouseX, mouseY, delta);
}

/* Narration */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
package dev.lambdaurora.lambdynlights.gui;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
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.PrideFlag;
import io.github.queerbric.pride.PrideFlagShapes;
import io.github.queerbric.pride.PrideFlags;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.util.Identifier;
import org.joml.Matrix4f;
import org.joml.Vector4f;
Expand All @@ -46,16 +45,15 @@ public RandomPrideFlagBackground(PrideFlag flag) {
}

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

RenderSystem.setShader(GameRenderer::getPositionColorShader);
if (this.flag.getShape() == PrideFlagShapes.get(new Identifier("pride", "horizontal_stripes"))) {
var model = graphics.getMatrices().peek().getModel();
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
if (this.flag.getShape() == PrideFlagShapes.get(Identifier.of("pride", "horizontal_stripes"))) {
var model = drawContext.getMatrices().peek().getPositionMatrix();
var tessellator = Tessellator.getInstance();
var vertices = tessellator.getBufferBuilder();
vertices.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
var vertices = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);

int width = widget.getWidth();
int height = widget.getHeight();
Expand All @@ -67,39 +65,43 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m
float leftY = y;

int[] color = ColorUtil.unpackARGBColor(this.flag.getColors().getInt(0));
vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]);

rightY += partHeight;

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

vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]);

vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, leftY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, leftY + partHeight, 0).color(color[0], color[1], color[2], color[3]);

rightY += partHeight;
leftY += partHeight;
}

// Last one
color = ColorUtil.unpackARGBColor(this.flag.getColors().getInt(this.flag.getColors().size() - 1));
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x, y + height, 0).color(color[0], color[1], color[2], color[3]).next();
vertex(vertices, model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, leftY, 0).color(color[0], color[1], color[2], color[3]);
vertex(vertices, model, x, y + height, 0).color(color[0], color[1], color[2], color[3]);

tessellator.draw();
BuiltBuffer builtBuffer = vertices.endNullable();
if (builtBuffer != null) {
BufferRenderer.drawWithGlobalProgram(builtBuffer);
}
tessellator.clear();
} else {
this.flag.render(graphics.getMatrices(), x, y, widget.getWidth(), widget.getHeight());
this.flag.render(drawContext.getMatrices(), x, y, widget.getWidth(), widget.getHeight());
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void init() {
null, this.tabContainerBuilder(this::buildEntitiesTab));
this.tabbedWidget.addTabEntry(Text.empty().append(dynamicLightSources).append(": ").append(this.blockEntitiesOption.getPrefix()),
null, this.tabContainerBuilder(this::buildBlockEntitiesTab));
this.addSelectableElement(this.tabbedWidget);
this.addSelectableChild(this.tabbedWidget);
}

private SpruceTabbedWidget.ContainerFactory tabContainerBuilder(SpruceTabbedWidget.ContainerFactory innerFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package dev.lambdaurora.lambdynlights.mixin;

import dev.lambdaurora.lambdynlights.LambDynLights;
import net.minecraft.client.gui.hud.debug.DebugHud;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Loading

0 comments on commit 4286c10

Please sign in to comment.