5151public class ClientModelManager {
5252 public static Map <ResourceLocation , List <ResourceLocation >> MODELS = Maps .newHashMap ();
5353 public static Map <ResourceLocation , Pair <Double , Double >> SCALE_INFO = Maps .newHashMap ();
54- public static Map <ResourceLocation , List <String >> EXTRA_INFO = Maps .newHashMap ();
55- public static Map <ResourceLocation , String > MODEL_NAME = Maps .newHashMap ();
56- public static Map <ResourceLocation , String []> EXTRA_ANIMATION_NAME = Maps .newHashMap ();
57- public static Map <ResourceLocation , String > PREVIEW_ANIMATION = Maps .newHashMap ();
58- public static Map <ResourceLocation , Boolean > DISABLE_PREVIEW_ROTATION = Maps .newHashMap ();
59- public static Map <ResourceLocation , Boolean > GUI_FOREGROUND = Maps .newHashMap ();
60- public static Map <ResourceLocation , Boolean > GUI_BACKGROUND = Maps .newHashMap ();
61-
62-
54+ public static Map <ResourceLocation , List <String >> META_DATA = Maps .newHashMap ();
55+ public static Map <ResourceLocation , ExtraInfo > EXTRA_INFO = Maps .newHashMap ();
6356 public static AnimationFile DEFAULT_ANIMATION_FILE = new AnimationFile ();
64- public static AnimationFile DEFAULT_ARROW_ANIMATION_FILE = new AnimationFile ();
6557 public static List <String > CACHE_MD5 = Lists .newArrayList ();
6658 public static List <String > AUTH_MODELS = Lists .newArrayList ();
6759 public static byte [] PASSWORD ;
@@ -112,7 +104,7 @@ private static void registerGeo(ResourceLocation modelId, String partName, byte[
112104 public static void registerTexture (ResourceLocation modelId , Map <String , byte []> mapData ) {
113105 List <ResourceLocation > textures = Lists .newArrayList ();
114106 for (String name : mapData .keySet ()) {
115- if (isTexture ( name )) {
107+ if (isModelTexture ( ModelIdUtil . getInfoId ( modelId ), name )) {
116108 ResourceLocation textureId = ModelIdUtil .getSubModelId (modelId , name );
117109 textures .add (textureId );
118110 }
@@ -124,14 +116,12 @@ public static void registerTexture(ResourceLocation modelId, Map<String, byte[]>
124116 }
125117 }
126118
127- private static boolean isTexture (String name ) {
128- return switch (name ) {
129- case IArrowExtraInfo .TEXTURE_NAME , "background.png" , "foreground.png" -> false ;
130- default -> true ;
131- };
119+ private static boolean isModelTexture (ResourceLocation infoId , String name ) {
120+ if (name .equals (IArrowExtraInfo .TEXTURE_NAME )) return false ;
121+ final ExtraInfo extraInfo = EXTRA_INFO .get (infoId );
122+ return !name .equals (extraInfo .getGuiBackground ()) && !name .equals (extraInfo .getGuiForeground ());
132123 }
133124
134-
135125 private static void registerTexture (ResourceLocation textureId , byte [] data ) {
136126 // 确保主线程上传
137127 final Minecraft mc = Minecraft .getMinecraft ();
@@ -183,6 +173,9 @@ private static AnimationFile getAnimationFile(String file) {
183173 return animationFile ;
184174 }
185175
176+ /**
177+ * @return main animation
178+ */
186179 private static AnimationFile mergeAnimationFile (AnimationFile main , AnimationFile other ) {
187180 other .animations ().forEach (main ::putAnimation );
188181 return main ;
@@ -191,11 +184,16 @@ private static AnimationFile mergeAnimationFile(AnimationFile main, AnimationFil
191184 public static void loadDefaultModel () {
192185 try {
193186 ModelData data = FolderFormat .getModelData (ServerModelManager .BUILTIN , "default" , false );
187+ ExtraInfo extraInfo = null ;
188+ byte [] infoBytes = data .getModel ().get ("info" );
189+ if (infoBytes != null && ObjectStreamUtil .toObject (infoBytes ) instanceof ExtraInfo info ) {
190+ extraInfo = info ;
191+ }
192+ final String guiBackground = (extraInfo != null && extraInfo .getGuiBackground () != null ) ? extraInfo .getGuiBackground () : "" ;
193+ final String guiForeground = (extraInfo != null && extraInfo .getGuiForeground () != null ) ? extraInfo .getGuiForeground () : "" ;
194194 data .getAnimation ().forEach ((name , bytes ) -> {
195195 AnimationFile animationFile = getAnimationFile (new String (bytes , StandardCharsets .UTF_8 ));
196- if ("arrow" .equals (name )) {
197- mergeAnimationFile (DEFAULT_ARROW_ANIMATION_FILE , animationFile );
198- } else {
196+ if (!"arrow" .equals (name ) && !guiBackground .equals (name ) && !guiForeground .equals (name )) {
199197 mergeAnimationFile (DEFAULT_ANIMATION_FILE , animationFile );
200198 }
201199 });
@@ -210,12 +208,8 @@ public static void sendSyncModelMessage() {
210208 CACHE_MD5 .clear ();
211209 AUTH_MODELS .clear ();
212210 SCALE_INFO .clear ();
211+ META_DATA .clear ();
213212 EXTRA_INFO .clear ();
214- EXTRA_ANIMATION_NAME .clear ();
215- PREVIEW_ANIMATION .clear ();
216- GUI_FOREGROUND .clear ();
217- GUI_BACKGROUND .clear ();
218- MODEL_NAME .clear ();
219213 ConditionManager .clear ();
220214 String [] md5Info = getMd5Info ();
221215 SyncModelFiles syncModelFiles = new SyncModelFiles (md5Info );
@@ -249,33 +243,21 @@ private static byte[] getBytes(Path root, String fileName) throws IOException {
249243 private static void addExtraInfo (ResourceLocation modelId , @ Nullable ExtraInfo extraInfo ) {
250244 if (extraInfo == null ) return ;
251245 ResourceLocation infoId = ModelIdUtil .getInfoId (modelId );
252- EXTRA_INFO .put (infoId , handleExtraInfo (extraInfo ));
246+ EXTRA_INFO .put (infoId , extraInfo );
247+ META_DATA .put (infoId , readMetaData (extraInfo ));
253248 if (extraInfo .getFree ()) {
254249 AUTH_MODELS .remove (modelId .getPath ());
255250 }
256- if (extraInfo .getExtraAnimationNames () != null && extraInfo .getExtraAnimationNames ().length > 0 ) {
257- EXTRA_ANIMATION_NAME .put (infoId , extraInfo .getExtraAnimationNames ());
258- }
259- if (extraInfo .getPreviewAnimation () != null && !extraInfo .getPreviewAnimation ().isEmpty ()) {
260- PREVIEW_ANIMATION .put (infoId , extraInfo .getPreviewAnimation ());
261- DISABLE_PREVIEW_ROTATION .put (infoId , extraInfo .getDisablePreviewRotation ());
262- }
263- GUI_FOREGROUND .put (infoId , extraInfo .getGuiForeGround ());
264- GUI_BACKGROUND .put (infoId , extraInfo .getGuiBackGround ());
265- if (extraInfo .getName () != null && !extraInfo .getName ().isEmpty ()) {
266- MODEL_NAME .put (infoId , extraInfo .getName ());
267- }
268-
269251 }
270252
271253 @ Nullable
272- private static List <String > handleExtraInfo (@ Nullable ExtraInfo extraInfo ) {
254+ private static List <String > readMetaData (@ Nullable ExtraInfo extraInfo ) {
273255 if (extraInfo == null || StringUtils .isBlank (extraInfo .getName ())) {
274256 return null ;
275257 }
276258 List <String > component = Lists .newArrayList ();
277259 component .add (TextFormatting .GOLD + extraInfo .getName ());
278- if (StringUtils .isNoneBlank (extraInfo .getTips ())) {
260+ if (extraInfo . getTips () != null && StringUtils .isNoneBlank (extraInfo .getTips ())) {
279261 String [] split = extraInfo .getTips ().split ("\n " );
280262 Arrays .stream (split ).forEach (s -> component .add (TextFormatting .GRAY + I18n .format (s )));
281263 }
0 commit comments