159 lines
5.6 KiB
Kotlin
159 lines
5.6 KiB
Kotlin
|
package net.shadowfacts.phycon.client.model
|
||
|
|
||
|
import net.minecraft.block.BlockState
|
||
|
import net.minecraft.client.render.model.*
|
||
|
import net.minecraft.client.texture.Sprite
|
||
|
import net.minecraft.client.util.SpriteIdentifier
|
||
|
import net.minecraft.util.Identifier
|
||
|
import net.minecraft.util.math.Direction
|
||
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||
|
import java.util.Random
|
||
|
import java.util.function.Function
|
||
|
|
||
|
/**
|
||
|
* @author shadowfacts
|
||
|
*/
|
||
|
object InterfaceModel: UnbakedModel, BakedModel {
|
||
|
|
||
|
private val interfaceSideID = Identifier(PhysicalConnectivity.MODID, "block/interface_side")
|
||
|
private val interfaceCableStraightID = Identifier(PhysicalConnectivity.MODID, "block/interface_cable_straight")
|
||
|
private val interfaceCableCornerID = Identifier(PhysicalConnectivity.MODID, "block/interface_cable_corner")
|
||
|
private val interfaceCableCorner2ID = Identifier(PhysicalConnectivity.MODID, "block/interface_cable_corner_2")
|
||
|
private var interfaceSides = Array<BakedModel?>(6) { null }
|
||
|
private var interfaceCableStraight = Array<BakedModel?>(6) { null }
|
||
|
private var interfaceCableCorner = mutableMapOf<ModelRotation, BakedModel>()
|
||
|
private var interfaceCableCorner2 = mutableMapOf<ModelRotation, BakedModel>()
|
||
|
|
||
|
override fun getModelDependencies(): Collection<Identifier> {
|
||
|
return listOf(
|
||
|
interfaceSideID,
|
||
|
interfaceCableStraightID,
|
||
|
interfaceCableCornerID,
|
||
|
interfaceCableCorner2ID,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
override fun getTextureDependencies(
|
||
|
unbakedModelGetter: Function<Identifier, UnbakedModel>,
|
||
|
unresolvedTextureReferences: MutableSet<com.mojang.datafixers.util.Pair<String, String>>
|
||
|
): Collection<SpriteIdentifier> {
|
||
|
return listOf()
|
||
|
}
|
||
|
|
||
|
override fun bake(loader: ModelLoader, textureGetter: Function<SpriteIdentifier, Sprite>, rotationContainer: ModelBakeSettings, modelId: Identifier): BakedModel {
|
||
|
listOf(
|
||
|
ModelRotation.X0_Y0,
|
||
|
ModelRotation.X180_Y0,
|
||
|
ModelRotation.X270_Y0,
|
||
|
ModelRotation.X90_Y0,
|
||
|
ModelRotation.X90_Y90,
|
||
|
ModelRotation.X90_Y270,
|
||
|
).forEachIndexed { i, rot ->
|
||
|
interfaceSides[i] = loader.bake(interfaceSideID, rot)
|
||
|
interfaceCableStraight[i] = loader.bake(interfaceCableStraightID, rot)
|
||
|
}
|
||
|
|
||
|
mapOf(
|
||
|
interfaceCableCorner to interfaceCableCornerID to ModelRotation.values().toList(),
|
||
|
interfaceCableCorner2 to interfaceCableCorner2ID to listOf(
|
||
|
ModelRotation.X0_Y0,
|
||
|
ModelRotation.X0_Y90,
|
||
|
ModelRotation.X0_Y180,
|
||
|
ModelRotation.X0_Y270,
|
||
|
ModelRotation.X180_Y0,
|
||
|
ModelRotation.X180_Y90,
|
||
|
ModelRotation.X180_Y180,
|
||
|
ModelRotation.X180_Y270,
|
||
|
),
|
||
|
).forEach { (k, rotations) ->
|
||
|
val (map, id) = k
|
||
|
map.clear()
|
||
|
rotations.forEach { rot ->
|
||
|
val model = loader.bake(id, rot)
|
||
|
if (model == null) map.remove(rot)
|
||
|
else map[rot] = model
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return this
|
||
|
}
|
||
|
|
||
|
override fun getQuads(state: BlockState?, face: Direction?, random: Random): List<BakedQuad> {
|
||
|
if (state == null) return listOf()
|
||
|
val facing = state[FaceDeviceBlock.FACING]
|
||
|
val connection = state[FaceDeviceBlock.CABLE_CONNECTION]
|
||
|
|
||
|
val sideQuads = interfaceSides[facing.ordinal]?.getQuads(state, face, random) ?: listOf()
|
||
|
val cableQuads = if (connection == facing.opposite) {
|
||
|
interfaceCableStraight[facing.ordinal]?.getQuads(state, face, random) ?: listOf()
|
||
|
} else {
|
||
|
val model = when (facing) {
|
||
|
Direction.DOWN -> when (connection) {
|
||
|
Direction.NORTH -> interfaceCableCorner[ModelRotation.X0_Y0]
|
||
|
Direction.EAST -> interfaceCableCorner[ModelRotation.X0_Y90]
|
||
|
Direction.SOUTH -> interfaceCableCorner[ModelRotation.X0_Y180]
|
||
|
Direction.WEST -> interfaceCableCorner[ModelRotation.X0_Y270]
|
||
|
else -> null
|
||
|
}
|
||
|
Direction.UP -> when (connection) {
|
||
|
Direction.NORTH -> interfaceCableCorner[ModelRotation.X180_Y180]
|
||
|
Direction.EAST -> interfaceCableCorner[ModelRotation.X180_Y270]
|
||
|
Direction.SOUTH -> interfaceCableCorner[ModelRotation.X180_Y0]
|
||
|
Direction.WEST -> interfaceCableCorner[ModelRotation.X180_Y90]
|
||
|
else -> null
|
||
|
}
|
||
|
Direction.NORTH -> when (connection) {
|
||
|
Direction.UP -> interfaceCableCorner[ModelRotation.X270_Y0]
|
||
|
Direction.EAST -> interfaceCableCorner2[ModelRotation.X180_Y180]
|
||
|
Direction.DOWN -> interfaceCableCorner[ModelRotation.X90_Y180]
|
||
|
Direction.WEST -> interfaceCableCorner2[ModelRotation.X0_Y0]
|
||
|
else -> null
|
||
|
}
|
||
|
Direction.SOUTH -> when (connection) {
|
||
|
Direction.UP -> interfaceCableCorner[ModelRotation.X270_Y180]
|
||
|
Direction.WEST -> interfaceCableCorner2[ModelRotation.X180_Y0]
|
||
|
Direction.DOWN -> interfaceCableCorner[ModelRotation.X90_Y0]
|
||
|
Direction.EAST -> interfaceCableCorner2[ModelRotation.X0_Y180]
|
||
|
else -> null
|
||
|
}
|
||
|
Direction.WEST -> when (connection) {
|
||
|
Direction.UP -> interfaceCableCorner[ModelRotation.X270_Y270]
|
||
|
Direction.NORTH -> interfaceCableCorner2[ModelRotation.X180_Y90]
|
||
|
Direction.DOWN -> interfaceCableCorner[ModelRotation.X90_Y90]
|
||
|
Direction.SOUTH -> interfaceCableCorner2[ModelRotation.X0_Y270]
|
||
|
else -> null
|
||
|
}
|
||
|
Direction.EAST -> when (connection) {
|
||
|
Direction.UP -> interfaceCableCorner[ModelRotation.X270_Y90]
|
||
|
Direction.SOUTH -> interfaceCableCorner2[ModelRotation.X180_Y270]
|
||
|
Direction.DOWN -> interfaceCableCorner[ModelRotation.X90_Y270]
|
||
|
Direction.NORTH -> interfaceCableCorner2[ModelRotation.X0_Y90]
|
||
|
else -> null
|
||
|
}
|
||
|
else -> null
|
||
|
}
|
||
|
model?.getQuads(state, face, random) ?: listOf()
|
||
|
}
|
||
|
|
||
|
return sideQuads + cableQuads
|
||
|
}
|
||
|
|
||
|
override fun useAmbientOcclusion() = true
|
||
|
|
||
|
override fun hasDepth() = false
|
||
|
|
||
|
override fun isSideLit() = false
|
||
|
|
||
|
override fun isBuiltin() = false
|
||
|
|
||
|
override fun getSprite(): Sprite {
|
||
|
return interfaceSides.first()!!.sprite
|
||
|
}
|
||
|
|
||
|
override fun getTransformation() = null
|
||
|
|
||
|
override fun getOverrides() = null
|
||
|
|
||
|
}
|