Skip to content

Commit

Permalink
Port to Minecraft 1.20.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Jun 9, 2023
1 parent 95d6b4c commit 30622dc
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ The first release of LambdaBetterGrass!

- Added Brazilian Portuguese translations ([#85](https://github.com/LambdAurora/LambdaBetterGrass/pull/85)).
- Fixed several issues with custom resource packs with custom grass models ([#48](https://github.com/LambdAurora/LambdaBetterGrass/issues/48) and partially [#76](https://github.com/LambdAurora/LambdaBetterGrass/issues/76)).
- (1.20) Added better snow data to the new Minecraft blocks.

[SpruceUI]: https://github.com/LambdAurora/SpruceUI
[Connected Block Textures]: https://www.curseforge.com/minecraft/mc-mods/connected-block-textures "Connected Block Textures CurseForge page"
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ String getVersionType() {
}

String parseReadme() {
def linkRegex = /!\[([A-z_ ]+)]\((images\/[A-z.\/_]+)\)/
def linkRegex = /!\[([A-z._ ]+)]\((images\/[A-z.\/_]+)\)/

def readme = (String) file('README.md').text
def lines = new ArrayList<>(Arrays.asList(readme.split("\n")))
Expand All @@ -84,7 +84,7 @@ String parseReadme() {
}

readme = lines.join("\n")
readme = readme.replaceAll(linkRegex, '![$1](https://raw.githubusercontent.com/LambdAurora/LambdaBetterGrass/1.19.3/$2)')
readme = readme.replaceAll(linkRegex, '![$1](https://raw.githubusercontent.com/LambdAurora/LambdaBetterGrass/1.20/$2)')
return readme
}

Expand Down
4 changes: 4 additions & 0 deletions datagen/better_snow.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"double_flower": [
"lilac",
"peony",
"pitcher_crop",
"pitcher_plant",
"rose_bush",
"sunflower"
],
Expand Down Expand Up @@ -642,6 +644,7 @@
"id": "small_dripleaf",
"waterloggable": true
},
"sniffer_egg",
"spruce_door",
{
"id": "spruce_fence",
Expand Down Expand Up @@ -674,6 +677,7 @@
"id": "tube_coral_wall_fan",
"waterloggable": true
},
"turtle_egg",
"twisting_vines",
"vine",
"warped_door",
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
org.gradle.jvmargs=-Xmx1G

# Quilt Properties
minecraft_version=1.19.4
quilt_mappings=5
loader_version=0.18.6-beta.1
qsl_version=5.0.0-beta.1
fabric_api_version=6.0.0-beta.2+0.76.0
minecraft_version=1.20
quilt_mappings=2
loader_version=0.18.10
qsl_version=6.0.1
fabric_api_version=7.0.1+0.83.0

# Mod Properties
mod_version=1.5.1
Expand All @@ -16,5 +16,5 @@ modrinth_id=2Uev7LdA
curseforge_id=400322

# Dependencies
spruceui_version=4.2.0+1.19.4
modmenu_version=6.1.0-rc.4
spruceui_version=5.0.0+1.20
modmenu_version=7.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
import dev.lambdaurora.lambdabettergrass.metadata.LBGState;
import dev.lambdaurora.lambdabettergrass.resource.LBGResourcePack;
import dev.lambdaurora.lambdabettergrass.resource.LBGResourceReloader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
Expand Down Expand Up @@ -73,8 +70,7 @@ public void onInitializeClient(ModContainer mod) {
}

@Override
public void onEndResourcePackReload(MinecraftClient client, ResourceManager resourceManager, boolean first,
@Nullable Throwable error) {
public void onEndResourcePackReload(ClientResourceLoaderEvents.EndResourcePackReload.Context context) {
if (this.config.isDebug()) {
this.resourcePack.dumpTo(Path.of("debug/lbg_out"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import dev.lambdaurora.spruceui.widget.SpruceButtonWidget;
import dev.lambdaurora.spruceui.widget.SpruceLabelWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Util;
Expand Down Expand Up @@ -125,7 +125,7 @@ private void buildLabels() {
}

@Override
public void renderTitle(MatrixStack matrices, int mouseX, int mouseY, float delta) {
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
public void renderTitle(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
graphics.drawCenteredShadowedText(this.textRenderer, this.title, this.width / 2, 8, 16777215);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelBaker;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.resource.Material;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -87,7 +89,7 @@ public void resolveParents(Function<Identifier, UnbakedModel> models) {
* @param rotationContainer the rotation container
* @param modelId the model identifier
*/
public void bake(ModelBaker baker, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
public void bake(ModelBaker baker, Function<Material, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (this.unbakedModels.layerModel() != null) {
this.bakedLayerModel = this.unbakedModels.layerModel().bake(baker, textureGetter, rotationContainer, modelId);
}
Expand Down Expand Up @@ -127,7 +129,7 @@ public int emitBlockQuads(BlockRenderView world, BlockState state, BlockPos pos,
vec.sub(offsetVec);
quad.pos(i, vec);
}
quad.material(RendererAccess.INSTANCE.getRenderer().materialFinder().disableAo(0, false).find());
quad.material(RendererAccess.INSTANCE.getRenderer().materialFinder().ambientOcclusion(TriState.FALSE).find());
return true;
});
pushed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
package dev.lambdaurora.lambdabettergrass.metadata;

import com.google.gson.JsonObject;
import com.mojang.blaze3d.texture.NativeImage;
import dev.lambdaurora.lambdabettergrass.LambdaBetterGrass;
import dev.lambdaurora.lambdabettergrass.util.LBGTextureGenerator;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.render.model.ModelLoader;
import com.mojang.blaze3d.texture.NativeImage;
import net.minecraft.client.resource.Material;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -50,10 +50,10 @@ public class LBGLayer {
private final Identifier sideTexture;

/* Generated textures */
private SpriteIdentifier connectTexture;
private SpriteIdentifier blendUpTexture;
private SpriteIdentifier blendUpMirroredTexture;
private SpriteIdentifier archTexture;
private Material connectTexture;
private Material blendUpTexture;
private Material blendUpMirroredTexture;
private Material archTexture;

private final Map<String, Sprite> bakedSprites = new Object2ObjectOpenHashMap<>();

Expand Down Expand Up @@ -113,9 +113,9 @@ public LBGLayer(LBGMetadata metadata, JsonObject json) {
* @param name the name of the texture
* @return {@code null} if not specified, else the identifier of the overriden texture
*/
private @Nullable SpriteIdentifier getOverridenTexture(JsonObject overrides, String name) {
private @Nullable Material getOverridenTexture(JsonObject overrides, String name) {
if (overrides.has(name)) {
var id = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(overrides.get(name).getAsString()));
var id = new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(overrides.get(name).getAsString()));
this.parentMetadata.textures.add(id);
return id;
}
Expand Down Expand Up @@ -176,32 +176,32 @@ private static Identifier getTexturePath(Identifier id) {
return new Identifier(id.getNamespace(), "textures/" + id.getPath() + ".png");
}

private static SpriteIdentifier genTexture(String name, NativeImage side, NativeImage top, NativeImage mask) {
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, LBGTextureGenerator.generateTexture(name, side, top, mask));
private static Material genTexture(String name, NativeImage side, NativeImage top, NativeImage mask) {
return new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, LBGTextureGenerator.generateTexture(name, side, top, mask));
}

/**
* Bakes the textures of this layer.
*
* @param textureGetter the texture getter
*/
public void bakeTextures(Function<SpriteIdentifier, Sprite> textureGetter) {
public void bakeTextures(Function<Material, Sprite> textureGetter) {
this.tryBakeSprite("connect", this.connectTexture, textureGetter);
this.tryBakeSprite("blend_up", this.blendUpTexture, textureGetter);
this.tryBakeSprite("blend_up_m", this.blendUpMirroredTexture, textureGetter);
this.tryBakeSprite("arch", this.archTexture, textureGetter);
}

private void tryBakeSprite(String name, @Nullable SpriteIdentifier id, Function<SpriteIdentifier, Sprite> textureGetter) {
private void tryBakeSprite(String name, @Nullable Material id, Function<Material, Sprite> textureGetter) {
if (id == null)
id = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelLoader.MISSING_ID);
id = new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelLoader.MISSING_ID);

try {
this.bakedSprites.put(name, textureGetter.apply(id));
} catch (NullPointerException e) {
LambdaBetterGrass.get().warn("Could not bake sprite `" + name + "` with id `" + id + "`!");

this.bakedSprites.put(name, textureGetter.apply(new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelLoader.MISSING_ID)));
this.bakedSprites.put(name, textureGetter.apply(new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelLoader.MISSING_ID)));
}
}

Expand Down Expand Up @@ -246,9 +246,9 @@ public static LBGLayer mergeLayers(LBGLayer parent, LBGLayer child) {
// Merge textures into parent
if (parent.connectTexture != null && child.connectTexture != null) {
final NativeImage parentConnect
= LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.connectTexture.getTextureId()));
= LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.connectTexture.getTexture()));
final NativeImage childConnect
= LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.connectTexture.getTextureId()));
= LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.connectTexture.getTexture()));

parent.parentMetadata.textures.remove(parent.connectTexture);
parent.parentMetadata.textures.add(
Expand All @@ -260,9 +260,9 @@ public static LBGLayer mergeLayers(LBGLayer parent, LBGLayer child) {

if (parent.blendUpTexture != null && child.blendUpTexture != null) {
final NativeImage parentBlendUp =
LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.blendUpTexture.getTextureId()));
LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.blendUpTexture.getTexture()));
final NativeImage childBlendUp =
LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.blendUpTexture.getTextureId()));
LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.blendUpTexture.getTexture()));

