Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Jun 14, 2023
2 parents 2391948 + 5a6ad62 commit e1e3f94
Show file tree
Hide file tree
Showing 41 changed files with 406 additions and 276 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 7.5.3

* Invalid skins are now hidden by default in the Skin Library
* Added even more sanity checks when uploading stuff
* Fixed father/mother at baby item not always being correct

# 7.5.2

* Removed gold dust
Expand Down
50 changes: 37 additions & 13 deletions common/src/main/java/net/mca/client/gui/SkinLibraryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.mca.Config;
import net.mca.MCA;
import net.mca.client.gui.immersiveLibrary.Api;
import net.mca.client.gui.immersiveLibrary.Auth;
import net.mca.client.gui.immersiveLibrary.SkinCache;
import net.mca.client.gui.immersiveLibrary.Workspace;
import net.mca.client.gui.immersiveLibrary.*;
import net.mca.client.gui.immersiveLibrary.responses.*;
import net.mca.client.gui.immersiveLibrary.types.LiteContent;
import net.mca.client.gui.immersiveLibrary.types.User;
Expand Down Expand Up @@ -67,6 +64,7 @@ public class SkinLibraryScreen extends Screen implements SkinListUpdateListener

private String filteredString = "";
private SortingMode sortingMode = SortingMode.LIKES;
private boolean filterInvalidSkins = true;

private final List<LiteContent> serverContent = new ArrayList<>();
private List<LiteContent> filteredContent = new ArrayList<>();
Expand Down Expand Up @@ -118,6 +116,7 @@ public class SkinLibraryScreen extends Screen implements SkinListUpdateListener
private static HorizontalColorPickerWidget saturationWidget;
private static HorizontalColorPickerWidget brightnessWidget;
private TextFieldWidget textFieldWidget;
private boolean skipHairWarning;

