/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.ImmutableMap * com.google.common.collect.ImmutableSet * com.google.common.collect.Streams * com.google.gson.JsonElement * com.google.gson.JsonObject */ package net.minecraft.client.data.models.model; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.stream.Stream; import net.minecraft.client.data.models.model.ModelInstance; import net.minecraft.client.data.models.model.ModelLocationUtils; import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.client.data.models.model.TextureSlot; import net.minecraft.resources.Identifier; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; public class ModelTemplate { private final Optional model; private final Set requiredSlots; private final Optional suffix; public ModelTemplate(Optional model, Optional suffix, TextureSlot ... requiredSlots) { this.model = model; this.suffix = suffix; this.requiredSlots = ImmutableSet.copyOf((Object[])requiredSlots); } public Identifier getDefaultModelLocation(Block block) { return ModelLocationUtils.getModelLocation(block, this.suffix.orElse("")); } public Identifier create(Block block, TextureMapping textures, BiConsumer output) { return this.create(ModelLocationUtils.getModelLocation(block, this.suffix.orElse("")), textures, output); } public Identifier createWithSuffix(Block block, String extraSuffix, TextureMapping textures, BiConsumer output) { return this.create(ModelLocationUtils.getModelLocation(block, extraSuffix + this.suffix.orElse("")), textures, output); } public Identifier createWithOverride(Block block, String suffixOverride, TextureMapping textures, BiConsumer output) { return this.create(ModelLocationUtils.getModelLocation(block, suffixOverride), textures, output); } public Identifier create(Item item, TextureMapping textures, BiConsumer output) { return this.create(ModelLocationUtils.getModelLocation(item, this.suffix.orElse("")), textures, output); } public Identifier create(Identifier target, TextureMapping textures, BiConsumer output) { Map slots = this.createMap(textures); output.accept(target, () -> { JsonObject result = new JsonObject(); this.model.ifPresent(m -> result.addProperty("parent", m.toString())); if (!slots.isEmpty()) { JsonObject textureObj = new JsonObject(); slots.forEach((slot, value) -> textureObj.addProperty(slot.getId(), value.toString())); result.add("textures", (JsonElement)textureObj); } return result; }); return target; } private Map createMap(TextureMapping mapping) { return (Map)Streams.concat((Stream[])new Stream[]{this.requiredSlots.stream(), mapping.getForced()}).collect(ImmutableMap.toImmutableMap(Function.identity(), mapping::get)); } }