Skip to content

Commit

Permalink
Merge branch '1.19.3' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Jun 4, 2023
2 parents 1245120 + 2391948 commit f1e3b77
Show file tree
Hide file tree
Showing 54 changed files with 223 additions and 209 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 7.5.2

* Removed gold dust
* Added compression to skin library networking
* Skin Editor will now reject most invalid skins
* Existing invalid skins are marked
* Changing workspace will rebuild trades

# 7.5.1

* Fixed a critical performance issue when childrens are stuck in a wall
Expand Down
54 changes: 36 additions & 18 deletions common/src/main/java/net/mca/client/gui/SkinLibraryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class SkinLibraryScreen extends Screen implements SkinListUpdateListener
private static HorizontalColorPickerWidget hueWidget;
private static HorizontalColorPickerWidget saturationWidget;
private static HorizontalColorPickerWidget brightnessWidget;
private TextFieldWidget textFieldWidget;

public SkinLibraryScreen() {
this(null, null);
Expand Down Expand Up @@ -210,10 +211,6 @@ private void reloadDatabase(Runnable callback) {
}).thenRunAsync(callback);
}

private void clearSearch() {
filteredString = "";
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
hoveredContent = null;
Expand Down Expand Up @@ -439,6 +436,11 @@ private List<Text> getMetaDataText(LiteContent content) {
Text.translatable("gui.skin_library.chance_val", (int) (meta.get().getChance() * 100)).formatted(Formatting.GRAY)
));
texts.addAll(wrap);

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

