Skip to content

Commit

Permalink
more model parenting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jul 23, 2022
1 parent 3eac20b commit 046de9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 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.2
mod_version = 6.0.3
maven_group = net.ludocrypt
archives_base_name = limlib
12 changes: 0 additions & 12 deletions src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@

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 @@ -41,19 +41,14 @@ public abstract class JsonUnbakedModelMixin implements UnbakedModelAccess {

@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) -> {
List<Pair<BakedQuad, Optional<Direction>>> quads = Lists.newArrayList();
subElement.forEach((modelElement) -> {
for (Direction direction : modelElement.faces.keySet()) {
ModelElementFace modelElementFace = modelElement.faces.get(direction);
Sprite sprite2 = textureGetter.apply(((JsonUnbakedModel) (Object) this).resolveSprite(modelElementFace.textureId));
Sprite sprite2 = textureGetter.apply(parent.resolveSprite(modelElementFace.textureId));
if (modelElementFace.cullFace == null) {
quads.add(Pair.of(createQuad(modelElement, modelElementFace, sprite2, direction, settings, id), Optional.empty()));
continue;
Expand All @@ -65,19 +60,23 @@ public Map<Identifier, List<Pair<BakedQuad, Optional<Direction>>>> bakeQuads(Mod
subQuads.put(subElementId, quads);
});

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

return subQuads;
((BakedModelAccess) ci.getReturnValue()).getSubQuads().putAll(subQuads);
}

@Shadow
private native static BakedQuad createQuad(ModelElement element, ModelElementFace elementFace, Sprite sprite, Direction side, ModelBakeSettings settings, Identifier id);

@Override
public Map<Identifier, List<ModelElement>> getSubElements() {
return subElements;
Map<Identifier, List<ModelElement>> conjoinedElements = Maps.newHashMap();

conjoinedElements.putAll(this.subElements);

if (this.parent != null) {
conjoinedElements.putAll(((UnbakedModelAccess) this.parent).getSubElements());
}

return conjoinedElements;
}

@Override
Expand Down

0 comments on commit 046de9c

Please sign in to comment.