Search in sources :

Example 1 with ModelIdentifier

use of net.minecraft.client.util.ModelIdentifier in project artifality by PinkGoosik.

the class ItemRendererMixin method twoModelsItemImplementation.

@Inject(method = "renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/world/World;III)V", at = @At("HEAD"))
void twoModelsItemImplementation(LivingEntity entity, ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, World world, int light, int overlay, int seed, CallbackInfo ci) {
    if (!stack.isEmpty() && entity != null) {
        TwoModelsItemRegistry.ENTRIES.forEach((id, item) -> {
            if (stack.isOf(item)) {
                BakedModel model = models.getModelManager().getModel(new ModelIdentifier(id + "_in_hand#inventory"));
                renderItem(stack, renderMode, leftHanded, matrices, vertexConsumers, light, overlay, model);
                matrices.scale(0, 0, 0);
            }
        });
    }
/*
        replaces the default enchanted book model
        with the custom one if a book has a lunar
        enchantment
        */
// if(!stack.isEmpty() && stack.isOf(Items.ENCHANTED_BOOK)) {
// NbtList enchantments = EnchantedBookItem.getEnchantmentNbt(stack);
// 
// for(int i = 0; i < enchantments.size(); ++i) {
// NbtCompound nbtCompound = enchantments.getCompound(i);
// 
// Registry.ENCHANTMENT.getOrEmpty(Identifier.tryParse(nbtCompound.getString("id"))).ifPresent((enchantment) -> {
// if(enchantment instanceof LunarEnchantment) {
// BakedModel model = models.getModelManager().getModel(new ModelIdentifier("artifality:lunar_enchanted_book#inventory"));
// renderItem(stack, renderMode, leftHanded, matrices, vertexConsumers, light, overlay, model);
// matrices.scale(0, 0, 0);
// }
// });
// }
// }
}
Also used : ModelIdentifier(net.minecraft.client.util.ModelIdentifier) BakedModel(net.minecraft.client.render.model.BakedModel)

Example 2 with ModelIdentifier

use of net.minecraft.client.util.ModelIdentifier in project CITResewn by SHsuperCM.

the class ModelLoaderMixin method initCITs.

@Inject(method = "addModel", at = @At("TAIL"))
public void initCITs(ModelIdentifier eventModelId, CallbackInfo ci) {
    if (eventModelId != ModelLoader.MISSING_ID)
        return;
    if (CITResewn.INSTANCE.activeCITs != null) {
        info("Clearing active CITs..");
        CITResewn.INSTANCE.activeCITs.dispose();
        CITResewn.INSTANCE.activeCITs = null;
    }
    if (!CITResewnConfig.INSTANCE().enabled)
        return;
    info("Parsing CITs...");
    List<CITPack> parsedPacks = CITParser.parseCITs(resourceManager.streamResourcePacks().collect(Collectors.toCollection(ArrayList::new)));
    List<CIT> parsed = parsedPacks.stream().flatMap(pack -> pack.cits.stream()).collect(Collectors.toCollection(ArrayList::new));
    if (parsed.size() > 0) {
        info("Activating CITs...");
        CITResewn.INSTANCE.activeCITs = new ActiveCITs(parsedPacks, parsed);
    } else
        info("No cit packs found.");
}
Also used : ActiveCITs(shcm.shsupercm.fabric.citresewn.ActiveCITs) CITParser(shcm.shsupercm.fabric.citresewn.pack.CITParser) Inject(org.spongepowered.asm.mixin.injection.Inject) CITResewn(shcm.shsupercm.fabric.citresewn.CITResewn) Collection(java.util.Collection) ModelLoader(net.minecraft.client.render.model.ModelLoader) ResourceManager(net.minecraft.resource.ResourceManager) Final(org.spongepowered.asm.mixin.Final) Collectors(java.util.stream.Collectors) CITResewnConfig(shcm.shsupercm.fabric.citresewn.config.CITResewnConfig) ArrayList(java.util.ArrayList) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) List(java.util.List) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) Mixin(org.spongepowered.asm.mixin.Mixin) CITPack(shcm.shsupercm.fabric.citresewn.pack.CITPack) CIT(shcm.shsupercm.fabric.citresewn.pack.cits.CIT) Shadow(org.spongepowered.asm.mixin.Shadow) At(org.spongepowered.asm.mixin.injection.At) CITResewn.info(shcm.shsupercm.fabric.citresewn.CITResewn.info) ActiveCITs(shcm.shsupercm.fabric.citresewn.ActiveCITs) ArrayList(java.util.ArrayList) CITPack(shcm.shsupercm.fabric.citresewn.pack.CITPack) CIT(shcm.shsupercm.fabric.citresewn.pack.cits.CIT) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ModelIdentifier

use of net.minecraft.client.util.ModelIdentifier in project fabric by FabricMC.

the class ModelModClient method onInitializeClient.