return texts;
}
}
Expand Down Expand Up @@ -504,13 +506,13 @@ protected void mouseMoved(double x, double y, double deltaX, double deltaY) {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (page == Page.EDITOR) {
// Pan
if (keyCode == GLFW.GLFW_KEY_SPACE) {
isPanning = true;
return true;
}
// Pan
if (keyCode == GLFW.GLFW_KEY_SPACE && (textFieldWidget == null || !textFieldWidget.isFocused())) {
isPanning = true;
return true;
}

if (page == Page.EDITOR && (textFieldWidget == null || !textFieldWidget.isFocused())) {
// Reset viewport
if (keyCode == GLFW.GLFW_KEY_R) {
x0 = 0.0f;
Expand Down Expand Up @@ -778,6 +780,15 @@ private void rebuild() {
int cy = height / 2 + 15 + (int) ((y - CLOTHES_V / 2.0 + 0.5) * 80);

drawControls(c, false, cx, cy);

//sorting icons
if (!SkinCache.isValid(c.contentid())) {
addDrawableChild(new ToggleableTooltipIconButtonWidget(cx + 12, cy - 16, 9 * 16, 3 * 16,
true,
Text.translatable("gui.skin_library.probably_not_valids"),
v -> {
}));
}
i++;
} else {
break;
Expand Down Expand Up @@ -894,7 +905,7 @@ private void rebuild() {
}
case EDITOR -> {
// name
TextFieldWidget textFieldWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, width / 2 - 60, height / 2 - 105, 120, 20,
textFieldWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, width / 2 - 60, height / 2 - 105, 120, 20,
Text.translatable("gui.skin_library.name")));
textFieldWidget.setMaxLength(1024);
textFieldWidget.setText(workspace.title);
Expand Down Expand Up @@ -1147,9 +1158,10 @@ private void drawControls(LiteContent content, boolean advanced, int cx, int cy)
// edit
if (advanced && canModifyContent(content)) {
widgets.add(new ToggleableTooltipIconButtonWidget(0, 0, 2 * 16, 3 * 16,
isLiked(content),
false,
Text.translatable("gui.skin_library.edit"),
v -> {

SkinCache.getImage(content).ifPresent(image -> {
SkinCache.getMeta(content).ifPresent(meta -> {
workspace = new Workspace(image, meta, content);
Expand Down Expand Up @@ -1177,8 +1189,13 @@ private void drawControls(LiteContent content, boolean advanced, int cx, int cy)
true,
Text.translatable("gui.skin_library.edit"),
v -> {
focusedContent = content;
setPage(Page.DETAIL);
if (isPanning && isModerator()) {
//admin tool
removeContent(content.contentid());
} else {
focusedContent = content;
setPage(Page.DETAIL);
}
}));
}

Expand Down Expand Up @@ -1265,10 +1282,6 @@ public void setPage(Page page) {
return;
}

if (page != this.page) {
clearSearch();
}

this.page = page;

if (page == Page.EDITOR) {
Expand Down Expand Up @@ -1398,6 +1411,11 @@ private void publish() {
return;
}

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

if (!uploading) {
uploading = true;
CompletableFuture.runAsync(() -> {
Expand Down
12 changes: 10 additions & 2 deletions common/src/main/java/net/mca/client/gui/immersiveLibrary/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;

public class Api {
private static final Gson gson = new GsonBuilder()
Expand Down Expand Up @@ -43,13 +44,14 @@ public static Response request(HttpMethod httpMethod, Class<? extends Response>
.collect(Collectors.joining("&", fullUrl + "?", ""));
}

HttpURLConnection con = (HttpURLConnection)(new URL(fullUrl)).openConnection();
HttpURLConnection con = (HttpURLConnection) (new URL(fullUrl)).openConnection();

// Set request method
con.setRequestMethod(httpMethod.name());

// Set request headers
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept-Encoding", "gzip");
con.setRequestProperty("Accept", "application/json");

// Set request body
Expand All @@ -69,7 +71,13 @@ public static Response request(HttpMethod httpMethod, Class<? extends Response>
}

// Parse answer
String response = IOUtils.toString(con.getInputStream(), StandardCharsets.UTF_8);
String response;
if ("gzip".equals(con.getContentEncoding())) {
response = IOUtils.toString(new GZIPInputStream(con.getInputStream()), StandardCharsets.UTF_8);
} else {
response = IOUtils.toString(con.getInputStream(), StandardCharsets.UTF_8);
}

return gson.fromJson(response, expectedAnswer);
} catch (IOException e) {
return new ErrorResponse(-1, e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 @@ -28,6 +29,7 @@ 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 @@ -106,6 +108,22 @@ 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 @@ -122,6 +140,7 @@ 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 @@ -151,6 +170,10 @@ 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
Expand Up @@ -7,7 +7,7 @@ public record Content(int contentid, int userid, String username, int likes, Set
public String toString() {
return "Content{" +
"contentid=" + contentid +
"userid=" + userid +
", userid=" + userid +
", username='" + username + '\'' +
", likes=" + likes +
", tags=" + tags +
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/net/mca/client/resources/SkinLocations.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import net.minecraft.text.Text;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

public class SkinLocations {
public enum Part {
Expand All @@ -13,7 +15,18 @@ public Text getTranslation() {
}
}

public static Set<Part> SKIN_PARTS = new HashSet<>();
static {
SKIN_PARTS.add(Part.HEAD);
SKIN_PARTS.add(Part.RIGHT_LEG);
SKIN_PARTS.add(Part.BODY);
SKIN_PARTS.add(Part.RIGHT_ARM);
SKIN_PARTS.add(Part.LEFT_LEG);
SKIN_PARTS.add(Part.LEFT_ARM);
}

public static final Part[][] LOOKUP = new Part[64][64];
public static final boolean[][] SKIN_LOOKUP = new boolean[64][64];

static {
add(Part.HEAD, 8, 0, 16, 8);
Expand Down Expand Up @@ -95,6 +108,10 @@ private static void add(Part part, int x0, int y0, int x1, int y1) {
for (int x = x0; x < x1; x++) {
for (int y = y0; y < y1; y++) {
LOOKUP[x][y] = part;

if (SKIN_PARTS.contains(part)) {
SKIN_LOOKUP[x][y] = true;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static NativeImage portLegacySkin(NativeImage image) {
* Checks if that skin could be a slim format
*/
public static boolean isSlimFormat(NativeImage image) {
return image.getOpacity(55, 25) <= 0;
return image.getOpacity(53, 25) <= 0;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/net/mca/entity/VillagerEntityMCA.java
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,9 @@ public void makeMercenary() {
inventory.addStack(new ItemStack(Items.FISHING_ROD));
inventory.addStack(new ItemStack(Items.BREAD, 16));
}

public void customLevelUp() {
this.setVillagerData(this.getVillagerData().withLevel(this.getVillagerData().getLevel() + 1));
this.fillRecipes();
}
}
21 changes: 13 additions & 8 deletions common/src/main/java/net/mca/entity/ai/Residency.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setWorkplace(ServerPlayerEntity player) {
// Set
GlobalPos globalPos = GlobalPos.create(player.getWorld().getRegistryKey(), blockPos);
entity.getBrain().remember(MemoryModuleType.JOB_SITE, globalPos);
player.getWorld().sendEntityStatus(entity, (byte)14);
player.getWorld().sendEntityStatus(entity, (byte) 14);
MinecraftServer minecraftServer = player.getWorld().getServer();
Optional.ofNullable(minecraftServer.getWorld(globalPos.getDimension())).flatMap((world) -> {
return world.getPointOfInterestStorage().getType(globalPos.getPos());
Expand All @@ -73,7 +73,12 @@ public void setWorkplace(ServerPlayerEntity player) {
return profession.heldWorkstation().test(registryEntry);
}).findFirst();
}).ifPresent((profession) -> {
entity.setVillagerData(entity.getVillagerData().withProfession(profession));
int level = entity.getVillagerData().getLevel();
entity.setVillagerData(entity.getVillagerData().withProfession(profession).withLevel(1));
entity.setOffers(null);
for (int l = 1; l < level; l++) {
entity.customLevelUp();
}
entity.reinitializeBrain(player.getWorld());
});

Expand All @@ -87,7 +92,7 @@ public void setWorkplace(ServerPlayerEntity player) {
}

public Optional<Village> getHomeVillage() {
VillageManager manager = VillageManager.get((ServerWorld)entity.world);
VillageManager manager = VillageManager.get((ServerWorld) entity.world);
return manager.getOrEmpty(entity.getTrackedValue(VILLAGE));
}

Expand All @@ -96,7 +101,7 @@ public Optional<Village> getHomeVillage() {
*/
public void seekHome() {
if (entity.requiresHome()) {
VillageManager manager = VillageManager.get((ServerWorld)entity.world);
VillageManager manager = VillageManager.get((ServerWorld) entity.world);
manager.findNearestVillage(entity).ifPresent(v -> {
leaveHome();
v.updateResident(entity);
Expand Down Expand Up @@ -156,10 +161,10 @@ public void tick() {

//report potential buildings within this villagers reach
private void reportBuildings() {
VillageManager manager = VillageManager.get((ServerWorld)entity.world);
VillageManager manager = VillageManager.get((ServerWorld) entity.world);

//fetch all near POIs
Stream<BlockPos> stream = ((ServerWorld)entity.world).getPointOfInterestStorage().getPositions(
Stream<BlockPos> stream = ((ServerWorld) entity.world).getPointOfInterestStorage().getPositions(
(type) -> true,
(p) -> !manager.cache.contains(p),
entity.getBlockPos(),
Expand All @@ -170,7 +175,7 @@ private void reportBuildings() {
stream.forEach(manager::reportBuilding);

// also add tombstones
GraveyardManager.get((ServerWorld)entity.world).reportToVillageManager(entity);
GraveyardManager.get((ServerWorld) entity.world).reportToVillageManager(entity);
}

public void setHome(ServerPlayerEntity player) {
Expand All @@ -180,7 +185,7 @@ public void setHome(ServerPlayerEntity player) {
}

// also trigger a building refresh, because why not
VillageManager manager = VillageManager.get((ServerWorld)player.world);
VillageManager manager = VillageManager.get((ServerWorld) player.world);
manager.processBuilding(player.getBlockPos(), true, false);

seekHome();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;

public class SmarterOpenDoorsTask extends MultiTickTask<LivingEntity> {
private static final int RUN_TIME = 20;
Expand All @@ -43,8 +44,10 @@ public SmarterOpenDoorsTask() {

@Override
protected boolean shouldRun(ServerWorld world, LivingEntity entity) {
//noinspection OptionalGetWithoutIsPresent
Path path = entity.getBrain().getOptionalMemory(MemoryModuleType.PATH).get();
Optional<Path> optionalMemory = entity.getBrain().getOptionalMemory(MemoryModuleType.PATH);
if (optionalMemory.isEmpty()) return false;

Path path = optionalMemory.get();

//Luke100000: I removed the path.isStart() check as this caused villagers to slam their face onto the door, not being able to open it anymore.
if (path.isFinished()) {
Expand Down
Loading

0 comments on commit f1e3b77

Please sign in to comment.