Skip to content

Commit

Permalink
Port from 1.20.6 to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Aug 21, 2024
1 parent 6fc5775 commit f06eb17
Show file tree
Hide file tree
Showing 38 changed files with 535 additions and 714 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11

#Fabric api
fabric_version=0.98.0+1.20.6
# Fabric API
fabric_version=0.100.7+1.21

# Mod Properties
mod_version = 0.4.7_dev
maven_group = net.vulkanmod
archives_base_name = VulkanMod_1.20.6
archives_base_name = VulkanMod_1.21
31 changes: 12 additions & 19 deletions src/main/java/net/vulkanmod/config/gui/GuiRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,14 @@ public static void fill(float x0, float y0, float x1, float y1, int color) {

public static void fill(float x0, float y0, float x1, float y1, float z, int color) {
Matrix4f matrix4f = pose.last().pose();

float a = (float)FastColor.ARGB32.alpha(color) / 255.0F;
float r = (float)FastColor.ARGB32.red(color) / 255.0F;
float g = (float)FastColor.ARGB32.green(color) / 255.0F;
float b = (float)FastColor.ARGB32.blue(color) / 255.0F;

BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bufferBuilder.vertex(matrix4f, x0, y0, z).color(r, g, b, a).endVertex();
bufferBuilder.vertex(matrix4f, x0, y1, z).color(r, g, b, a).endVertex();
bufferBuilder.vertex(matrix4f, x1, y1, z).color(r, g, b, a).endVertex();
bufferBuilder.vertex(matrix4f, x1, y0, z).color(r, g, b, a).endVertex();
Tesselator.getInstance().end();
bufferBuilder.addVertex(matrix4f, x0, y0, z).setColor(color);
bufferBuilder.addVertex(matrix4f, x0, y1, z).setColor(color);
bufferBuilder.addVertex(matrix4f, x1, y1, z).setColor(color);
bufferBuilder.addVertex(matrix4f, x1, y0, z).setColor(color);
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());
}

public static void renderBoxBorder(float x0, float y0, float width, float height, float borderWidth, int color) {
Expand Down Expand Up @@ -95,14 +89,13 @@ public static void fillGradient(float x0, float y0, float x1, float y1, float z,

Matrix4f matrix4f = pose.last().pose();

BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bufferBuilder.vertex(matrix4f, x0, y0, z).color(r1, g1, b1, a1).endVertex();
bufferBuilder.vertex(matrix4f, x0, y1, z).color(r2, g2, b2, a2).endVertex();
bufferBuilder.vertex(matrix4f, x1, y1, z).color(r2, g2, b2, a2).endVertex();
bufferBuilder.vertex(matrix4f, x1, y0, z).color(r1, g1, b1, a1).endVertex();
Tesselator.getInstance().end();
bufferBuilder.addVertex(matrix4f, x0, y0, z).setColor(r1, g1, b1, a1);
bufferBuilder.addVertex(matrix4f, x0, y1, z).setColor(r2, g2, b2, a2);
bufferBuilder.addVertex(matrix4f, x1, y1, z).setColor(r2, g2, b2, a2);
bufferBuilder.addVertex(matrix4f, x1, y0, z).setColor(r1, g1, b1, a1);
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());
}

