cute trick (probably too cute)

This commit is contained in:
quat1024 2023-07-02 05:41:40 -04:00
parent 0c4a7f1ed8
commit ed42e4da9f
3 changed files with 23 additions and 38 deletions

View File

@ -18,7 +18,10 @@ Template blocks can be placed in the world, then right-clicked with a full-size
* Re-generalize the model system (I removed a layer of indirection while rewriting it, so it's just slopes now)
* Upside-down slopes would be nice...
* Pass UVs as part of the mesh and retexture them at runtime too
* "Counterrotate" blockstates
* In the old system, the north/south/east/west faces were constructed individually, so it'd look at the north side of the theme model when computing the north face, the east side of the theme model when computing the east face, etc
* In the current system, there is only one (south-facing) slope model, and I move its vertices around with a quad transformer to obtain other rotations. (built off the vanilla `AffineTransformation`)
* But this means... when i'm building the "left" side of the slope, what side of the block should i look at? I have to undo this affine transformation
## Notes for addon developers

View File

@ -5,13 +5,17 @@ import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.minecraft.util.math.Direction;
public class SlopeBaseMesh {
public static final int TAG_SLOPE = 0;
public static final int TAG_LEFT = 1;
public static final int TAG_RIGHT = 2;
public static final int TAG_BACK = 3;
public static final int TAG_BOTTOM = 4;
/**
* @see SlopeQuadTransformFactory.Transformer for why these values were chosen
*/
public static final int TAG_SLOPE = Direction.UP.ordinal();
public static final int TAG_LEFT = Direction.EAST.ordinal();
public static final int TAG_RIGHT = Direction.WEST.ordinal();
public static final int TAG_BACK = Direction.SOUTH.ordinal();
public static final int TAG_BOTTOM = Direction.DOWN.ordinal();
public static Mesh make() {
Renderer renderer = RendererAccess.INSTANCE.getRenderer();

View File

@ -16,7 +16,6 @@ import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
@ -37,8 +36,6 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
@Override
public @NotNull RenderContext.QuadTransform blockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
Direction dir = state.get(Properties.HORIZONTAL_FACING);
Object renderAttach = ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos);
BlockState template = (renderAttach instanceof BlockState s) ? s : Blocks.AIR.getDefaultState();
Block block = template.getBlock();
@ -47,7 +44,7 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
RenderMaterial material;
int globalTint;
if(block == null || block == Blocks.AIR) {
if(block == Blocks.AIR) {
appearance = tam.getDefaultAppearance();
material = r.materialFinder().clear().blendMode(BlendMode.CUTOUT).find();
globalTint = 0xFFFFFF;
@ -72,39 +69,20 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
return new Transformer(tam.getDefaultAppearance(), r.materialFinder().clear().find(), 0xFFFFFF);
}
private static record Transformer(TemplateAppearance appearance, RenderMaterial material, int color) implements RenderContext.QuadTransform {
public static record Transformer(TemplateAppearance appearance, RenderMaterial material, int color) implements RenderContext.QuadTransform {
private static final Direction[] DIRECTIONS = Direction.values();
@Override
public boolean transform(MutableQuadView quad) {
quad.material(material);
Sprite sprite = null;
//The quad tag numbers were selected so this magic trick works:
Direction dir = DIRECTIONS[quad.tag()];
//TODO: this newly-simplified direction passing in hasColor is almost certainly incorrect
switch(quad.tag()) {
case SlopeBaseMesh.TAG_SLOPE -> {
if(appearance.hasColor(Direction.UP)) quad.color(color, color, color, color);
sprite = appearance.getSprite(Direction.UP);
}
case SlopeBaseMesh.TAG_LEFT -> {
if(appearance.hasColor(Direction.EAST)) quad.color(color, color, color, color);
sprite = appearance.getSprite(Direction.EAST);
}
case SlopeBaseMesh.TAG_RIGHT -> {
if(appearance.hasColor(Direction.WEST)) quad.color(color, color, color, color);
sprite = appearance.getSprite(Direction.WEST);
}
case SlopeBaseMesh.TAG_BACK -> {
if(appearance.hasColor(Direction.SOUTH)) quad.color(color, color, color, color);
sprite = appearance.getSprite(Direction.SOUTH);
}
case SlopeBaseMesh.TAG_BOTTOM -> {
if(appearance.hasColor(Direction.DOWN)) quad.color(color, color, color, color);
sprite = appearance.getSprite(Direction.DOWN);
}
}
if(sprite == null) return false; //remove this quad
//TODO: this newly-simplified direction passing to hasColor is almost certainly incorrect
// I think hasColor was kinda incorrect in the first place tho
if(appearance.hasColor(dir)) quad.color(color, color, color, color);
Sprite sprite = appearance.getSprite(dir);
quad.spriteBake(sprite, MutableQuadView.BAKE_NORMALIZED);
return true;