|
@@ -9,6 +9,7 @@ import me.shedaniel.cloth.hooks.ClothClientHooks;
|
|
import me.shedaniel.rei.api.*;
|
|
import me.shedaniel.rei.api.*;
|
|
import me.shedaniel.rei.client.*;
|
|
import me.shedaniel.rei.client.*;
|
|
import me.shedaniel.rei.gui.ContainerScreenOverlay;
|
|
import me.shedaniel.rei.gui.ContainerScreenOverlay;
|
|
|
|
+import me.shedaniel.rei.listeners.RecipeBookGuiHooks;
|
|
import net.fabricmc.api.ClientModInitializer;
|
|
import net.fabricmc.api.ClientModInitializer;
|
|
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
|
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
@@ -19,6 +20,7 @@ import net.minecraft.client.gui.ContainerScreen;
|
|
import net.minecraft.client.gui.Element;
|
|
import net.minecraft.client.gui.Element;
|
|
import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen;
|
|
import net.minecraft.client.gui.ingame.CreativePlayerInventoryScreen;
|
|
import net.minecraft.client.gui.ingame.PlayerInventoryScreen;
|
|
import net.minecraft.client.gui.ingame.PlayerInventoryScreen;
|
|
|
|
+import net.minecraft.client.gui.recipebook.RecipeBookGui;
|
|
import net.minecraft.client.gui.widget.RecipeBookButtonWidget;
|
|
import net.minecraft.client.gui.widget.RecipeBookButtonWidget;
|
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
import net.minecraft.util.ActionResult;
|
|
import net.minecraft.util.ActionResult;
|
|
@@ -34,7 +36,7 @@ import java.util.Optional;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
-
|
|
|
|
|
|
+
|
|
public static final Logger LOGGER;
|
|
public static final Logger LOGGER;
|
|
private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl();
|
|
private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl();
|
|
private static final PluginDisabler PLUGIN_DISABLER = new PluginDisablerImpl();
|
|
private static final PluginDisabler PLUGIN_DISABLER = new PluginDisablerImpl();
|
|
@@ -42,70 +44,70 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl();
|
|
private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl();
|
|
private static final Map<Identifier, REIPluginEntry> plugins = Maps.newHashMap();
|
|
private static final Map<Identifier, REIPluginEntry> plugins = Maps.newHashMap();
|
|
private static ConfigManagerImpl configManager;
|
|
private static ConfigManagerImpl configManager;
|
|
-
|
|
|
|
|
|
+
|
|
static {
|
|
static {
|
|
LOGGER = LogManager.getFormatterLogger("REI");
|
|
LOGGER = LogManager.getFormatterLogger("REI");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static RecipeHelper getRecipeHelper() {
|
|
public static RecipeHelper getRecipeHelper() {
|
|
return RECIPE_HELPER;
|
|
return RECIPE_HELPER;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static me.shedaniel.rei.api.ConfigManager getConfigManager() {
|
|
public static me.shedaniel.rei.api.ConfigManager getConfigManager() {
|
|
return configManager;
|
|
return configManager;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static ItemRegistry getItemRegisterer() {
|
|
public static ItemRegistry getItemRegisterer() {
|
|
return ITEM_REGISTRY;
|
|
return ITEM_REGISTRY;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static PluginDisabler getPluginDisabler() {
|
|
public static PluginDisabler getPluginDisabler() {
|
|
return PLUGIN_DISABLER;
|
|
return PLUGIN_DISABLER;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static DisplayHelper getDisplayHelper() {
|
|
public static DisplayHelper getDisplayHelper() {
|
|
return DISPLAY_HELPER;
|
|
return DISPLAY_HELPER;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static REIPluginEntry registerPlugin(Identifier identifier, REIPluginEntry plugin) {
|
|
public static REIPluginEntry registerPlugin(Identifier identifier, REIPluginEntry plugin) {
|
|
plugins.put(identifier, plugin);
|
|
plugins.put(identifier, plugin);
|
|
RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName());
|
|
RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName());
|
|
plugin.onFirstLoad(getPluginDisabler());
|
|
plugin.onFirstLoad(getPluginDisabler());
|
|
return plugin;
|
|
return plugin;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static List<REIPluginEntry> getPlugins() {
|
|
public static List<REIPluginEntry> getPlugins() {
|
|
return new LinkedList<>(plugins.values());
|
|
return new LinkedList<>(plugins.values());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static Optional<Identifier> getPluginIdentifier(REIPluginEntry plugin) {
|
|
public static Optional<Identifier> getPluginIdentifier(REIPluginEntry plugin) {
|
|
for(Identifier identifier : plugins.keySet())
|
|
for(Identifier identifier : plugins.keySet())
|
|
if (identifier != null && plugins.get(identifier).equals(plugin))
|
|
if (identifier != null && plugins.get(identifier).equals(plugin))
|
|
return Optional.of(identifier);
|
|
return Optional.of(identifier);
|
|
return Optional.empty();
|
|
return Optional.empty();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean hasPermissionToUsePackets() {
|
|
public static boolean hasPermissionToUsePackets() {
|
|
return hasOperatorPermission() && canUsePackets();
|
|
return hasOperatorPermission() && canUsePackets();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean hasOperatorPermission() {
|
|
public static boolean hasOperatorPermission() {
|
|
return MinecraftClient.getInstance().getNetworkHandler().getCommandSource().hasPermissionLevel(1);
|
|
return MinecraftClient.getInstance().getNetworkHandler().getCommandSource().hasPermissionLevel(1);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static boolean canUsePackets() {
|
|
public static boolean canUsePackets() {
|
|
return ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET) && ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET);
|
|
return ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET) && ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void onInitializeClient() {
|
|
public void onInitializeClient() {
|
|
configManager = new ConfigManagerImpl();
|
|
configManager = new ConfigManagerImpl();
|
|
-
|
|
|
|
|
|
+
|
|
registerClothEvents();
|
|
registerClothEvents();
|
|
discoverOldPlugins();
|
|
discoverOldPlugins();
|
|
discoverPluginEntries();
|
|
discoverPluginEntries();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void discoverPluginEntries() {
|
|
private void discoverPluginEntries() {
|
|
for(REIPluginEntry reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPluginEntry.class)) {
|
|
for(REIPluginEntry reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPluginEntry.class)) {
|
|
try {
|
|
try {
|
|
@@ -118,7 +120,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void discoverOldPlugins() {
|
|
private void discoverOldPlugins() {
|
|
List<Pair<Identifier, String>> list = Lists.newArrayList();
|
|
List<Pair<Identifier, String>> list = Lists.newArrayList();
|
|
for(ModMetadata metadata : FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).filter(metadata -> metadata.containsCustomElement("roughlyenoughitems:plugins")).collect(Collectors.toList())) {
|
|
for(ModMetadata metadata : FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).filter(metadata -> metadata.containsCustomElement("roughlyenoughitems:plugins")).collect(Collectors.toList())) {
|
|
@@ -157,7 +159,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void loadPluginFromJsonObject(List<Pair<Identifier, String>> list, ModMetadata modMetadata, JsonObject object) {
|
|
private void loadPluginFromJsonObject(List<Pair<Identifier, String>> list, ModMetadata modMetadata, JsonObject object) {
|
|
String namespace = modMetadata.getId();
|
|
String namespace = modMetadata.getId();
|
|
if (object.has("namespace"))
|
|
if (object.has("namespace"))
|
|
@@ -166,7 +168,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
String className = object.get("class").getAsString();
|
|
String className = object.get("class").getAsString();
|
|
list.add(new Pair<>(new Identifier(namespace, id), className));
|
|
list.add(new Pair<>(new Identifier(namespace, id), className));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void registerClothEvents() {
|
|
private void registerClothEvents() {
|
|
ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> {
|
|
ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> {
|
|
((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager);
|
|
((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager);
|
|
@@ -225,7 +227,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
ScreenHelper.getLastOverlay().lateRender(i, i1, v);
|
|
ScreenHelper.getLastOverlay().lateRender(i, i1, v);
|
|
});
|
|
});
|
|
ClothClientHooks.SCREEN_KEY_PRESSED.register((minecraftClient, screen, i, i1, i2) -> {
|
|
ClothClientHooks.SCREEN_KEY_PRESSED.register((minecraftClient, screen, i, i1, i2) -> {
|
|
- if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget)
|
|
|
|
|
|
+ if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget || (screen.getFocused() instanceof RecipeBookGui && ((RecipeBookGuiHooks)screen.getFocused()).rei_getSearchField().isFocused()))
|
|
return ActionResult.PASS;
|
|
return ActionResult.PASS;
|
|
if (screen instanceof ContainerScreen)
|
|
if (screen instanceof ContainerScreen)
|
|
if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2))
|
|
if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2))
|
|
@@ -233,5 +235,5 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer {
|
|
return ActionResult.PASS;
|
|
return ActionResult.PASS;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|