parent.parentMetadata.textures.remove(parent.blendUpTexture);
parent.parentMetadata.textures.add(
Expand All @@ -275,10 +275,10 @@ public static LBGLayer mergeLayers(LBGLayer parent, LBGLayer child) {
if (parent.blendUpMirroredTexture != null && child.blendUpMirroredTexture != null) {
final NativeImage parentBlendUp =
LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager,
getTexturePath(parent.blendUpMirroredTexture.getTextureId()));
getTexturePath(parent.blendUpMirroredTexture.getTexture()));
final NativeImage childBlendUp =
LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager,
getTexturePath(child.blendUpMirroredTexture.getTextureId()));
getTexturePath(child.blendUpMirroredTexture.getTexture()));

parent.parentMetadata.textures.remove(parent.blendUpMirroredTexture);
parent.parentMetadata.textures.add(
Expand All @@ -291,9 +291,9 @@ public static LBGLayer mergeLayers(LBGLayer parent, LBGLayer child) {

if (parent.archTexture != null && child.archTexture != null) {
final NativeImage parentArch =
LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.archTexture.getTextureId()));
LBGTextureGenerator.getNativeImage(parent.parentMetadata.resourceManager, getTexturePath(parent.archTexture.getTexture()));
final NativeImage childArch =
LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.archTexture.getTextureId()));
LBGTextureGenerator.getNativeImage(child.parentMetadata.resourceManager, getTexturePath(child.archTexture.getTexture()));

