Skip to content

Commit

Permalink
Inline platform-specific model builders
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperCode1 committed Dec 8, 2024
1 parent 7617c8e commit 2697fc1
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 423 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
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");
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* 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);

Expand Down Expand Up @@ -88,7 +88,7 @@ private record TransformedPartial<T>(PartialModel partial, T key, BiConsumer<T,
private Model create() {
var stack = new PoseStack();
transformer.accept(key, stack);
return BakedModelBuilder.create(partial.get())
return new BakedModelBuilder(partial.get())
.poseStack(stack)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

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;
Expand All @@ -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;
Expand All @@ -55,5 +50,11 @@ public BakedModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material>
return this;
}

public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}

return FlwLibXplat.INSTANCE.buildBakedModelBuilder(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

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;
Expand All @@ -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;
Expand All @@ -47,5 +42,11 @@ public BlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material>
return this;
}

public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}

return FlwLibXplat.INSTANCE.buildBlockModelBuilder(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

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
Expand All @@ -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;
Expand All @@ -48,5 +43,11 @@ public MultiBlockModelBuilder materialFunc(BiFunction<RenderType, Boolean, Mater
return this;
}

public abstract SimpleModel build();
public SimpleModel build() {
if (materialFunc == null) {
materialFunc = ModelUtil::getMaterial;
}

return FlwLibXplat.INSTANCE.buildMultiBlockModelBuilder(this);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2697fc1

Please sign in to comment.