Skip to content

Commit

Permalink
Add 1.21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Jun 17, 2024
1 parent ab7a59e commit 37e32aa
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 70 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ dependencies {
include api(project(path: ':microdurability-1.19.4', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.20', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.20.5', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.21', configuration: 'namedElements'))

modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version_1_20_5}"
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version_1_20_5}"
Expand Down
22 changes: 18 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ minecraft_version_1_20_5 = 1.20.6
yarn_mappings_1_20_5 = 1.20.6+build.3
cloth_config_version_1_20_5 = 14.0.126
modmenu_version_1_20_5 = 10.0.0-beta.1
# 1.21
minecraft_version_1_21 = 1.21
yarn_mappings_1_21 = 1.21+build.2
cloth_config_version_1_21 = 15.0.127
modmenu_version_1_21 = 11.0.0-rc.4

# Dev-Env Mods
use_third_party_mods = true
Expand Down Expand Up @@ -82,19 +87,28 @@ raised_version_1_19_4 = Fabric-1.19.4-3.1.3
double_hotbar_version_1_19_4 = 1.3.1-mc1.19.4-fabric
# 1.20
fabric_api_version_1_20 = 0.92.1+1.20.1
sodium_version_1_20 = mc1.20.1-0.5.8
sodium_version_1_20 = mc1.20.1-0.5.10
lithium_version_1_20 = mc1.20.1-0.11.2
ferritecore_version_1_20 = 6.0.1-fabric
threadtweak_version_1_20 = 0.1.1+mc1.20.2
fadeless_version_1_20 = 1.0.1
raised_version_1_20 = Fabric-1.20.2-3.1.3
double_hotbar_version_1_20 = 1.3.1-mc1.20.1-fabric
# 1.20.5
fabric_api_version_1_20_5 = 0.100.0+1.20.6
sodium_version_1_20_5 = mc1.20.6-0.5.8
lithium_version_1_20_5 = mc1.20.6-0.12.3
fabric_api_version_1_20_5 = 0.100.2+1.20.6
sodium_version_1_20_5 = mc1.20.6-0.5.9
lithium_version_1_20_5 = mc1.20.6-0.12.4
ferritecore_version_1_20_5 = 6.1.1-fabric
threadtweak_version_1_20_5 = 0.1.3+mc1.20.6
fadeless_version_1_20_5 = 1.0.1
raised_version_1_20_5 = Fabric-24w10a-3.1.3
# double_hotbar_version_1_20_5 =
# 1.21
fabric_api_version_1_21 = 0.100.2+1.21
sodium_version_1_21 = mc1.21-0.5.9
lithium_version_1_21 = mc1.21-0.12.5
ferritecore_version_1_21 = 7.0.0-fabric
# threadtweak_version_1_21 =
fadeless_version_1_21 = 1.0.1
#raised_version_1_21 =
# double_hotbar_version_1_21 =
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

/**
* See {@link ItemRenderer#renderGuiItemOverlay(TextRenderer, ItemStack, int, int, String)}.
*/
public class Renderer117 extends Renderer {
// Of type Object to prevent crashes on later MC versions where DrawableHelper doesn't exist
private Object drawableHelper;
Expand All @@ -20,29 +29,38 @@ void init() {
}

@Override
protected void disableRenderSystems() {
protected boolean hasMending(ItemStack stack) {
return EnchantmentHelper.getLevel(Enchantments.MENDING, stack) > 0;
}

@Override
protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) {
RenderSystem.setShaderTexture(0, texture);
((DrawableHelper) drawableHelper).drawTexture((MatrixStack) context, x, y, u, v, width, height);
RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE);
}

@Override
protected void preRenderGuiQuads() {
RenderSystem.disableDepthTest();
RenderSystem.disableTexture();
RenderSystem.disableBlend();
}

@Override
protected void enableRenderSystems() {
protected void postRenderGuiQuads() {
RenderSystem.enableBlend();
RenderSystem.enableTexture();
RenderSystem.enableDepthTest();
}

@Override
protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) {
RenderSystem.setShaderTexture(0, texture);
((DrawableHelper) drawableHelper).drawTexture((MatrixStack) context, x, y, u, v, width, height);
RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE);
}

