Permute faces
This commit is contained in:
parent
1b0fd21481
commit
3c57778ea1
@ -16,12 +16,8 @@ Template blocks can be placed in the world, then right-clicked with a full-size
|
|||||||
|
|
||||||
## Todo
|
## Todo
|
||||||
|
|
||||||
* 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...
|
||||||
* "Counterrotate" blockstates
|
* More templates !!
|
||||||
* 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
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ import net.minecraft.util.math.random.Random;
|
|||||||
import net.minecraft.world.BlockRenderView;
|
import net.minecraft.world.BlockRenderView;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public final class TemplateBakedModel extends ForwardingBakedModel {
|
public final class TemplateBakedModel extends ForwardingBakedModel {
|
||||||
@ -31,12 +33,28 @@ public final class TemplateBakedModel extends ForwardingBakedModel {
|
|||||||
this.tam = tam;
|
this.tam = tam;
|
||||||
this.affineTransformer = new AffineQuadTransformer(aff);
|
this.affineTransformer = new AffineQuadTransformer(aff);
|
||||||
this.baseMesh = baseMesh;
|
this.baseMesh = baseMesh;
|
||||||
|
|
||||||
|
//Hard to explain what this is for...
|
||||||
|
//Basically, the previous incarnation of this mod assembled the north/south/east/west faces all individually.
|
||||||
|
//This means it was easy to get the orientation of the block correct - to popular the north face of the slope, look at
|
||||||
|
//the north texture of the theme block. In this version, there is only *one* slope model that is dynamically rotated
|
||||||
|
//to form the other possible orientations. If I populate the north face of the model using the north face of the theme,
|
||||||
|
//that model will then be rotated so it's no longer facing the right way.
|
||||||
|
//
|
||||||
|
//This seems to work, but I'm kinda surprised I don't need to invert the transformation here, which is a clue that
|
||||||
|
//I don't really understand all the math, loool
|
||||||
|
for(Direction input : Direction.values()) {
|
||||||
|
Direction output = Direction.transform(aff.getMatrix(), input);
|
||||||
|
facePermutation.put(input, output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final TemplateAppearanceManager tam;
|
private final TemplateAppearanceManager tam;
|
||||||
private final AffineQuadTransformer affineTransformer;
|
private final AffineQuadTransformer affineTransformer;
|
||||||
private final Mesh baseMesh;
|
private final Mesh baseMesh;
|
||||||
|
|
||||||
|
private final Map<Direction, Direction> facePermutation = new EnumMap<>(Direction.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVanillaAdapter() {
|
public boolean isVanillaAdapter() {
|
||||||
return false;
|
return false;
|
||||||
@ -68,11 +86,11 @@ public final class TemplateBakedModel extends ForwardingBakedModel {
|
|||||||
|
|
||||||
public @NotNull RenderContext.QuadTransform retexturingBlockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
|
public @NotNull RenderContext.QuadTransform retexturingBlockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
|
||||||
BlockState template = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null;
|
BlockState template = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null;
|
||||||
if(template == null || template.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF);
|
if(template == null || template.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation);
|
||||||
|
|
||||||
BlockColorProvider prov = ColorProviderRegistry.BLOCK.get(template.getBlock());
|
BlockColorProvider prov = ColorProviderRegistry.BLOCK.get(template.getBlock());
|
||||||
int globalTint = prov != null ? prov.getColor(state, blockView, pos, 1) : 0xFFFFFFFF;
|
int globalTint = prov != null ? prov.getColor(state, blockView, pos, 1) : 0xFFFFFFFF;
|
||||||
return new RetexturingTransformer(tam.getAppearance(template), globalTint);
|
return new RetexturingTransformer(tam.getAppearance(template), globalTint, facePermutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull RenderContext.QuadTransform retexturingItemTransformer(ItemStack stack, Supplier<Random> randomSupplier) {
|
public @NotNull RenderContext.QuadTransform retexturingItemTransformer(ItemStack stack, Supplier<Random> randomSupplier) {
|
||||||
@ -80,13 +98,13 @@ public final class TemplateBakedModel extends ForwardingBakedModel {
|
|||||||
NbtCompound tag = BlockItem.getBlockEntityNbt(stack);
|
NbtCompound tag = BlockItem.getBlockEntityNbt(stack);
|
||||||
if(tag != null && tag.contains("BlockState")) {
|
if(tag != null && tag.contains("BlockState")) {
|
||||||
BlockState state = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), tag.getCompound("BlockState"));
|
BlockState state = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), tag.getCompound("BlockState"));
|
||||||
if(!state.isAir()) return new RetexturingTransformer(tam.getAppearance(state), 0xFFFFFFFF);
|
if(!state.isAir()) return new RetexturingTransformer(tam.getAppearance(state), 0xFFFFFFFF, facePermutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF);
|
return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static record RetexturingTransformer(TemplateAppearance appearance, int color) implements RenderContext.QuadTransform {
|
public static record RetexturingTransformer(TemplateAppearance appearance, int color, Map<Direction, Direction> facePermutation) implements RenderContext.QuadTransform {
|
||||||
private static final Direction[] DIRECTIONS = Direction.values();
|
private static final Direction[] DIRECTIONS = Direction.values();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,7 +112,7 @@ public final class TemplateBakedModel extends ForwardingBakedModel {
|
|||||||
quad.material(appearance.getRenderMaterial());
|
quad.material(appearance.getRenderMaterial());
|
||||||
|
|
||||||
//The quad tag numbers were selected so this magic trick works:
|
//The quad tag numbers were selected so this magic trick works:
|
||||||
Direction dir = DIRECTIONS[quad.tag()];
|
Direction dir = facePermutation.get(DIRECTIONS[quad.tag()]);
|
||||||
|
|
||||||
//TODO: this newly-simplified direction passing to 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
|
// I think hasColor was kinda incorrect in the first place tho
|
||||||
|
Loading…
Reference in New Issue
Block a user