Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
- bugfixes regarding skull rendering
Browse files Browse the repository at this point in the history
- code cleanup
  • Loading branch information
UltraBlackLinux committed May 6, 2021
1 parent fa8ec37 commit 2df9bda
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ MineMenuFabric is a customizable menu, that lets you manage commands and chat me
Supports enchanted/playerhead icons and copying text, opening links, saying a message in the chat and creating categories to keep your menu sorted!


**Note: You need to reset the config after some major updates, as config sometimes changes and crashes your game, when you open the menu!**
**Note: You may need to reset the config after major updates, as the as it might change and crash your game, as you open the menu!**

Thanks to Girafi for the original mod [❤️](https://www.curseforge.com/minecraft/mc-mods/minemenu)
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Wrong user input in the config - working?

#Not working stuff
- enchant button sometimes requires two presses to get toggled

#TODO
~~- toggle keybind~~ You can't press a key, while in a gui
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.5
yarn_mappings=1.16.5+build.8
loader_version=0.11.3
# Mod Properties
mod_version=2.1
mod_version=2.2
maven_group=me.UltraBlackLinux
archives_base_name=MineMenuFabric
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import me.shedaniel.autoconfig.AutoConfig;
import me.ultrablacklinux.minemenufabric.client.config.Config;
import me.ultrablacklinux.minemenufabric.client.screen.MineMenuSelectScreen;
import me.ultrablacklinux.minemenufabric.client.screen.MineMenuSettingsScreen;
import me.ultrablacklinux.minemenufabric.client.util.GsonUtil;
import me.ultrablacklinux.minemenufabric.client.util.RandomUtil;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -13,6 +15,7 @@
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.lwjgl.glfw.GLFW;
import java.util.ArrayList;
Expand All @@ -24,8 +27,7 @@ public class MineMenuFabricClient implements ClientModInitializer {
public static KeyBinding keyBinding;
public static JsonObject minemenuData;
public static ArrayList<String> datapath;
public static HashMap<String, ItemStack> playerHeadData = new HashMap<>();
private static boolean buttonPressed;
public static HashMap<String, ItemStack> playerHeadCache = new HashMap<>();

@Override
public void onInitializeClient() {
Expand All @@ -42,15 +44,27 @@ public void onInitializeClient() {
minemenuData = new JsonObject();
AutoConfig.getConfigHolder(Config.class).save();
}

if (Config.get().minemenuFabric.resetHeadCache) {
Config.get().minemenuFabric.resetHeadCache = false;
playerHeadCache.clear();
}

if (mineMenuSelectScreen != null) this.mineMenuSelectScreen.tick();
});

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (keyBinding.wasPressed()) {
if (!(client.currentScreen instanceof MineMenuSelectScreen)) {
minemenuData = GsonUtil.fixEntryAmount(minemenuData);
client.openScreen(new MineMenuSelectScreen(minemenuData,
new TranslatableText("minemenu.default.title").getString(), null));
minemenuData = GsonUtil.fixEntryAmount(minemenuData); //it is not already assigned dumb intelli
try {
client.openScreen(new MineMenuSelectScreen(MineMenuFabricClient.minemenuData,
new TranslatableText("minemenu.default.title").getString(), null));
} catch (NullPointerException e) {
client.openScreen(null);
client.player.sendMessage(new TranslatableText("minemenu.error.config"), false);
}

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
import me.shedaniel.autoconfig.serializer.PartitioningSerializer;
import net.minecraft.item.ItemStack;

import java.util.HashMap;

@me.shedaniel.autoconfig.annotation.Config(name = "MinemenuFabric")
@me.shedaniel.autoconfig.annotation.Config.Gui.Background("minecraft:textures/block/gray_concrete.png")
Expand Down Expand Up @@ -50,9 +53,9 @@ public static class MinemenuFabric implements ConfigData {
public String emptyItemIcon = "minecraft:air";

@ConfigEntry.Gui.Tooltip
public boolean resetConfig = false;
public boolean resetHeadCache = false;

@ConfigEntry.Gui.Tooltip
public boolean resetConfig = false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ private void renderGui(MatrixStack matrixStack, int mouseX, int mouseY) {
JsonObject iconData = value.get("icon").getAsJsonObject();
this.skullowner = iconData.get("skullOwner").getAsString();
ItemStack i;
if (MineMenuFabricClient.playerHeadData.containsKey(iconData.get("skullOwner").getAsString()) && !iconData.get("skullOwner").getAsString().isEmpty()) {
client.getItemRenderer().renderInGui(playerHeadData.get(iconData.get("skullOwner").getAsString()), drawX, drawY);
if (MineMenuFabricClient.playerHeadCache.containsKey(iconData.get("skullOwner").getAsString()) &&
!iconData.get("skullOwner").getAsString().trim().isEmpty()) {
client.getItemRenderer().renderInGui(playerHeadCache.get(iconData.get("skullOwner").getAsString()), drawX, drawY);
}
else {
i = RandomUtil.iconify(this::setSkullMap, iconData.get("iconItem").getAsString(),
i = RandomUtil.iconify(iconData.get("iconItem").getAsString(),
iconData.get("enchanted").getAsBoolean(), iconData.get("skullOwner").getAsString());
if (i == null) try {
client.getItemRenderer().renderInGui(playerHeadData.get(iconData.get("skullOwner").getAsString()), drawX, drawY);
client.getItemRenderer().renderInGui(playerHeadCache.get(iconData.get("skullOwner").getAsString()), drawX, drawY);
} catch (Exception e) {}
else client.getItemRenderer().renderInGui(i, drawX, drawY);
}
Expand Down Expand Up @@ -153,22 +154,17 @@ private void renderGui(MatrixStack matrixStack, int mouseX, int mouseY) {
}
}

private void setSkullMap(ItemStack itemStack) {
MineMenuFabricClient.playerHeadData.put(skullowner, itemStack);
}

@Override
public void tick() {
if (true){ //keybinding mode - hold or pressed
if (keyBinding.wasPressed()) { //check for keybinding pressed
final double mouseX = this.client.mouse.getX() * ((double) this.client.getWindow().getScaledWidth() /
this.client.getWindow().getWidth());
final double mouseY = this.client.mouse.getY() * ((double) this.client.getWindow().getScaledHeight() /
this.client.getWindow().getHeight());

this.mouseClicked(mouseX, mouseY, 0);
}
if (keyBinding.wasPressed()) {
final double mouseX = this.client.mouse.getX() * ((double) this.client.getWindow().getScaledWidth() /
this.client.getWindow().getWidth());
final double mouseY = this.client.mouse.getY() * ((double) this.client.getWindow().getScaledHeight() /
this.client.getWindow().getHeight());

//this.mouseClicked(mouseX, mouseY, 0);
}

}

@Override
Expand Down Expand Up @@ -200,7 +196,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
switch (value.get("type").getAsString()) {
case "empty":
dontClose = true;
this.openConfigScreen();
RandomUtil.openConfigScreen(this);
break;

case "print":
Expand All @@ -220,7 +216,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}
}
else if (button == 1) {
this.openConfigScreen();
RandomUtil.openConfigScreen(this);
}
}

Expand All @@ -234,15 +230,6 @@ else if (button == 1) {
return false;
}

private void openConfigScreen() {
try {
client.openScreen(new MineMenuSettingsScreen(this, datapath));
} catch (NullPointerException e) {
client.openScreen(null);
client.player.sendMessage(Text.of("§l§c Corrupt config! Reset it via the config menu!"), false);
}
}

@Override
public boolean isPauseScreen() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;

import java.util.ArrayList;

import static me.ultrablacklinux.minemenufabric.client.MineMenuFabricClient.*;
import static me.ultrablacklinux.minemenufabric.client.MineMenuFabricClient.playerHeadData;
import static me.ultrablacklinux.minemenufabric.client.config.Config.*;

public class MineMenuSettingsScreen extends Screen {
private TypeCycle typeCycle;
Expand Down Expand Up @@ -105,6 +104,8 @@ protected void init() {

this.itemData = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, 141, 200, 20, //TEXT INPUT
new TranslatableText("minemenu.settings.data"));


if (typeCycle == TypeCycle.PRINT || typeCycle == TypeCycle.CLIPBOARD) {
this.itemData.setText(data.get("data").getAsJsonObject().get("message").getAsString());
}
Expand All @@ -120,7 +121,7 @@ else if (typeCycle == TypeCycle.LINK) {
typeCycle = typeCycle.next();
this.type.setMessage(typeCycle.getName());
this.updateStates();
this.updateStates();
this.updateIconInput();
}));

//----------------------------
Expand All @@ -131,7 +132,6 @@ else if (typeCycle == TypeCycle.LINK) {
this.done = this.addButton(new ButtonWidget(this.width / 2, 220, 100, 20,
ScreenTexts.DONE, (buttonWidget) -> close(false)));

this.updateStates();
this.updateStates();
this.updateIconInput();
}
Expand All @@ -155,15 +155,13 @@ private void saveIconVariable() {

private void updateIconInput() {
this.iconDataYesNo.active = itemConfigCycle == ItemConfigCycle.ENCHANTED;
this.iconDataText.setEditable(itemConfigCycle != ItemConfigCycle.ENCHANTED);
this.iconDataText.setEditable(itemConfigCycle != ItemConfigCycle.ENCHANTED && typeCycle != TypeCycle.EMPTY);
this.itemSettingType.active = typeCycle != TypeCycle.EMPTY;
if (itemConfigCycle != ItemConfigCycle.ENCHANTED) this.iconDataYesNo.setMessage(Text.of(""));
if (itemConfigCycle == ItemConfigCycle.SKULLOWNER) this.iconDataText.setEditable(iconItem.endsWith("player_head"));
if (itemConfigCycle == ItemConfigCycle.SKULLOWNER) this.iconItem = "player_head";
this.iconDataYesNo.setMessage(iconDataBoolean ? ScreenTexts.YES : ScreenTexts.NO);

switch (itemConfigCycle) {
case ENCHANTED:
this.iconDataYesNo.setMessage(enchanted ? ScreenTexts.YES : ScreenTexts.NO);
break;

case ICON:
this.iconDataText.setText(this.iconItem);
break;
Expand All @@ -176,6 +174,7 @@ private void updateIconInput() {

private void updateStates() {
this.itemName.setEditable(typeCycle != TypeCycle.EMPTY);

this.itemData.setEditable(typeCycle == TypeCycle.PRINT || typeCycle == TypeCycle.LINK || typeCycle == TypeCycle.CLIPBOARD);
this.done.active = typeCycle == TypeCycle.EMPTY || !this.itemName.getText().isEmpty();
}
Expand Down Expand Up @@ -211,25 +210,20 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.itemData.render(matrices, mouseX, mouseY, delta);

ItemStack i;
if (MineMenuFabricClient.playerHeadData.containsKey(skullowner)) {
client.getItemRenderer().renderInGui(playerHeadData.get(skullowner), this.width / 2 - 120, 82);
if (playerHeadCache.containsKey(skullowner) && !skullowner.trim().isEmpty()) {
client.getItemRenderer().renderInGui(playerHeadCache.get(skullowner), this.width / 2 - 120, 82);
}
else {
i = RandomUtil.iconify(this::setSkullMap, iconItem, enchanted, skullowner);
i = RandomUtil.iconify(iconItem, enchanted, skullowner);
if (i == null) try {
client.getItemRenderer().renderInGui(MineMenuFabricClient.playerHeadData.get(skullowner), this.width / 2 - 120, 82);
client.getItemRenderer().renderInGui(playerHeadCache.get(skullowner), this.width / 2 - 120, 82);
} catch (Exception e) {}
else client.getItemRenderer().renderInGui(i, this.width / 2 - 120, 82);
}


super.render(matrices, mouseX, mouseY, delta);
}

private void setSkullMap(ItemStack itemStack) {
MineMenuFabricClient.playerHeadData.put(skullowner, itemStack);
}


private void close(boolean cancel) {
if (!cancel) applySettings();
Expand Down Expand Up @@ -267,7 +261,7 @@ private void applySettings() {
}

GsonUtil.saveJson(GsonUtil.template(name, typeCycle.name().toLowerCase(), subData, iconItem, enchanted, skullowner));
Config.get().minemenuFabric.minemenuData = minemenuData;
get().minemenuFabric.minemenuData = minemenuData;
AutoConfig.getConfigHolder(Config.class).save();
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package me.ultrablacklinux.minemenufabric.client.util;

import com.mojang.authlib.GameProfile;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.math.Color;
import me.ultrablacklinux.minemenufabric.client.MineMenuFabricClient;
import me.ultrablacklinux.minemenufabric.client.config.Config;
import me.ultrablacklinux.minemenufabric.client.screen.MineMenuSelectScreen;
import me.ultrablacklinux.minemenufabric.client.screen.MineMenuSettingsScreen;
import net.minecraft.block.AbstractSkullBlock;
import net.minecraft.block.entity.SkullBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;

import static me.ultrablacklinux.minemenufabric.client.MineMenuFabricClient.datapath;

public class RandomUtil {
public static me.shedaniel.math.Color getColor(String inp) {
Expand All @@ -29,7 +41,7 @@ public static me.shedaniel.math.Color getColor(String inp) {
return Color.ofRGBA(f, f1, f2, f3);
}

public static ItemStack iconify(Consumer<ItemStack> consumer, String iconItem, boolean enchanted, String skullowner) {
public static ItemStack iconify(String iconItem, boolean enchanted, String skullowner) {
ItemStack out;
try {
out = itemStackFromString(iconItem);
Expand All @@ -47,7 +59,9 @@ public static ItemStack iconify(Consumer<ItemStack> consumer, String iconItem, b
GameProfile gameProfile = new GameProfile((UUID)null, skullowner);
gameProfile = SkullBlockEntity.loadProperties(gameProfile);
tag.put("SkullOwner", NbtHelper.fromGameProfile(new CompoundTag(), gameProfile));
consumer.accept(finalOut);
MineMenuFabricClient.playerHeadCache.putIfAbsent(skullowner, finalOut);
//Config.get().minemenuFabric.playerHeadCache = MineMenuFabricClient.playerHeadCache;
//AutoConfig.getConfigHolder(Config.class).save();
});
nbTater.start();
out = null;
Expand All @@ -69,4 +83,15 @@ public static boolean isSkullItem(ItemStack stack) {
return stack.getItem() instanceof BlockItem && ((net.minecraft.item.BlockItem)
stack.getItem()).getBlock() instanceof AbstractSkullBlock;
}


public static void openConfigScreen(Screen parent) {
MinecraftClient client = MinecraftClient.getInstance();
try {
client.openScreen(new MineMenuSettingsScreen(parent, datapath));
} catch (NullPointerException e) {
client.openScreen(null);
client.player.sendMessage(new TranslatableText("minemenu.error.config"), false);
}
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/minemenufabric/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"text.autoconfig.MinemenuFabric.option.minemenuFabric.secondaryColor.@Tooltip": "Hex Farbe - Unterstützt \"#\", \"0x\" und mehr",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.emptyItemIcon": "Leeres Icon",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.emptyItemIcon.@Tooltip": "Icon für leere Einträge",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.resetHeadCache": "Spielerkopf-cache leeren",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.resetHeadCache.@Tooltip": "Der Spielerkopf-cache wird geleert sobald du Fertig drückst",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.resetConfig": "Config zurücksetzen",
"text.autoconfig.MinemenuFabric.option.minemenuFabric.resetConfig.@Tooltip": "Die Config wird zurückgesetzt sobald du Fertig drückst",
"minemenu.setting.itemconfigcycle.Icon": "Icon",
Expand All @@ -29,5 +31,6 @@
"minemenu.setting.typecycle.Empty": "Platzhalter",
"minemenu.setting.input.name": "Name:",
"minemenu.setting.input.icon": "Icon:",
"minemenu.setting.input.text": "Text:"
"minemenu.setting.input.text": "Text:",
"minemenu.error.config": "§l§c Unbrauchbare Config! Setze sie über das Konfigurationsmenü zurück! \n(Dies kann nach einem Update passieren)"
}
Loading

0 comments on commit 2df9bda

Please sign in to comment.