render robot model with blockentrenderer

This commit is contained in:
2026-05-01 23:25:22 +02:00
parent b8968942f8
commit 323d213291
12 changed files with 153 additions and 150 deletions

View File

@@ -35,7 +35,7 @@ object Blocks {
val REDSTONEIO_BLOCK: RegistrySupplier<Block> = BaseBlock.register("redio") { RedstoneIOBlock() }
val CABLE_BLOCK: RegistrySupplier<Block> = BaseBlock.register("cable") { CableBlock() }
val RELAY_BLOCK: RegistrySupplier<Block> = BaseBlock.register("relay") { RelayBlock() }
val ROBOT_BLOCK: RegistrySupplier<Block> = BaseBlock.register("robot") { BaseBlock(BlockBehaviour.Properties.of().noOcclusion()) }
val ROBOT_BLOCK: RegistrySupplier<Block> = BaseBlock.register("robot") { RobotBlock() }
fun registerBlockItems() {
BLOCKS.forEach(Consumer { sup: RegistrySupplier<Block> ->

View File

@@ -0,0 +1,26 @@
package org.neoflock.neocomputers.block
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.RenderShape
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockBehaviour
import net.minecraft.world.level.block.state.BlockState
import org.neoflock.neocomputers.NeoComputers
import org.neoflock.neocomputers.entity.RobotEntity
class RobotBlock : BaseBlock(Properties.of().noOcclusion()), EntityBlock { // todo: node stuff
override fun newBlockEntity(pos: BlockPos, state: BlockState): BlockEntity {
NeoComputers.LOGGER.info("block entity created..")
Blocks.CHEST
return RobotEntity(pos, state)
}
override fun getRenderShape(state: BlockState): RenderShape {
return RenderShape.INVISIBLE // this is so not good
}
// public RenderShape getRenderShape(BlockState state) {
// return RenderShape.ENTITYBLOCK_ANIMATED;
// }
}

View File

@@ -19,7 +19,7 @@ import net.minecraft.util.RandomSource
import net.minecraft.world.level.block.state.BlockState
import java.util.function.Function
abstract class AbstractModel : BakedModel, UnbakedModel {
abstract class AbstractModel : BakedModel {
val atlas = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS)
var baker: ModelBaker? = null;
var mesh: Map<Direction, List<BakedQuad>> = mapOf(
@@ -47,7 +47,7 @@ abstract class AbstractModel : BakedModel, UnbakedModel {
return atlas.apply(particle())
}
// abstract fun bake(atlas: (ResourceLocation) -> TextureAtlasSprite)
abstract fun bake(atlas: Function<Material?, TextureAtlasSprite?>, state: ModelState): BakedModel
abstract fun particle(): ResourceLocation

View File

@@ -23,14 +23,11 @@ class RobotModel() : AbstractModel() {
val size = 0.4f
val l = 0.5f-size;
val h = 0.5f+size;
override fun getDependencies(): Collection<ResourceLocation?> = listOf()
override fun resolveParents(resolver: Function<ResourceLocation?, UnbakedModel?>) { }
// override fun bake(atlas: (ResourceLocation) -> TextureAtlasSprite) {
override fun bake(baker: ModelBaker, atlas: Function<Material?, TextureAtlasSprite?>, state: ModelState): BakedModel? {
override fun bake(atlas: Function<Material?, TextureAtlasSprite?>, state: ModelState): BakedModel {
NeoComputers.LOGGER.info("baking")
val sprite = atlas.apply(Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "block/robot")))!!
val sprite = atlas.apply(Material(TextureAtlas.LOCATION_BLOCKS, ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "robot")))!!
var verts: SchizoConsumer = SchizoConsumer()
// top pyramid, enjoy reading this schizo mess

View File

@@ -94,6 +94,12 @@ object BlockEntities {
)
}
val ROBOT_ENTITY: RegistrySupplier<BlockEntityType<RobotEntity>> = BLOCKENTITIES.register("robot") {
BlockEntityType(
::RobotEntity, setOf(Blocks.ROBOT_BLOCK.get()), BullshitFix()
)
}
fun registerPowerBlocks() {
PowerManager.registerPowerDevice(CAPACITOR_ENTITY.get())
PowerManager.registerPowerDevice(CAPACITOR2_ENTITY.get())

View File

@@ -0,0 +1,15 @@
package org.neoflock.neocomputers.entity
import net.minecraft.client.model.geom.ModelPart
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import org.neoflock.neocomputers.NeoComputers
class RobotEntity(pos: BlockPos, state: BlockState) : BlockEntity(BlockEntities.ROBOT_ENTITY.get(), pos, state,) {
val body: ModelPart? = null
init {
NeoComputers.LOGGER.info("yooo")
}
}

View File

@@ -0,0 +1,96 @@
package org.neoflock.neocomputers.entity.render
import com.mojang.blaze3d.vertex.DefaultVertexFormat
import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.blaze3d.vertex.VertexConsumer
import com.mojang.blaze3d.vertex.VertexFormat
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.ItemBlockRenderTypes
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.RenderStateShard
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.renderer.block.ModelBlockRenderer
import net.minecraft.client.renderer.block.model.BakedQuad
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.client.renderer.texture.OverlayTexture
import net.minecraft.client.renderer.texture.TextureAtlas
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.resources.model.BakedModel
import net.minecraft.client.resources.model.Material
import net.minecraft.client.resources.model.ModelState
import net.minecraft.resources.ResourceLocation
import net.minecraft.util.RandomSource
import org.neoflock.neocomputers.NeoComputers
import org.neoflock.neocomputers.block.model.RobotModel
import org.neoflock.neocomputers.entity.RobotEntity
import kotlin.math.sin
class RobotEntityRenderer(val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<RobotEntity> {
// val body: ModelPart = context.modelSet.bakeLayer(ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "block/robot"), "inventory"))
// val body: BlockModel = BlockModel
val atlas: (Material?) -> TextureAtlasSprite = { m ->
Minecraft.getInstance().getTextureAtlas(m!!.atlasLocation()).apply(m!!.texture())
}
val loc: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "block/robot")
var model: BakedModel? = RobotModel().bake(atlas, object : ModelState {})
val renderer: ModelBlockRenderer = ModelBlockRenderer(Minecraft.getInstance().blockColors) // so ass
// val RENDER_TYPE = RenderType.create("nc_case", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS,
// RenderType.TRANSIENT_BUFFER_SIZE, RenderType.CompositeState.builder()
// .setShaderState(RenderStateShard.RENDERTYPE_)
// .createCompositeState(false))
// val RENDER_TYPE = { tex: ResourceLocation -> RenderType.create("nc_robot", DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, VertexFormat.Mode.QUADS,
// RenderType.SMALL_BUFFER_SIZE, RenderType.CompositeState.builder()
// .setShaderState(RenderStateShard.POSITION_COLOR_TEX_LIGHTMAP_SHADER)
// .setLightmapState(RenderStateShard.LIGHTMAP)
// .setTextureState(RenderStateShard.TextureStateShard(tex, false, false))
// .createCompositeState(false)) }
override fun render(ent: RobotEntity, partialTick: Float, poseStack: PoseStack, bufferSource: MultiBufferSource, packedLight: Int, packedOverlay: Int) {
// if (model == null) this.model = Minecraft.getInstance().modelManager.getModel(loc) // worst cant describe how much ts sux holy shit!!!!!
// if (model == null) this.model =
// NeoComputers.LOGGER.info(model.toString())
poseStack.pushPose()
// NeoComputers.LOGGER.info(sin(ent.level!!.dayTime.toFloat()/20F).toString())
poseStack.translate(0f, sin(ent.level!!.dayTime.toFloat()/20F)*0.2F, 0f)
// val buffer = bufferSource.getBuffer(RENDER_TYPE(ResourceLocation.withDefaultNamespace("textures/atlas/block.png-atlas")))
// Minecraft.getInstance().blockRenderer
// val buffer = bufferSource.getBuffer(RenderType.entityCutout(ResourceLocation.withDefaultNamespace("textures/atlas/block.png")))
NeoComputers.LOGGER.info(packedLight.toHexString())
renderModel(poseStack.last(), bufferSource, model!!.getQuads(ent.blockState, null, RandomSource.create()), packedLight)
// renderer.renderModel(poseStack.last(), bufferSource, ent.blockState, model!!, 1f, 1f, 1f, 0xF000F0, packedOverlay)
poseStack.popPose()
}
fun renderModel(pose: PoseStack.Pose, bufferSource: MultiBufferSource, quads: List<BakedQuad>, light: Int) {
for (quad in quads) {
val data = quad.vertices
val buffer = bufferSource.getBuffer(RenderType.entitySolid(ResourceLocation.fromNamespaceAndPath(
NeoComputers.MODID, "textures/block/robot.png"))) // TODO: use atlas tex instead of ts, also slanted normals
for (i in 0..3) {
val offset = i*8
val fu = quad.sprite.u1 - quad.sprite.u0
val fv = quad.sprite.v1 - quad.sprite.v0
val x = Float.fromBits(data[offset+0])
val y = Float.fromBits(data[offset+1])
val z = Float.fromBits(data[offset+2])
val col = data[offset+3]
val u = Float.fromBits(data[offset+4])/fu
val v = Float.fromBits(data[offset+5])/fv
buffer.addVertex(pose, x, y, z).setColor(col).setUv(u, v).setLight(light).setNormal(quad.direction.stepX.toFloat(),quad.direction.stepY.toFloat(),quad.direction.stepZ.toFloat()).setOverlay(
OverlayTexture.NO_OVERLAY)
// buffer.addVertex(pose, x, y, z).setUv(u, v)
}
// Minecraft.getInstance().blockRenderer.
}
}
}