parent.parentMetadata.textures.remove(parent.archTexture);
parent.parentMetadata.textures.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.resource.Material;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
Expand All @@ -41,7 +41,7 @@ public class LBGMetadata {
public final Identifier id;

protected final ResourceManager resourceManager;
protected final List<SpriteIdentifier> textures = new ArrayList<>();
protected final List<Material> textures = new ArrayList<>();

private final List<LBGLayer> layers = new ArrayList<>();

Expand Down Expand Up @@ -96,7 +96,7 @@ private void buildTextures() {
*
* @param textureGetter the texture getter
*/
public void bakeTextures(Function<SpriteIdentifier, Sprite> textureGetter) {
public void bakeTextures(Function<Material, Sprite> textureGetter) {
for (var layer : this.layers) {
layer.bakeTextures(textureGetter);
}
Expand All @@ -119,7 +119,7 @@ public Optional<LBGLayer> getLayer(int colorIndex) {
/**
* {@return the textures}
*/
public Collection<SpriteIdentifier> getTextures() {
public Collection<Material> getTextures() {
return this.textures;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

import dev.lambdaurora.lambdabettergrass.gui.LBGOption;
import dev.lambdaurora.spruceui.Tooltip;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.screen.option.VideoOptionsScreen;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.Option;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -55,7 +55,7 @@ private Option<?>[] addOptionButton(Option<?>[] old) {
}

@Inject(method = "render", at = @At("TAIL"))
private void onRender(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
Tooltip.renderAll(this, matrices);
private void onRender(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
Tooltip.renderAll(graphics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Represents the LambdaBetterGrass baked model.
*
* @author LambdAurora
* @version 1.4.0
* @version 1.5.1
* @since 1.0.0
*/
public class LBGBakedModel extends ForwardingBakedModel {
Expand Down Expand Up @@ -181,7 +181,7 @@ private static boolean canConnect(BlockState self, BlockState adjacent) {
private static boolean spriteBake(MutableQuadView quad, LBGLayer layer, String texture) {
var sprite = layer.getBakedTexture(texture);
if (sprite != null)
quad.spriteBake(0, sprite, MutableQuadView.BAKE_LOCK_UV);
quad.spriteBake(sprite, MutableQuadView.BAKE_LOCK_UV);
return sprite != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

package dev.lambdaurora.lambdabettergrass.model;

import com.mojang.datafixers.util.Pair;
import dev.lambdaurora.lambdabettergrass.metadata.LBGCompiledLayerMetadata;
import net.minecraft.client.render.model.*;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelBaker;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.resource.Material;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -50,7 +52,7 @@ public void resolveParents(Function<Identifier, UnbakedModel> models) {
}

@Override
public @Nullable BakedModel bake(ModelBaker baker, Function<SpriteIdentifier, Sprite> textureGetter,
public @Nullable BakedModel bake(ModelBaker baker, Function<Material, Sprite> textureGetter,
ModelBakeSettings rotationContainer, Identifier modelId) {
this.metadatas.forEach(metadata -> metadata.bake(baker, textureGetter, rotationContainer, modelId));
return new LBGLayerBakedModel(Objects.requireNonNull(this.baseModel.bake(baker, textureGetter, rotationContainer, modelId)),
Expand Down
Loading

0 comments on commit 30622dc

Please sign in to comment.