Skip to content

Commit

Permalink
Fabric loader version downgraded to 0.16.0
Browse files Browse the repository at this point in the history
Fixed a bug with displaying when there are more than 12 of them
  • Loading branch information
PrometheuzzZ committed Oct 10, 2024
1 parent aa8ac79 commit a9f2f9e
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Minecraft_Server.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions gradle.properties2
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions src/main/java/pj/inventorybinds/ru/InventoryBinds.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ private static void loadButtons(){

if(!firstRun){


ModConfigs.reloadConfig();

} else {

firstRun = false;

}

ButtonsList buttonsList = ButtonsConfig.getButtonsList();
Expand All @@ -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++;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pj/inventorybinds/ru/config/SimpleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> config = new HashMap<>();
private final ConfigRequest request;
private boolean broken = false;
Expand Down Expand Up @@ -108,8 +108,6 @@ private void loadConfig() throws IOException {
allConfig += line;
}


System.out.println(allConfig);
config.put( "BUTTONS", allConfig );
}

Expand Down
32 changes: 28 additions & 4 deletions src/main/java/pj/inventorybinds/ru/gui/buttons/ButtonWidget.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

114 changes: 114 additions & 0 deletions src/main/java/pj/inventorybinds/ru/utils/ImageUtils.java
Original file line number Diff line number Diff line change
@@ -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<BufferedImage> getPlayerSkin(String name, GetSkinDecorator getSkinDecorator) throws NullPointerException, JsonIOException, IOException {
Optional<BufferedImage> skin = getSkinDecorator.getSkin(name);

if (skin.isEmpty()) {
LOGGER.warn("[ImageUtils] skin of '{}' was not found", name);
}

return skin;
}

public static Optional<BufferedImage> 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;
}



}
7 changes: 4 additions & 3 deletions src/main/resources/inventorybinds.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"mixins": [
],
"client": [
"HandledScreenHook",
"RecipeBookWidgetMixin",
"AbstractInventoryScreenMixin",
"ChatScreenMixin"
"ChatScreenMixin",
"HandledScreenHook",
"PlayerSkinTextureAccessor",
"RecipeBookWidgetMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit a9f2f9e

Please sign in to comment.