Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rendering module #83

Draft
wants to merge 2 commits into
base: 1.18
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ indent_style = tab

[*.java]
indent_style = tab
ij_java_class_count_to_use_import_on_demand = 99
ij_java_names_count_to_use_import_on_demand = 99
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.minecraft.**,|,org.quiltmc.**

[*.json]
indent_style = space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public enum ConfigurationType {
API(JavaPlugin.API_CONFIGURATION_NAME),
IMPLEMENTATION(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME),
TESTMOD("testmodImplementation"),
COMPILE_ONLY("compileOnly");
COMPILE_ONLY(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);

private final String configurationName;
ConfigurationType(String configurationName) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"AbstractBlockSettingsAccessor",
"MaterialBuilderAccessor"
],
"client": [
"client.RenderLayersMixin"
],
"injectors": {
"defaultRequire": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
import org.quiltmc.qsl.block.extensions.api.QuiltMaterialBuilder;

public final class Initializer implements ModInitializer {
public final class BlockExtensionsTestMod implements ModInitializer {
public static final String ID = "quilt_block_extensions_testmod";

public static final Material MATERIAL = QuiltMaterialBuilder.copyOf(Material.GLASS, MapColor.DARK_GREEN)
.pistonBehavior(PistonBehavior.PUSH_ONLY)
.build();

public static final Block BLOCK = Registry.register(Registry.BLOCK,
new Identifier("quilt_block_extensions_testmod", "test_block"),
new Identifier(ID, "test_block"),
new GlassBlock(QuiltBlockSettings.copyOf(Blocks.GLASS)
.material(MATERIAL)
.luminance(15)));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
},
"entrypoints": {
"init": [
"org.quiltmc.qsl.block.extensions.test.Initializer"
],
"client_init": [
"org.quiltmc.qsl.block.extensions.test.ClientInitializer"
"org.quiltmc.qsl.block.extensions.test.BlockExtensionsTestMod"
]
}
}
8 changes: 8 additions & 0 deletions library/rendering/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("qsl.library")
}

qslLibrary {
libraryName = "rendering"
version = "1.0.0"
}
18 changes: 18 additions & 0 deletions library/rendering/model/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("qsl.module")
}

qslModule {
moduleName = "model"
version = "1.0.0"
library = "rendering"
moduleDependencies {
core {
api("qsl_base")
}
}
}

