diff options
Diffstat (limited to 'src')
6 files changed, 117 insertions, 7 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java index 3b87619..726cdbf 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java @@ -1,5 +1,7 @@ package shcm.shsupercm.fabric.citresewn; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.item.ItemStack; import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; import java.util.Collection; @@ -14,4 +16,9 @@ public class ActiveCITs { public void dispose() { } + + public BakedModel getItemModel(ItemStack stack, BakedModel model) { + //stub + return null; + } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index fa084ef..8880010 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -3,23 +3,23 @@ package shcm.shsupercm.fabric.citresewn; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.render.model.BakedModel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.WeakHashMap; + @Environment(EnvType.CLIENT) public class CITResewn implements ClientModInitializer { public static final Logger LOG = LogManager.getLogger("citresewn"); public static CITResewn INSTANCE; + public final WeakHashMap<BakedModel, String> bakedOverridesCache = new WeakHashMap<>(); + public ActiveCITs activeCITs = null; @Override public void onInitializeClient() { - INSTANCE = this; - /*net.minecraft.client.render.model.json.ModelOverrideList#apply - eval override - */ - /*net.minecraft.client.render.entity.feature.ArmorFeatureRenderer#renderArmor take entity.getEquippedStack(armorSlot) eval override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java new file mode 100644 index 0000000..1679188 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java @@ -0,0 +1,25 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.CITResewn; + +@Mixin(ItemRenderer.class) +public class ItemRendererMixin { + @Inject(method = "getHeldItemModel", cancellable = true, at = @At("RETURN")) + public void getItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { + if (CITResewn.INSTANCE.activeCITs == null) + return; + + BakedModel citModel = CITResewn.INSTANCE.activeCITs.getItemModel(stack, cir.getReturnValue()); + if (citModel != null) + cir.setReturnValue(citModel); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelOverrideListMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelOverrideListMixin.java new file mode 100644 index 0000000..0bfaa4e --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelOverrideListMixin.java @@ -0,0 +1,27 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.ModelLoader; +import net.minecraft.client.render.model.UnbakedModel; +import net.minecraft.client.render.model.json.JsonUnbakedModel; +import net.minecraft.client.render.model.json.ModelOverride; +import net.minecraft.client.render.model.json.ModelOverrideList; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.CITResewn; + +import java.util.function.Function; + +@Mixin(ModelOverrideList.class) +public class ModelOverrideListMixin { + @Inject(method = "bakeOverridingModel", at = @At("RETURN")) + public void onBakeOverridingModel(ModelLoader loader, JsonUnbakedModel parent, Function<Identifier, UnbakedModel> unbakedModelGetter, ModelOverride override, CallbackInfoReturnable<BakedModel> cir) { + if (cir.getReturnValue() != null) { + String[] split = override.getModelId().getPath().split("/"); + CITResewn.INSTANCE.bakedOverridesCache.put(cir.getReturnValue(), split[split.length - 1]); + } + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java index 7a7e963..a7d0c10 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java @@ -1,13 +1,62 @@ package shcm.shsupercm.fabric.citresewn.pack.cits; +import net.minecraft.client.render.model.BakedModel; import net.minecraft.util.Identifier; +import shcm.shsupercm.fabric.citresewn.CITResewn; import shcm.shsupercm.fabric.citresewn.ex.CITParseException; import shcm.shsupercm.fabric.citresewn.pack.CITPack; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; public class CITItem extends CIT { + private BakedModel bakedModel = null; + private HashMap<String, BakedModel> subItems = null; + public CITItem(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { super(pack, identifier, properties); + try { + Identifier modelIdentifier = resolvePath(identifier, properties.getProperty("model"), ".json", pack.resourcePack); + Map<String, Identifier> subIdentifiers = new HashMap<>(); + + for (Object o : properties.keySet()) + if (o instanceof String property && property.startsWith("model.")) { + Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".json", pack.resourcePack); + if (subIdentifier == null) + throw new Exception("Cannot resolve path for " + property); + subIdentifiers.put(property.substring(5), subIdentifier); + } + + if (modelIdentifier == null && subIdentifiers.size() == 0) { + Identifier textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", pack.resourcePack); + + for (Object o : properties.keySet()) + if (o instanceof String property && property.startsWith("texture.")) { + Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", pack.resourcePack); + if (subIdentifier == null) + throw new Exception("Cannot resolve path for " + property); + subIdentifiers.put(property.substring(5), subIdentifier); + } + + if (textureIdentifier == null && subIdentifiers.size() == 0) + throw new Exception("Cannot resolve path for model/texture"); + + // load textures + } + + // load models + } catch (Exception e) { + throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); + } + } + + public BakedModel getBakedModel(BakedModel originalModel) { + + String subItemName; + if (originalModel == null || (subItemName = CITResewn.INSTANCE.bakedOverridesCache.get(originalModel)) == null) + return this.bakedModel; + + return this.subItems == null ? this.bakedModel : this.subItems.getOrDefault(subItemName, this.bakedModel); } } diff --git a/src/main/resources/citresewn.mixins.json b/src/main/resources/citresewn.mixins.json index e31d152..ff6683d 100644 --- a/src/main/resources/citresewn.mixins.json +++ b/src/main/resources/citresewn.mixins.json @@ -3,10 +3,12 @@ "minVersion": "0.8", "package": "shcm.shsupercm.fabric.citresewn.mixin", "compatibilityLevel": "JAVA_16", - "client": [ + "mixins": [ "ReloadableResourceManagerImplMixin", "NbtCompoundAccessor", - "IdentifierMixin" + "IdentifierMixin", + "ModelOverrideListMixin", + "ItemRendererMixin" ], "injectors": { "defaultRequire": 1 |