/* * Decompiled with CFR 0.152. */ package net.minecraft.client.data.models.model; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Optional; import net.minecraft.client.color.item.Constant; import net.minecraft.client.color.item.ItemTintSource; import net.minecraft.client.renderer.item.BlockModelWrapper; import net.minecraft.client.renderer.item.CompositeModel; import net.minecraft.client.renderer.item.ConditionalItemModel; import net.minecraft.client.renderer.item.ItemModel; import net.minecraft.client.renderer.item.RangeSelectItemModel; import net.minecraft.client.renderer.item.SelectItemModel; import net.minecraft.client.renderer.item.SpecialModelWrapper; import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperty; import net.minecraft.client.renderer.item.properties.conditional.HasComponent; import net.minecraft.client.renderer.item.properties.conditional.IsUsingItem; import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty; import net.minecraft.client.renderer.item.properties.select.ContextDimension; import net.minecraft.client.renderer.item.properties.select.ItemBlockState; import net.minecraft.client.renderer.item.properties.select.LocalTime; import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty; import net.minecraft.client.renderer.special.SpecialModelRenderer; import net.minecraft.core.component.DataComponentType; import net.minecraft.resources.Identifier; import net.minecraft.util.SpecialDates; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.properties.Property; public class ItemModelUtils { public static ItemModel.Unbaked plainModel(Identifier id) { return new BlockModelWrapper.Unbaked(id, List.of()); } public static ItemModel.Unbaked tintedModel(Identifier id, ItemTintSource ... tints) { return new BlockModelWrapper.Unbaked(id, List.of(tints)); } public static ItemTintSource constantTint(int color) { return new Constant(color); } public static ItemModel.Unbaked composite(ItemModel.Unbaked ... models) { return new CompositeModel.Unbaked(List.of(models)); } public static ItemModel.Unbaked specialModel(Identifier base, SpecialModelRenderer.Unbaked model) { return new SpecialModelWrapper.Unbaked(base, model); } public static RangeSelectItemModel.Entry override(ItemModel.Unbaked model, float value) { return new RangeSelectItemModel.Entry(value, model); } public static ItemModel.Unbaked rangeSelect(RangeSelectItemModelProperty property, ItemModel.Unbaked fallback, RangeSelectItemModel.Entry ... entries) { return new RangeSelectItemModel.Unbaked(property, 1.0f, List.of(entries), Optional.of(fallback)); } public static ItemModel.Unbaked rangeSelect(RangeSelectItemModelProperty property, float scale, ItemModel.Unbaked fallback, RangeSelectItemModel.Entry ... entries) { return new RangeSelectItemModel.Unbaked(property, scale, List.of(entries), Optional.of(fallback)); } public static ItemModel.Unbaked rangeSelect(RangeSelectItemModelProperty property, ItemModel.Unbaked fallback, List entries) { return new RangeSelectItemModel.Unbaked(property, 1.0f, entries, Optional.of(fallback)); } public static ItemModel.Unbaked rangeSelect(RangeSelectItemModelProperty property, List entries) { return new RangeSelectItemModel.Unbaked(property, 1.0f, entries, Optional.empty()); } public static ItemModel.Unbaked rangeSelect(RangeSelectItemModelProperty property, float scale, List entries) { return new RangeSelectItemModel.Unbaked(property, scale, entries, Optional.empty()); } public static ItemModel.Unbaked conditional(ConditionalItemModelProperty property, ItemModel.Unbaked onTrue, ItemModel.Unbaked onFalse) { return new ConditionalItemModel.Unbaked(property, onTrue, onFalse); } public static SelectItemModel.SwitchCase when(T value, ItemModel.Unbaked model) { return new SelectItemModel.SwitchCase(List.of(value), model); } public static SelectItemModel.SwitchCase when(List values, ItemModel.Unbaked model) { return new SelectItemModel.SwitchCase(values, model); } @SafeVarargs public static ItemModel.Unbaked select(SelectItemModelProperty property, ItemModel.Unbaked fallback, SelectItemModel.SwitchCase ... cases) { return ItemModelUtils.select(property, fallback, List.of(cases)); } public static ItemModel.Unbaked select(SelectItemModelProperty property, ItemModel.Unbaked fallback, List> cases) { return new SelectItemModel.Unbaked(new SelectItemModel.UnbakedSwitch, T>(property, cases), Optional.of(fallback)); } @SafeVarargs public static ItemModel.Unbaked select(SelectItemModelProperty property, SelectItemModel.SwitchCase ... cases) { return ItemModelUtils.select(property, List.of(cases)); } public static ItemModel.Unbaked select(SelectItemModelProperty property, List> cases) { return new SelectItemModel.Unbaked(new SelectItemModel.UnbakedSwitch, T>(property, cases), Optional.empty()); } public static ConditionalItemModelProperty isUsingItem() { return new IsUsingItem(); } public static ConditionalItemModelProperty hasComponent(DataComponentType component) { return new HasComponent(component, false); } public static ItemModel.Unbaked inOverworld(ItemModel.Unbaked ifTrue, ItemModel.Unbaked ifFalse) { return ItemModelUtils.select(new ContextDimension(), ifFalse, ItemModelUtils.when(Level.OVERWORLD, ifTrue)); } public static > ItemModel.Unbaked selectBlockItemProperty(Property property, ItemModel.Unbaked fallback, Map cases) { List> entries = cases.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(e -> { String valueName = property.getName((Comparable)e.getKey()); return new SelectItemModel.SwitchCase(List.of(valueName), (ItemModel.Unbaked)e.getValue()); }).toList(); return ItemModelUtils.select(new ItemBlockState(property.getName()), fallback, entries); } public static ItemModel.Unbaked isXmas(ItemModel.Unbaked onTrue, ItemModel.Unbaked onFalse) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd", Locale.ROOT); List days = SpecialDates.CHRISTMAS_RANGE.stream().map(formatter::format).toList(); return ItemModelUtils.select(LocalTime.create("MM-dd", "", Optional.empty()), onFalse, List.of(ItemModelUtils.when(days, onTrue))); } }