loom {
accessWidenerPath = file("src/main/resources/quilt_model.accesswidener")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.model.api.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;

import org.quiltmc.qsl.base.api.util.InjectedInterface;

@Environment(EnvType.CLIENT)
@InjectedInterface(BakedModelManager.class)
public interface QuiltBakedModelManager {
/**
* An alternative to {@link BakedModelManager#getModel(ModelIdentifier)} that accepts an
* {@link Identifier} instead.
*
* <p><b>This method, as well as its vanilla counterpart, should only be used after the
* {@link BakedModelManager} has completed reloading.</b> Otherwise, the result will be
* null or an old model.
*
* @param id the id of the model
* @return the model
*/
BakedModel getModel(Identifier id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.model.mixin.client;

import java.util.Map;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.util.Identifier;

import org.quiltmc.qsl.model.api.client.QuiltBakedModelManager;

@Mixin(BakedModelManager.class)
public class BakedModelManagerMixin implements QuiltBakedModelManager {
@Shadow
private Map<Identifier, BakedModel> models;
@Shadow
private BakedModel missingModel;

@Override
public BakedModel getModel(Identifier id) {
return models.getOrDefault(id, missingModel);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions library/rendering/model/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"schemaVersion": 1,
"id": "quilt_model",
"name": "Quilt Model API",
"version": "${version}",
"environment": "client",
"license": "Apache-2.0",
"icon": "assets/quilt_model/icon.png",
"contact": {
"homepage": "https://quiltmc.org",
"issues": "https://github.com/QuiltMC/quilt-standard-libraries/issues",
"sources": "https://github.com/QuiltMC/quilt-standard-libraries"
},
"authors": [
"QuiltMC"
],
"depends": {
"fabricloader": ">=0.12",
"minecraft": ">=1.18.2",
"quilt_base": "*"
},
"description": "Hooks for models and model loading.",
"mixins": [
"quilt_model.mixins.json"
],
"accessWidener": "quilt_model.accesswidener",
"custom": {
"loom:injected_interfaces": {
"net/minecraft/class_1092": [
"org/quiltmc/qsl/model/api/QuiltBakedModelManager"
]
},
"modmenu": {
"badges": [
"library"
],
"parent": {
"id": "qsl",
"name": "Quilt Standard Libraries",
"description": "A set of libraries to assist in making Quilt mods.",
"icon": "assets/quilt_model/icon.png",
"badges": [
"library"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v2 named
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)Lnet/minecraft/client/item/UnclampedModelPredicateProvider;
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/item/Item;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)V
11 changes: 11 additions & 0 deletions library/rendering/model/src/main/resources/quilt_model.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "org.quiltmc.qsl.rendering.model.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"BakedModelManagerMixin"
],
"injectors": {
"defaultRequire": 1
}
}
18 changes: 18 additions & 0 deletions library/rendering/registration/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("qsl.module")
}

qslModule {
moduleName = "rendering_registration"
version = "1.0.0"
library = "rendering"
moduleDependencies {
core {
api("qsl_base")
}
}
}

loom {
accessWidenerPath = file("src/main/resources/quilt_rendering_registration.accesswidener")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2022 QuiltMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.rendering.registration.api.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;

import org.quiltmc.qsl.rendering.registration.impl.client.ArmorRendererRegistryImpl;

/**
* Armor renderers render worn armor items with custom code.
* They may be used to render armor with special models or effects.
*
* <p>The renderers are registered with {@link ArmorRenderer#register(ItemConvertible, ArmorRenderer)}.
*/
@Environment(EnvType.CLIENT)
@FunctionalInterface
public interface ArmorRenderer {
/**
* Registers the armor renderer for the specified item.
*
* @param item the item
* @param renderer the renderer
* @throws IllegalArgumentException if the item already has a registered armor renderer
* @throws NullPointerException if either the item or the renderer is null
*/
static void register(ItemConvertible item, ArmorRenderer renderer) {
ArmorRendererRegistryImpl.register(item, renderer);
}

/**
* Renders an armor part.
*
* @param matrices the matrix stack
* @param vertexConsumers the vertex consumer provider
* @param stack the item stack of the armor item
* @param entity the entity wearing the armor item
* @param slot the equipment slot in which the armor stack is worn
* @param light packed lightmap coordinates
* @param armorModel the default armor model provided by the feature renderer
* @param featureRenderer the feature renderer which invoked this renderer
*/
void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, ItemStack stack, LivingEntity entity, EquipmentSlot slot, int light, BipedEntityModel<?> armorModel, ArmorFeatureRenderer<?, ?, ?> featureRenderer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.quiltmc.qsl.block.extensions.api.client;
package org.quiltmc.qsl.rendering.registration.api.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -23,7 +23,7 @@
import net.minecraft.client.render.RenderLayer;
import net.minecraft.fluid.Fluid;

import org.quiltmc.qsl.block.extensions.impl.client.BlockRenderLayerMapImpl;
import org.quiltmc.qsl.rendering.registration.impl.client.BlockRenderLayerMapImpl;

/**
* Provides methods to set the {@link RenderLayer} of blocks and fluids.
Expand All @@ -40,7 +40,7 @@ private BlockRenderLayerMap() {
* @param blocks target blocks
*/
public static void put(RenderLayer layer, Block... blocks) {
for (var block : blocks) {
for (Block block : blocks) {
BlockRenderLayerMapImpl.put(block, layer);
}
}
Expand All @@ -52,7 +52,7 @@ public static void put(RenderLayer layer, Block... blocks) {
* @param fluids target fluids
*/
public static void put(RenderLayer layer, Fluid... fluids) {
for (var fluid : fluids) {
for (Fluid fluid : fluids) {
BlockRenderLayerMapImpl.put(fluid, layer);
}
}
Expand Down
Loading