| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import java.util.Arrays;
|
| 5 | import java.util.Comparator;
|
| 6 | import java.util.HashMap;
|
| 7 | import java.util.List;
|
| 8 | import java.util.Map;
|
| 9 | import net.fabricmc.api.EnvType;
|
| 10 | import net.fabricmc.api.Environment;
|
| 11 | import net.minecraft.client.renderer.blockentity.state.ChestRenderState;
|
| 12 | import net.minecraft.client.renderer.rendertype.RenderType;
|
| 13 | import net.minecraft.client.renderer.rendertype.RenderTypes;
|
| 14 | import net.minecraft.client.renderer.special.ChestSpecialRenderer;
|
| 15 | import net.minecraft.client.renderer.texture.TextureAtlas;
|
| 16 | import net.minecraft.client.resources.model.sprite.SpriteId;
|
| 17 | import net.minecraft.core.Holder;
|
| 18 | import net.minecraft.resources.Identifier;
|
| 19 | import net.minecraft.world.item.DyeColor;
|
| 20 | import net.minecraft.world.level.block.WeatheringCopperCollection.ByState;
|
| 21 | import net.minecraft.world.level.block.entity.BannerPattern;
|
| 22 | import net.minecraft.world.level.block.state.properties.ChestType;
|
| 23 |
|
| 24 | @Environment(EnvType.CLIENT)
|
| 25 | public class Sheets {
|
| 26 | public static final Identifier SHULKER_SHEET = Identifier.withDefaultNamespace("textures/atlas/shulker_boxes.png");
|
| 27 | public static final Identifier BANNER_SHEET = Identifier.withDefaultNamespace("textures/atlas/banner_patterns.png");
|
| 28 | public static final Identifier SHIELD_SHEET = Identifier.withDefaultNamespace("textures/atlas/shield_patterns.png");
|
| 29 | public static final Identifier CHEST_SHEET = Identifier.withDefaultNamespace("textures/atlas/chest.png");
|
| 30 | public static final Identifier DECORATED_POT_SHEET = Identifier.withDefaultNamespace("textures/atlas/decorated_pot.png");
|
| 31 | public static final Identifier GUI_SHEET = Identifier.withDefaultNamespace("textures/atlas/gui.png");
|
| 32 | public static final Identifier MAP_DECORATIONS_SHEET = Identifier.withDefaultNamespace("textures/atlas/map_decorations.png");
|
| 33 | public static final Identifier PAINTINGS_SHEET = Identifier.withDefaultNamespace("textures/atlas/paintings.png");
|
| 34 | public static final Identifier CELESTIAL_SHEET = Identifier.withDefaultNamespace("textures/atlas/celestials.png");
|
| 35 | private static final RenderType CUTOUT_BLOCK_ITEM_SHEET = RenderTypes.itemCutout(TextureAtlas.LOCATION_BLOCKS);
|
| 36 | private static final RenderType CUTOUT_BLOCK_ITEM_GLINT_SHEET = RenderTypes.itemCutoutGlint(TextureAtlas.LOCATION_BLOCKS);
|
| 37 | private static final RenderType CUTOUT_BLOCK_ITEM_GLINT_SPECIAL_SHEET = RenderTypes.itemCutoutGlintSpecial(TextureAtlas.LOCATION_BLOCKS);
|
| 38 | private static final RenderType TRANSLUCENT_BLOCK_ITEM_SHEET = RenderTypes.itemTranslucent(TextureAtlas.LOCATION_BLOCKS);
|
| 39 | private static final RenderType TRANSLUCENT_BLOCK_ITEM_GLINT_SHEET = RenderTypes.itemTranslucentGlint(TextureAtlas.LOCATION_BLOCKS);
|
| 40 | private static final RenderType TRANSLUCENT_BLOCK_ITEM_GLINT_SPECIAL_SHEET = RenderTypes.itemTranslucentGlintSpecial(TextureAtlas.LOCATION_BLOCKS);
|
| 41 | private static final RenderType CUTOUT_ITEM_SHEET = RenderTypes.itemCutout(TextureAtlas.LOCATION_ITEMS);
|
| 42 | private static final RenderType CUTOUT_ITEM_GLINT_SHEET = RenderTypes.itemCutoutGlint(TextureAtlas.LOCATION_ITEMS);
|
| 43 | private static final RenderType CUTOUT_ITEM_GLINT_SPECIAL_SHEET = RenderTypes.itemCutoutGlintSpecial(TextureAtlas.LOCATION_ITEMS);
|
| 44 | private static final RenderType TRANSLUCENT_ITEM_SHEET = RenderTypes.itemTranslucent(TextureAtlas.LOCATION_ITEMS);
|
| 45 | private static final RenderType TRANSLUCENT_ITEM_GLINT_SHEET = RenderTypes.itemTranslucentGlint(TextureAtlas.LOCATION_ITEMS);
|
| 46 | private static final RenderType TRANSLUCENT_ITEM_GLINT_SPECIAL_SHEET = RenderTypes.itemTranslucentGlintSpecial(TextureAtlas.LOCATION_ITEMS);
|
| 47 | public static final SpriteMapper ITEMS_MAPPER = new SpriteMapper(TextureAtlas.LOCATION_ITEMS, "item");
|
| 48 | public static final SpriteMapper BLOCKS_MAPPER = new SpriteMapper(TextureAtlas.LOCATION_BLOCKS, "block");
|
| 49 | public static final SpriteMapper BLOCK_ENTITIES_MAPPER = new SpriteMapper(TextureAtlas.LOCATION_BLOCKS, "entity");
|
| 50 | public static final SpriteMapper BANNER_MAPPER = new SpriteMapper(BANNER_SHEET, "entity/banner");
|
| 51 | public static final SpriteMapper SHIELD_MAPPER = new SpriteMapper(SHIELD_SHEET, "entity/shield");
|
| 52 | public static final SpriteMapper CHEST_MAPPER = new SpriteMapper(CHEST_SHEET, "entity/chest");
|
| 53 | public static final SpriteMapper DECORATED_POT_MAPPER = new SpriteMapper(DECORATED_POT_SHEET, "entity/decorated_pot");
|
| 54 | public static final SpriteMapper SHULKER_MAPPER = new SpriteMapper(SHULKER_SHEET, "entity/shulker");
|
| 55 | public static final SpriteId DEFAULT_SHULKER_TEXTURE_LOCATION = SHULKER_MAPPER.defaultNamespaceApply("shulker");
|
| 56 | public static final List<SpriteId> SHULKER_TEXTURE_LOCATION = Arrays.stream(DyeColor.values())
|
| 57 | .sorted(Comparator.comparingInt(DyeColor::getId))
|
| 58 | .map(Sheets::createShulkerSprite)
|
| 59 | .collect(ImmutableList.toImmutableList());
|
| 60 | public static final SpriteId BANNER_BASE = BANNER_MAPPER.defaultNamespaceApply("banner_base");
|
| 61 | public static final SpriteId SHIELD_BASE = SHIELD_MAPPER.defaultNamespaceApply("shield_base");
|
| 62 | public static final SpriteId SHIELD_BASE_NO_PATTERN = SHIELD_MAPPER.defaultNamespaceApply("shield_base_nopattern");
|
| 63 | public static final SpriteId BANNER_PATTERN_BASE = BANNER_MAPPER.defaultNamespaceApply("base");
|
| 64 | public static final SpriteId SHIELD_PATTERN_BASE = SHIELD_MAPPER.defaultNamespaceApply("base");
|
| 65 | private static final Map<Identifier, SpriteId> BANNER_SPRITES = new HashMap<>();
|
| 66 | private static final Map<Identifier, SpriteId> SHIELD_SPRITES = new HashMap<>();
|
| 67 | public static final SpriteId DECORATED_POT_BASE = DECORATED_POT_MAPPER.defaultNamespaceApply("decorated_pot_base");
|
| 68 | public static final SpriteId DECORATED_POT_SIDE = DECORATED_POT_MAPPER.defaultNamespaceApply("decorated_pot_side");
|
| 69 | public static final SpriteId ENDER_CHEST_LOCATION = CHEST_MAPPER.defaultNamespaceApply("ender");
|
| 70 | public static final MultiblockChestResources<SpriteId> CHEST_REGULAR = ChestSpecialRenderer.REGULAR.map(CHEST_MAPPER::apply);
|
| 71 | public static final MultiblockChestResources<SpriteId> CHEST_TRAPPED = ChestSpecialRenderer.TRAPPED.map(CHEST_MAPPER::apply);
|
| 72 | public static final MultiblockChestResources<SpriteId> CHEST_CHRISTMAS = ChestSpecialRenderer.CHRISTMAS.map(CHEST_MAPPER::apply);
|
| 73 | public static final ByState<MultiblockChestResources<SpriteId>> CHEST_COPPER = ChestSpecialRenderer.COPPER.map(r -> r.map(CHEST_MAPPER::apply));
|
| 74 |
|
| 75 | public static RenderType cutoutBlockItemSheet() {
|
| 76 | return CUTOUT_BLOCK_ITEM_SHEET;
|
| 77 | }
|
| 78 |
|
| 79 | public static RenderType cutoutBlockItemGlintSheet() {
|
| 80 | return CUTOUT_BLOCK_ITEM_GLINT_SHEET;
|
| 81 | }
|
| 82 |
|
| 83 | public static RenderType cutoutBlockItemGlintSpecialSheet() {
|
| 84 | return CUTOUT_BLOCK_ITEM_GLINT_SPECIAL_SHEET;
|
| 85 | }
|
| 86 |
|
| 87 | public static RenderType cutoutItemSheet() {
|
| 88 | return CUTOUT_ITEM_SHEET;
|
| 89 | }
|
| 90 |
|
| 91 | public static RenderType cutoutItemGlintSheet() {
|
| 92 | return CUTOUT_ITEM_GLINT_SHEET;
|
| 93 | }
|
| 94 |
|
| 95 | public static RenderType cutoutItemGlintSpecialSheet() {
|
| 96 | return CUTOUT_ITEM_GLINT_SPECIAL_SHEET;
|
| 97 | }
|
| 98 |
|
| 99 | public static RenderType translucentItemSheet() {
|
| 100 | return TRANSLUCENT_ITEM_SHEET;
|
| 101 | }
|
| 102 |
|
| 103 | public static RenderType translucentItemGlintSheet() {
|
| 104 | return TRANSLUCENT_ITEM_GLINT_SHEET;
|
| 105 | }
|
| 106 |
|
| 107 | public static RenderType translucentItemGlintSpecialSheet() {
|
| 108 | return TRANSLUCENT_ITEM_GLINT_SPECIAL_SHEET;
|
| 109 | }
|
| 110 |
|
| 111 | public static RenderType translucentBlockItemSheet() {
|
| 112 | return TRANSLUCENT_BLOCK_ITEM_SHEET;
|
| 113 | }
|
| 114 |
|
| 115 | public static RenderType translucentBlockItemGlintSheet() {
|
| 116 | return TRANSLUCENT_BLOCK_ITEM_GLINT_SHEET;
|
| 117 | }
|
| 118 |
|
| 119 | public static RenderType translucentBlockItemGlintSpecialSheet() {
|
| 120 | return TRANSLUCENT_BLOCK_ITEM_GLINT_SPECIAL_SHEET;
|
| 121 | }
|
| 122 |
|
| 123 | public static SpriteId getShulkerBoxSprite(final DyeColor color) {
|
| 124 | return SHULKER_TEXTURE_LOCATION.get(color.getId());
|
| 125 | }
|
| 126 |
|
| 127 | public static Identifier colorToShulkerSprite(final DyeColor color) {
|
| 128 | return Identifier.withDefaultNamespace("shulker_" + color.getName());
|
| 129 | }
|
| 130 |
|
| 131 | public static SpriteId createShulkerSprite(final DyeColor color) {
|
| 132 | return SHULKER_MAPPER.apply(colorToShulkerSprite(color));
|
| 133 | }
|
| 134 |
|
| 135 | public static SpriteId getBannerSprite(final Holder<BannerPattern> pattern) {
|
| 136 | return BANNER_SPRITES.computeIfAbsent(pattern.value().assetId(), BANNER_MAPPER::apply);
|
| 137 | }
|
| 138 |
|
| 139 | public static SpriteId getShieldSprite(final Holder<BannerPattern> pattern) {
|
| 140 | return SHIELD_SPRITES.computeIfAbsent(pattern.value().assetId(), SHIELD_MAPPER::apply);
|
| 141 | }
|
| 142 |
|
| 143 | public static SpriteId chooseSprite(final ChestRenderState.ChestMaterialType materialType, final ChestType type) {
|
| 144 | return switch (materialType) {
|
| 145 | case ENDER_CHEST -> ENDER_CHEST_LOCATION;
|
| 146 | case REGULAR -> (SpriteId)CHEST_REGULAR.select(type);
|
| 147 | case CHRISTMAS -> (SpriteId)CHEST_CHRISTMAS.select(type);
|
| 148 | case TRAPPED -> (SpriteId)CHEST_TRAPPED.select(type);
|
| 149 | case COPPER_UNAFFECTED -> (SpriteId)CHEST_COPPER.unaffected().select(type);
|
| 150 | case COPPER_EXPOSED -> (SpriteId)CHEST_COPPER.exposed().select(type);
|
| 151 | case COPPER_WEATHERED -> (SpriteId)CHEST_COPPER.weathered().select(type);
|
| 152 | case COPPER_OXIDIZED -> (SpriteId)CHEST_COPPER.oxidized().select(type);
|
| 153 | };
|
| 154 | }
|
| 155 | }
|
| 156 |
|