public static void drawString(Font font, Component component, int x, int y, int color) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/vulkanmod/config/gui/VOptionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class VOptionScreen extends Screen {
public final static int RED = ColorUtil.ARGB.pack(0.3f, 0.0f, 0.0f, 0.8f);
final ResourceLocation ICON = new ResourceLocation("vulkanmod", "vlogo_transparent.png");
final ResourceLocation ICON = ResourceLocation.fromNamespaceAndPath("vulkanmod", "vlogo_transparent.png");

private final Screen parent;

Expand Down Expand Up @@ -238,13 +238,13 @@ public void renderBackground(GuiGraphics guiGraphics, int i, int j, float f) {

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
this.renderBackground(guiGraphics, 0, 0, delta);

GuiRenderer.guiGraphics = guiGraphics;
GuiRenderer.setPoseStack(guiGraphics.pose());

RenderSystem.enableBlend();

this.renderBackground(guiGraphics, 0, 0, 0);

int size = minecraft.font.lineHeight * 4;

guiGraphics.blit(ICON, 30, 4, 0f, 0f, size, size, size, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void setStatus(boolean status) {

void renderButton(PoseStack matrices, double mouseX, double mouseY) {
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
BufferBuilder bufferBuilder = tesselator.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION);

RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);

Expand All @@ -143,23 +143,21 @@ else if(this.active)
else
RenderSystem.setShaderColor(0.3f, 0.3f, 0.3f, 0.8f);

bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION);

float h = f;
float w = f - 1.0f;
float yC = y + height * 0.5f;
float xC = x + width * 0.5f;
if (this.direction == Direction.LEFT) {
bufferBuilder.vertex(matrix4f, xC - w, yC, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC + h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC + w, yC - h, 0).endVertex();
bufferBuilder.addVertex(matrix4f, xC - w, yC, 0);
bufferBuilder.addVertex(matrix4f, xC + w, yC + h, 0);
bufferBuilder.addVertex(matrix4f, xC + w, yC - h, 0);
} else {
bufferBuilder.vertex(matrix4f, xC + w, yC, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC - h, 0).endVertex();
bufferBuilder.vertex(matrix4f, xC - w, yC + h, 0).endVertex();
bufferBuilder.addVertex(matrix4f, xC + w, yC, 0);
bufferBuilder.addVertex(matrix4f, xC - w, yC - h, 0);
bufferBuilder.addVertex(matrix4f, xC - w, yC + h, 0);
}

tesselator.end();
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());

RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
Expand Down
41 changes: 33 additions & 8 deletions src/main/java/net/vulkanmod/config/gui/widget/OptionWidget.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package net.vulkanmod.config.gui.widget;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
import net.vulkanmod.config.gui.GuiElement;
import net.vulkanmod.config.gui.GuiRenderer;
import net.vulkanmod.config.option.CyclingOption;
import net.vulkanmod.config.option.Option;
import net.vulkanmod.render.util.MathUtil;
import net.vulkanmod.vulkan.util.ColorUtil;

public abstract class OptionWidget<O extends Option<?>> extends VAbstractWidget {
private final Component name;
import java.util.Objects;

public abstract class OptionWidget<O extends Option<?>> extends VAbstractWidget
implements NarratableEntry {

public int controlX;
public int controlWidth;
private final Component name;
protected Component displayedValue;

protected boolean controlHovered;
Expand Down Expand Up @@ -56,6 +71,7 @@ public void renderWidget(double mouseX, double mouseY) {

RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
int i = this.getYImage(this.isHovered());
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();
Expand All @@ -69,6 +85,7 @@ public void renderWidget(double mouseX, double mouseY) {
this.renderHovering(0, 0);

color = this.active ? 0xFFFFFF : 0xA0A0A0;
// j = 0xB0f0d0a0;

Font textRenderer = minecraftClient.font;
GuiRenderer.drawString(textRenderer, this.getName().getVisualOrderText(), this.x + 8, this.y + (this.height - 8) / 2, color);
Expand Down Expand Up @@ -100,6 +117,10 @@ public boolean isHovered() {

protected abstract void onDrag(double mouseX, double mouseY, double deltaX, double deltaY);

protected boolean isValidClickButton(int button) {
return button == 0;
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
if (this.isValidClickButton(button)) {
Expand Down Expand Up @@ -134,21 +155,21 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {

@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return this.active && this.visible && mouseX >= (double) this.x && mouseY >= (double) this.y && mouseX < (double) (this.x + this.width) && mouseY < (double) (this.y + this.height);
return this.active && this.visible && mouseX >= (double)this.x && mouseY >= (double)this.y && mouseX < (double)(this.x + this.width) && mouseY < (double)(this.y + this.height);
}

@Override
public boolean isFocused() {
return this.focused;
public void setFocused(boolean bl) {
this.focused = bl;
}

@Override
public void setFocused(boolean bl) {
this.focused = bl;
public boolean isFocused() {
return this.focused;
}

protected boolean clicked(double mouseX, double mouseY) {
return this.active && this.visible && mouseX >= (double) this.controlX && mouseY >= (double) this.y && mouseX < (double) (this.x + this.width) && mouseY < (double) (this.y + this.height);
return this.active && this.visible && mouseX >= (double)this.controlX && mouseY >= (double)this.y && mouseX < (double)(this.x + this.width) && mouseY < (double)(this.y + this.height);
}

public Component getName() {
Expand Down Expand Up @@ -182,4 +203,8 @@ public NarrationPriority narrationPriority() {
public final void updateNarration(NarrationElementOutput narrationElementOutput) {
}

public void playDownSound(SoundManager soundManager) {
soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0f));
}

}
23 changes: 14 additions & 9 deletions src/main/java/net/vulkanmod/mixin/chunk/LevelRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.*;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.BlockDestructionProgress;
import net.minecraft.util.Mth;
import net.minecraft.world.TickRateManager;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -89,11 +91,11 @@ private void allChanged(CallbackInfo ci) {
}

@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 1, shift = At.Shift.BEFORE))
private void renderBlockEntities(float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
private void renderBlockEntities(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
Vec3 pos = camera.getPosition();
PoseStack poseStack = new PoseStack();

this.worldRenderer.renderBlockEntities(poseStack, pos.x(), pos.y(), pos.z(), this.destructionProgress, f);
this.worldRenderer.renderBlockEntities(poseStack, pos.x(), pos.y(), pos.z(), this.destructionProgress, deltaTracker.getGameTimeDeltaPartialTick(false));
}

/**
Expand Down Expand Up @@ -210,13 +212,13 @@ public int countRenderedSections() {
* @reason
*/
@Overwrite
private void renderEntity(Entity entity, double d, double e, double f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource) {
private void renderEntity(Entity entity, double d, double e, double f, float partialTicks, PoseStack poseStack, MultiBufferSource multiBufferSource) {
if (!Initializer.CONFIG.entityCulling) {
double h = Mth.lerp(g, entity.xOld, entity.getX());
double i = Mth.lerp(g, entity.yOld, entity.getY());
double j = Mth.lerp(g, entity.zOld, entity.getZ());
float k = Mth.lerp(g, entity.yRotO, entity.getYRot());
this.entityRenderDispatcher.render(entity, h - d, i - e, j - f, k, g, poseStack, multiBufferSource, this.entityRenderDispatcher.getPackedLightCoords(entity, g));
double h = Mth.lerp(partialTicks, entity.xOld, entity.getX());
double i = Mth.lerp(partialTicks, entity.yOld, entity.getY());
double j = Mth.lerp(partialTicks, entity.zOld, entity.getZ());
float k = Mth.lerp(partialTicks, entity.yRotO, entity.getYRot());
this.entityRenderDispatcher.render(entity, h - d, i - e, j - f, k, partialTicks, poseStack, multiBufferSource, this.entityRenderDispatcher.getPackedLightCoords(entity, partialTicks));
return;
}

Expand All @@ -236,11 +238,12 @@ private void renderEntity(Entity entity, double d, double e, double f, float g,
target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endLastBatch()V",
shift = At.Shift.AFTER, ordinal = 0)
)
private void renderEntities(float partialTicks, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f MV, Matrix4f P, CallbackInfo ci) {
private void renderEntities(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
if (!Initializer.CONFIG.entityCulling)
return;

Vec3 cameraPos = WorldRenderer.getCameraPos();
TickRateManager tickRateManager = this.minecraft.level.tickRateManager();

PoseStack poseStack = new PoseStack();

Expand All @@ -249,6 +252,8 @@ private void renderEntities(float partialTicks, long l, boolean bl, Camera camer
Entity entity = pair.first;
MultiBufferSource multiBufferSource = pair.second;

float partialTicks = deltaTracker.getGameTimeDeltaPartialTick(!tickRateManager.isEntityFrozen(entity));

double h = Mth.lerp(partialTicks, entity.xOld, entity.getX());
double i = Mth.lerp(partialTicks, entity.yOld, entity.getY());
double j = Mth.lerp(partialTicks, entity.zOld, entity.getZ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ private void createShaders(ResourceProvider resourceManager, String vertexShader

try {
String[] vshPathInfo = this.decompose(vertexShader, ':');
ResourceLocation vshLocation = new ResourceLocation(vshPathInfo[0], "shaders/program/" + vshPathInfo[1] + ".vsh");
ResourceLocation vshLocation = ResourceLocation.fromNamespaceAndPath(vshPathInfo[0], "shaders/program/" + vshPathInfo[1] + ".vsh");
Resource resource = resourceManager.getResourceOrThrow(vshLocation);
InputStream inputStream = resource.open();
String vshSrc = IOUtils.toString(inputStream, StandardCharsets.UTF_8);

String[] fshPathInfo = this.decompose(fragShader, ':');
ResourceLocation fshLocation = new ResourceLocation(fshPathInfo[0], "shaders/program/" + fshPathInfo[1] + ".fsh");
ResourceLocation fshLocation = ResourceLocation.fromNamespaceAndPath(fshPathInfo[0], "shaders/program/" + fshPathInfo[1] + ".fsh");
resource = resourceManager.getResourceOrThrow(fshLocation);
inputStream = resource.open();
String fshSrc = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
Expand Down Expand Up @@ -174,7 +174,6 @@ private String[] decompose(String string, char c) {
*/
@Overwrite
public void apply() {
RenderSystem.assertOnGameThread();
this.dirty = false;
this.blend.apply();

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/vulkanmod/mixin/compatibility/PostPassM.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public void process(float f) {

this.effect.apply();

BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
bufferBuilder.vertex(0.0, 0.0, 500.0).endVertex();
bufferBuilder.vertex(g, 0.0, 500.0).endVertex();
bufferBuilder.vertex(g, h, 500.0).endVertex();
bufferBuilder.vertex(0.0, h, 500.0).endVertex();
BufferUploader.draw(bufferBuilder.end());
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
bufferBuilder.addVertex(0.0f, 0.0f, 500.0f);
bufferBuilder.addVertex(g, 0.0f, 500.0f);
bufferBuilder.addVertex(g, h, 500.0f);
bufferBuilder.addVertex(0.0f, h, 500.0f);
BufferUploader.draw(bufferBuilder.buildOrThrow());
RenderSystem.depthFunc(515);

this.effect.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/vulkanmod/mixin/profiling/GuiMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.vulkanmod.mixin.profiling;

import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -24,7 +25,7 @@ private void createProfilerOverlay(Minecraft minecraft, CallbackInfo ci) {
}

@Inject(method = "render", at = @At(value = "RETURN"))
private void renderProfilerOverlay(GuiGraphics guiGraphics, float f, CallbackInfo ci) {
private void renderProfilerOverlay(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
if(ProfilerOverlay.shouldRender && !this.debugOverlay.showDebugScreen())
ProfilerOverlay.INSTANCE.render(guiGraphics.pose());
}
Expand Down
Loading

0 comments on commit f06eb17

Please sign in to comment.