diff --git a/.idea/runConfigurations/Minecraft_Server.xml b/.idea/runConfigurations/Minecraft_Server.xml
index e087494..d26f272 100644
--- a/.idea/runConfigurations/Minecraft_Server.xml
+++ b/.idea/runConfigurations/Minecraft_Server.xml
@@ -12,5 +12,5 @@
-
+
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index fa8abb7..ed590e3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -3,14 +3,13 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
- minecraft_version=1.21
- yarn_mappings=1.21+build.9
- loader_version=0.16.5
+minecraft_version=1.21.1
+yarn_mappings=1.21.1+build.3
+loader_version=0.16.0
# Mod Properties
- mod_version = 2.0-1.21
+ mod_version = 2.1-1.21.1
maven_group = pj.inventorybinds.ru
archives_base_name = InventoryBinds
# Dependencies
# check this on https://modmuss50.me/fabric.html
- fabric_version=0.102.0+1.21
-
+fabric_version=0.105.0+1.21.1
diff --git a/gradle.properties2 b/gradle.properties2
new file mode 100644
index 0000000..dbb3f5b
--- /dev/null
+++ b/gradle.properties2
@@ -0,0 +1,15 @@
+# Done to increase the memory available to gradle.
+org.gradle.jvmargs=-Xmx1G
+
+# Fabric Properties
+# check these on https://modmuss50.me/fabric.html
+minecraft_version=1.21
+yarn_mappings=1.21+build.9
+loader_version=0.16.0
+# Mod Properties
+mod_version = 2.1-1.21
+maven_group = pj.inventorybinds.ru
+archives_base_name = InventoryBinds
+# Dependencies
+# check this on https://modmuss50.me/fabric.html
+fabric_version=0.102.0+1.21
diff --git a/src/main/java/pj/inventorybinds/ru/InventoryBinds.java b/src/main/java/pj/inventorybinds/ru/InventoryBinds.java
index 497344f..478bbfc 100644
--- a/src/main/java/pj/inventorybinds/ru/InventoryBinds.java
+++ b/src/main/java/pj/inventorybinds/ru/InventoryBinds.java
@@ -82,11 +82,12 @@ private static void loadButtons(){
if(!firstRun){
-
ModConfigs.reloadConfig();
} else {
+
firstRun = false;
+
}
ButtonsList buttonsList = ButtonsConfig.getButtonsList();
@@ -95,17 +96,8 @@ private static void loadButtons(){
int row = 0;
for (ButtonJson buttonJson : buttonsList.getButtons()){
- if(index==6){
- index = 0;
- row++;
- }
-
- if(index==12){
- index = 0;
- row++;
- }
- if(index==18){
+ if (index % 6 == 0 && index != 0) {
index = 0;
row++;
}
diff --git a/src/main/java/pj/inventorybinds/ru/config/SimpleConfig.java b/src/main/java/pj/inventorybinds/ru/config/SimpleConfig.java
index 640b517..ea1d13d 100644
--- a/src/main/java/pj/inventorybinds/ru/config/SimpleConfig.java
+++ b/src/main/java/pj/inventorybinds/ru/config/SimpleConfig.java
@@ -18,7 +18,7 @@
public class SimpleConfig {
- private static final Logger LOGGER = LogManager.getLogger("SimpleConfig");
+ public static final Logger LOGGER = LogManager.getLogger("INVENTORY_BINDS");
private final HashMap config = new HashMap<>();
private final ConfigRequest request;
private boolean broken = false;
@@ -108,8 +108,6 @@ private void loadConfig() throws IOException {
allConfig += line;
}
-
- System.out.println(allConfig);
config.put( "BUTTONS", allConfig );
}
diff --git a/src/main/java/pj/inventorybinds/ru/gui/buttons/ButtonWidget.java b/src/main/java/pj/inventorybinds/ru/gui/buttons/ButtonWidget.java
index 4bed1fb..889cc40 100644
--- a/src/main/java/pj/inventorybinds/ru/gui/buttons/ButtonWidget.java
+++ b/src/main/java/pj/inventorybinds/ru/gui/buttons/ButtonWidget.java
@@ -1,17 +1,19 @@
package pj.inventorybinds.ru.gui.buttons;
+import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.gui.PlayerSkinDrawer;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.MerchantScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
-import net.minecraft.client.option.KeyBinding;
+import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
@@ -20,9 +22,15 @@
import pj.inventorybinds.ru.InventoryBinds;
import pj.inventorybinds.ru.config.ButtonsConfig;
import pj.inventorybinds.ru.config.buttons.ButtonJson;
-import pj.inventorybinds.ru.gui.ModCreateBindScreen;
import pj.inventorybinds.ru.gui.ModEditBindScreen;
import pj.inventorybinds.ru.gui.screen.PJScreen;
+import pj.inventorybinds.ru.utils.GetSkinFromMojang;
+import pj.inventorybinds.ru.utils.ImageUtils;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Optional;
+import java.util.UUID;
import static pj.inventorybinds.ru.InventoryBinds.MOD_ID;
@@ -39,6 +47,8 @@ public class ButtonWidget extends TexturedButtonWidget {
private final int buttonId;
private final boolean setting;
+
+
private PressAction onPress;
public ButtonWidget(HandledScreen> screen, int buttonIndex, int row, String description, Item items, PressAction pressAction, int buttonId) {
@@ -94,9 +104,11 @@ public int getX() {
x += 77;
}
- if (this.row == 1) {
- x += 22;
+ if (this.row > 0) {
+ x += (22*this.row);
}
+
+
return x;
}
@@ -190,11 +202,23 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt
this.drawTexture(context, TEXTURE_SETTINGS, this.getX(), this.getY(), 0, 0, offset, this.width, this.height, 20, 40);
}
+
if (this.itemIco == Items.ENDER_CHEST) {
context.drawItem(new ItemStack(this.itemIco), this.getX() + 2, this.getY() + 2);
context.drawItem(new ItemStack(this.itemIco), this.getX() + 2, this.getY() + 2);
} else if (this.itemIco == Items.CHEST) {
context.drawItem(new ItemStack(this.itemIco), this.getX() + 2, this.getY() + 2);
+ // } else if (this.itemIco == Items.TRAPPED_CHEST) {
+
+
+ // UUID uuid = UUID.fromString("069a79f4-44e9-4726-a5be-fca90e38aaf5");
+
+ // PlayerListEntry playerListEntry = new PlayerListEntry(new GameProfile(uuid, "Notch"), true);
+
+ // PlayerSkinDrawer.draw(context, playerListEntry.getSkinTextures().texture(), this.getX() + 2, this.getY() + 2, 16, true, true);
+
+
+
} else {
context.drawItem(new ItemStack(this.itemIco), this.getX() + 2, this.getY() + 2);
}
diff --git a/src/main/java/pj/inventorybinds/ru/mixin/PlayerSkinTextureAccessor.java b/src/main/java/pj/inventorybinds/ru/mixin/PlayerSkinTextureAccessor.java
new file mode 100644
index 0000000..6e103f0
--- /dev/null
+++ b/src/main/java/pj/inventorybinds/ru/mixin/PlayerSkinTextureAccessor.java
@@ -0,0 +1,15 @@
+package pj.inventorybinds.ru.mixin;
+
+import net.minecraft.client.texture.PlayerSkinTexture;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import java.io.File;
+
+@Mixin(PlayerSkinTexture.class)
+public interface PlayerSkinTextureAccessor {
+
+ @Accessor
+ File getCacheFile();
+}
+
diff --git a/src/main/java/pj/inventorybinds/ru/utils/ImageUtils.java b/src/main/java/pj/inventorybinds/ru/utils/ImageUtils.java
new file mode 100644
index 0000000..d713278
--- /dev/null
+++ b/src/main/java/pj/inventorybinds/ru/utils/ImageUtils.java
@@ -0,0 +1,114 @@
+package pj.inventorybinds.ru.utils;
+
+import com.google.gson.JsonIOException;
+import net.minecraft.client.texture.NativeImage;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+
+import static pj.inventorybinds.ru.config.SimpleConfig.LOGGER;
+
+public class ImageUtils {
+
+ public static BufferedImage getBufferedImgFromNativeImg(NativeImage nativeImage) {
+ int width = nativeImage.getWidth();
+ int height = nativeImage.getHeight();
+ BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int color = nativeImage.getColor(x, y);//ABGR
+
+ bufferedImage.setRGB(x, y, ((color >> 16) & 0xFF) | ((color & 0xFF) << 16) | (color & 0xFF00FF00));//ARGB
+ }
+ }
+
+ return bufferedImage;
+ }
+
+
+ public static Optional getPlayerSkin(String name, GetSkinDecorator getSkinDecorator) throws NullPointerException, JsonIOException, IOException {
+ Optional skin = getSkinDecorator.getSkin(name);
+
+ if (skin.isEmpty()) {
+ LOGGER.warn("[ImageUtils] skin of '{}' was not found", name);
+ }
+
+ return skin;
+ }
+
+ public static Optional getImageFromUrl(String urlLocation) throws IOException {
+ try (var httpClient = FzmmUtils.getHttpClient()) {
+ HttpGet httpGet = new HttpGet(urlLocation);
+
+ HttpResponse response = httpClient.execute(httpGet);
+ HttpEntity resEntity = response.getEntity();
+ if (resEntity != null) {
+ try (InputStream inputStream = resEntity.getContent()) {
+ BufferedImage image = ImageIO.read(inputStream);
+ return Optional.ofNullable(image);
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
+ public static NativeImage toNativeImage(BufferedImage image) {
+
+ // """NativeImage.Format.RGBA""" = ABGR
+ NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, image.getWidth(), image.getHeight(), false);
+ ColorModel colorModel = image.getColorModel();
+ for (int y = 0; y < image.getHeight(); y++) {
+ for (int x = 0; x < image.getWidth(); x++) {
+
+ // avoid using image.getRGB(x, y) because it will result in packing
+ // in ARGB format, and then it would have to unpack it to repack
+ // it in ABGR format. By avoiding this, it can directly pack in ABGR format
+ Object elements = image.getRaster().getDataElements(x, y, null);
+
+ int abgr = (colorModel.getAlpha(elements) << 24) |
+ (colorModel.getBlue(elements) << 16) |
+ (colorModel.getGreen(elements) << 8) |
+ colorModel.getRed(elements);
+
+ nativeImage.setColor(x, y, abgr);
+ }
+ }
+ return nativeImage;
+ }
+
+ public static BufferedImage withType(BufferedImage image, int type) {
+ BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), type);
+
+ Graphics2D g = newImage.createGraphics();
+ g.drawImage(image, 0, 0, null);
+ g.dispose();
+
+ image.flush();
+ return newImage;
+ }
+
+ public static boolean isEquals(BufferedImage image1, BufferedImage image2) {
+ if (image1.getWidth() != image2.getWidth() || image1.getHeight() != image2.getHeight())
+ return false;
+
+ for (int y = 0; y < image1.getHeight(); y++) {
+ for (int x = 0; x < image1.getWidth(); x++) {
+ if (image1.getRGB(x, y) != image2.getRGB(x, y))
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+
+}
diff --git a/src/main/resources/inventorybinds.mixins.json b/src/main/resources/inventorybinds.mixins.json
index 27939e9..234d50f 100644
--- a/src/main/resources/inventorybinds.mixins.json
+++ b/src/main/resources/inventorybinds.mixins.json
@@ -6,10 +6,11 @@
"mixins": [
],
"client": [
- "HandledScreenHook",
- "RecipeBookWidgetMixin",
"AbstractInventoryScreenMixin",
- "ChatScreenMixin"
+ "ChatScreenMixin",
+ "HandledScreenHook",
+ "PlayerSkinTextureAccessor",
+ "RecipeBookWidgetMixin"
],
"injectors": {
"defaultRequire": 1