Skip to content

Commit

Permalink
model parenting
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jul 23, 2022
1 parent e51af2e commit 3eac20b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ satin_version=1.8.0
sodium_version=mc1.19-0.4.2
iris_version=1.19.x-v1.2.5

mod_version = 6.0.1
mod_version = 6.0.2
maven_group = net.ludocrypt
archives_base_name = limlib
15 changes: 15 additions & 0 deletions src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import com.mojang.datafixers.util.Pair;

import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.render.model.json.ModelElement;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;

public interface UnbakedModelAccess {

public Map<Identifier, List<ModelElement>> getSubElements();

public JsonUnbakedModel getParent();

public Map<Identifier, List<Pair<BakedQuad, Optional<Direction>>>> bakeQuads(ModelLoader loader, JsonUnbakedModel parent, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public abstract class JsonUnbakedModelMixin implements UnbakedModelAccess {
@Unique
private Map<Identifier, List<ModelElement>> subElements = Maps.newHashMap();

@Shadow
protected JsonUnbakedModel parent;

@Inject(method = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel;bake(Lnet/minecraft/client/render/model/ModelLoader;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/function/Function;Lnet/minecraft/client/render/model/ModelBakeSettings;Lnet/minecraft/util/Identifier;Z)Lnet/minecraft/client/render/model/BakedModel;", at = @At("RETURN"), cancellable = true)
private void limlib$bake(ModelLoader loader, JsonUnbakedModel parent, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth, CallbackInfoReturnable<BakedModel> ci) {
((BakedModelAccess) ci.getReturnValue()).getSubQuads().putAll(this.bakeQuads(loader, parent, textureGetter, settings, id, hasDepth));
}

@Override
public Map<Identifier, List<Pair<BakedQuad, Optional<Direction>>>> bakeQuads(ModelLoader loader, JsonUnbakedModel parent, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth) {
Map<Identifier, List<Pair<BakedQuad, Optional<Direction>>>> subQuads = Maps.newHashMap();

this.getSubElements().forEach((subElementId, subElement) -> {
Expand All @@ -57,7 +65,11 @@ public abstract class JsonUnbakedModelMixin implements UnbakedModelAccess {
subQuads.put(subElementId, quads);
});

((BakedModelAccess) ci.getReturnValue()).getSubQuads().putAll(subQuads);
if (((UnbakedModelAccess) parent).getParent() != null) {
subQuads.putAll(((UnbakedModelAccess) ((UnbakedModelAccess) parent).getParent()).bakeQuads(loader, ((UnbakedModelAccess) parent).getParent(), textureGetter, settings, id, hasDepth));
}

return subQuads;
}

@Shadow
Expand All @@ -68,4 +80,9 @@ public Map<Identifier, List<ModelElement>> getSubElements() {
return subElements;
}

@Override
public JsonUnbakedModel getParent() {
return this.parent;
}

}

0 comments on commit 3eac20b

Please sign in to comment.