aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java')
-rw-r--r--src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java266
1 files changed, 0 insertions, 266 deletions
diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java
deleted file mode 100644
index 700a0ab97..000000000
--- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Roughly Enough Items by Danielshe.
- * Licensed under the MIT License.
- */
-
-package me.shedaniel.rei.client;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-import io.netty.buffer.Unpooled;
-import me.shedaniel.rei.RoughlyEnoughItemsCore;
-import me.shedaniel.rei.RoughlyEnoughItemsNetwork;
-import me.shedaniel.rei.api.ClientHelper;
-import me.shedaniel.rei.api.RecipeCategory;
-import me.shedaniel.rei.api.RecipeDisplay;
-import me.shedaniel.rei.api.RecipeHelper;
-import me.shedaniel.rei.gui.PreRecipeViewingScreen;
-import me.shedaniel.rei.gui.RecipeViewingScreen;
-import me.shedaniel.rei.gui.VillagerRecipeViewingScreen;
-import me.shedaniel.rei.gui.config.RecipeScreenType;
-import me.zeroeightsix.fiber.exception.FiberException;
-import net.fabricmc.api.ClientModInitializer;
-import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
-import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
-import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl;
-import net.fabricmc.loader.api.FabricLoader;
-import net.fabricmc.loader.api.ModContainer;
-import net.fabricmc.loader.api.metadata.ModMetadata;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
-import net.minecraft.client.util.InputUtil;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.item.Items;
-import net.minecraft.text.TranslatableText;
-import net.minecraft.util.DefaultedList;
-import net.minecraft.util.Formatting;
-import net.minecraft.util.Identifier;
-import net.minecraft.util.PacketByteBuf;
-import net.minecraft.util.registry.Registry;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-public class ClientHelperImpl implements ClientHelper, ClientModInitializer {
-
- public static ClientHelperImpl instance;
- private final Identifier recipeKeybind = new Identifier("roughlyenoughitems", "recipe_keybind");
- private final Identifier usageKeybind = new Identifier("roughlyenoughitems", "usage_keybind");
- private final Identifier hideKeybind = new Identifier("roughlyenoughitems", "hide_keybind");
- private final Identifier previousPageKeybind = new Identifier("roughlyenoughitems", "previous_page");
- private final Identifier nextPageKeybind = new Identifier("roughlyenoughitems", "next_page");
- private final Identifier focusSearchFieldKeybind = new Identifier("roughlyenoughitems", "focus_search");
- private final Map<String, String> modNameCache = Maps.newHashMap();
- public FabricKeyBinding recipe, usage, hide, previousPage, nextPage, focusSearchField;
-
- @Override
- public String getFormattedModFromItem(Item item) {
- String mod = getModFromItem(item);
- if (mod.isEmpty())
- return "";
- return Formatting.BLUE.toString() + Formatting.ITALIC.toString() + mod;
- }
-
- @Override
- public String getFormattedModFromIdentifier(Identifier identifier) {
- String mod = getModFromIdentifier(identifier);
- if (mod.isEmpty())
- return "";
- return Formatting.BLUE.toString() + Formatting.ITALIC.toString() + mod;
- }
-
- @Override
- public FabricKeyBinding getRecipeKeyBinding() {
- return recipe;
- }
-
- @Override
- public FabricKeyBinding getUsageKeyBinding() {
- return usage;
- }
-
- @Override
- public FabricKeyBinding getHideKeyBinding() {
- return hide;
- }
-
- @Override
- public FabricKeyBinding getPreviousPageKeyBinding() {
- return previousPage;
- }
-
- @Override
- public FabricKeyBinding getNextPageKeyBinding() {
- return nextPage;
- }
-
- @Override
- public FabricKeyBinding getFocusSearchFieldKeyBinding() {
- return focusSearchField;
- }
-
- @Override
- public String getModFromItem(Item item) {
- if (item.equals(Items.AIR))
- return "";
- return getModFromIdentifier(Registry.ITEM.getId(item));
- }
-
- @Override
- public String getModFromIdentifier(Identifier identifier) {
- if (identifier == null)
- return "";
- Optional<String> any = Optional.ofNullable(modNameCache.getOrDefault(identifier.getNamespace(), null));
- if (any.isPresent())
- return any.get();
- String modid = identifier.getNamespace();
- String s = FabricLoader.getInstance().getModContainer(modid).map(ModContainer::getMetadata).map(ModMetadata::getName).orElse(modid);
- modNameCache.put(modid, s);
- return s;
- }
-
- @Override
- public boolean isCheating() {
- return RoughlyEnoughItemsCore.getConfigManager().getConfig().isCheating();
- }
-
- @Override
- public void setCheating(boolean cheating) {
- RoughlyEnoughItemsCore.getConfigManager().getConfig().setCheating(cheating);
- try {
- RoughlyEnoughItemsCore.getConfigManager().saveConfig();
- } catch (IOException | FiberException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void sendDeletePacket() {
- if (ScreenHelper.getLastContainerScreen() instanceof CreativeInventoryScreen) {
- MinecraftClient.getInstance().player.inventory.setCursorStack(ItemStack.EMPTY);
- return;
- }
- ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()));
- }
-
- @Override
- public boolean tryCheatingStack(ItemStack cheatedStack) {
- if (RoughlyEnoughItemsCore.canUsePackets()) {
- try {
- ClientSidePacketRegistry.INSTANCE.sendToServer(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET, new PacketByteBuf(Unpooled.buffer()).writeItemStack(cheatedStack.copy()));
- return true;
- } catch (Exception e) {
- return false;
- }
- } else {
- Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem());
- String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : "";
- String og = cheatedStack.getCount() == 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand().replaceAll(" \\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand();
- String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getCount()));
- if (madeUpCommand.length() > 256) {
- madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getCount()));
- MinecraftClient.getInstance().player.addChatMessage(new TranslatableText("text.rei.too_long_nbt"), false);
- }
- MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand);
- return true;
- }
- }
-
- @Override
- public boolean executeRecipeKeyBind(ItemStack stack) {
- Map<RecipeCategory<?>, List<RecipeDisplay>> map = RecipeHelper.getInstance().getRecipesFor(stack);
- if (map.keySet().size() > 0)
- openRecipeViewingScreen(map);
- return map.keySet().size() > 0;
- }
-
- @Override
- public boolean executeUsageKeyBind(ItemStack stack) {
- Map<RecipeCategory<?>, List<RecipeDisplay>> map = RecipeHelper.getInstance().getUsagesFor(stack);
- if (map.keySet().size() > 0)
- openRecipeViewingScreen(map);
- return map.keySet().size() > 0;
- }
-
- @Override
- public List<ItemStack> getInventoryItemsTypes() {
- List<DefaultedList<ItemStack>> field_7543 = ImmutableList.of(MinecraftClient.getInstance().player.inventory.main, MinecraftClient.getInstance().player.inventory.armor, MinecraftClient.getInstance().player.inventory.offHand);
- List<ItemStack> inventoryStacks = new ArrayList<>();
- field_7543.forEach(itemStacks -> itemStacks.forEach(itemStack -> {
- if (!itemStack.isEmpty())
- inventoryStacks.add(itemStack);
- }));
- return inventoryStacks;
- }
-
- @Override
- public boolean executeViewAllRecipesKeyBind() {
- Map<RecipeCategory<?>, List<RecipeDisplay>> map = RecipeHelper.getInstance().getAllRecipes();
- if (map.keySet().size() > 0)
- openRecipeViewingScreen(map);
- return map.keySet().size() > 0;
- }
-
- @Override
- public boolean executeViewAllRecipesFromCategory(Identifier category) {
- Map<RecipeCategory<?>, List<RecipeDisplay>> map = Maps.newLinkedHashMap();
- Optional<RecipeCategory> any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny();
- if (!any.isPresent())
- return false;
- RecipeCategory<?> recipeCategory = any.get();
- map.put(recipeCategory, RecipeHelper.getInstance().getAllRecipesFromCategory(recipeCategory));
- if (map.keySet().size() > 0)
- openRecipeViewingScreen(map);
- return map.keySet().size() > 0;
- }
-
- @Override
- public boolean executeViewAllRecipesFromCategories(List<Identifier> categories) {
- Map<RecipeCategory<?>, List<RecipeDisplay>> map = Maps.newLinkedHashMap();
- for (Identifier category : categories) {
- Optional<RecipeCategory> any = RecipeHelper.getInstance().getAllCategories().stream().filter(c -> c.getIdentifier().equals(category)).findAny();
- if (!any.isPresent())
- continue;
- RecipeCategory<?> recipeCategory = any.get();
- map.put(recipeCategory, RecipeHelper.getInstance().getAllRecipesFromCategory(recipeCategory));
- }
- if (map.keySet().size() > 0)
- openRecipeViewingScreen(map);
- return map.keySet().size() > 0;
- }
-
- @Override
- public void openRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map) {
- if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.VILLAGER)
- MinecraftClient.getInstance().openScreen(new VillagerRecipeViewingScreen(map));
- else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.UNSET)
- MinecraftClient.getInstance().openScreen(new PreRecipeViewingScreen(map));
- else
- MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(map));
- }
-
- @Override
- public void onInitializeClient() {
- ClientHelperImpl.instance = (ClientHelperImpl) this;
- registerFabricKeyBinds();
- modNameCache.put("minecraft", "Minecraft");
- modNameCache.put("c", "Common");
- }
-
- @Override
- public void registerFabricKeyBinds() {
- String category = "key.rei.category";
- KeyBindingRegistryImpl.INSTANCE.addCategory(category);
- KeyBindingRegistryImpl.INSTANCE.register(recipe = FabricKeyBinding.Builder.create(recipeKeybind, InputUtil.Type.KEYSYM, 82, category).build());
- KeyBindingRegistryImpl.INSTANCE.register(usage = FabricKeyBinding.Builder.create(usageKeybind, InputUtil.Type.KEYSYM, 85, category).build());
- KeyBindingRegistryImpl.INSTANCE.register(hide = FabricKeyBinding.Builder.create(hideKeybind, InputUtil.Type.KEYSYM, 79, category).build());
- KeyBindingRegistryImpl.INSTANCE.register(previousPage = FabricKeyBinding.Builder.create(previousPageKeybind, InputUtil.Type.KEYSYM, -1, category).build());
- KeyBindingRegistryImpl.INSTANCE.register(nextPage = FabricKeyBinding.Builder.create(nextPageKeybind, InputUtil.Type.KEYSYM, -1, category).build());
- KeyBindingRegistryImpl.INSTANCE.register(focusSearchField = FabricKeyBinding.Builder.create(focusSearchFieldKeybind, InputUtil.Type.KEYSYM, -1, category).build());
- }
-
-}