@Override
public void onInitializeClient() {
    ModelLoadingRegistry.INSTANCE.registerAppender((manager, out) -> {
        System.out.println("--- ModelAppender called! ---");
        out.accept(new ModelIdentifier("fabric:model#custom"));
    });
    ModelLoadingRegistry.INSTANCE.registerVariantProvider(manager -> ((modelId, context) -> {
        if (modelId.getVariant().equals("custom") && modelId.getNamespace().equals("fabric")) {
            System.out.println("--- ModelVariantProvider called! ---");
            return context.loadModel(new Identifier("fabric:custom"));
        } else {
            return null;
        }
    }));
    ModelLoadingRegistry.INSTANCE.registerResourceProvider(manager -> ((id, context) -> {
        if (id.toString().equals("fabric:custom")) {
            return context.loadModel(new Identifier("fabric:custom2"));
        } else if (id.toString().equals("fabric:custom2")) {
            System.out.println("--- ModelResourceProvider called! ---");
            return new UnbakedModel() {

                @Override
                public Collection<Identifier> getModelDependencies() {
                    return Collections.emptyList();
                }

                @Override
                public Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) {
                    return Collections.emptyList();
                }

                @Override
                public BakedModel bake(ModelLoader var1, Function<Identifier, Sprite> var2, ModelBakeSettings var3) {
                    System.out.println("--- Model baked! ---");
                    return bakedModel = new BakedModel() {

                        @Override
                        public List<BakedQuad> getQuads(BlockState var1, Direction var2, Random var3) {
                            return Collections.emptyList();
                        }

                        @Override
                        public boolean useAmbientOcclusion() {
                            return false;
                        }

                        @Override
                        public boolean hasDepthInGui() {
                            return false;
                        }

                        @Override
                        public boolean isBuiltin() {
                            return false;
                        }

                        @Override
                        public Sprite getSprite() {
                            return MinecraftClient.getInstance().getSpriteAtlas().getSprite("missingno");
                        }

                        @Override
                        public ModelTransformation getTransformation() {
                            return ModelTransformation.NONE;
                        }

                        @Override
                        public ModelItemPropertyOverrideList getItemPropertyOverrides() {
                            return ModelItemPropertyOverrideList.EMPTY;
                        }
                    };
                }
            };
        } else {
            return null;
        }
    }));
    ClientTickCallback.EVENT.register((client) -> {
        if (client.getBakedModelManager().getModel(new ModelIdentifier("fabric:model#custom")) == bakedModel && bakedModel != null) {
            System.out.println("--- MODEL LOADED! ---");
        } else {
            System.out.println("--- MODEL NOT LOADED! ---");
        }
    });
}
Also used : ClientModInitializer(net.fabricmc.api.ClientModInitializer) ModelItemPropertyOverrideList(net.minecraft.client.render.model.json.ModelItemPropertyOverrideList) Direction(net.minecraft.util.math.Direction) Sprite(net.minecraft.client.texture.Sprite) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) ModelLoadingRegistry(net.fabricmc.fabric.api.client.model.ModelLoadingRegistry) Identifier(net.minecraft.util.Identifier) ClientTickCallback(net.fabricmc.fabric.api.event.client.ClientTickCallback) MinecraftClient(net.minecraft.client.MinecraftClient) BlockState(net.minecraft.block.BlockState) Function(java.util.function.Function) ModelTransformation(net.minecraft.client.render.model.json.ModelTransformation) Sprite(net.minecraft.client.texture.Sprite) ModelItemPropertyOverrideList(net.minecraft.client.render.model.json.ModelItemPropertyOverrideList) Direction(net.minecraft.util.math.Direction) Function(java.util.function.Function) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) Identifier(net.minecraft.util.Identifier) BlockState(net.minecraft.block.BlockState) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) ModelTransformation(net.minecraft.client.render.model.json.ModelTransformation) ModelItemPropertyOverrideList(net.minecraft.client.render.model.json.ModelItemPropertyOverrideList)

Example 4 with ModelIdentifier

use of net.minecraft.client.util.ModelIdentifier in project artifality by PinkGoosik.

the class BalloonRenderer method render.

@Override
public void render(ItemStack stack, SlotReference slotReference, EntityModel<? extends LivingEntity> contextModel, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
    ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
    matrices.push();
    if (entity.isInSneakingPose())
        matrices.translate(0D, -1.25D, 0D);
    else
        matrices.translate(0D, -1.5D, 0D);
    matrices.scale(0.8F, 0.8F, 0.8F);
    matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180.0F));
    String modelId = "artifality:balloon_in_hand#inventory";
    itemRenderer.renderItem(stack, ModelTransformation.Mode.FIXED, false, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV, itemRenderer.getModels().getModelManager().getModel(new ModelIdentifier(modelId)));
    matrices.pop();
}
Also used : ModelIdentifier(net.minecraft.client.util.ModelIdentifier) ItemRenderer(net.minecraft.client.render.item.ItemRenderer)

Aggregations

ModelIdentifier (net.minecraft.client.util.ModelIdentifier)4 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 ClientModInitializer (net.fabricmc.api.ClientModInitializer)1 ModelLoadingRegistry (net.fabricmc.fabric.api.client.model.ModelLoadingRegistry)1 ClientTickCallback (net.fabricmc.fabric.api.event.client.ClientTickCallback)1 BlockState (net.minecraft.block.BlockState)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ItemRenderer (net.minecraft.client.render.item.ItemRenderer)1 BakedModel (net.minecraft.client.render.model.BakedModel)1 ModelLoader (net.minecraft.client.render.model.ModelLoader)1 ModelItemPropertyOverrideList (net.minecraft.client.render.model.json.ModelItemPropertyOverrideList)1 ModelTransformation (net.minecraft.client.render.model.json.ModelTransformation)1 Sprite (net.minecraft.client.texture.Sprite)1 ResourceManager (net.minecraft.resource.ResourceManager)1 Identifier (net.minecraft.util.Identifier)1 Direction (net.minecraft.util.math.Direction)1