cute trick (probably too cute)
This commit is contained in:
parent
0c4a7f1ed8
commit
ed42e4da9f
@ -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)
|
* 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...
|
* 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
|
## Notes for addon developers
|
||||||
|
|
||||||
|
@ -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.Mesh;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
|
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
public class SlopeBaseMesh {
|
public class SlopeBaseMesh {
|
||||||
public static final int TAG_SLOPE = 0;
|
/**
|
||||||
public static final int TAG_LEFT = 1;
|
* @see SlopeQuadTransformFactory.Transformer for why these values were chosen
|
||||||
public static final int TAG_RIGHT = 2;
|
*/
|
||||||
public static final int TAG_BACK = 3;
|
public static final int TAG_SLOPE = Direction.UP.ordinal();
|
||||||
public static final int TAG_BOTTOM = 4;
|
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() {
|
public static Mesh make() {
|
||||||
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
|
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
|
||||||
|
@ -16,7 +16,6 @@ import net.minecraft.client.color.block.BlockColorProvider;
|
|||||||
import net.minecraft.client.render.RenderLayers;
|
import net.minecraft.client.render.RenderLayers;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.property.Properties;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
@ -37,8 +36,6 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull RenderContext.QuadTransform blockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
|
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);
|
Object renderAttach = ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos);
|
||||||
BlockState template = (renderAttach instanceof BlockState s) ? s : Blocks.AIR.getDefaultState();
|
BlockState template = (renderAttach instanceof BlockState s) ? s : Blocks.AIR.getDefaultState();
|
||||||
Block block = template.getBlock();
|
Block block = template.getBlock();
|
||||||
@ -47,7 +44,7 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
|
|||||||
RenderMaterial material;
|
RenderMaterial material;
|
||||||
int globalTint;
|
int globalTint;
|
||||||
|
|
||||||
if(block == null || block == Blocks.AIR) {
|
if(block == Blocks.AIR) {
|
||||||
appearance = tam.getDefaultAppearance();
|
appearance = tam.getDefaultAppearance();
|
||||||
material = r.materialFinder().clear().blendMode(BlendMode.CUTOUT).find();
|
material = r.materialFinder().clear().blendMode(BlendMode.CUTOUT).find();
|
||||||
globalTint = 0xFFFFFF;
|
globalTint = 0xFFFFFF;
|
||||||
@ -72,39 +69,20 @@ public class SlopeQuadTransformFactory implements TemplateQuadTransformFactory {
|
|||||||
return new Transformer(tam.getDefaultAppearance(), r.materialFinder().clear().find(), 0xFFFFFF);
|
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
|
@Override
|
||||||
public boolean transform(MutableQuadView quad) {
|
public boolean transform(MutableQuadView quad) {
|
||||||
quad.material(material);
|
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
|
//TODO: this newly-simplified direction passing to hasColor is almost certainly incorrect
|
||||||
|
// I think hasColor was kinda incorrect in the first place tho
|
||||||
switch(quad.tag()) {
|
if(appearance.hasColor(dir)) quad.color(color, color, color, color);
|
||||||
case SlopeBaseMesh.TAG_SLOPE -> {
|
Sprite sprite = appearance.getSprite(dir);
|
||||||
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
|
|
||||||
|
|
||||||
quad.spriteBake(sprite, MutableQuadView.BAKE_NORMALIZED);
|
quad.spriteBake(sprite, MutableQuadView.BAKE_NORMALIZED);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user