Skip to content

Commit

Permalink
Backport to Minecraft 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jun 7, 2024
1 parent 87f165a commit d4407ae
Show file tree
Hide file tree
Showing 38 changed files with 109 additions and 187 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
object Constants {
// https://fabricmc.net/develop/
const val MINECRAFT_VERSION: String = "1.20.6"
const val YARN_VERSION: String = "1.20.6+build.3"
const val MINECRAFT_VERSION: String = "1.20.1"
const val YARN_VERSION: String = "1.20.1+build.10"
const val FABRIC_LOADER_VERSION: String = "0.15.11"
const val FABRIC_API_VERSION: String = "0.99.4+1.20.6"
const val FABRIC_API_VERSION: String = "0.92.2+1.20.1"

// https://semver.org/
const val MOD_VERSION: String = "0.5.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static boolean isExternalResourcePack(ResourcePack pack) {
}

private static String getResourcePackName(ResourcePack pack) {
var path = pack.getId();
var path = pack.getName();

// Omit 'file/' prefix for the in-game message
return path.startsWith("file/") ? path.substring(5) : path;
Expand All @@ -200,7 +200,7 @@ private static List<String> determineIgnoredShaders(ResourcePack resourcePack) {
ignoredShaders.addAll(meta.ignoredShaders());
}
} catch (IOException x) {
LOGGER.error("Failed to load pack.mcmeta file for resource pack '{}'", resourcePack.getId());
LOGGER.error("Failed to load pack.mcmeta file for resource pack '{}'", resourcePack.getName());
}
return ignoredShaders;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.client.gui.screen.option.VideoOptionsScreen;
import net.minecraft.text.OrderedText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Language;
Expand Down Expand Up @@ -241,6 +242,8 @@ private void rebuildGUIOptions() {
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
this.updateControls();

super.renderBackground(drawContext);

super.render(drawContext, this.prompt != null ? -1 : mouseX, this.prompt != null ? -1 : mouseY, delta);

if (this.hoveredElement != null) {
Expand Down Expand Up @@ -442,9 +445,9 @@ public Dim2i getDimensions() {
static {
DONATION_PROMPT_MESSAGE = List.of(
StringVisitable.concat(Text.literal("Hello!")),
StringVisitable.concat(Text.literal("It seems that you've been enjoying "), Text.literal("Sodium").withColor(0x27eb92), Text.literal(", the free and open-source optimization mod for Minecraft.")),
StringVisitable.concat(Text.literal("Mods like these are complex. They require "), Text.literal("thousands of hours").withColor(0xff6e00), Text.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")),
StringVisitable.concat(Text.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Text.literal("buying us a coffee").withColor(0xed49ce), Text.literal(".")),
StringVisitable.concat(Text.literal("It seems that you've been enjoying "), Text.literal("Sodium").setStyle(Style.EMPTY.withColor(0x27eb92)), Text.literal(", the free and open-source optimization mod for Minecraft.")),
StringVisitable.concat(Text.literal("Mods like these are complex. They require "), Text.literal("thousands of hours").setStyle(Style.EMPTY.withColor(0xff6e00)), Text.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")),
StringVisitable.concat(Text.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Text.literal("buying us a coffee").setStyle(Style.EMPTY.withColor(0xed49ce)), Text.literal(".")),
StringVisitable.concat(Text.literal("And thanks again for using our mod! We hope it helps you (and your computer.)"))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ColorProviderRegistry(BlockColors blockColors) {
// TODO: Allow mods to install their own color resolvers here
private void installOverrides() {
this.registerBlocks(DefaultColorProviders.GrassColorProvider.BLOCKS,
Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.SHORT_GRASS, Blocks.POTTED_FERN,
Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN,
Blocks.PINK_PETALS, Blocks.SUGAR_CANE, Blocks.LARGE_FERN, Blocks.TALL_GRASS);

this.registerBlocks(DefaultColorProviders.FoliageColorProvider.BLOCKS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import org.lwjgl.system.SharedLibrary;

import static org.lwjgl.system.APIUtil.apiCreateLibrary;
import static org.lwjgl.system.APIUtil.apiGetFunctionAddressOptional;
import static org.lwjgl.system.MemoryUtil.NULL;

public class Gdi32 {
private static final SharedLibrary LIBRARY = apiCreateLibrary("gdi32");

public static final long PFN_D3DKMTQueryAdapterInfo = apiGetFunctionAddressOptional(LIBRARY, "D3DKMTQueryAdapterInfo");
public static final long PFN_D3DKMTCloseAdapter = apiGetFunctionAddressOptional(LIBRARY, "D3DKMTCloseAdapter");
public static final long PFN_D3DKMTEnumAdapters = apiGetFunctionAddressOptional(LIBRARY, "D3DKMTEnumAdapters");
public static final long PFN_D3DKMTQueryAdapterInfo = LIBRARY.getFunctionAddress("D3DKMTQueryAdapterInfo");
public static final long PFN_D3DKMTCloseAdapter = LIBRARY.getFunctionAddress( "D3DKMTCloseAdapter");
public static final long PFN_D3DKMTEnumAdapters = LIBRARY.getFunctionAddress("D3DKMTEnumAdapters");

public static boolean isD3DKMTSupported() {
return PFN_D3DKMTQueryAdapterInfo != NULL && PFN_D3DKMTCloseAdapter != NULL && PFN_D3DKMTEnumAdapters != NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static boolean isSupportedAdapterType(int adapterType) {
private static @Nullable String queryDriverFileName(int adapter) {
try (MemoryStack stack = MemoryStack.stackPush()) {
D3DKMTOpenGLInfoStruct info = D3DKMTOpenGLInfoStruct.calloc(stack);
d3dkmtQueryAdapterInfo(adapter, KMTQAITYPE_UMOPENGLINFO, memByteBuffer(info));
d3dkmtQueryAdapterInfo(adapter, KMTQAITYPE_UMOPENGLINFO, memByteBuffer(info.address(), info.sizeof()));

return info.getUserModeDriverFileName();
}
Expand All @@ -142,7 +142,7 @@ private static boolean isSupportedAdapterType(int adapterType) {
private static @NotNull String queryFriendlyName(int adapter) {
try (MemoryStack stack = MemoryStack.stackPush()) {
D3DKMTAdapterRegistryInfoStruct registryInfo = D3DKMTAdapterRegistryInfoStruct.calloc(stack);
d3dkmtQueryAdapterInfo(adapter, KMTQAITYPE_ADAPTERREGISTRYINFO, memByteBuffer(registryInfo));
d3dkmtQueryAdapterInfo(adapter, KMTQAITYPE_ADAPTERREGISTRYINFO, memByteBuffer(registryInfo.address(), registryInfo.sizeof()));

String name = registryInfo.getAdapterString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// ULONG NumOfSources;
// BOOL bPrecisePresentRegionsPreferred;
// } D3DKMT_ADAPTERINFO;
class D3DKMTAdapterInfoStruct extends Struct<D3DKMTAdapterInfoStruct> {
class D3DKMTAdapterInfoStruct extends Struct {
public static final int SIZEOF, ALIGNOF;

private static final int OFFSET_HADAPTER;
Expand Down Expand Up @@ -45,11 +45,6 @@ class D3DKMTAdapterInfoStruct extends Struct<D3DKMTAdapterInfoStruct> {
super(address, container);
}

@Override
protected D3DKMTAdapterInfoStruct create(long address, ByteBuffer container) {
return new D3DKMTAdapterInfoStruct(address, container);
}

public static D3DKMTAdapterInfoStruct create(long address) {
return new D3DKMTAdapterInfoStruct(address, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// WCHAR DacType[MAX_PATH];
// WCHAR ChipType[MAX_PATH];
// } D3DKMT_ADAPTERREGISTRYINFO;
class D3DKMTAdapterRegistryInfoStruct extends Struct<D3DKMTAdapterRegistryInfoStruct> {
class D3DKMTAdapterRegistryInfoStruct extends Struct {
private static final int MAX_PATH = 260;
private static final int SIZEOF, ALIGNOF;

Expand Down Expand Up @@ -45,11 +45,6 @@ private D3DKMTAdapterRegistryInfoStruct(long address, ByteBuffer container) {
super(address, container);
}

@Override
protected D3DKMTAdapterRegistryInfoStruct create(long address, ByteBuffer container) {
return new D3DKMTAdapterRegistryInfoStruct(address, container);
}

public static D3DKMTAdapterRegistryInfoStruct calloc(MemoryStack stack) {
return new D3DKMTAdapterRegistryInfoStruct(stack.ncalloc(ALIGNOF, 1, SIZEOF), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// [in] ULONG NumAdapters;
// D3DKMT_ADAPTERINFO Adapters[MAX_ENUM_ADAPTERS];
//} D3DKMT_ENUMADAPTERS;
class D3DKMTEnumAdaptersStruct extends Struct<D3DKMTEnumAdaptersStruct> {
class D3DKMTEnumAdaptersStruct extends Struct {
private static final int SIZEOF, ALIGNOF;
private static final int MAX_ENUM_ADAPTERS = 16;

Expand All @@ -39,11 +39,6 @@ private D3DKMTEnumAdaptersStruct(long address, @Nullable ByteBuffer container) {
super(address, container);
}

@Override
protected @NotNull D3DKMTEnumAdaptersStruct create(long address, ByteBuffer container) {
return new D3DKMTEnumAdaptersStruct(address, container);
}

public static D3DKMTEnumAdaptersStruct calloc(MemoryStack stack) {
return new D3DKMTEnumAdaptersStruct(stack.ncalloc(ALIGNOF, 1, SIZEOF), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// [out] ULONG Version;
// [in] ULONG Flags;
// } D3DKMT_OPENGLINFO;
public class D3DKMTOpenGLInfoStruct extends Struct<D3DKMTOpenGLInfoStruct> {
public class D3DKMTOpenGLInfoStruct extends Struct {
private static final int MAX_PATH = 260;
private static final int SIZEOF, ALIGNOF;

Expand All @@ -43,11 +43,6 @@ private D3DKMTOpenGLInfoStruct(long address, @Nullable ByteBuffer container) {
super(address, container);
}

@Override
protected @NotNull D3DKMTOpenGLInfoStruct create(long address, ByteBuffer container) {
return new D3DKMTOpenGLInfoStruct(address, container);
}

public static D3DKMTOpenGLInfoStruct calloc() {
return new D3DKMTOpenGLInfoStruct(MemoryUtil.nmemCalloc(1, SIZEOF), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// VOID *pPrivateDriverData;
// UINT PrivateDriverDataSize;
// } D3DKMT_QUERYADAPTERINFO;
class D3DKMTQueryAdapterInfoStruct extends Struct<D3DKMTAdapterInfoStruct> {
class D3DKMTQueryAdapterInfoStruct extends Struct {
private static final int SIZEOF, ALIGNOF;

private static final int OFFSET_ADAPTER_HANDLE;
Expand Down Expand Up @@ -47,11 +47,6 @@ private D3DKMTQueryAdapterInfoStruct(long address, @Nullable ByteBuffer containe
super(address, container);
}

@Override
protected @NotNull D3DKMTAdapterInfoStruct create(long address, ByteBuffer container) {
return new D3DKMTAdapterInfoStruct(address, container);
}

public static D3DKMTQueryAdapterInfoStruct malloc(MemoryStack stack) {
return new D3DKMTQueryAdapterInfoStruct(stack.nmalloc(ALIGNOF, SIZEOF), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.nio.ByteBuffer;

public class MsgBoxParamSw extends Struct<MsgBoxParamSw> {
public class MsgBoxParamSw extends Struct {
public static final int SIZEOF;
public static final int ALIGNOF;
public static final int
Expand Down Expand Up @@ -61,11 +61,6 @@ private MsgBoxParamSw(long address, @Nullable ByteBuffer container) {
super(address, container);
}

@Override
protected @NotNull MsgBoxParamSw create(long address, ByteBuffer container) {
return new MsgBoxParamSw(address, container);
}

@Override
public int sizeof() {
return SIZEOF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// DWORD dwFileDateLS;
// } VS_FIXEDFILEINFO;

public class VersionFixedFileInfoStruct extends Struct<VersionFixedFileInfoStruct> {
public class VersionFixedFileInfoStruct extends Struct {
private static final int SIZEOF, ALIGNOF;

private static final int OFFSET_DW_SIGNATURE;
Expand Down Expand Up @@ -80,11 +80,6 @@ public static VersionFixedFileInfoStruct from(long address) {
return new VersionFixedFileInfoStruct(address, null);
}

@Override
protected VersionFixedFileInfoStruct create(long address, ByteBuffer container) {
return new VersionFixedFileInfoStruct(address, container);
}

public int getFileVersionMostSignificantBits() {
return MemoryUtil.memGetInt(this.address + OFFSET_DW_FILE_VERSION_MS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private static void renderBlockEntity(MatrixStack matrices,

MatrixStack.Entry entry = matrices.peek();
VertexConsumer transformer = new OverlayVertexConsumer(bufferBuilder,
entry, 1.0f);
entry.getPositionMatrix(), entry.getNormalMatrix(), 1.0f);

consumer = (layer) -> layer.hasCrumbling() ? VertexConsumers.union(transformer, immediate.getBuffer(layer)) : immediate.getBuffer(layer);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B
if (velocity.x == 0.0D && velocity.z == 0.0D) {
sprite = sprites[0];
facing = ModelQuadFacing.POS_Y;
u1 = sprite.getFrameU(0.0f);
v1 = sprite.getFrameV(0.0f);
u1 = sprite.getFrameU(0.0D);
v1 = sprite.getFrameV(0.0D);
u2 = u1;
v2 = sprite.getFrameV(1.0f);
u3 = sprite.getFrameU(1.0f);
v2 = sprite.getFrameV(16.0D);
u3 = sprite.getFrameU(16.0D);
v3 = v2;
u4 = u3;
v4 = v1;
Expand All @@ -194,19 +194,21 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B
float dir = (float) MathHelper.atan2(velocity.z, velocity.x) - (1.5707964f);
float sin = MathHelper.sin(dir) * 0.25F;
float cos = MathHelper.cos(dir) * 0.25F;
u1 = sprite.getFrameU(0.5F + (-cos - sin));
v1 = sprite.getFrameV(0.5F + -cos + sin);
u2 = sprite.getFrameU(0.5F + -cos + sin);
v2 = sprite.getFrameV(0.5F + cos + sin);
u3 = sprite.getFrameU(0.5F + cos + sin);
v3 = sprite.getFrameV(0.5F + (cos - sin));
u4 = sprite.getFrameU(0.5F + (cos - sin));
v4 = sprite.getFrameV(0.5F + (-cos - sin));
u1 = sprite.getFrameU(8.0F + (-cos - sin) * 16.0F);
v1 = sprite.getFrameV(8.0F + (-cos + sin) * 16.0F);
u2 = sprite.getFrameU(8.0F + (-cos + sin) * 16.0F);
v2 = sprite.getFrameV(8.0F + (cos + sin) * 16.0F);
u3 = sprite.getFrameU(8.0F + (cos + sin) * 16.0F);
v3 = sprite.getFrameV(8.0F + (cos - sin) * 16.0F);
u4 = sprite.getFrameU(8.0F + (cos - sin) * 16.0F);
v4 = sprite.getFrameV(8.0F + (-cos - sin) * 16.0F);
}

float uAvg = (u1 + u2 + u3 + u4) / 4.0F;
float vAvg = (v1 + v2 + v3 + v4) / 4.0F;
float s3 = sprites[0].getAnimationFrameDelta();
float s1 = (float) sprites[0].getContents().getWidth() / (sprites[0].getMaxU() - sprites[0].getMinU());
float s2 = (float) sprites[0].getContents().getHeight() / (sprites[0].getMaxV() - sprites[0].getMinV());
float s3 = 4.0F / Math.max(s2, s1);

u1 = MathHelper.lerp(s3, u1, uAvg);
u2 = MathHelper.lerp(s3, u2, uAvg);
Expand Down Expand Up @@ -333,11 +335,11 @@ public void render(WorldSlice world, FluidState fluidState, BlockPos blockPos, B
}
}

float u1 = sprite.getFrameU(0.0F);
float u2 = sprite.getFrameU(0.5F);
float v1 = sprite.getFrameV((1.0F - c1) * 0.5F);
float v2 = sprite.getFrameV((1.0F - c2) * 0.5F);
float v3 = sprite.getFrameV(0.5F);
float u1 = sprite.getFrameU(0.0D);
float u2 = sprite.getFrameU(8.0D);
float v1 = sprite.getFrameV((1.0F - c1) * 16.0F * 0.5F);
float v2 = sprite.getFrameV((1.0F - c2) * 16.0F * 0.5F);
float v3 = sprite.getFrameV(8.0D);

quad.setSprite(sprite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entr
long ptr = buffer;

// The packed transformed normal vector
var normal = MatrixHelper.transformNormal(matNormal, matrices.canSkipNormalization, quad.getLightFace());
var normal = MatrixHelper.transformNormal(matNormal, true, quad.getLightFace());

for (int i = 0; i < 4; i++) {
// The position vector
Expand Down Expand Up @@ -51,7 +51,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entr
long ptr = buffer;

// The packed transformed normal vector
var normal = MatrixHelper.transformNormal(matNormal, matrices.canSkipNormalization, quad.getLightFace());
var normal = MatrixHelper.transformNormal(matNormal, true, quad.getLightFace());

for (int i = 0; i < 4; i++) {
// The position vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ private static void prepareVertices(MatrixStack.Entry matrices, ModelCuboid cubo
}

private static void prepareNormals(MatrixStack.Entry matrices) {
CUBE_NORMALS[FACE_NEG_Y] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.DOWN);
CUBE_NORMALS[FACE_POS_Y] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.UP);
CUBE_NORMALS[FACE_NEG_Z] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.NORTH);
CUBE_NORMALS[FACE_POS_Z] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.SOUTH);
CUBE_NORMALS[FACE_POS_X] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.WEST);
CUBE_NORMALS[FACE_NEG_X] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), matrices.canSkipNormalization, Direction.EAST);
CUBE_NORMALS[FACE_NEG_Y] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.DOWN);
CUBE_NORMALS[FACE_POS_Y] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.UP);
CUBE_NORMALS[FACE_NEG_Z] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.NORTH);
CUBE_NORMALS[FACE_POS_Z] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.SOUTH);
CUBE_NORMALS[FACE_POS_X] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.WEST);
CUBE_NORMALS[FACE_NEG_X] = MatrixHelper.transformNormal(matrices.getNormalMatrix(), true, Direction.EAST);

// When mirroring is used, the normals for EAST and WEST are swapped.
CUBE_NORMALS_MIRRORED[FACE_NEG_Y] = CUBE_NORMALS[FACE_NEG_Y];
Expand Down
Loading

0 comments on commit d4407ae

Please sign in to comment.