Skip to content

Commit f5aa372

Browse files
committed
格式化代码,添加显示模型 ID 的选项,优化
1 parent a444b0c commit f5aa372

15 files changed

Lines changed: 143 additions & 171 deletions

File tree

src/main/java/com/elfmcys/yesstevemodel/client/ClientModelManager.java

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,9 @@
5151
public 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
}

src/main/java/com/elfmcys/yesstevemodel/client/gui/AnimationRouletteScreen.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import org.lwjgl.input.Keyboard;
2525
import org.lwjgl.opengl.GL11;
2626

27+
import javax.annotation.Nullable;
2728
import java.io.IOException;
2829

2930
public class AnimationRouletteScreen extends Screen {
3031
private int x;
3132
private int y;
3233
private int selectId = -1;
33-
private String[] names;
34+
private @Nullable String[] names;
3435

3536
public AnimationRouletteScreen() {
3637
}
@@ -43,9 +44,7 @@ public void initGui() {
4344
if (this.mc != null && this.mc.player != null) {
4445
CapabilityEvent.getModelInfoCap(this.mc.player).ifPresent(cap -> {
4546
ResourceLocation modelId = cap.getModelId();
46-
if (ClientModelManager.EXTRA_ANIMATION_NAME.containsKey(ModelIdUtil.getInfoId(modelId))) {
47-
this.names = ClientModelManager.EXTRA_ANIMATION_NAME.get(ModelIdUtil.getInfoId(modelId));
48-
}
47+
this.names = ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(modelId)).getExtraAnimationNames();
4948
});
5049
}
5150
}

