diff --git a/src/client/kotlin/dev/hybridlabs/aquatic/HybridAquaticClient.kt b/src/client/kotlin/dev/hybridlabs/aquatic/HybridAquaticClient.kt index 9513295ee..67344f039 100644 --- a/src/client/kotlin/dev/hybridlabs/aquatic/HybridAquaticClient.kt +++ b/src/client/kotlin/dev/hybridlabs/aquatic/HybridAquaticClient.kt @@ -5,26 +5,40 @@ import dev.hybridlabs.aquatic.block.entity.HybridAquaticBlockEntityTypes import dev.hybridlabs.aquatic.client.item.tooltip.FishingNetTooltip import dev.hybridlabs.aquatic.client.model.HybridAquaticEntityModelLayers import dev.hybridlabs.aquatic.client.network.HybridAquaticClientNetworking -import dev.hybridlabs.aquatic.client.render.block.entity.* +import dev.hybridlabs.aquatic.client.render.block.entity.AnemoneBlockEntityRenderer +import dev.hybridlabs.aquatic.client.render.block.entity.BuoyBlockEntityRenderer +import dev.hybridlabs.aquatic.client.render.block.entity.CrabPotBlockEntityRenderer +import dev.hybridlabs.aquatic.client.render.block.entity.FishingPlaqueBlockEntityRenderer +import dev.hybridlabs.aquatic.client.render.block.entity.HydrothermalVentBlockEntityRenderer +import dev.hybridlabs.aquatic.client.render.block.entity.MessageInABottleBlockEntityRenderer import dev.hybridlabs.aquatic.client.render.entity.HybridAquaticEntityRenderers import dev.hybridlabs.aquatic.client.render.hud.FishingNetHUDRenderer -import dev.hybridlabs.aquatic.client.render.item.* +import dev.hybridlabs.aquatic.client.render.item.AnemoneBlockItemRenderer +import dev.hybridlabs.aquatic.client.render.item.BuoyBlockItemRenderer +import dev.hybridlabs.aquatic.client.render.item.CrabPotBlockItemRenderer +import dev.hybridlabs.aquatic.client.render.item.FishingNetItemRenderer +import dev.hybridlabs.aquatic.client.render.item.HydrothermalVentBlockItemRenderer +import dev.hybridlabs.aquatic.client.render.item.MessageInABottleBlockItemRenderer import dev.hybridlabs.aquatic.item.HybridAquaticItems import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback +import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback +import net.fabricmc.fabric.api.resource.ResourceManagerHelper import net.minecraft.client.MinecraftClient import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.block.entity.BlockEntityRendererFactories import net.minecraft.client.render.block.entity.BlockEntityRendererFactory +import net.minecraft.resource.ResourceType object HybridAquaticClient : ClientModInitializer { override fun onInitializeClient() { HybridAquaticEntityModelLayers HybridAquaticClientNetworking + registerClientResourceListeners() registerBlockRenderLayers() registerBlockEntityRenderers() registerBuiltinItemRenderers() @@ -32,6 +46,8 @@ object HybridAquaticClient : ClientModInitializer { registerWeatherRenderers() registerTooltips() registerHudAddons() + + ModelLoadingPlugin.register { context -> context.addModels(FishingNetItemRenderer.INVENTORY_MODEL_ID.withPrefixedPath("models/")) } } private fun registerWeatherRenderers() { @@ -53,6 +69,10 @@ object HybridAquaticClient : ClientModInitializer { ) } + private fun registerClientResourceListeners(registry: ResourceManagerHelper = ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)) { + registry.registerReloadListener(FishingNetItemRenderer) + } + private fun registerBlockEntityRenderers() { BlockEntityRendererFactories.register(HybridAquaticBlockEntityTypes.ANEMONE, ::AnemoneBlockEntityRenderer) BlockEntityRendererFactories.register(HybridAquaticBlockEntityTypes.MESSAGE_IN_A_BOTTLE, ::MessageInABottleBlockEntityRenderer) @@ -72,6 +92,7 @@ object HybridAquaticClient : ClientModInitializer { registry.register(HybridAquaticItems.CRAB_POT, CrabPotBlockItemRenderer()) registry.register(HybridAquaticItems.MESSAGE_IN_A_BOTTLE, MessageInABottleBlockItemRenderer()) registry.register(HybridAquaticItems.HYDROTHERMAL_VENT, HydrothermalVentBlockItemRenderer()) + registry.register(HybridAquaticItems.FISHING_NET, FishingNetItemRenderer) } fun createBlockEntityRendererFactoryContext(): BlockEntityRendererFactory.Context { diff --git a/src/client/kotlin/dev/hybridlabs/aquatic/client/model/HybridAquaticEntityModelLayers.kt b/src/client/kotlin/dev/hybridlabs/aquatic/client/model/HybridAquaticEntityModelLayers.kt index bb46178c0..18ad2b9db 100644 --- a/src/client/kotlin/dev/hybridlabs/aquatic/client/model/HybridAquaticEntityModelLayers.kt +++ b/src/client/kotlin/dev/hybridlabs/aquatic/client/model/HybridAquaticEntityModelLayers.kt @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap import dev.hybridlabs.aquatic.HybridAquatic import dev.hybridlabs.aquatic.block.PlushieBlock import dev.hybridlabs.aquatic.client.model.block.entity.plushie.* +import dev.hybridlabs.aquatic.client.model.item.FishingNetItemModel import dev.hybridlabs.aquatic.mixin.client.SkullBlockEntityRendererMixin import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry.TexturedModelDataProvider @@ -26,6 +27,8 @@ object HybridAquaticEntityModelLayers { val TIGER_SHARK_PLUSHIE = register("tiger_shark_plushie", TigerSharkPlushieModel::createModelData) val WHALE_SHARK_PLUSHIE = register("whale_shark_plushie", WhaleSharkPlushieModel::createModelData) + val FISHING_NET = register("fishing_net", FishingNetItemModel::createModelData) + private fun register(id: String, modelProvider: TexturedModelDataProvider): EntityModelLayer { val layer = EntityModelLayer(Identifier(HybridAquatic.MOD_ID, id), "main") EntityModelLayerRegistry.registerModelLayer(layer, modelProvider) diff --git a/src/client/kotlin/dev/hybridlabs/aquatic/client/model/item/FishingNetItemModel.kt b/src/client/kotlin/dev/hybridlabs/aquatic/client/model/item/FishingNetItemModel.kt new file mode 100644 index 000000000..32dbd0529 --- /dev/null +++ b/src/client/kotlin/dev/hybridlabs/aquatic/client/model/item/FishingNetItemModel.kt @@ -0,0 +1,56 @@ +package dev.hybridlabs.aquatic.client.model.item + +import net.minecraft.client.model.Model +import net.minecraft.client.model.ModelData +import net.minecraft.client.model.ModelPart +import net.minecraft.client.model.ModelPartBuilder +import net.minecraft.client.model.ModelTransform +import net.minecraft.client.model.TexturedModelData +import net.minecraft.client.render.RenderLayer +import net.minecraft.client.render.VertexConsumer +import net.minecraft.client.util.math.MatrixStack + +class FishingNetItemModel( + val root: ModelPart +) : Model(RenderLayer::getEntitySolid) { + override fun render( + matrices: MatrixStack, + vertices: VertexConsumer, + light: Int, + overlay: Int, + red: Float, + green: Float, + blue: Float, + alpha: Float + ) { + this.root.render(matrices, vertices, light, overlay, red, green, blue, alpha) + } + + companion object { + fun createModelData(): TexturedModelData { + return TexturedModelData.of( + ModelData().apply { + root.addChild( + "fishing_net", + ModelPartBuilder.create() + .uv(0, 0) + .cuboid(0.5f, -8.0f, 1.0f, 1.0f, 1.0f, 16.0f) + .uv(0, 2) + .cuboid(-2.0f, -8.0f, 0.0f, 6.0f, 1.0f, 1.0f) + .uv(20, 22) + .cuboid(4.0f, -8.0f, -7.0f, 1.0f, 1.0f, 8.0f) + .uv(18, 0) + .cuboid(-3.0f, -8.0f, -7.0f, 1.0f, 1.0f, 8.0f) + .uv(0, 0) + .cuboid(-2.0f, -8.0f, -7.0f, 6.0f, 1.0f, 1.0f) + .uv(0, 17) + .cuboid(-2.5f, -7.5f, -6.5f, 7.0f, 6.0f, 7.0f), + ModelTransform.pivot(-1.0f, 23.0f, -9.0f) + ) + }, + 64, + 64 + ) + } + } +} diff --git a/src/client/kotlin/dev/hybridlabs/aquatic/client/render/item/FishingNetItemRenderer.kt b/src/client/kotlin/dev/hybridlabs/aquatic/client/render/item/FishingNetItemRenderer.kt new file mode 100644 index 000000000..45c899e6a --- /dev/null +++ b/src/client/kotlin/dev/hybridlabs/aquatic/client/render/item/FishingNetItemRenderer.kt @@ -0,0 +1,88 @@ +package dev.hybridlabs.aquatic.client.render.item + +import dev.hybridlabs.aquatic.HybridAquatic +import dev.hybridlabs.aquatic.client.model.HybridAquaticEntityModelLayers +import dev.hybridlabs.aquatic.client.model.item.FishingNetItemModel +import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry +import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener +import net.minecraft.client.MinecraftClient +import net.minecraft.client.render.VertexConsumerProvider +import net.minecraft.client.render.item.ItemRenderer +import net.minecraft.client.render.model.BakedModel +import net.minecraft.client.render.model.json.ModelTransformationMode +import net.minecraft.client.util.ModelIdentifier +import net.minecraft.client.util.math.MatrixStack +import net.minecraft.item.ItemStack +import net.minecraft.resource.ResourceManager +import net.minecraft.util.Identifier + +object FishingNetItemRenderer : BuiltinItemRendererRegistry.DynamicItemRenderer, SimpleSynchronousResourceReloadListener { + private val TEXTURE_ID = Identifier(HybridAquatic.MOD_ID, "textures/item/fishing_net.png") + val INVENTORY_MODEL_ID = Identifier(HybridAquatic.MOD_ID, "item/fishing_net_in_inventory") + private val INVENTORY_MODEL_IDENTIFIER = ModelIdentifier(INVENTORY_MODEL_ID, "inventory") + + private val LISTENER_ID = Identifier(HybridAquatic.MOD_ID, "fishing_net_item_model") + + private lateinit var model: FishingNetItemModel + private lateinit var inventoryModel: BakedModel + private lateinit var itemRenderer: ItemRenderer + + override fun render( + stack: ItemStack, + mode: ModelTransformationMode, + matrices: MatrixStack, + vertices: VertexConsumerProvider, + light: Int, + overlay: Int + ) { + itemRenderer.let { renderer -> + if (mode == ModelTransformationMode.GUI || mode == ModelTransformationMode.GROUND || mode == ModelTransformationMode.FIXED) { + matrices.push() + renderer.renderItem( + stack, + mode, + false, + matrices, + vertices, + light, + overlay, + inventoryModel + ) + matrices.pop() + } else { + matrices.push() + matrices.scale(1.0f, -1.0f, -1.0f) + val vertex = ItemRenderer.getDirectItemGlintConsumer( + vertices, + model.getLayer(TEXTURE_ID), + false, + stack.hasGlint() + ) + model.render(matrices, vertex, light, overlay, 1.0f, 1.0f, 1.0f, 1.0f) + matrices.pop() + } + } + } + + override fun reload(manager: ResourceManager) { + val client = MinecraftClient.getInstance() + client.itemRenderer.let { renderer -> + itemRenderer = renderer + + val entityModelLoader = client.entityModelLoader + val bakedModelManager = client.bakedModelManager + + model = FishingNetItemModel(entityModelLoader.getModelPart(HybridAquaticEntityModelLayers.FISHING_NET)) + inventoryModel = bakedModelManager.getModel(INVENTORY_MODEL_IDENTIFIER) + } + } + + override fun getFabricId(): Identifier { + return LISTENER_ID + } + + override fun getFabricDependencies(): Collection { + return listOf(ResourceReloadListenerKeys.MODELS) + } +} diff --git a/src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net.json b/src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net_in_inventory.json similarity index 50% rename from src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net.json rename to src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net_in_inventory.json index a3c50c095..bfba36670 100644 --- a/src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net.json +++ b/src/generated/resources/assets/hybrid-aquatic/models/item/fishing_net_in_inventory.json @@ -1,6 +1,6 @@ { "parent": "minecraft:item/generated", "textures": { - "layer0": "hybrid-aquatic:item/fishing_net" + "layer0": "hybrid-aquatic:item/fishing_net_in_inventory" } } \ No newline at end of file diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/data/client/ModelProvider.kt b/src/main/kotlin/dev/hybridlabs/aquatic/data/client/ModelProvider.kt index 2d487c904..2e5f52d7d 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/data/client/ModelProvider.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/data/client/ModelProvider.kt @@ -95,10 +95,11 @@ class ModelProvider(output: FabricDataOutput) : FabricModelProvider(output) { HybridAquaticItems.BARBED_HOOK, HybridAquaticItems.GLOWING_HOOK, HybridAquaticItems.MAGNETIC_HOOK, - HybridAquaticItems.FISHING_NET, ).forEach { item -> generator.register(item, Models.GENERATED) } + + generator.register(HybridAquaticItems.FISHING_NET, "_in_inventory", Models.GENERATED) } companion object { diff --git a/src/main/resources/assets/hybrid-aquatic/models/item/fishing_net.json b/src/main/resources/assets/hybrid-aquatic/models/item/fishing_net.json new file mode 100644 index 000000000..248259c7b --- /dev/null +++ b/src/main/resources/assets/hybrid-aquatic/models/item/fishing_net.json @@ -0,0 +1,125 @@ +{ + "parent": "minecraft:builtin/entity", + "gui_light": "front", + "display": { + "thirdperson_righthand": { + "rotation": [ + 0, + 60, + 0 + ], + "translation": [ + 11, + 17, + -2 + ], + "scale": [ + 1, + 1, + 1 + ] + }, + "thirdperson_lefthand": { + "rotation": [ + 0, + 60, + 0 + ], + "translation": [ + 3, + 17, + 12 + ], + "scale": [ + 1, + 1, + 1 + ] + }, + "firstperson_righthand": { + "rotation": [ + 0, + -90, + 25 + ], + "translation": [ + -3, + 17, + 1 + ], + "scale": [ + 1, + 1, + 1 + ] + }, + "firstperson_lefthand": { + "rotation": [ + 0, + 90, + -25 + ], + "translation": [ + 13, + 17, + 1 + ], + "scale": [ + 1, + 1, + 1 + ] + }, + "gui": { + "rotation": [ + 15, + -25, + -5 + ], + "translation": [ + 2, + 3, + 0 + ], + "scale": [ + 0.65, + 0.65, + 0.65 + ] + }, + "fixed": { + "rotation": [ + 0, + 180, + 0 + ], + "translation": [ + -2, + 4, + -5 + ], + "scale": [ + 0.5, + 0.5, + 0.5 + ] + }, + "ground": { + "rotation": [ + 0, + 0, + 0 + ], + "translation": [ + 4, + 4, + 2 + ], + "scale": [ + 0.25, + 0.25, + 0.25 + ] + } + } +} diff --git a/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net.png b/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net.png index d49b1678b..8730bd32d 100644 Binary files a/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net.png and b/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net.png differ diff --git a/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net_in_inventory.png b/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net_in_inventory.png new file mode 100644 index 000000000..d49b1678b Binary files /dev/null and b/src/main/resources/assets/hybrid-aquatic/textures/item/fishing_net_in_inventory.png differ