Skip to content

Commit

Permalink
fix: loading of animation models
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 8, 2024
1 parent 272b28b commit acf07b3
Showing 1 changed file with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mojang.math.Vector3f;
import com.mojang.math.Vector4f;
import com.troblecodings.signals.OpenSignalsMain;
import com.troblecodings.signals.contentpacks.SignalAnimationConfigParser;
import com.troblecodings.signals.core.SignalAngel;

import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -87,15 +88,15 @@ private static void transform(final BakedQuad quad, final Matrix4f quaterion) {
private BakedModelPair transform(final SignalModelLoaderInfo info, final ModelBakery bakery,
final ResourceLocation location, final Function<Material, TextureAtlasSprite> function,
final Map<String, Either<Material, String>> material, final Quaternion rotation) {
final Transformation transformation =
new Transformation(new Vector3f(info.x, info.y, info.z), null, null, null);
final Transformation transformation = new Transformation(
new Vector3f(info.x, info.y, info.z), null, null, null);
final BlockModel blockModel = (BlockModel) info.model;
final ImmutableMap<String, Either<Material, String>> defaultMap =
ImmutableMap.copyOf(blockModel.textureMap);
final ImmutableMap<String, Either<Material, String>> defaultMap = ImmutableMap
.copyOf(blockModel.textureMap);
info.retexture.forEach((id, texture) -> blockModel.textureMap.computeIfPresent(id,
(_u, old) -> material.get(texture)));
final BakedModel model =
info.model.bake(bakery, function, new SimpleModelState(transformation), location);
final BakedModel model = info.model.bake(bakery, function,
new SimpleModelState(transformation), location);
blockModel.textureMap.putAll(defaultMap);
final Matrix4f reverse = new Matrix4f();
reverse.setIdentity();
Expand All @@ -112,13 +113,6 @@ private BakedModelPair transform(final SignalModelLoaderInfo info, final ModelBa
model.getQuads(null, direction, RANDOM, EmptyModelData.INSTANCE)
.forEach(quad -> transform(quad, matrix));
}
if (angel.equals(SignalAngel.ANGEL0)) {
locationToModel.put(new ResourceLocation(OpenSignalsMain.MODID, info.name),
info.model.bake(bakery, function,
new SimpleModelState(
new Transformation(Vector3f.ZERO, null, null, null)),
location));
}
return new BakedModelPair(info.state, model);
}

Expand All @@ -145,8 +139,8 @@ public BakedModel bake(final ModelBakery bakery,
final ResourceLocation resource) {
list.forEach(info -> {
if (info.model == null) {
final ResourceLocation location =
new ResourceLocation(OpenSignalsMain.MODID, "block/" + info.name);
final ResourceLocation location = new ResourceLocation(OpenSignalsMain.MODID,
"block/" + info.name);
if (bakery instanceof ForgeModelBakery) {
info.model = ((ForgeModelBakery) bakery).getModelOrLogError(location,
String.format("Could not find %s!", location));
Expand All @@ -155,6 +149,7 @@ public BakedModel bake(final ModelBakery bakery,
}
}
});
loadAnimationModels(bakery, function, resource);
final Quaternion quaternion = angel.getQuaternion();
return new SignalBakedModel(
list.stream()
Expand All @@ -163,6 +158,26 @@ public BakedModel bake(final ModelBakery bakery,
.collect(Collectors.toUnmodifiableList()));
}

private void loadAnimationModels(final ModelBakery bakery,
final Function<Material, TextureAtlasSprite> function,
final ResourceLocation resource) {
if (!angel.equals(SignalAngel.ANGEL0))
return;
final List<String> modelNames = new ArrayList<>();
SignalAnimationConfigParser.ALL_ANIMATIONS.values()
.forEach(map -> map.keySet().forEach(entry -> modelNames.add(entry.getKey())));
for (final String name : modelNames) {
final UnbakedModel unbaked = bakery
.getModel(new ResourceLocation(OpenSignalsMain.MODID, "block/" + name));
final BakedModel baked = unbaked.bake(bakery, function,
new SimpleModelState(new Transformation(Vector3f.ZERO, null, null, null)),
resource);
final ResourceLocation location = new ResourceLocation(OpenSignalsMain.MODID, name);
if (!locationToModel.containsKey(location))
locationToModel.put(new ResourceLocation(OpenSignalsMain.MODID, name), baked);
}
}

public static BakedModel getModelFromLocation(final ResourceLocation location) {
return locationToModel.getOrDefault(location,
Minecraft.getInstance().getModelManager().getMissingModel());
Expand Down

0 comments on commit acf07b3

Please sign in to comment.