diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-01-09 23:35:45 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-01-09 23:35:45 +0800 |
| commit | 1b21d26487636e50d03979acd5ca4a2a07761a25 (patch) | |
| tree | d7d066b4e7491474f3a962593e97a2d6f0aa2ea2 /src/main/java | |
| parent | 77af6b3f548d34bfdafc585847d3d80ec783c7e7 (diff) | |
| download | RoughlyEnoughItems-1b21d26487636e50d03979acd5ca4a2a07761a25.tar.gz RoughlyEnoughItems-1b21d26487636e50d03979acd5ca4a2a07761a25.tar.bz2 RoughlyEnoughItems-1b21d26487636e50d03979acd5ca4a2a07761a25.zip | |
Starting off rewrite
Diffstat (limited to 'src/main/java')
79 files changed, 244 insertions, 4598 deletions
diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java deleted file mode 100755 index ec1061e2f..000000000 --- a/src/main/java/me/shedaniel/ClientListener.java +++ /dev/null @@ -1,106 +0,0 @@ -package me.shedaniel; - -import me.shedaniel.api.IREIPlugin; -import me.shedaniel.gui.REIRenderHelper; -import me.shedaniel.impl.REIRecipeManager; -import me.shedaniel.library.KeyBindFunction; -import me.shedaniel.listenerdefinitions.DoneLoading; -import me.shedaniel.listenerdefinitions.RecipeLoadListener; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.registry.Registry; - -import java.util.*; - -public class ClientListener implements DoneLoading, RecipeLoadListener { - - public static KeyBindFunction recipeKeyBind; - public static KeyBindFunction hideKeyBind; - public static KeyBindFunction usageKeyBind; - public static List<KeyBindFunction> keyBinds = new ArrayList<>(); - - private List<IREIPlugin> plugins; - public static List<ItemStack> stackList; - - public static boolean processGuiKeyBinds(int typedChar) { - for(KeyBindFunction keyBind : keyBinds) - if (keyBind.apply(typedChar)) - return true; - return false; - } - - @Override - public void onDoneLoading() { - plugins = new ArrayList<>(); - stackList = new ArrayList<>(); - - buildItemList(); - } - - public void onInitializeKeyBind() { - recipeKeyBind = new KeyBindFunction(Core.config.recipeKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.recipeKeyBind(); - return key == this.getKey(); - } - }; - hideKeyBind = new KeyBindFunction(Core.config.hideKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.hideKeyBind(); - return key == this.getKey(); - } - }; - usageKeyBind = new KeyBindFunction(Core.config.usageKeyBind) { - @Override - public boolean apply(int key) { - if (key == this.getKey()) - REIRenderHelper.useKeyBind(); - return key == this.getKey(); - } - }; - keyBinds.addAll(Arrays.asList(recipeKeyBind, hideKeyBind, usageKeyBind)); - } - - private void buildItemList() { - if (!Registry.ITEM.isEmpty()) - Registry.ITEM.forEach(this::processItem); - if (Registry.ENCHANTMENT.stream().count() > 0) - Registry.ENCHANTMENT.forEach(enchantment -> { - for(int i = enchantment.getMinimumLevel(); i < enchantment.getMaximumLevel(); i++) { - ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK); - Map<Enchantment, Integer> map = new HashMap<>(); - map.put(enchantment, i); - EnchantmentHelper.set(map, stack); - processItemStack(stack); - } - }); - } - - private void processItem(Item item) { - DefaultedList<ItemStack> items = DefaultedList.create(); - try { - item.addStacksForDisplay(item.getItemGroup(), items); - items.forEach(stackList::add); - } catch (NullPointerException e) { - } - } - - private void processItemStack(ItemStack item) { - stackList.add(item); - } - - @Override - public void recipesLoaded(RecipeManager recipeManager) { - REIRecipeManager.instance().RecipesLoaded(recipeManager); - } - -} diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java deleted file mode 100755 index 2cc74161b..000000000 --- a/src/main/java/me/shedaniel/Core.java +++ /dev/null @@ -1,122 +0,0 @@ -package me.shedaniel; - -import me.shedaniel.config.REIConfig; -import me.shedaniel.config.REIRuntimeConfig; -import me.shedaniel.listenerdefinitions.ClientTickable; -import me.shedaniel.listenerdefinitions.IEvent; -import me.shedaniel.listeners.DrawContainerListener; -import me.shedaniel.network.CheatPacket; -import me.shedaniel.plugin.VanillaPlugin; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.events.client.ClientTickEvent; -import net.fabricmc.loader.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.item.ItemStack; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -/** - * Created by James on 7/27/2018. - */ -public class Core implements ClientModInitializer { - - private static List<IEvent> events = new LinkedList<>(); - public static final File configFile = new File(FabricLoader.INSTANCE.getConfigDirectory(), "rei.json"); - public static REIConfig config; - public static REIRuntimeConfig runtimeConfig; - public static ClientListener clientListener; - public static Logger LOGGER = LogManager.getFormatterLogger("REI"); - - @Override - public void onInitializeClient() { - this.clientListener = new ClientListener(); - registerSelfEvents(); - registerFabricEvents(); - try { - loadConfig(); - runtimeConfig = new REIRuntimeConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - this.clientListener.onInitializeKeyBind(); - } - - private void registerFabricEvents() { - ClientTickEvent.CLIENT.register(minecraftClient -> { - getListeners(ClientTickable.class).forEach(ClientTickable::clientTick); - if (!Core.config.enableCraftableOnlyButton) - Core.runtimeConfig.craftableOnly = false; - }); - } - - private void registerSelfEvents() { - registerEvent(new DrawContainerListener()); - registerEvent(clientListener); - registerPlugin(new VanillaPlugin()); - } - - public static void registerPlugin(VanillaPlugin vanillaPlugin) { - registerEvent(vanillaPlugin); - } - - private static void registerEvent(IEvent event) { - events.add(event); - } - - public static <T> List<T> getListeners(Class<T> listenerInterface) { - List<T> list = new ArrayList<>(); - events.forEach(iEvent -> { - if (listenerInterface.isAssignableFrom(iEvent.getClass())) - list.add(listenerInterface.cast(iEvent)); - }); - return list; - } - - public static void loadConfig() throws IOException { - if (!configFile.exists() || !configFile.canRead()) { - config = new REIConfig(); - saveConfig(); - return; - } - boolean failed = false; - try { - config = REIConfig.GSON.fromJson(new InputStreamReader(Files.newInputStream(configFile.toPath())), REIConfig.class); - } catch (Exception e) { - failed = true; - } - if (failed || config == null) { - Core.LOGGER.error("REI: Failed to load config! Overwriting with default config."); - config = new REIConfig(); - } - saveConfig(); - } - - public static void saveConfig() throws IOException { - configFile.getParentFile().mkdirs(); - if (!configFile.exists() && !configFile.createNewFile()) { - Core.LOGGER.error("REI: Failed to save config! Overwriting with default config."); - config = new REIConfig(); - return; - } - FileWriter writer = new FileWriter(configFile, false); - try { - REIConfig.GSON.toJson(config, writer); - } finally { - writer.close(); - } - } - - public static void cheatItems(ItemStack cheatedStack) { - MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CheatPacket(cheatedStack)); - } - -} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategory.java b/src/main/java/me/shedaniel/api/IDisplayCategory.java deleted file mode 100755 index 309a836ac..000000000 --- a/src/main/java/me/shedaniel/api/IDisplayCategory.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.shedaniel.api; - -import me.shedaniel.gui.widget.Control; -import me.shedaniel.gui.widget.REISlot; -import net.minecraft.item.ItemStack; - -import java.util.List; - -/** - * Created by James on 8/7/2018. - */ -public interface IDisplayCategory<T extends IRecipe> { - - public String getId(); - - public String getDisplayName(); - - public void addRecipe(T recipe); - - public void resetRecipes(); - - public List<REISlot> setupDisplay(int number); - - public boolean canDisplay(T recipe); - - public void drawExtras |
