Skip to content

Commit

Permalink
fishing net e
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Dec 15, 2023
1 parent 5f37e23 commit 5f88e27
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/client/kotlin/dev/hybridlabs/aquatic/HybridAquaticClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,49 @@ 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()
registerEntityRenderers()
registerWeatherRenderers()
registerTooltips()
registerHudAddons()

ModelLoadingPlugin.register { context -> context.addModels(FishingNetItemRenderer.INVENTORY_MODEL_ID.withPrefixedPath("models/")) }
}

private fun registerWeatherRenderers() {
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Identifier> {
return listOf(ResourceReloadListenerKeys.MODELS)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "hybrid-aquatic:item/fishing_net"
"layer0": "hybrid-aquatic:item/fishing_net_in_inventory"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
125 changes: 125 additions & 0 deletions src/main/resources/assets/hybrid-aquatic/models/item/fishing_net.json
Original file line number Diff line number Diff line change
@@ -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
]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5f88e27

Please sign in to comment.