poke at SpriteSet a bit
This commit is contained in:
parent
7928a9de70
commit
871c3ac54e
@ -19,14 +19,12 @@ public final class SlopeBakedModel extends ForwardingBakedModel {
|
||||
public SlopeBakedModel(BakedModel baseModel, BlockState slopeState, Function<SpriteIdentifier, Sprite> spriteLookup) {
|
||||
this.wrapped = baseModel;
|
||||
this.slopeState = slopeState;
|
||||
this.spriteLookup = spriteLookup;
|
||||
|
||||
this.xform = new SlopeMeshTransformer(spriteLookup);
|
||||
this.baseMesh = SlopeBaseMesh.make(slopeState);
|
||||
}
|
||||
|
||||
public final BlockState slopeState;
|
||||
public final Function<SpriteIdentifier, Sprite> spriteLookup;
|
||||
|
||||
private final MeshTransformer xform;
|
||||
private final Mesh baseMesh;
|
||||
|
@ -61,7 +61,7 @@ public class SlopeMeshTransformer implements MeshTransformer {
|
||||
.find();
|
||||
|
||||
BakedModel model = minecraft.getBlockRenderManager().getModel(template);
|
||||
sprites.prepare(model, randomSupplier.get());
|
||||
sprites.inspect(model, randomSupplier.get());
|
||||
BlockColorProvider blockColor = ColorProviderRegistry.BLOCK.get(block);
|
||||
if(blockColor != null) color = 0xff000000 | blockColor.getColor(template, blockView, pos, 1);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public record SlopeUnbakedModel(BlockState slopeState) implements UnbakedModel {
|
||||
|
||||
@Override
|
||||
public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> function, ModelBakeSettings modelBakeSettings, Identifier identifier) {
|
||||
//TODO: weird, should use my own model instead of STONE
|
||||
//TODO: weird, should use my own model instead
|
||||
BakedModel baseModel = baker.bake(BlockModels.getModelId(Blocks.SANDSTONE_STAIRS.getDefaultState()), modelBakeSettings);
|
||||
|
||||
return new SlopeBakedModel(baseModel, slopeState, function);
|
||||
|
@ -11,6 +11,7 @@ import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -33,7 +34,9 @@ public class SpriteSet {
|
||||
private final Sprite defaultSprite;
|
||||
private final Sprite missingSprite;
|
||||
|
||||
private final EnumMap<Direction, BakedQuad> quads = new EnumMap<>(Direction.class);
|
||||
private final EnumMap<Direction, Sprite> sprites = new EnumMap<>(Direction.class);
|
||||
private final EnumSet<Direction> hasColor = EnumSet.noneOf(Direction.class);
|
||||
|
||||
private boolean isDefault = true;
|
||||
|
||||
/** Allow re-use of instances to avoid allocation in render loop */
|
||||
@ -43,34 +46,34 @@ public class SpriteSet {
|
||||
|
||||
/** Allow re-use of instances to avoid allocation in render loop */
|
||||
//TODO: pass in block state?
|
||||
public void prepare(BakedModel model, Random rand) {
|
||||
this.quads.clear();
|
||||
public void inspect(BakedModel model, Random rand) {
|
||||
sprites.clear();
|
||||
hasColor.clear();
|
||||
isDefault = false;
|
||||
|
||||
for(Direction dir : DIRECTIONS) {
|
||||
List<BakedQuad> quads = model.getQuads(null, dir, rand);
|
||||
if(!quads.isEmpty()) this.quads.put(dir, quads.get(0));
|
||||
List<BakedQuad> sideQuads = model.getQuads(null, dir, rand);
|
||||
if(sideQuads.isEmpty()) continue;
|
||||
|
||||
BakedQuad arbitraryQuad = sideQuads.get(0); //maybe pick a largest quad instead?
|
||||
if(arbitraryQuad == null) continue;
|
||||
|
||||
if(arbitraryQuad.hasColor()) hasColor.add(dir);
|
||||
|
||||
Sprite sprite = arbitraryQuad.getSprite();
|
||||
if(sprite == null) continue;
|
||||
|
||||
sprites.put(dir, sprite);
|
||||
}
|
||||
}
|
||||
|
||||
public Sprite getSprite(Direction dir) {
|
||||
if(isDefault) return defaultSprite;
|
||||
|
||||
BakedQuad quad = quads.get(dir);
|
||||
if(quad == null) return missingSprite;
|
||||
|
||||
Sprite sprite = quad.getSprite();
|
||||
if(sprite == null) return missingSprite;
|
||||
|
||||
return sprite;
|
||||
else return sprites.getOrDefault(dir, missingSprite);
|
||||
}
|
||||
|
||||
public boolean hasColor(Direction dir) {
|
||||
if(isDefault) return false;
|
||||
|
||||
BakedQuad quad = quads.get(dir);
|
||||
if(quad == null) return false;
|
||||
|
||||
return quad.hasColor();
|
||||
else return hasColor.contains(dir);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user