50 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.client.renderer.block.model;
 | |
| 
 | |
| import java.util.List;
 | |
| import net.fabricmc.api.EnvType;
 | |
| import net.fabricmc.api.Environment;
 | |
| import net.minecraft.client.renderer.texture.TextureAtlasSprite;
 | |
| import net.minecraft.client.resources.model.ModelBaker;
 | |
| import net.minecraft.client.resources.model.ModelDebugName;
 | |
| import net.minecraft.client.resources.model.ModelState;
 | |
| import net.minecraft.client.resources.model.QuadCollection;
 | |
| import net.minecraft.client.resources.model.SpriteGetter;
 | |
| import net.minecraft.client.resources.model.UnbakedGeometry;
 | |
| import net.minecraft.core.Direction;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public record SimpleUnbakedGeometry(List<BlockElement> elements) implements UnbakedGeometry {
 | |
| 	@Override
 | |
| 	public QuadCollection bake(TextureSlots textureSlots, ModelBaker modelBaker, ModelState modelState, ModelDebugName modelDebugName) {
 | |
| 		return bake(this.elements, textureSlots, modelBaker.sprites(), modelState, modelDebugName);
 | |
| 	}
 | |
| 
 | |
| 	public static QuadCollection bake(
 | |
| 		List<BlockElement> elements, TextureSlots textureSlots, SpriteGetter sprites, ModelState modelState, ModelDebugName debugName
 | |
| 	) {
 | |
| 		QuadCollection.Builder builder = new QuadCollection.Builder();
 | |
| 
 | |
| 		for (BlockElement blockElement : elements) {
 | |
| 			blockElement.faces()
 | |
| 				.forEach(
 | |
| 					(direction, blockElementFace) -> {
 | |
| 						TextureAtlasSprite textureAtlasSprite = sprites.resolveSlot(textureSlots, blockElementFace.texture(), debugName);
 | |
| 						if (blockElementFace.cullForDirection() == null) {
 | |
| 							builder.addUnculledFace(bakeFace(blockElement, blockElementFace, textureAtlasSprite, direction, modelState));
 | |
| 						} else {
 | |
| 							builder.addCulledFace(
 | |
| 								Direction.rotate(modelState.transformation().getMatrix(), blockElementFace.cullForDirection()),
 | |
| 								bakeFace(blockElement, blockElementFace, textureAtlasSprite, direction, modelState)
 | |
| 							);
 | |
| 						}
 | |
| 					}
 | |
| 				);
 | |
| 		}
 | |
| 
 | |
| 		return builder.build();
 | |
| 	}
 | |
| 
 | |
| 	private static BakedQuad bakeFace(BlockElement element, BlockElementFace face, TextureAtlasSprite sprite, Direction direction, ModelState modelState) {
 | |
| 		return FaceBakery.bakeQuad(element.from(), element.to(), face, sprite, direction, modelState, element.rotation(), element.shade(), element.lightEmission());
 | |
| 	}
 | |
| }
 |