Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
public class ClientModelManager {
public static Map<ResourceLocation, List<ResourceLocation>> MODELS = Maps.newHashMap();
public static Map<ResourceLocation, Pair<Double, Double>> SCALE_INFO = Maps.newHashMap();
public static Map<ResourceLocation, List<String>> EXTRA_INFO = Maps.newHashMap();
public static Map<ResourceLocation, String[]> EXTRA_ANIMATION_NAME = Maps.newHashMap();
public static Map<ResourceLocation, List<String>> META_DATA = Maps.newHashMap();
public static Map<ResourceLocation, ExtraInfo> EXTRA_INFO = Maps.newHashMap();
public static AnimationFile DEFAULT_ANIMATION_FILE = new AnimationFile();
public static AnimationFile DEFAULT_ARROW_ANIMATION_FILE = new AnimationFile();
public static List<String> CACHE_MD5 = Lists.newArrayList();
public static List<String> AUTH_MODELS = Lists.newArrayList();
public static byte[] PASSWORD;
Expand Down Expand Up @@ -105,7 +104,7 @@ private static void registerGeo(ResourceLocation modelId, String partName, byte[
public static void registerTexture(ResourceLocation modelId, Map<String, byte[]> mapData) {
List<ResourceLocation> textures = Lists.newArrayList();
for (String name : mapData.keySet()) {
if (!name.equals(IArrowExtraInfo.TEXTURE_NAME)) {
if (isModelTexture(ModelIdUtil.getInfoId(modelId), name)) {
ResourceLocation textureId = ModelIdUtil.getSubModelId(modelId, name);
textures.add(textureId);
}
Expand All @@ -117,6 +116,12 @@ public static void registerTexture(ResourceLocation modelId, Map<String, byte[]>
}
}

private static boolean isModelTexture(ResourceLocation infoId, String name) {
if (name.equals(IArrowExtraInfo.TEXTURE_NAME)) return false;
final ExtraInfo extraInfo = EXTRA_INFO.get(infoId);
return !name.equals(extraInfo.getGuiBackground()) && !name.equals(extraInfo.getGuiForeground());
}

private static void registerTexture(ResourceLocation textureId, byte[] data) {
// 确保主线程上传
final Minecraft mc = Minecraft.getMinecraft();
Expand All @@ -140,6 +145,7 @@ private static void registerAnimations(ResourceLocation mainId, Map<String, byte
AnimationFile other = getAnimationFile(new String(bytes, StandardCharsets.UTF_8));
mergeAnimationFile(main, other);
});
// 从默认补全缺失的动画
DEFAULT_ANIMATION_FILE.animations().forEach((name, action) -> {
if (!main.animations().containsKey(name)) {
main.putAnimation(name, action);
Expand Down Expand Up @@ -168,6 +174,9 @@ private static AnimationFile getAnimationFile(String file) {
return animationFile;
}

/**
* @return main animation
*/
private static AnimationFile mergeAnimationFile(AnimationFile main, AnimationFile other) {
other.animations().forEach(main::putAnimation);
return main;
Expand All @@ -178,11 +187,7 @@ public static void loadDefaultModel() {
ModelData data = FolderFormat.getModelData(ServerModelManager.BUILTIN, "default", false);
data.getAnimation().forEach((name, bytes) -> {
AnimationFile animationFile = getAnimationFile(new String(bytes, StandardCharsets.UTF_8));
if ("arrow".equals(name)) {
mergeAnimationFile(DEFAULT_ARROW_ANIMATION_FILE, animationFile);
} else {
mergeAnimationFile(DEFAULT_ANIMATION_FILE, animationFile);
}
if (!"arrow".equals(name)) mergeAnimationFile(DEFAULT_ANIMATION_FILE, animationFile);
});
ClientModelManager.registerAll(data);
} catch (IOException e) {
Expand All @@ -195,8 +200,8 @@ public static void sendSyncModelMessage() {
CACHE_MD5.clear();
AUTH_MODELS.clear();
SCALE_INFO.clear();
META_DATA.clear();
EXTRA_INFO.clear();
EXTRA_ANIMATION_NAME.clear();
ConditionManager.clear();
String[] md5Info = getMd5Info();
SyncModelFiles syncModelFiles = new SyncModelFiles(md5Info);
Expand Down Expand Up @@ -230,23 +235,24 @@ private static byte[] getBytes(Path root, String fileName) throws IOException {
private static void addExtraInfo(ResourceLocation modelId, @Nullable ExtraInfo extraInfo) {
if (extraInfo == null) return;
ResourceLocation infoId = ModelIdUtil.getInfoId(modelId);
EXTRA_INFO.put(infoId, handleExtraInfo(extraInfo));
EXTRA_INFO.put(infoId, extraInfo);
META_DATA.put(infoId, readMetaData(extraInfo));
if (extraInfo.getFree()) {
AUTH_MODELS.remove(modelId.getPath());
}
if (extraInfo.getExtraAnimationNames() != null && extraInfo.getExtraAnimationNames().length > 0) {
EXTRA_ANIMATION_NAME.put(infoId, extraInfo.getExtraAnimationNames());
if (modelId.getPath().equals("default") && extraInfo.getPreviewAnimation() != null) {
DEFAULT_ANIMATION_FILE.animations().remove(extraInfo.getPreviewAnimation());
}
}

@Nullable
private static List<String> handleExtraInfo(@Nullable ExtraInfo extraInfo) {
private static List<String> readMetaData(@Nullable ExtraInfo extraInfo) {
if (extraInfo == null || StringUtils.isBlank(extraInfo.getName())) {
return null;
}
List<String> component = Lists.newArrayList();
component.add(TextFormatting.GOLD + extraInfo.getName());
if (StringUtils.isNoneBlank(extraInfo.getTips())) {
if (extraInfo.getTips() != null && StringUtils.isNoneBlank(extraInfo.getTips())) {
String[] split = extraInfo.getTips().split("\n");
Arrays.stream(split).forEach(s -> component.add(TextFormatting.GRAY + I18n.format(s)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import javax.annotation.Nullable;
import java.io.IOException;

public class AnimationRouletteScreen extends Screen {
private int x;
private int y;
private int selectId = -1;
private String[] names;
private @Nullable String[] names;

public AnimationRouletteScreen() {
}
Expand All @@ -43,9 +44,7 @@ public void initGui() {
if (this.mc != null && this.mc.player != null) {
CapabilityEvent.getModelInfoCap(this.mc.player).ifPresent(cap -> {
ResourceLocation modelId = cap.getModelId();
if (ClientModelManager.EXTRA_ANIMATION_NAME.containsKey(ModelIdUtil.getInfoId(modelId))) {
this.names = ClientModelManager.EXTRA_ANIMATION_NAME.get(ModelIdUtil.getInfoId(modelId));
}
this.names = ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(modelId)).getExtraAnimationNames();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public void initGui() {

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

this.addButton(new ConfigCheckBox(x + 5, y + 25, "disable_self_model", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 25, "config.disable_self_model", this.fontRenderer,
GeneralConfig.DISABLE_SELF_MODEL, (value) -> GeneralConfig.DISABLE_SELF_MODEL = value));
this.addButton(new ConfigCheckBox(x + 5, y + 47, "disable_other_model", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 47, "config.disable_other_model", this.fontRenderer,
GeneralConfig.DISABLE_OTHER_MODEL, (value) -> GeneralConfig.DISABLE_OTHER_MODEL = value));
this.addButton(new ConfigCheckBox(x + 5, y + 69, "print_animation_roulette_msg", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 69, "config.print_animation_roulette_msg", this.fontRenderer,
GeneralConfig.PRINT_ANIMATION_ROULETTE_MSG, (value) -> GeneralConfig.PRINT_ANIMATION_ROULETTE_MSG = value));
this.addButton(new ConfigCheckBox(x + 5, y + 91, "disable_self_hands", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 91, "config.disable_self_hands", this.fontRenderer,
GeneralConfig.DISABLE_SELF_HANDS, (value) -> GeneralConfig.DISABLE_SELF_HANDS = value));
this.addButton(new ConfigCheckBox(x + 5, y + 112, "disable_player_render", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 112, "config.disable_player_render", this.fontRenderer,
ExtraPlayerScreenConfig.DISABLE_PLAYER_RENDER, (value) -> ExtraPlayerScreenConfig.DISABLE_PLAYER_RENDER = value));
this.addButton(new ConfigCheckBox(x + 5, y + 134, "disable_arrows_model", this.fontRenderer,
this.addButton(new ConfigCheckBox(x + 5, y + 134, "config.disable_arrows_model", this.fontRenderer,
GeneralConfig.DISABLE_ARROWS_MODEL, (value) -> GeneralConfig.DISABLE_ARROWS_MODEL = value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.elfmcys.yesstevemodel.client.ClientModelManager;
import com.elfmcys.yesstevemodel.client.gui.button.*;
import com.elfmcys.yesstevemodel.client.input.PlayerModelScreenKey;
import com.elfmcys.yesstevemodel.config.Config;
import com.elfmcys.yesstevemodel.config.GeneralConfig;
import com.elfmcys.yesstevemodel.event.CapabilityEvent;
import com.elfmcys.yesstevemodel.geckolib3.geo.raw.pojo.ExtraInfo;
import com.elfmcys.yesstevemodel.util.ModelIdUtil;
import com.elfmcys.yesstevemodel.util.RenderUtil;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -115,6 +118,15 @@ public void initGui() {
}).setTooltips("gui.yes_steve_model.model.texture"));
this.addButton(new StarButton(this.x + 110, this.y + 5));

this.addButton(new ConfigCheckBox(this.x + 5, this.y - 22, "show_model_id_first", this.fontRenderer,
GeneralConfig.SHOW_MODEL_ID_FIRST, value -> GeneralConfig.SHOW_MODEL_ID_FIRST = value) {
@Override
public void onPress() {
super.onPress();
Config.save();
}
});

this.addButton(new FlatIconButton(this.x + 328, this.y + 5, 18, 18, 32, 0, (b) -> {
if (this.category != Category.ALL) {
this.category = Category.ALL;
Expand Down Expand Up @@ -173,9 +185,9 @@ public void initGui() {
int yStart = this.y + 28 + 93 * (i / 5);
CapabilityEvent.getAuthModelsCap(this.player).ifPresent(cap -> {
if (ClientModelManager.AUTH_MODELS.contains(id.getPath()) && !cap.containModel(id)) {
this.addButton(new ModelButton(xStart, yStart, true, Pair.of(id, this.models.get(id)), ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(id)), this.player));
this.addButton(new ModelButton(xStart, yStart, true, Pair.of(id, this.models.get(id)), ClientModelManager.META_DATA.get(ModelIdUtil.getInfoId(id)), this.player));
} else {
this.addButton(new ModelButton(xStart, yStart, false, Pair.of(id, this.models.get(id)), ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(id)), this.player));
this.addButton(new ModelButton(xStart, yStart, false, Pair.of(id, this.models.get(id)), ClientModelManager.META_DATA.get(ModelIdUtil.getInfoId(id)), this.player));
}
});
}
Expand All @@ -197,6 +209,10 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {

CapabilityEvent.getModelInfoCap(this.player).ifPresent(cap -> {
String modelName = cap.getModelId().getPath();
final ExtraInfo extraInfo = ClientModelManager.EXTRA_INFO.get(ModelIdUtil.getInfoId(cap.getModelId()));
if (extraInfo.getName() != null && !extraInfo.getName().isEmpty()) {
modelName = extraInfo.getName();
}
List<String> modelNameSplit = this.fontRenderer.listFormattedStringToWidth(modelName, 125);
int lineY = this.y + 205;
for (String line : modelNameSplit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class PlayerTextureScreen extends Screen {
private float pitch = -5;
private boolean showGround = true;


public PlayerTextureScreen(PlayerModelScreen parent, ResourceLocation modelId, List<ResourceLocation> textures) {
this.parent = parent;
this.modelId = modelId;
Expand Down Expand Up @@ -141,12 +140,13 @@ public void initGui() {

@Override
public void drawScreen(int mouseX, int mouseY, float partialTick) {
//GlStateManager.translate(0, 0, -1000);
final float zLevel = this.zLevel;
this.zLevel -= 1000;
this.drawDefaultBackground();
this.drawGradientRect(this.x, this.y + 22, this.x + 90, this.y + 235, 0xff_222222, 0xff_222222);
this.drawGradientRect(this.x + 93, this.y, this.x + 299, this.y + 235, 0xff_222222, 0xff_222222);
this.drawGradientRect(this.x + 302, this.y, this.x + 420, this.y + 235, 0xff_222222, 0xff_222222);
//GlStateManager.translate(0, 0, 1000);
this.zLevel = zLevel;

CapabilityEvent.getModelInfoCap(this.player).ifPresent(cap -> {
RenderUtil.scissor(this.x + 93, this.y, 206, 235);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ConfigCheckBox extends Checkbox {
* @param font 计算宽度用,文本较长时按钮宽度(点击区域)也会跟着变长。
*/
public ConfigCheckBox(int pX, int pY, String key, @Nonnull FontRenderer font, boolean current, Consumer<Boolean> setter) {
super(pX, pY, I18n.format("gui.yes_steve_model.config." + key), font, current, (button -> {
super(pX, pY, I18n.format("gui.yes_steve_model." + key), font, current, (button -> {
setter.accept(((Checkbox) button).selected());
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void renderToolTip(GuiScreen screen, int pMouseX, int pMouseY) {
}

@Override
public void renderWidget(@Nonnull Minecraft mc, int mouseX, int mouseY, float pPartialTick) {
protected void renderWidget(@Nonnull Minecraft mc, int mouseX, int mouseY, float pPartialTick) {
FontRenderer font = mc.fontRenderer;
if (this.isSelect) {
this.drawGradientRect(this.x, this.y, this.x + this.width, this.y + this.height, 0xff_1E90FF, 0xff_1E90FF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FlatIconButton(int x, int y, int width, int height, int textureX, int tex
}

@Override
public void renderWidget(@Nonnull Minecraft mc, int mouseX, int mouseY, float pPartialTick) {
protected void renderWidget(@Nonnull Minecraft mc, int mouseX, int mouseY, float pPartialTick) {
super.renderWidget(mc, mouseX, mouseY, pPartialTick);
mc.getTextureManager().bindTexture(ICON);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Expand Down
Loading