public SkinLibraryScreen() {
this(null, null);
Expand Down Expand Up @@ -201,7 +200,15 @@ private void reloadDatabase(Runnable callback) {
}
}).thenRunAsync(() -> {
// fetch assets
Response response = request(Api.HttpMethod.GET, ContentListResponse.class, "content/mca");
Response response;
if (filterInvalidSkins) {
response = request(Api.HttpMethod.GET, ContentListResponse.class, "content/mca", Map.of(
"tag_filter", "invalid",
"invert_filter", "true"
));
} else {
response = request(Api.HttpMethod.GET, ContentListResponse.class, "content/mca");
}
if (response instanceof ContentListResponse contentListResponse) {
SkinCache.setContent(List.of(contentListResponse.contents()));
updateSearch();
Expand Down Expand Up @@ -437,7 +444,7 @@ private List<Text> getMetaDataText(LiteContent content) {
));
texts.addAll(wrap);

if (!SkinCache.isValid(content.contentid())) {
if (content.tags().contains("invalid")) {
texts.add(Text.translatable("gui.skin_library.probably_not_valids").formatted(Formatting.BOLD).formatted(Formatting.RED));
}

Expand Down Expand Up @@ -744,6 +751,17 @@ private void rebuild() {
updateSearch();
}));


//filter
addDrawableChild(new ToggleableTooltipIconButtonWidget(width / 2 + 130 + 22 * 2, height / 2 + 82, 9 * 16, 3 * 16,
filterInvalidSkins,
Text.translatable("gui.skin_library.filter_invalid"),
v -> {
filterInvalidSkins = !filterInvalidSkins;
reloadDatabase();
}));


//search
TextFieldWidget textFieldWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, width / 2 - 200 + 65, height / 2 - 110 + 2, 110, 16,
Text.translatable("gui.skin_library.search")));
Expand Down Expand Up @@ -782,7 +800,7 @@ private void rebuild() {
drawControls(c, false, cx, cy);

//sorting icons
if (!SkinCache.isValid(c.contentid())) {
if (c.tags().contains("invalid")) {
addDrawableChild(new ToggleableTooltipIconButtonWidget(cx + 12, cy - 16, 9 * 16, 3 * 16,
true,
Text.translatable("gui.skin_library.probably_not_valids"),
Expand Down Expand Up @@ -871,7 +889,6 @@ private void rebuild() {
//tags
int ty = height / 2 - 70;
for (String tag : focusedContent.tags()) {
// todo blacklisted tags could be a bit more smooth, maybe include professions
if (!tag.equals("clothing") && !tag.equals("hair")) {
int w = textRenderer.getWidth(tag) + 10;
if (canModifyFocusedContent()) {
Expand Down Expand Up @@ -1360,7 +1377,7 @@ private void setSelectionPage(int p) {
}

private int getMaxPages() {
return (int) Math.ceil(filteredContent.size() / 24.0);
return (int) Math.ceil(filteredContent.size() / ((double) CLOTHES_PER_PAGE));
}

@Override
Expand Down Expand Up @@ -1411,11 +1428,18 @@ private void publish() {
return;
}

if (!SkinCache.verify(workspace.currentImage)) {
if (!Utils.verify(workspace.currentImage)) {
setError(Text.translatable("gui.skin_library.read_the_help"));
return;
}

if (workspace.skinType == SkinType.HAIR && !Utils.verifyHair(workspace.currentImage) && !skipHairWarning) {
setError(Text.translatable("gui.skin_library.read_the_help_hair"));
skipHairWarning = true;
return;
}
skipHairWarning = false;

if (!uploading) {
uploading = true;
CompletableFuture.runAsync(() -> {
Expand Down Expand Up @@ -1445,7 +1469,7 @@ private void publish() {
}

// open detail page
getContentById(contentid).ifPresent(content -> {
getSubmittedContent(contentid).ifPresent(content -> {
focusedContent = content;
setPage(Page.DETAIL);
uploading = false;
Expand Down Expand Up @@ -1474,7 +1498,7 @@ private Optional<LiteContent> getServerContentById(int contentid) {
return serverContent.stream().filter(v -> v.contentid() == contentid).findAny();
}

private Optional<LiteContent> getSubscribedContentById(int contentid) {
private Optional<LiteContent> getSubmittedContent(int contentid) {
return currentUser == null ? Optional.empty() : currentUser.submissions().stream().filter(v -> v.contentid() == contentid).findAny();
}

Expand All @@ -1490,7 +1514,7 @@ private void setTag(int contentid, String tag, boolean add) {
c.tags().remove(tag);
}
});
getSubscribedContentById(contentid).ifPresent(c -> {
getSubmittedContent(contentid).ifPresent(c -> {
if (add) {
c.tags().add(tag);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.mca.client.gui.immersiveLibrary.responses.ContentResponse;
import net.mca.client.gui.immersiveLibrary.responses.Response;
import net.mca.client.gui.immersiveLibrary.types.LiteContent;
import net.mca.client.resources.SkinLocations;
import net.mca.client.resources.SkinMeta;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.NativeImage;
Expand All @@ -29,7 +28,6 @@ public class SkinCache {
private static final Gson gson = new Gson();

static final Map<Integer, Boolean> requested = new ConcurrentHashMap<>();
static final Map<Integer, Boolean> probablyValid = new HashMap<>();
static final Map<Integer, Identifier> textureIdentifiers = new HashMap<>();
static final Map<Integer, NativeImage> images = new HashMap<>();
static final Map<Integer, SkinMeta> metaCache = new HashMap<>();
Expand Down Expand Up @@ -108,22 +106,6 @@ public static void sync(int contentid, int currentVersion) {
}
}

// Sanity check of skins by checking if at least one skin pixel is transparent, thus not being a valid vanilla skin, thus requiring at least minimal effort to convert to a valid skin
public static boolean verify(NativeImage image) {
int errors = 0;
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
if (SkinLocations.SKIN_LOOKUP[x][y] && image.getOpacity(x, y) == 0) {
errors++;
if (errors > 6) {
return true;
}
}
}
}
return false;
}

private static void loadResources(int contentid) {
// Load meta
try {
Expand All @@ -140,7 +122,6 @@ private static void loadResources(int contentid) {
// Load new
NativeImage image = NativeImage.read(stream);
Identifier identifier = new Identifier("immersive_library", String.valueOf(contentid));
probablyValid.put(contentid, verify(image));
MinecraftClient.getInstance().getTextureManager().registerTexture(identifier, new NativeImageBackedTexture(image));
textureIdentifiers.put(contentid, identifier);
images.put(contentid, image);
Expand Down Expand Up @@ -170,10 +151,6 @@ public static Identifier getTextureIdentifier(int contentid) {
return textureIdentifiers.getOrDefault(contentid, DEFAULT_SKIN);
}

public static boolean isValid(int contentid) {
return probablyValid.getOrDefault(contentid, true);
}

public static void setContent(List<LiteContent> content) {
requested.clear();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.mca.client.gui.immersiveLibrary;

import net.mca.client.resources.SkinLocations;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.util.math.MathHelper;

public class Utils {
// Sanity check of skins by checking if at least one skin pixel is transparent, thus not being a valid vanilla skin, thus requiring at least minimal effort to convert to a valid skin
public static boolean verify(NativeImage image) {
int errors = 0;
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
if (SkinLocations.SKIN_LOOKUP[x][y] && image.getOpacity(x, y) == 0) {
errors++;
if (errors > 6) {
return true;
}
}
}
}
return false;
}

//Check if hair is grayscale and bright
public static boolean verifyHair(NativeImage image) {
int errors = 0;
int pixels = 0;
double brightness = 0;
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
int r = image.getRed(x, y) & 0xFF;
int g = image.getGreen(x, y) & 0xFF;
int b = image.getBlue(x, y) & 0xFF;
int a = image.getOpacity(x, y) & 0xFF;

if (a > 0) {
int l = MathHelper.clamp((int) (0.2126 * r + 0.7152 * g + 0.0722 * b), 0, 255);

brightness += l;

pixels++;

errors += Math.abs(r - l);
errors += Math.abs(g - l);
errors += Math.abs(b - l);
}
}
}

brightness /= pixels;

return errors < pixels && brightness > 160.0;
}
}
3 changes: 2 additions & 1 deletion common/src/main/java/net/mca/entity/ai/Pregnancy.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public void procreate(Entity spouse) {

long seed = random.nextLong();
for (int i = 0; i < count; i++) {
ItemStack stack = BabyItem.createItem(mother, spouse, seed);
boolean flip = mother.getGenetics().getGender() == Gender.MALE;
ItemStack stack = BabyItem.createItem(flip ? spouse : mother, flip ? mother : spouse, seed);
if (!(spouse instanceof PlayerEntity player && player.giveItemStack(stack))) {
mother.getInventory().addStack(stack);
}
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/af_za.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/ar_sa.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/be_by.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/cs_cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Helligkeit erhöhen",
"gui.skin_library.remove_saturation": "Sättigung entfernen",
"gui.skin_library.hair_color": "Farbvorschau",
"gui.skin_library.probably_not_valids": "Skin könnte ungültig sein!",
"gui.skin_library.read_the_help": "Dieser Skin scheint ungültig zu sein!",
"gui.skin_library.meta.chance": "Wahrscheinlichkeit",
"gui.skin_library.meta.chance.tooltip": "Wahrscheinlichkeit, dass dieser Vermögenswert von den Dorfbewohnern genutzt wird.",
"gui.skin_library.meta.by": "Von %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/el_gr.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/en_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"gui.skin_library.more_brightness": "Increase brightness",
"gui.skin_library.remove_saturation": "Remove Saturation",
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
"gui.skin_library.meta.by": "By %s",
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/mca/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
"gui.skin_library.subscribe": "Use server wide!",
"gui.skin_library.sort_likes": "Sort by likes",
"gui.skin_library.sort_newest": "Sort by date",
"gui.skin_library.filter_invalid": "Filter invalid content",
"gui.skin_library.like": "Like",
"gui.skin_library.edit": "Edit",
"gui.skin_library.delete": "Delete",
Expand All @@ -384,6 +385,7 @@
"gui.skin_library.hair_color": "Preview color",
"gui.skin_library.probably_not_valids": "Skin could be invalid!",
"gui.skin_library.read_the_help": "This skin appears to be invalid!",
"gui.skin_library.read_the_help_hair": "This hair might be too dark or not grayscale!",

"gui.skin_library.meta.chance": "Chance",
"gui.skin_library.meta.chance.tooltip": "Probability that this asset is used by villagers.",
Expand Down
Loading

0 comments on commit e1e3f94

Please sign in to comment.