Skip to content

Commit

Permalink
1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jun 14, 2024
1 parent f0388d1 commit d673e7f
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 42 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G

# Quilt Properties
minecraft_version=1.20.6
quilt_mappings=6
minecraft_version=1.21
quilt_mappings=2
loader_version=0.15.11
fabric_api_version=0.100.0+1.20.6
fabric_api_version=0.100.1+1.21

# Mod Properties
mod_version=1.5.3
maven_group=com.github.dima_dencep.mods
archives_base_name=SuperBetterGrass

# Dependencies
cloth_config_version=14.0.126
modmenu_version=10.0.0-beta.1
cloth_config_version=15.0.127
modmenu_version=11.0.0-beta.1
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public void onInitializeClient() {

ModelLoadingPlugin.register(pluginCtx -> {
pluginCtx.modifyModelOnLoad().register(ModelModifier.WRAP_PHASE, (model, context) -> {
if (context.id() instanceof ModelIdentifier modelId) {
if (context.topLevelId() instanceof ModelIdentifier modelId) {
if (!modelId.getVariant().equals("inventory")) {
var stateId = new Identifier(modelId.getNamespace(), modelId.getPath());
var stateId = modelId.id();

// Get cached states metadata.
var state = LBGState.getMetadataState(stateId);
Expand Down Expand Up @@ -130,7 +130,7 @@ public boolean hasBetterLayer() {
* @param path the path
*/
public static Identifier id(@NotNull String path) {
return new Identifier(NAMESPACE, path);
return Identifier.of(NAMESPACE, path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ public void resolveParents(Function<Identifier, UnbakedModel> models) {
* @param baker the model baker
* @param textureGetter the texture getter
* @param rotationContainer the rotation container
* @param modelId the model identifier
*/
public void bake(ModelBaker baker, Function<Material, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
public void bake(ModelBaker baker, Function<Material, Sprite> textureGetter, ModelBakeSettings rotationContainer) {
if (this.unbakedModels.layerModel() != null) {
this.bakedLayerModel = this.unbakedModels.layerModel().bake(baker, textureGetter, rotationContainer, modelId);
this.bakedLayerModel = this.unbakedModels.layerModel().bake(baker, textureGetter, rotationContainer);
}

if (this.unbakedModels.alternateModel() != null) {
this.bakedAlternateModel = this.unbakedModels.alternateModel().bake(baker, textureGetter, rotationContainer, modelId);
this.bakedAlternateModel = this.unbakedModels.alternateModel().bake(baker, textureGetter, rotationContainer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public LBGGrassState(@NotNull Identifier id, @NotNull ResourceManager resourceMa
variants.entrySet().forEach(entry -> {
var variant = entry.getValue().getAsJsonObject();
if (variant.has("data")) {
var metadataId = new Identifier(variant.get("data").getAsString());
var metadataId = Identifier.tryParse(variant.get("data").getAsString());

this.metadatas.put(entry.getKey(), this.loadMetadata(resourceManager, metadataId));
}
Expand All @@ -63,8 +63,8 @@ public LBGGrassState(@NotNull Identifier id, @NotNull ResourceManager resourceMa

this.metadata = null;
} else if (json.has("data")) { // Look for a common metadata if no variants are specified.
var metadataId = new Identifier(json.get("data").getAsString());
this.metadata = this.loadMetadata(resourceManager, metadataId);
var metadataId = Identifier.tryParse(json.get("data").getAsString());
this.metadata = metadataId != null ? this.loadMetadata(resourceManager, metadataId) : null;
} else // The state file is invalid, cannot find any metadata.
this.metadata = null;
}
Expand All @@ -77,7 +77,7 @@ public LBGGrassState(@NotNull Identifier id, @NotNull ResourceManager resourceMa
* @return the metadata if loaded successfully, else {@code null}
*/
private @Nullable LBGMetadata loadMetadata(@NotNull ResourceManager resourceManager, @NotNull Identifier metadataId) {
var metadataResourceId = new Identifier(metadataId.getNamespace(), metadataId.getPath() + ".json");
var metadataResourceId = Identifier.of(metadataId.getNamespace(), metadataId.getPath() + ".json");
try (var reader = new InputStreamReader(resourceManager.getResourceOrThrow(metadataResourceId).open())) {
var metadataJson = JsonParser.parseReader(reader).getAsJsonObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public LBGLayer(LBGMetadata metadata, JsonObject json) {
if (json.has("textures")) {
var textures = json.getAsJsonObject("textures");
if (textures.has("top"))
topTexture = new Identifier(textures.get("top").getAsString());
topTexture = Identifier.tryParse(textures.get("top").getAsString());
if (textures.has("side"))
sideTexture = new Identifier(textures.get("side").getAsString());
sideTexture = Identifier.tryParse(textures.get("side").getAsString());

if (textures.has("overrides")) {
var overrides = textures.getAsJsonObject("overrides");
Expand All @@ -92,13 +92,13 @@ public LBGLayer(LBGMetadata metadata, JsonObject json) {
if (json.has("masks")) {
var mask = json.getAsJsonObject("masks");
if (mask.has("connect")) {
connectMask = new Identifier(mask.get("connect").getAsString() + ".png");
connectMask = Identifier.tryParse(mask.get("connect").getAsString() + ".png");
}
if (mask.has("blend_up")) {
blendUpMask = new Identifier(mask.get("blend_up").getAsString() + ".png");
blendUpMask = Identifier.tryParse(mask.get("blend_up").getAsString() + ".png");
}
if (mask.has("arch")) {
blendArchMask = new Identifier(mask.get("arch").getAsString() + ".png");
blendArchMask = Identifier.tryParse(mask.get("arch").getAsString() + ".png");
}
}
this.connectMask = connectMask;
Expand All @@ -115,7 +115,7 @@ public LBGLayer(LBGMetadata metadata, JsonObject json) {
*/
private @Nullable Material getOverridenTexture(JsonObject overrides, String name) {
if (overrides.has(name)) {
var id = new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(overrides.get(name).getAsString()));
var id = new Material(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, Identifier.tryParse(overrides.get(name).getAsString()));
this.parentMetadata.textures.add(id);
return id;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public void buildTextures() {
}

private static Identifier getTexturePath(Identifier id) {
return new Identifier(id.getNamespace(), "textures/" + id.getPath() + ".png");
return Identifier.of(id.getNamespace(), "textures/" + id.getPath() + ".png");
}

private static Material genTexture(String name, NativeImage side, NativeImage top, NativeImage mask) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public LBGLayerState(Identifier id, Block block, ResourceManager resourceManager
private void loadVariant(String variant, JsonObject json, ResourceManager resourceManager,
ModelVariantMap.DeserializationContext deserializationContext) {
var metadataId = Identifier.tryParse(json.get("data").getAsString());
var metadataResourceId = new Identifier(metadataId.getNamespace(), metadataId.getPath() + ".json");
var metadataResourceId = Identifier.of(metadataId.getNamespace(), metadataId.getPath() + ".json");

LBGLayerType.forEach(type -> {
this.putOrReplaceMetadata(variant, metadataId, type, DEFAULT_METADATA_LAYER_JSON, deserializationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ public static void forEach(Consumer<LBGLayerType> consumer) {
}

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

var affectId = new Identifier(json.get("block").getAsString());
var affectId = Identifier.tryParse(json.get("block").getAsString());
var block = Registries.BLOCK.get(affectId);

if (block == Blocks.AIR)
return;

var modelId = new Identifier(json.get("model").getAsString());
var modelId = Identifier.tryParse(json.get("model").getAsString());

var acceptedRenderLayers = new ReferenceArrayList<RenderLayer>();
RenderLayer defaultRenderLayer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void emitBlockQuads(BlockRenderView world, BlockState state, BlockPos pos
var up = world.getBlockState(upPos);
if (!up.isAir()) {
var blockId = Registries.BLOCK.getId(up.getBlock());
var stateId = new Identifier(blockId.getNamespace(), blockId.getPath());
var stateId = Identifier.of(blockId.getNamespace(), blockId.getPath());
if (LayeredBlockUtils.shouldGrassBeSnowy(world, pos, stateId, up, false)) {
((FabricBakedModel) this.metadata.getSnowyModelVariant())
.emitBlockQuads(world, state.with(Properties.SNOWY, true), pos, randomSupplier, context);
Expand Down Expand Up @@ -163,7 +163,7 @@ private static boolean canConnect(BlockRenderView world, BlockState self, BlockP
return true;
else if (adjacent.getBlock() instanceof SnowyBlock) {
var blockId = Registries.BLOCK.getId(up.getBlock());
var stateId = new Identifier(blockId.getNamespace(), "bettergrass/states/" + blockId.getPath());
var stateId = Identifier.of(blockId.getNamespace(), "bettergrass/states/" + blockId.getPath());
if (LayeredBlockUtils.shouldGrassBeSnowy(world, adjacentPos, stateId, up, true))
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ public void resolveParents(Function<Identifier, UnbakedModel> models) {
}

@Override
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)),
public @Nullable BakedModel bake(ModelBaker baker, Function<Material, Sprite> textureGetter, ModelBakeSettings rotationContainer) {
this.metadatas.forEach(metadata -> metadata.bake(baker, textureGetter, rotationContainer));
return new LBGLayerBakedModel(Objects.requireNonNull(this.baseModel.bake(baker, textureGetter, rotationContainer)),
this.metadatas
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public void resolveParents(Function<Identifier, UnbakedModel> models) {
}

@Override
public @Nullable BakedModel bake(ModelBaker baker, Function<Material, Sprite> textureGetter,
ModelBakeSettings rotationContainer, Identifier modelId) {
public @Nullable BakedModel bake(ModelBaker baker, Function<Material, Sprite> textureGetter, ModelBakeSettings rotationContainer) {
this.metadata.bakeTextures(textureGetter);

var model = new LBGBakedModel(Objects.requireNonNull(this.baseModel.bake(baker, textureGetter, rotationContainer, modelId)), this.metadata);
var model = new LBGBakedModel(Objects.requireNonNull(this.baseModel.bake(baker, textureGetter, rotationContainer)), this.metadata);

this.metadata.propagate(model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LBGResourcePack(LambdaBetterGrass mod) {
}

public Identifier dynamicallyPutImage(String name, NativeImage image) {
final var id = new Identifier(LambdaBetterGrass.NAMESPACE, "block/bettergrass/" + name);
final var id = Identifier.of(LambdaBetterGrass.NAMESPACE, "block/bettergrass/" + name);

Supplier<byte[]> suppler = () -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void loadStates(ResourceManager resourceManager) {
*/
private void loadState(ResourceManager resourceManager, Identifier id, Resource resource,
ModelVariantMap.DeserializationContext variantMapDeserializationContext) {
var stateId = new Identifier(
var stateId = Identifier.of(
id.getNamespace(),
id.getPath().substring(LBGState.PATH_PREFIX.length() + 1, id.getPath().length() - ".json".length())
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
],
"accessWidener": "lambdabettergrass.accesswidener",
"depends": {
"fabricloader": ">=0.14.7",
"minecraft": "~1.20",
"fabricloader": ">=0.15.0",
"minecraft": "~1.21",
"java": ">=17",
"cloth-config": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/resourcepacks/32x/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pack": {
"pack_format": 32,
"pack_format": 34,
"description": "LambdaBetterGrass - 32x32 extension."
}
}
2 changes: 1 addition & 1 deletion src/main/resources/resourcepacks/default/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pack": {
"pack_format": 32,
"pack_format": 34,
"description": "LambdaBetterGrass - Default extension."
}
}

0 comments on commit d673e7f

Please sign in to comment.