aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/client
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-02-16 17:52:40 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-02-16 17:52:40 +0800
commit2e0e576b64545cb45a0ab3e0d0fe81cfb7a61307 (patch)
tree33ab48fd72c49fa1b2a78c05b29de67da7ab6064 /src/main/java/me/shedaniel/rei/client
parent074a627663e0150e23d47a87486afb852dd2cfdd (diff)
downloadRoughlyEnoughItems-2.3.0.17.tar.gz
RoughlyEnoughItems-2.3.0.17.tar.bz2
RoughlyEnoughItems-2.3.0.17.zip
Same as v2.3 in Fabricv2.3.0.17
Diffstat (limited to 'src/main/java/me/shedaniel/rei/client')
-rw-r--r--src/main/java/me/shedaniel/rei/client/ClientHelper.java53
-rw-r--r--src/main/java/me/shedaniel/rei/client/ConfigHelper.java19
-rw-r--r--src/main/java/me/shedaniel/rei/client/GuiHelper.java18
-rw-r--r--src/main/java/me/shedaniel/rei/client/ItemListHelper.java53
-rw-r--r--src/main/java/me/shedaniel/rei/client/REIConfig.java1
-rw-r--r--src/main/java/me/shedaniel/rei/client/RecipeHelper.java20
6 files changed, 93 insertions, 71 deletions
diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
index 87e438ab3..fd5418516 100644
--- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java
@@ -1,21 +1,17 @@
package me.shedaniel.rei.client;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
import me.shedaniel.rei.api.IRecipeCategory;
import me.shedaniel.rei.api.IRecipeDisplay;
import me.shedaniel.rei.gui.ContainerGuiOverlay;
-import me.shedaniel.rei.gui.widget.ConfigWidget;
+import me.shedaniel.rei.gui.config.ConfigGui;
import me.shedaniel.rei.gui.widget.RecipeViewingWidgetGui;
import me.shedaniel.rei.network.CreateItemsPacket;
import me.shedaniel.rei.network.DeleteItemsPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHelper;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.enchantment.Enchantment;
-import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Items;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
@@ -24,19 +20,13 @@ import org.dimdev.riftloader.RiftLoader;
import java.awt.*;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ClientHelper {
- private static List<ItemStack> itemList;
private static boolean cheating = false;
- public ClientHelper() {
- this.itemList = Lists.newLinkedList();
- }
-
public static String getModFromItemStack(ItemStack stack) {
if (!stack.isEmpty()) {
ResourceLocation location = IRegistry.ITEM.getKey(stack.getItem());
@@ -53,10 +43,6 @@ public class ClientHelper {
return "";
}
- public static List<ItemStack> getItemList() {
- return itemList;
- }
-
public static Point getMouseLocation() {
Minecraft client = Minecraft.getInstance();
MouseHelper mouse = client.mouseHelper;
@@ -117,7 +103,7 @@ public class ClientHelper {
}
public static void openConfigWindow(GuiScreen parent) {
- Minecraft.getInstance().displayGuiScreen(new ConfigWidget(parent));
+ Minecraft.getInstance().displayGuiScreen(new ConfigGui(parent));
}
public static List<ItemStack> getInventoryItemsTypes() {
@@ -130,39 +116,4 @@ public class ClientHelper {
return inventoryStacks;
}
- public void clientLoaded() {
- IRegistry.ITEM.forEach(item -> {
- if (!item.equals(Items.ENCHANTED_BOOK))
- registerItem(item);
- });
- IRegistry.ENCHANTMENT.forEach(enchantment -> {
- for(int i = enchantment.getMinLevel(); i < enchantment.getMaxLevel(); i++) {
- Map<Enchantment, Integer> map = new HashMap<>();
- map.put(enchantment, i);
- ItemStack itemStack = new ItemStack(Items.ENCHANTED_BOOK);
- EnchantmentHelper.setEnchantments(map, itemStack);
- registerItemStack(itemStack);
- }
- });
- }
-
- public void registerItem(Item item) {
- registerItemStack(item.getDefaultInstance());
- NonNullList<ItemStack> stacks = NonNullList.create();
- item.fillItemGroup(item.getGroup(), stacks);
- stacks.forEach(this::registerItemStack);
- }
-
- public void registerItemStack(ItemStack stack) {
- if (!stack.getItem().equals(Items.AIR) && !alreadyContain(stack))
- itemList.add(stack);
- }
-
- private boolean alreadyContain(ItemStack stack) {
- for(ItemStack itemStack : itemList)
- if (ItemStack.areItemStacksEqual(stack, itemStack))
- return true;
- return false;
- }
-
}
diff --git a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java b/src/main/java/me/shedaniel/rei/client/ConfigHelper.java
index 9b6c15596..ff03ba720 100644
--- a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/ConfigHelper.java
@@ -11,15 +11,11 @@ import java.nio.file.Files;
public class ConfigHelper {
+ private static ConfigHelper instance = new ConfigHelper();
private final File configFile;
private REIConfig config;
- private static ConfigHelper instance = new ConfigHelper();
private boolean craftableOnly;
- public static ConfigHelper getInstance() {
- return instance;
- }
-
public ConfigHelper() {
this.configFile = new File(RiftLoader.instance.configDir, "rei.json");
this.craftableOnly = false;
@@ -27,11 +23,16 @@ public class ConfigHelper {
if (!configFile.getParentFile().exists() || !configFile.getParentFile().isDirectory())
configFile.getParentFile().mkdirs();
loadConfig();
+ RoughlyEnoughItemsCore.LOGGER.info("REI: Config is loaded.");
} catch (IOException e) {
e.printStackTrace();
}
}
+ public static ConfigHelper getInstance() {
+ return instance;
+ }
+
public void saveConfig() throws IOException {
configFile.getParentFile().mkdirs();
if (!configFile.exists() && !configFile.createNewFile()) {
@@ -126,4 +127,12 @@ public class ConfigHelper {
config.mirrorItemPanel = mirrorItemPanel;
}
+ public boolean isLoadingDefaultPlugin() {
+ return config.loadDefaultPlugin;
+ }
+
+ public void setLoadingDefaultPlugin(boolean loadDefaultPlugin) {
+ config.loadDefaultPlugin = loadDefaultPlugin;
+ }
+
}
diff --git a/src/main/java/me/shedaniel/rei/client/GuiHelper.java b/src/main/java/me/shedaniel/rei/client/GuiHelper.java
index 1f603463b..78e283b52 100644
--- a/src/main/java/me/shedaniel/rei/client/GuiHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/GuiHelper.java
@@ -19,7 +19,6 @@ public class GuiHelper implements ClientTickable {
private static boolean overlayVisible = true;
private static ContainerGuiOverlay overlay;
private static GuiContainer lastGuiContainer;
- private static IMixinGuiContainer lastMixinGuiContainer;
public static boolean isOverlayVisible() {
return overlayVisible;
@@ -29,13 +28,16 @@ public class GuiHelper implements ClientTickable {
overlayVisible = !overlayVisible;
}
- public static ContainerGuiOverlay getLastOverlay() {
+ public static ContainerGuiOverlay getLastOverlay(boolean reset) {
+ if (overlay == null || reset) {
+ overlay = new ContainerGuiOverlay();
+ overlay.onInitialized();
+ }
return overlay;
}
- public static void setOverlay(ContainerGuiOverlay overlay) {
- GuiHelper.overlay = overlay;
- overlay.onInitialized();
+ public static ContainerGuiOverlay getLastOverlay() {
+ return getLastOverlay(false);
}
public static GuiContainer getLastGuiContainer() {
@@ -47,18 +49,14 @@ public class GuiHelper implements ClientTickable {
}
public static IMixinGuiContainer getLastMixinGuiContainer() {
- return lastMixinGuiContainer;
+ return (IMixinGuiContainer) lastGuiContainer;
}
- public static void setLastMixinGuiContainer(IMixinGuiContainer lastMixinGuiContainer) {
- GuiHelper.lastMixinGuiContainer = lastMixinGuiContainer;
- }
@Override
public void clientTick(Minecraft client) {
if (client.currentScreen instanceof GuiContainer && lastGuiContainer != client.currentScreen) {
GuiHelper.lastGuiContainer = (GuiContainer) client.currentScreen;
- GuiHelper.lastMixinGuiContainer = (IMixinGuiContainer) lastGuiContainer;
}
UpdateAnnouncer.clientTick(client);
}
diff --git a/src/main/java/me/shedaniel/rei/client/ItemListHelper.java b/src/main/java/me/shedaniel/rei/client/ItemListHelper.java
new file mode 100644
index 000000000..731c8e70c
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/client/ItemListHelper.java
@@ -0,0 +1,53 @@
+package me.shedaniel.rei.client;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.rei.api.IItemRegisterer;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.NonNullList;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+public class ItemListHelper implements IItemRegisterer {
+
+ private final List<ItemStack> itemList = Lists.newLinkedList();
+
+ @Override
+ public List<ItemStack> getItemList() {
+ return Collections.unmodifiableList(itemList);
+ }
+
+ @Deprecated
+ @Override
+ public List<ItemStack> getModifiableItemList() {
+ return itemList;
+ }
+
+ @Override
+ public ItemStack[] getAllStacksFromItem(Item item) {
+ NonNullList<ItemStack> list = NonNullList.create();
+ list.add(item.getDefaultInstance());
+ item.fillItemGroup(item.getGroup(), list);
+ TreeSet<ItemStack> stackSet = list.stream().collect(Collectors.toCollection(() -> new TreeSet<ItemStack>((p1, p2) -> ItemStack.areItemStacksEqual(p1, p2) ? 0 : 1)));
+ return Lists.newArrayList(stackSet).toArray(new ItemStack[0]);
+ }
+
+ @Override
+ public void registerItemStack(Item afterItem, ItemStack stack) {
+ if (!stack.isEmpty() && !alreadyContain(stack))
+ if (afterItem == null || afterItem.equals(Items.AIR))
+ itemList.add(stack);
+ else {
+ int last = itemList.size();
+ for(int i = 0; i < itemList.size(); i++)
+ if (itemList.get(i).getItem().equals(afterItem))
+ last = i + 1;
+ itemList.add(last, stack);
+ }
+ }
+
+}
diff --git a/src/main/java/me/shedaniel/rei/client/REIConfig.java b/src/main/java/me/shedaniel/rei/client/REIConfig.java
index b5b798371..be4eabfeb 100644
--- a/src/main/java/me/shedaniel/rei/client/REIConfig.java
+++ b/src/main/java/me/shedaniel/rei/client/REIConfig.java
@@ -14,5 +14,6 @@ public class REIConfig {
public String giveCommandPrefix = "/give";
public boolean checkUpdates = true;
public boolean mirrorItemPanel = false;
+ public boolean loadDefaultPlugin = true;
}
diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
index eec9f4bbc..79128d814 100644
--- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
+++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java
@@ -18,9 +18,9 @@ public class RecipeHelper {
private final Map<ResourceLocation, List<IRecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
private final List<IRecipeCategory> categories = Lists.newArrayList();
- private RecipeManager recipeManager;
private final Map<ResourceLocation, SpeedCraftAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap();
private final Map<ResourceLocation, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap();
+ private RecipeManager recipeManager;
public static RecipeHelper getInstance() {
return RoughlyEnoughItemsCore.getRecipeHelper();
@@ -60,7 +60,7 @@ public class RecipeHelper {
recipeCategoryListMap.put(category.getResourceLocation(), Lists.newLinkedList());
}
- public void registerRecipe(ResourceLocation categoryIdentifier, IRecipeDisplay display) {
+ public void registerDisplay(ResourceLocation categoryIdentifier, IRecipeDisplay display) {
if (!recipeCategoryListMap.containsKey(categoryIdentifier))
return;
recipeCategoryListMap.get(categoryIdentifier).add(display);
@@ -148,6 +148,7 @@ public class RecipeHelper {
speedCraftFunctionalMap.put(category, list);
}
+ @SuppressWarnings("deprecation")
public void recipesLoaded(RecipeManager recipeManager) {
this.recipeManager = recipeManager;
this.recipeCategoryListMap.clear();
@@ -163,10 +164,19 @@ public class RecipeHelper {
return resourceLocation == null ? "NULL" : resourceLocation;
}).collect(Collectors.toList())));
Collections.reverse(plugins);
+ RoughlyEnoughItemsCore.getItemRegisterer().getModifiableItemList().clear();
+ IPluginDisabler pluginDisabler = RoughlyEnoughItemsCore.getPluginDisabler();
plugins.forEach(plugin -> {
- plugin.registerPluginCategories();
- plugin.registerRecipes();
- plugin.registerSpeedCraft();
+ String location = RoughlyEnoughItemsPlugin.getPluginResourceLocation(plugin);
+ ResourceLocation resourceLocation = new ResourceLocation(location == null ? "null" : location);
+ if (pluginDisabler.isFunctionEnabled(resourceLocation, PluginFunction.REGISTER_ITEMS))
+ plugin.registerItems(RoughlyEnoughItemsCore.getItemRegisterer());
+ if (pluginDisabler.isFunctionEnabled(resourceLocation, PluginFunction.REGISTER_CATEGORIES))
+ plugin.registerPluginCategories(this);
+ if (pluginDisabler.isFunctionEnabled(resourceLocation, PluginFunction.REGISTER_RECIPE_DISPLAYS))
+ plugin.registerRecipeDisplays(this);
+ if (pluginDisabler.isFunctionEnabled(resourceLocation, PluginFunction.REGISTER_SPEED_CRAFT))
+ plugin.registerSpeedCraft(this);
});
RoughlyEnoughItemsCore.LOGGER.info("Registered REI Categories: " + String.join(", ", categories.stream().map(category -> {
return category.getCategoryName();