@Override
@SuppressWarnings("checkstyle:SingleSpaceSeparator")
protected void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
protected void renderGuiQuad(Object context, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
y -= getRaisedOffset();
height -= getRaisedOffset();

BufferBuilder buffer = Tessellator.getInstance().getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(x, y, 0.0D).color(red, green, blue, alpha).next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;

/**
* See {@link ItemRenderer#renderGuiItemOverlay(MatrixStack, TextRenderer, ItemStack, int, int, String)}.
*/
public class Renderer1194 extends Renderer119 {
@Override
protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) {
Expand All @@ -19,15 +21,21 @@ protected void drawWarningTexture(Identifier texture, Object context, int x, int
RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE);
}

@Override
protected void preRenderGuiQuads() {
RenderSystem.disableDepthTest();
RenderSystem.disableBlend();
}

@Override
protected void postRenderGuiQuads() {
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
}

@Override
@SuppressWarnings("checkstyle:SingleSpaceSeparator")
protected void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(x, y, 0.0D).color(red, green, blue, alpha).next();
buffer.vertex(x, y + height, 0.0D).color(red, green, blue, alpha).next();
buffer.vertex(x + width, y + height, 0.0D).color(red, green, blue, alpha).next();
buffer.vertex(x + width, y, 0.0D).color(red, green, blue, alpha).next();
BufferRenderer.drawWithGlobalProgram(buffer.end());
protected void renderGuiQuad(Object context, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
DrawableHelper.fill((MatrixStack) context, x, y, x + width, y + height, ColorHelper.Argb.getArgb(alpha, red, green, blue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;

/**
* See {@link ItemRenderer#renderGuiItemOverlay(TextRenderer, ItemStack, int, int, String)}.
*/
public class Renderer119 extends Renderer117 {
@Override
protected void disableRenderSystems() {
RenderSystem.disableDepthTest();
RenderSystem.disableBlend();
}

@Override
protected void enableRenderSystems() {
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
}

@Override
@SuppressWarnings("checkstyle:SingleSpaceSeparator")
protected void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
protected void renderGuiQuad(Object context, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
y -= getRaisedOffset();
height -= getRaisedOffset();

BufferBuilder buffer = Tessellator.getInstance().getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(x, y, 0.0D).color(red, green, blue, alpha).next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.reviversmc.microdurability.mccompat.McVersionHelper;

public class MicroDurability1205 extends McVersionCompatInitializer {
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.20.5", McVersionHelper.INFINITY);
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.20.5", "1.20.6");

@Override
public boolean isCompatible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class InGameHudMixin1205 {
@Shadow
private int ticks;

@Inject(method = "renderHotbar", at = @At("HEAD"))
@Inject(method = "renderHotbar", at = @At("RETURN"))
private void renderArmorArea(DrawContext context, float delta, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(context, ticks);
}

@Inject(method = "renderCrosshair", at = @At("HEAD"))
@Inject(method = "renderCrosshair", at = @At("RETURN"))
private void renderHeldItemExclamationMark(DrawContext context, float delta, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(context, ticks);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package com.github.reviversmc.microdurability;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;

/**
* See {@link DrawContext#drawItemInSlot(TextRenderer, ItemStack, int, int, String)}.
*/
public class Renderer120 extends Renderer1194 {
@Override
protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) {
((DrawContext) context).drawTexture(texture, x, y, u, v, width, height);
}

@Override
protected void preRenderGuiQuads() {
}

@Override
protected void postRenderGuiQuads() {
}

@Override
protected void renderGuiQuad(Object context, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
((DrawContext) context).fill(RenderLayer.getGuiOverlay(), x, y, x + width, y + height, ColorHelper.Argb.getArgb(alpha, red, green, blue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class InGameHudMixin120 {
@Shadow
private int ticks;

@Inject(method = "renderHotbar", at = @At("HEAD"))
@Inject(method = "renderHotbar", at = @At("RETURN"))
private void renderArmorArea(float delta, DrawContext context, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(context, ticks);
}

@Inject(method = "renderCrosshair", at = @At("HEAD"))
@Inject(method = "renderCrosshair", at = @At("RETURN"))
private void renderHeldItemExclamationMark(DrawContext context, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(context, ticks);
}
Expand Down
41 changes: 41 additions & 0 deletions microdurability-1.21/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
base {
archivesName = archivesName.get() + '-compat-1.21'
}

dependencies {
api project(path: ':microdurability-1.20.5', configuration: 'namedElements')

minecraft "com.mojang:minecraft:${project.minecraft_version_1_21}"
mappings "net.fabricmc:yarn:${project.yarn_mappings_1_21}:v2"

// Other mods
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version_1_21}"
modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version_1_21}") {
exclude(group: 'net.fabricmc.fabric-api')
}


if (project.use_third_party_mods == 'true') {
// Use full Fabric API bundle while debugging, since transitive deps aren't always declared correctly
modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version_1_21}"

modRuntimeOnly "maven.modrinth:sodium:${project.sodium_version_1_21}"
modRuntimeOnly "maven.modrinth:lithium:${project.lithium_version_1_21}"
modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_21}"
// modRuntimeOnly "maven.modrinth:threadtweak:${project.threadtweak_version_1_21}"
modRuntimeOnly "maven.modrinth:fadeless:${project.fadeless_version_1_21}"

// Comment out the following dependencies to check vanilla compatibility
// modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_21}"
// modRuntimeOnly "maven.modrinth:double-hotbar:${project.double_hotbar_version_1_21}"
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.reviversmc.microdurability;

import java.util.function.Supplier;

import com.github.reviversmc.microdurability.mccompat.McVersionCompatInitializer;
import com.github.reviversmc.microdurability.mccompat.McVersionHelper;

public class MicroDurability121 extends McVersionCompatInitializer {
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.21", McVersionHelper.INFINITY);

@Override
public boolean isCompatible() {
return IS_COMPATIBLE.get();
}

@Override
protected void initialize() {
MicroDurability.renderer = new Renderer121();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.reviversmc.microdurability;

import java.util.List;

import com.github.reviversmc.microdurability.mccompat.McVersionMixinProvider;

public class MixinProvider121 extends McVersionMixinProvider {
@Override
public List<String> getMixins() {
if (MicroDurability121.IS_COMPATIBLE.get()) {
return List.of("InGameHudMixin121");
}

return null;
}
}
Loading

0 comments on commit 37e32aa

Please sign in to comment.