Skip to content

Commit

Permalink
Update NeoForge, adjust dynamic resources for NF API
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jun 19, 2024
1 parent 700ccc2 commit d46d245
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,34 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {

private final Map<ModelResourceLocation, BakedModel> mfix$emulatedBakedRegistry = new DynamicOverridableMap<>(this::loadBakedModelDynamic);

@Unique
private UnbakedModel loadUnbakedModelDynamic(ModelResourceLocation location) {
@Override
public UnbakedModel mfix$loadUnbakedModelDynamic(ModelResourceLocation location) {
if(location.equals(MISSING_MODEL_VARIANT)) {
return missingModel;
}
if(DEBUG_MODEL_LOADS) {
ModernFix.LOGGER.info("Loading model {}", location);
}
if(location.variant().equals("inventory")) {
this.loadItemModelAndDependencies(location.id());
} else {
((IBlockStateModelLoader)dynamicLoader).loadSpecificBlock(location);
modelBakeryLock.lock();
try {
UnbakedModel existing = this.topLevelModels.get(location);
if (existing != null) {
return existing;
}
if(DEBUG_MODEL_LOADS) {
ModernFix.LOGGER.info("Loading model {}", location);
}
if(location.variant().equals("inventory")) {
this.loadItemModelAndDependencies(location.id());
} else {
((IBlockStateModelLoader)dynamicLoader).loadSpecificBlock(location);
}
return this.topLevelModels.getOrDefault(location, this.missingModel);
} finally {
modelBakeryLock.unlock();
}
return this.topLevelModels.getOrDefault(location, this.missingModel);
}

@Override
public UnbakedModel mfix$getMissingModel() {
return missingModel;
}

@Unique
Expand All @@ -101,7 +115,7 @@ private BakedModel loadBakedModelDynamic(ModelResourceLocation location) {
try {
model = bakedTopLevelModels.get(location);
if(model == null) {
UnbakedModel prototype = loadUnbakedModelDynamic(location);
UnbakedModel prototype = mfix$loadUnbakedModelDynamic(location);
prototype.resolveParents(this::getModel);
if(DEBUG_MODEL_LOADS) {
ModernFix.LOGGER.info("Baking model {}", location);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.embeddedt.modernfix.duck;

import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;

public interface IExtendedModelBakery {
void mfix$tick();
void mfix$finishLoading();
UnbakedModel mfix$loadUnbakedModelDynamic(ModelResourceLocation location);
UnbakedModel mfix$getMissingModel();
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mixinextras_version=0.3.2
mod_id=modernfix
minecraft_version=1.21
enabled_platforms=fabric,neoforge
forge_version=21.0.0-beta
forge_version=21.0.18-beta
# parchment_version=2023.07.09
refined_storage_version=4392788
jei_version=16.0.0.28
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.embeddedt.modernfix.neoforge.mixin.perf.dynamic_resources;

import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(targets = {"net/minecraft/client/resources/model/ModelBakery$ModelBakerImpl"})
@ClientOnlyMixin
public class ModelBakerImplMixin {
@Shadow @Final private ModelBakery field_40571;

/**
* @author embeddedt
* @reason Handle dynamic model loading
*/
@Overwrite(remap = false)
public UnbakedModel getTopLevelModel(ModelResourceLocation location) {
IExtendedModelBakery bakery = (IExtendedModelBakery)this.field_40571;
UnbakedModel model = bakery.mfix$loadUnbakedModelDynamic(location);
return model == bakery.mfix$getMissingModel() ? null : model;
}
}
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ modId = "neoforge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
type = "required" #mandatory
# The version range of the dependency
versionRange = "[21.0.0-alpha,)" #mandatory
versionRange = "[21.0.17-beta,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering = "NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
Expand Down

0 comments on commit d46d245

Please sign in to comment.