diff --git a/src/generated/resources/assets/kasuga_lib/blockstates/test/green_apple.json b/src/generated/resources/assets/kasuga_lib/blockstates/test/green_apple.json index 0805dc41..c2e2a007 100644 --- a/src/generated/resources/assets/kasuga_lib/blockstates/test/green_apple.json +++ b/src/generated/resources/assets/kasuga_lib/blockstates/test/green_apple.json @@ -1,7 +1,8 @@ { "variants": { - "": { - "model": "kasuga_lib:block/test/test_model_complicate" - } + + }, + "": { + "model": "kasuga_lib:block/test/test_model_complicate" } } \ No newline at end of file diff --git a/src/generated/resources/kasuga.mixins.json b/src/generated/resources/kasuga.mixins.json index d1f489fa..deb340ba 100644 --- a/src/generated/resources/kasuga.mixins.json +++ b/src/generated/resources/kasuga.mixins.json @@ -13,9 +13,9 @@ "client": [ "client.MixinBlockModel$Deserializer", "client.MixinBlockModelBinding", - "client.MixinTextureManager", - "client.MixinBlockModelBinding", - "client.MixinBlockModelShaper" + "client.MixinBlockModelShaper", + "client.MixinModelBakery", + "client.MixinTextureManager" ], "minVersion": "0.8" } diff --git a/src/main/java/kasuga/lib/core/client/model/BedrockModelLoader.java b/src/main/java/kasuga/lib/core/client/model/BedrockModelLoader.java index b4b86533..423ae515 100644 --- a/src/main/java/kasuga/lib/core/client/model/BedrockModelLoader.java +++ b/src/main/java/kasuga/lib/core/client/model/BedrockModelLoader.java @@ -8,6 +8,7 @@ import kasuga.lib.core.client.model.model_json.Geometry; import kasuga.lib.core.util.LazyRecomputable; import kasuga.lib.core.util.Resources; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransform; import net.minecraft.client.renderer.block.model.ItemTransforms; @@ -35,15 +36,13 @@ public class BedrockModelLoader implements IGeometryLoader, public static BedrockModelLoader INSTANCE = new BedrockModelLoader(); private ResourceManager manager; public static final HashSet UNREGISTERED = new HashSet<>(); + public static final HashSet ADDITIONAL_MATERIALS = new HashSet<>(); public static boolean registerFired = false; public static final HashMap MODELS = new HashMap<>(); - public static final ResourceLocation MISSING_MODEL_LOCATION = new ResourceLocation(KasugaLib.MOD_ID, "default/missing_model"); - private static final LazyRecomputable MISSING = new LazyRecomputable<>(() -> MODELS.get(MISSING_MODEL_LOCATION)); - public BedrockModelLoader() { - } + public BedrockModelLoader() {} @Override public void onResourceManagerReload(ResourceManager resourceManager) { this.manager = resourceManager; @@ -60,9 +59,11 @@ public UnbakedBedrockModel read(JsonObject jsonObject, @Nullable JsonDeserializa if (jsonObject.has("particle")) { String particleStr = jsonObject.get("particle").getAsString(); ResourceLocation location = new ResourceLocation(particleStr); - Material material = new Material(TextureAtlas.LOCATION_PARTICLES, - new ResourceLocation(location.getNamespace(), "textures/" + location.getPath() + ".png") - ); + Material material = new Material(TextureAtlas.LOCATION_PARTICLES, location); + ADDITIONAL_MATERIALS.add(material); + } + if (deserializationContext == null) { + ADDITIONAL_MATERIALS.add(model.getMaterial()); } return model; } @@ -124,7 +125,8 @@ public static LazyRecomputable fromFile(ResourceLocation lo KasugaLib.MAIN_LOGGER.error(location + " is not a JsonObject"); return MISSING; } - UnbakedBedrockModel model = INSTANCE.read(element.getAsJsonObject(), null); + JsonObject jsObj = element.getAsJsonObject(); + UnbakedBedrockModel model = INSTANCE.read(jsObj, null); MODELS.put(location, model); return LazyRecomputable.of(() -> model); } catch (IOException e) { diff --git a/src/main/java/kasuga/lib/core/client/model/model_json/UnbakedBedrockModel.java b/src/main/java/kasuga/lib/core/client/model/model_json/UnbakedBedrockModel.java index e244cdd9..b526a35c 100644 --- a/src/main/java/kasuga/lib/core/client/model/model_json/UnbakedBedrockModel.java +++ b/src/main/java/kasuga/lib/core/client/model/model_json/UnbakedBedrockModel.java @@ -22,6 +22,7 @@ import net.minecraftforge.client.model.geometry.IGeometryBakingContext; import net.minecraftforge.client.model.geometry.SimpleUnbakedGeometry; +import javax.annotation.Nullable; import java.io.IOException; import java.util.*; import java.util.function.Function; @@ -42,17 +43,26 @@ public UnbakedBedrockModel(ResourceLocation modelLocation, ResourceLocation text this.textureLocation = textureLocation; geometries = Lists.newArrayList(); legacy = false; - parse(); + parse(null); } - public void parse() { + public UnbakedBedrockModel(ResourceLocation modelLocation, Material material, boolean flipV) { + this.flipV = flipV; + this.modelLocation = modelLocation; + this.textureLocation = material.texture(); + this.geometries = new ArrayList<>(); + legacy = false; + parse(material); + } + + public void parse(@Nullable Material material) { JsonObject model = readModel(); if (model == null) { KasugaLib.MAIN_LOGGER.warn("Unable to open animated model: " + this.modelLocation.toString()); return; } formatVersion = model.get("format_version").getAsString(); - this.material = new Material(TextureAtlas.LOCATION_BLOCKS, textureLocation); + this.material = material == null ? new Material(TextureAtlas.LOCATION_BLOCKS, textureLocation) : material; JsonArray geos; if (model.has("minecraft:geometry")) { diff --git a/src/main/java/kasuga/lib/mixins/mixin/client/MixinModelBakery.java b/src/main/java/kasuga/lib/mixins/mixin/client/MixinModelBakery.java new file mode 100644 index 00000000..2a6b12d2 --- /dev/null +++ b/src/main/java/kasuga/lib/mixins/mixin/client/MixinModelBakery.java @@ -0,0 +1,20 @@ +package kasuga.lib.mixins.mixin.client; + +import kasuga.lib.core.client.model.BedrockModelLoader; +import net.minecraft.client.resources.model.Material; +import net.minecraft.client.resources.model.ModelBakery; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Collection; +import java.util.Set; + +@Mixin(ModelBakery.class) +public class MixinModelBakery { + + @Redirect(method = "", at = @At(value = "INVOKE", target = "Ljava/util/Set;addAll(Ljava/util/Collection;)Z")) + private boolean addAll(Set instance, Collection es) { + return instance.addAll(es) & instance.addAll(BedrockModelLoader.ADDITIONAL_MATERIALS); + } +}