Skip to content

Commit

Permalink
Rewrote the Caching System to Fix Texture issues
Browse files Browse the repository at this point in the history
Overhauled mesh trashcan model
  • Loading branch information
UnlikePaladin committed Sep 28, 2024
1 parent d559335 commit fb681b2
Show file tree
Hide file tree
Showing 117 changed files with 1,043 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
public abstract class AbstractBakedModel implements BakedModel {
protected final ModelBakeSettings settings;
private final List<BakedModel> templateBakedModels;

public static boolean reloading = false;
public AbstractBakedModel(ModelBakeSettings settings, List<BakedModel> templateBakedModels) {
this.settings = settings;
this.templateBakedModels = templateBakedModels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public static BlockType getBlockType(Identifier identifier) {
return BlockType.BLOCK;
}

public static VariantBase getVariant(Identifier identifier) {
VariantBase var = getExtraCounterType(identifier);
public static VariantBase<?> getVariant(Identifier identifier) {
VariantBase<?> var = getExtraCounterType(identifier);
if (var == null) {
var = getStoneType(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.unlikepaladin.pfm.data.materials.StoneVariantRegistry;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -68,23 +70,26 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(TABLE_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(TABLE_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(TABLE_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(TABLE_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : BASIC_MODEL_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(TABLE_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier modelId, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.datafixers.util.Pair;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.data.materials.*;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
Expand Down Expand Up @@ -70,23 +72,26 @@ public Collection<Identifier> getModelDependencies() {
return Collections.singleton(PARENT);
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(LAMP_MODEL_IDS.get(0)) && PFMRuntimeResources.modelCacheMap.get(LAMP_MODEL_IDS.get(0)).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(LAMP_MODEL_IDS.get(0), rotationContainer, PFMRuntimeResources.modelCacheMap.get(LAMP_MODEL_IDS.get(0)).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(LAMP_MODEL_IDS.get(0)))
PFMRuntimeResources.modelCacheMap.put(LAMP_MODEL_IDS.get(0), new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : ALL_MODEL_IDS) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(LAMP_MODEL_IDS.get(0)).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(LAMP_MODEL_IDS.get(0), rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier modelId, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.datafixers.util.Pair;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.data.materials.*;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -66,19 +68,23 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(TABLE_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(TABLE_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(TABLE_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(TABLE_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : BASIC_MODEL_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(TABLE_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(TABLE_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier modelId, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -78,23 +80,26 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(BED_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(BED_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(BED_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(BED_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(BED_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(BED_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : BED_MODEL_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(BED_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(BED_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier model, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.unlikepaladin.pfm.data.materials.StoneVariantRegistry;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
Expand Down Expand Up @@ -53,23 +55,26 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(CHAIR_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : CHAIR_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier model, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.unlikepaladin.pfm.data.materials.StoneVariantRegistry;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
Expand Down Expand Up @@ -52,23 +54,26 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(CHAIR_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : CHAIR_CLASSIC_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier modelId, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.datafixers.util.Pair;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.data.materials.*;
import com.unlikepaladin.pfm.runtime.PFMBakedModelContainer;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
Expand Down Expand Up @@ -50,23 +52,26 @@ public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier,
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));
if (PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID) && PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().containsKey(rotationContainer))
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().get(rotationContainer));

if (!PFMRuntimeResources.modelCacheMap.containsKey(CHAIR_MODEL_ID))
PFMRuntimeResources.modelCacheMap.put(CHAIR_MODEL_ID, new PFMBakedModelContainer());

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : CHAIR_DINNER_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);

PFMRuntimeResources.modelCacheMap.get(CHAIR_MODEL_ID).getCachedModelParts().put(rotationContainer, bakedModelList);
return getBakedModel(CHAIR_MODEL_ID, rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
public static BakedModel getBakedModel(Identifier modelId, ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Loading

0 comments on commit fb681b2

Please sign in to comment.