Inline platform-specific model builders

This commit is contained in:
PepperCode1 2024-12-08 12:15:52 -08:00
parent 7617c8e415
commit 2697fc11d3
18 changed files with 172 additions and 423 deletions

View file

@ -2,8 +2,6 @@ package dev.engine_room.flywheel.api;
import org.joml.Matrix4fc;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;

View file

@ -3,16 +3,14 @@ package dev.engine_room.flywheel.lib.internal;
import org.jetbrains.annotations.UnknownNullability;
import dev.engine_room.flywheel.api.internal.DependencyInjection;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public interface FlwLibXplat {
FlwLibXplat INSTANCE = DependencyInjection.load(FlwLibXplat.class, "dev.engine_room.flywheel.impl.FlwLibXplatImpl");
@ -22,9 +20,9 @@ public interface FlwLibXplat {
BlockRenderDispatcher createVanillaBlockRenderDispatcher();
BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel);
SimpleModel buildBakedModelBuilder(BakedModelBuilder builder);
BlockModelBuilder createBlockModelBuilder(BlockState state);
SimpleModel buildBlockModelBuilder(BlockModelBuilder builder);
MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions);
SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder);
}

View file

@ -20,7 +20,7 @@ import net.minecraft.client.renderer.block.BlockRenderDispatcher;
public final class ModelUtil {
/**
* An alternative BlockRenderDispatcher that circumvents the Forge rendering pipeline to ensure consistency.
* An alternative BlockRenderDispatcher that circumvents the NeoForge rendering pipeline to ensure consistency.
* Meant to be used for virtual rendering.
*/
public static final BlockRenderDispatcher VANILLA_RENDERER = FlwLibXplat.INSTANCE.createVanillaBlockRenderDispatcher();

View file

@ -20,9 +20,9 @@ import net.minecraft.world.level.block.state.BlockState;
* method with the same parameters will return the same object.
*/
public final class Models {
private static final ResourceReloadCache<BlockState, Model> BLOCK_STATE = new ResourceReloadCache<>(it -> BlockModelBuilder.create(it)
private static final ResourceReloadCache<BlockState, Model> BLOCK_STATE = new ResourceReloadCache<>(it -> new BlockModelBuilder(it)
.build());
private static final ResourceReloadCache<PartialModel, Model> PARTIAL = new ResourceReloadCache<>(it -> BakedModelBuilder.create(it.get())
private static final ResourceReloadCache<PartialModel, Model> PARTIAL = new ResourceReloadCache<>(it -> new BakedModelBuilder(it.get())
.build());
private static final ResourceReloadCache<TransformedPartial<?>, Model> TRANSFORMED_PARTIAL = new ResourceReloadCache<>(TransformedPartial::create);
@ -88,7 +88,7 @@ public final class Models {
private Model create() {
var stack = new PoseStack();
transformer.accept(key, stack);
return BakedModelBuilder.create(partial.get())
return new BakedModelBuilder(partial.get())
.poseStack(stack)
.build();
}

View file

@ -2,21 +2,20 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
@ApiStatus.NonExtendable
public abstract class BakedModelBuilder {
public final class BakedModelBuilder {
final BakedModel bakedModel;
@Nullable
BlockAndTintGetter level;
@ -27,14 +26,10 @@ public abstract class BakedModelBuilder {
@Nullable
BiFunction<RenderType, Boolean, Material> materialFunc;
BakedModelBuilder(BakedModel bakedModel) {
public BakedModelBuilder(BakedModel bakedModel) {
this.bakedModel = bakedModel;
}
public static BakedModelBuilder create(BakedModel bakedModel) {
return FlwLibXplat.INSTANCE.createBakedModelBuilder(bakedModel);
}
public BakedModelBuilder level(BlockAndTintGetter level) {
this.level = level;
return this;
@ -55,5 +50,11 @@ public abstract class BakedModelBuilder {
return this;
}
public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
return FlwLibXplat.INSTANCE.buildBakedModelBuilder(this);
}
}

View file

@ -2,20 +2,19 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
@ApiStatus.NonExtendable
public abstract class BlockModelBuilder {
public final class BlockModelBuilder {
final BlockState state;
@Nullable
BlockAndTintGetter level;
@ -24,14 +23,10 @@ public abstract class BlockModelBuilder {
@Nullable
BiFunction<RenderType, Boolean, Material> materialFunc;
BlockModelBuilder(BlockState state) {
public BlockModelBuilder(BlockState state) {
this.state = state;
}
public static BlockModelBuilder create(BlockState state) {
return FlwLibXplat.INSTANCE.createBlockModelBuilder(state);
}
public BlockModelBuilder level(BlockAndTintGetter level) {
this.level = level;
return this;
@ -47,5 +42,11 @@ public abstract class BlockModelBuilder {
return this;
}
public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
return FlwLibXplat.INSTANCE.buildBlockModelBuilder(this);
}
}

View file

@ -2,20 +2,19 @@ package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
@ApiStatus.NonExtendable
public abstract class MultiBlockModelBuilder {
public final class MultiBlockModelBuilder {
final BlockAndTintGetter level;
final Iterable<BlockPos> positions;
@Nullable
@ -24,15 +23,11 @@ public abstract class MultiBlockModelBuilder {
@Nullable
BiFunction<RenderType, Boolean, Material> materialFunc;
MultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
public MultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
this.level = level;
this.positions = positions;
}
public static MultiBlockModelBuilder create(BlockAndTintGetter level, Iterable<BlockPos> positions) {
return FlwLibXplat.INSTANCE.createMultiBlockModelBuilder(level, positions);
}
public MultiBlockModelBuilder poseStack(PoseStack poseStack) {
this.poseStack = poseStack;
return this;
@ -48,5 +43,11 @@ public abstract class MultiBlockModelBuilder {
return this;
}
public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
return FlwLibXplat.INSTANCE.buildMultiBlockModelBuilder(this);
}
}

View file

@ -1,64 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public final class FabricBakedModelBuilder extends BakedModelBuilder {
public FabricBakedModelBuilder(BakedModel bakedModel) {
super(bakedModel);
}
@Override
public FabricBakedModelBuilder level(BlockAndTintGetter level) {
super.level(level);
return this;
}
@Override
public FabricBakedModelBuilder blockState(BlockState blockState) {
super.blockState(blockState);
return this;
}
@Override
public FabricBakedModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public FabricBakedModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -1,57 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public final class FabricBlockModelBuilder extends BlockModelBuilder {
public FabricBlockModelBuilder(BlockState state) {
super(state);
}
@Override
public FabricBlockModelBuilder level(BlockAndTintGetter level) {
super.level(level);
return this;
}
@Override
public FabricBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public FabricBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -1,57 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
public final class FabricMultiBlockModelBuilder extends MultiBlockModelBuilder {
public FabricMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
super(level, positions);
}
@Override
public FabricMultiBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public FabricMultiBlockModelBuilder enableFluidRendering() {
super.enableFluidRendering();
return this;
}
@Override
public FabricMultiBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, renderFluids, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -0,0 +1,57 @@
package dev.engine_room.flywheel.lib.model.baked;
import org.jetbrains.annotations.ApiStatus;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
@ApiStatus.Internal
public final class ModelBuilderImpl {
private ModelBuilderImpl() {
}
public static SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), builder.level, builder.bakedModel, builder.blockState, builder.poseStack, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + builder.bakedModel + ",renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
public static SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, builder.level, builder.state, builder.poseStack, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + builder.state + ",renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
public static SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, builder.positions.iterator(), builder.level, builder.poseStack, builder.renderFluids, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
}

View file

@ -3,20 +3,16 @@ package dev.engine_room.flywheel.impl;
import org.jetbrains.annotations.UnknownNullability;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.FabricBakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.FabricBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.FabricMultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ModelBuilderImpl;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public class FlwLibXplatImpl implements FlwLibXplat {
@Override
@ -31,17 +27,17 @@ public class FlwLibXplatImpl implements FlwLibXplat {
}
@Override
public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) {
return new FabricBakedModelBuilder(bakedModel);
public SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) {
return ModelBuilderImpl.buildBakedModelBuilder(builder);
}
@Override
public BlockModelBuilder createBlockModelBuilder(BlockState state) {
return new FabricBlockModelBuilder(state);
public SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) {
return ModelBuilderImpl.buildBlockModelBuilder(builder);
}
@Override
public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
return new FabricMultiBlockModelBuilder(level, positions);
public SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) {
return ModelBuilderImpl.buildMultiBlockModelBuilder(builder);
}
}

View file

@ -0,0 +1,57 @@
package dev.engine_room.flywheel.lib.model.baked;
import org.jetbrains.annotations.ApiStatus;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
@ApiStatus.Internal
public final class ModelBuilderImpl {
private ModelBuilderImpl() {
}
public static SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), builder.level, builder.bakedModel, builder.blockState, builder.poseStack, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + builder.bakedModel + ",renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
public static SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, builder.level, builder.state, builder.poseStack, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + builder.state + ",renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
public static SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) {
var builder1 = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, builder.positions.iterator(), builder.level, builder.poseStack, builder.renderFluids, (renderType, shaded, data) -> {
Material material = builder.materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded);
builder1.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder1.build());
}
}

View file

@ -1,64 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public final class NeoForgeBakedModelBuilder extends BakedModelBuilder {
public NeoForgeBakedModelBuilder(BakedModel bakedModel) {
super(bakedModel);
}
@Override
public NeoForgeBakedModelBuilder level(BlockAndTintGetter level) {
super.level(level);
return this;
}
@Override
public NeoForgeBakedModelBuilder blockState(BlockState blockState) {
super.blockState(blockState);
return this;
}
@Override
public NeoForgeBakedModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public NeoForgeBakedModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferSingle(ModelUtil.VANILLA_RENDERER.getModelRenderer(), level, bakedModel, blockState, poseStack, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BakedModelBuilder," + "bakedModel=" + bakedModel + ",renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -1,57 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
public final class NeoForgeBlockModelBuilder extends BlockModelBuilder {
public NeoForgeBlockModelBuilder(BlockState state) {
super(state);
}
@Override
public NeoForgeBlockModelBuilder level(BlockAndTintGetter level) {
super.level(level);
return this;
}
@Override
public NeoForgeBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public NeoForgeBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferBlock(ModelUtil.VANILLA_RENDERER, level, state, poseStack, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=BlockModelBuilder," + "blockState=" + state + ",renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -1,57 +0,0 @@
package dev.engine_room.flywheel.lib.model.baked;
import java.util.function.BiFunction;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.model.Model;
import dev.engine_room.flywheel.lib.model.ModelUtil;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
public final class NeoForgeMultiBlockModelBuilder extends MultiBlockModelBuilder {
public NeoForgeMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
super(level, positions);
}
@Override
public NeoForgeMultiBlockModelBuilder poseStack(PoseStack poseStack) {
super.poseStack(poseStack);
return this;
}
@Override
public NeoForgeMultiBlockModelBuilder enableFluidRendering() {
super.enableFluidRendering();
return this;
}
@Override
public NeoForgeMultiBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
super.materialFunc(materialFunc);
return this;
}
@Override
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}
var builder = ChunkLayerSortedListBuilder.<Model.ConfiguredMesh>getThreadLocal();
BakedModelBufferer.bufferMultiBlock(ModelUtil.VANILLA_RENDERER, positions.iterator(), level, poseStack, renderFluids, (renderType, shaded, data) -> {
Material material = materialFunc.apply(renderType, shaded);
if (material != null) {
Mesh mesh = MeshHelper.blockVerticesToMesh(data, "source=MultiBlockModelBuilder," + "renderType=" + renderType + ",shaded=" + shaded);
builder.add(renderType, new Model.ConfiguredMesh(material, mesh));
}
});
return new SimpleModel(builder.build());
}
}

View file

@ -5,22 +5,18 @@ import java.lang.reflect.Field;
import org.jetbrains.annotations.UnknownNullability;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ModelBuilderImpl;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeBakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeBlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.NeoForgeMultiBlockModelBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
public class FlwLibXplatImpl implements FlwLibXplat {
@ -48,17 +44,17 @@ public class FlwLibXplatImpl implements FlwLibXplat {
}
@Override
public BakedModelBuilder createBakedModelBuilder(BakedModel bakedModel) {
return new NeoForgeBakedModelBuilder(bakedModel);
public SimpleModel buildBakedModelBuilder(BakedModelBuilder builder) {
return ModelBuilderImpl.buildBakedModelBuilder(builder);
}
@Override
public BlockModelBuilder createBlockModelBuilder(BlockState state) {
return new NeoForgeBlockModelBuilder(state);
public SimpleModel buildBlockModelBuilder(BlockModelBuilder builder) {
return ModelBuilderImpl.buildBlockModelBuilder(builder);
}
@Override
public MultiBlockModelBuilder createMultiBlockModelBuilder(BlockAndTintGetter level, Iterable<BlockPos> positions) {
return new NeoForgeMultiBlockModelBuilder(level, positions);
public SimpleModel buildMultiBlockModelBuilder(MultiBlockModelBuilder builder) {
return ModelBuilderImpl.buildMultiBlockModelBuilder(builder);
}
}

View file

@ -1,14 +1,14 @@
package dev.engine_room.flywheel;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.common.NeoForge;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.MixinEnvironment;
import net.minecraft.client.Minecraft;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.common.NeoForge;
@Mod("flywheel_testmod")
public class FlywheelTestModClient {