This commit is contained in:
2026-05-02 09:00:51 +02:00
parent 323d213291
commit c63912c1f3
6 changed files with 31 additions and 66 deletions

View File

@@ -1,8 +1,10 @@
package org.neoflock.neocomputers.platforms.fabric.client.model;
import kotlin.jvm.functions.Function1;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.impl.renderer.VanillaModelEncoder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.*;
@@ -49,7 +51,9 @@ public class FabricModelWrapper implements FabricBakedModel, UnbakedModel {
@Override
public @Nullable BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite> spriteGetter, ModelState state) {
model.bake(spriteGetter, state);
// NeoComputers.INSTANCE.getLOGGER().info("{}", spriteGetter.apply(new Material()));
model._bake(spriteGetter);
// model.bake((Function1<? super ResourceLocation, ? extends TextureAtlasSprite>) Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS));
return model;
}
}

View File

@@ -8,7 +8,7 @@ import org.neoflock.neocomputers.NeoComputers;
import org.neoflock.neocomputers.block.model.RobotModel;
public class ModelLoader implements ModelLoadingPlugin {
public static final ResourceLocation ROBOT = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "block/robot");
public static final ResourceLocation ROBOT = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "robot");
@Override
public void onInitializeModelLoader(Context pluginContext) {

View File

@@ -17,6 +17,7 @@ import net.minecraft.core.Direction
import net.minecraft.resources.ResourceLocation
import net.minecraft.util.RandomSource
import net.minecraft.world.level.block.state.BlockState
import org.neoflock.neocomputers.NeoComputers
import java.util.function.Function
abstract class AbstractModel : BakedModel {
@@ -43,11 +44,16 @@ abstract class AbstractModel : BakedModel {
}
}
fun _bake(spriteGetter: Function<Material, TextureAtlasSprite>): BakedModel {
bake { r: Material -> spriteGetter.apply(r) }
return this
}
override fun getParticleIcon(): TextureAtlasSprite? {
return atlas.apply(particle())
}
abstract fun bake(atlas: Function<Material?, TextureAtlasSprite?>, state: ModelState): BakedModel
abstract fun bake(atlas: (Material) -> TextureAtlasSprite)
abstract fun particle(): ResourceLocation
@@ -81,6 +87,8 @@ class SchizoConsumer {
if (sprite == null || normal == null) {
throw Error("quad not started")
}
// NeoComputers.LOGGER.info("{} {} -> {} {} ", u, v, sprite!!.getU(u), sprite!!.getV(v))
vertices.add(x.toBits())
vertices.add(y.toBits())
vertices.add(z.toBits())

View File

@@ -24,10 +24,10 @@ class RobotModel() : AbstractModel() {
val l = 0.5f-size;
val h = 0.5f+size;
// override fun bake(atlas: (ResourceLocation) -> TextureAtlasSprite) {
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, "robot")))!!
override fun bake(atlas: (Material) -> TextureAtlasSprite) {
// override fun bake(atlas: Function<Material?, TextureAtlasSprite?>, state: ModelState): BakedModel {
val sprite = atlas(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
@@ -56,7 +56,6 @@ class RobotModel() : AbstractModel() {
this.mesh = verts.mesh
return this
}
fun bakeTri(verts: SchizoConsumer, normal: Direction, sprite: TextureAtlasSprite, lx: Float, lz: Float, rx: Float, rz: Float, dy: Float, uy: Float, lu: Float, lv: Float, ru: Float, rv: Float) {

View File

@@ -5,6 +5,7 @@ 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.model.geom.ModelPart
import net.minecraft.client.renderer.ItemBlockRenderTypes
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.RenderStateShard
@@ -18,6 +19,7 @@ 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.ModelResourceLocation
import net.minecraft.client.resources.model.ModelState
import net.minecraft.resources.ResourceLocation
import net.minecraft.util.RandomSource
@@ -27,70 +29,22 @@ 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 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 loc: ResourceLocation = ResourceLocation.fromNamespaceAndPath(NeoComputers.MODID, "robot")
var model: BakedModel? = Minecraft.getInstance().modelManager.getModel(ModelResourceLocation.inventory(loc))
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.pushPose()
poseStack.translate(0f, sin(ent.level!!.dayTime.toFloat()/20F)*0.02F, 0f)
val buffer = bufferSource.getBuffer(RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS))
renderer.renderModel(poseStack.last(), buffer, ent.blockState, model!!, 1f, 1f, 1f, packedLight, 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.
}
}
}

View File

@@ -1,7 +1,7 @@
{
"variants": {
"": {
"model": ""
"model": "neocomputers:block/robot"
}
}
}