src/main/java/com/elfmcys/yesstevemodel/client/gui/ConfigScreen.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public void initGui() {
2424

2525
this.addButton(new FlatColorButton(x + 5, y, 80, 18, I18n.format("gui.yes_steve_model.model.return"), (b) -> this.mc.displayGuiScreen(this.parent)));
2626

27-
this.addButton(new ConfigCheckBox(x + 5, y + 25, "disable_self_model", this.fontRenderer,
27+
this.addButton(new ConfigCheckBox(x + 5, y + 25, "config.disable_self_model", this.fontRenderer,
2828
GeneralConfig.DISABLE_SELF_MODEL, (value) -> GeneralConfig.DISABLE_SELF_MODEL = value));
29-
this.addButton(new ConfigCheckBox(x + 5, y + 47, "disable_other_model", this.fontRenderer,
29+
this.addButton(new ConfigCheckBox(x + 5, y + 47, "config.disable_other_model", this.fontRenderer,
3030
GeneralConfig.DISABLE_OTHER_MODEL, (value) -> GeneralConfig.DISABLE_OTHER_MODEL = value));
31-
this.addButton(new ConfigCheckBox(x + 5, y + 69, "print_animation_roulette_msg", this.fontRenderer,
31+
this.addButton(new ConfigCheckBox(x + 5, y + 69, "config.print_animation_roulette_msg", this.fontRenderer,
3232
GeneralConfig.PRINT_ANIMATION_ROULETTE_MSG, (value) -> GeneralConfig.PRINT_ANIMATION_ROULETTE_MSG = value));
33-
this.addButton(new ConfigCheckBox(x + 5, y + 91, "disable_self_hands", this.fontRenderer,
33+
this.addButton(new ConfigCheckBox(x + 5, y + 91, "config.disable_self_hands", this.fontRenderer,
3434
GeneralConfig.DISABLE_SELF_HANDS, (value) -> GeneralConfig.DISABLE_SELF_HANDS = value));
35-
this.addButton(new ConfigCheckBox(x + 5, y + 112, "disable_player_render", this.fontRenderer,
35+
this.addButton(new ConfigCheckBox(x + 5, y + 112, "config.disable_player_render", this.fontRenderer,
3636
ExtraPlayerScreenConfig.DISABLE_PLAYER_RENDER, (value) -> ExtraPlayerScreenConfig.DISABLE_PLAYER_RENDER = value));
37-
this.addButton(new ConfigCheckBox(x + 5, y + 134, "disable_arrows_model", this.fontRenderer,
37+
this.addButton(new ConfigCheckBox(x + 5, y + 134, "config.disable_arrows_model", this.fontRenderer,
3838
GeneralConfig.DISABLE_ARROWS_MODEL, (value) -> GeneralConfig.DISABLE_ARROWS_MODEL = value));
3939
}
4040

src/main/java/com/elfmcys/yesstevemodel/client/gui/PlayerModelScreen.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import com.elfmcys.yesstevemodel.client.ClientModelManager;
55
import com.elfmcys.yesstevemodel.client.gui.button.*;
66
import com.elfmcys.yesstevemodel.client.input.PlayerModelScreenKey;
7+
import com.elfmcys.yesstevemodel.config.Config;
8+
import com.elfmcys.yesstevemodel.config.GeneralConfig;
79
import com.elfmcys.yesstevemodel.event.CapabilityEvent;
10+
import com.elfmcys.yesstevemodel.geckolib3.geo.raw.pojo.ExtraInfo;
811
import com.elfmcys.yesstevemodel.util.ModelIdUtil;
912
import com.elfmcys.yesstevemodel.util.RenderUtil;
1013
import com.google.common.collect.Lists;
@@ -115,6 +118,15 @@ public void initGui() {
115118
}).setTooltips("gui.yes_steve_model.model.texture"));
116119
this.addButton(new StarButton(this.x + 110, this.y + 5));
117120

121+
this.addButton(new ConfigCheckBox(this.x + 5, this.y - 22, "show_model_id_first", this.fontRenderer,
122+
GeneralConfig.SHOW_MODEL_ID_FIRST, value -> GeneralConfig.SHOW_MODEL_ID_FIRST = value) {
123+
@Override
124+
public void onPress() {
125+
super.onPress();
126+
Config.save();
127+
}
128+
});
129+
118130
this.addButton(new FlatIconButton(this.x + 328, this.y + 5, 18, 18, 32, 0, (b) -> {
119131
if (this.category != Category.ALL) {
120132
this.category = Category.ALL;
@@ -173,9 +185,9 @@ public void initGui() {
173185
int yStart = this.y + 28 + 93 * (i / 5);
174186
CapabilityEvent.getAuthModelsCap(this.player).ifPresent(cap -> {
175187
if (ClientModelManager.AUTH_MODELS.contains(id.getPath()) && !cap.containModel(id)) {
176-
this.addButton(new ModelButton(xStart, yStart, true, Pair.of(id, this.models.get(id)), ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(id)), this.player));
188+
this.addButton(new ModelButton(xStart, yStart, true, Pair.of(id, this.models.get(id)), ClientModelManager.META_DATA.get(ModelIdUtil.getInfoId(id)), this.player));
177189
} else {
178-
this.addButton(new ModelButton(xStart, yStart, false, Pair.of(id, this.models.get(id)), ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(id)), this.player));
190+
this.addButton(new ModelButton(xStart, yStart, false, Pair.of(id, this.models.get(id)), ClientModelManager.META_DATA.get(ModelIdUtil.getInfoId(id)), this.player));
179191
}
180192
});
181193
}
@@ -197,8 +209,9 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
197209

198210
CapabilityEvent.getModelInfoCap(this.player).ifPresent(cap -> {
199211
String modelName = cap.getModelId().getPath();
200-
if (ClientModelManager.MODEL_NAME.containsKey(ModelIdUtil.getInfoId(cap.getModelId()))) {
201-
modelName = ClientModelManager.MODEL_NAME.get(ModelIdUtil.getInfoId(cap.getModelId()));
212+
final ExtraInfo extraInfo = ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(cap.getModelId()));
213+
if (extraInfo.getName() != null && !extraInfo.getName().isEmpty()) {
214+
modelName = extraInfo.getName();
202215
}
203216
List<String> modelNameSplit = this.fontRenderer.listFormattedStringToWidth(modelName, 125);
204217
int lineY = this.y + 205;

src/main/java/com/elfmcys/yesstevemodel/client/gui/PlayerTextureScreen.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ public class PlayerTextureScreen extends Screen {
4545
private float pitch = -5;
4646
private boolean showGround = true;
4747

48-
4948
public PlayerTextureScreen(PlayerModelScreen parent, ResourceLocation modelId, List<ResourceLocation> textures) {
5049
this.parent = parent;
5150
this.modelId = modelId;
5251
this.textures = textures;
5352
this.textures.sort(ResourceLocation::compareTo);
54-
List<String> anmiatinon = new ArrayList<>(ClientModelManager.DEFAULT_ANIMATION_FILE.animations().keySet());
55-
anmiatinon.removeIf(animation -> animation.equals("gui"));
56-
this.animations = anmiatinon;
53+
this.animations = new ArrayList<>(ClientModelManager.DEFAULT_ANIMATION_FILE.animations().keySet());
5754
this.animations.sort(String::compareTo);
5855
this.player = parent.player;
5956
}
@@ -143,12 +140,13 @@ public void initGui() {
143140

144141
@Override
145142
public void drawScreen(int mouseX, int mouseY, float partialTick) {
146-
//GlStateManager.translate(0, 0, -1000);
143+
final float zLevel = this.zLevel;
144+
this.zLevel -= 1000;
147145
this.drawDefaultBackground();
148146
this.drawGradientRect(this.x, this.y + 22, this.x + 90, this.y + 235, 0xff_222222, 0xff_222222);
149147
this.drawGradientRect(this.x + 93, this.y, this.x + 299, this.y + 235, 0xff_222222, 0xff_222222);
150148
this.drawGradientRect(this.x + 302, this.y, this.x + 420, this.y + 235, 0xff_222222, 0xff_222222);
151-
//GlStateManager.translate(0, 0, 1000);
149+
this.zLevel = zLevel;
152150

153151
CapabilityEvent.getModelInfoCap(this.player).ifPresent(cap -> {
154152
RenderUtil.scissor(this.x + 93, this.y, 206, 235);

src/main/java/com/elfmcys/yesstevemodel/client/gui/ScreenUtils.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/com/elfmcys/yesstevemodel/client/gui/button/ConfigCheckBox.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ConfigCheckBox extends Checkbox {
1111
* @param font 计算宽度用,文本较长时按钮宽度(点击区域)也会跟着变长。
1212
*/
1313
public ConfigCheckBox(int pX, int pY, String key, @Nonnull FontRenderer font, boolean current, Consumer<Boolean> setter) {
14-
super(pX, pY, I18n.format("gui.yes_steve_model.config." + key), font, current, (button -> {
14+
super(pX, pY, I18n.format("gui.yes_steve_model." + key), font, current, (button -> {
1515
setter.accept(((Checkbox) button).selected());
1616
}));
1717
}

0 commit comments

Comments
 (0)