Leaderboard
Popular Content
Showing content with the highest reputation on 09/11/19 in Posts
-
Don't register your Capability in the @Mod files constructor instead do it in the FMLCommonSetupEvent.1 point
-
Yes it would be. Technically. The ICapabilityProvider is attached to the entity and it stores the "instance" field. Yes every time an entity is created it attaches a new ICapabilityProvider to that entity.1 point
-
1 point
-
I don't remember exactly. Use this: https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/util/LootUtils.java It already handles 99% of use cases with intelligently named parameters and will offer sensible alternatives when you just need to do something simple (such as not needing an ILootCondition or ILootFunction). If you have more specific questions, just ask. There's some examples of usage in my code (mostly in Harder Farming's EventHandler class).1 point
-
That's been confusing a lot of people. So a LazyOptional is an object that stores a value optionally and has many methods to allow you to interact with is such as LazyOptional#ifPresent which will run a NonNullConsumer (which you can just pass in a lambda) that will run only if the LazyOptional holds something. So what I do for the LazyOptional is just do private LazyOptional<SomeData> instance = LazyOptional.of(CAPABILITY_INSTANCE::getDefaultInstance); This will create one instance of the default instance when it is first needed. IE the first time you try to access it.1 point
-
No, this will be irrelevant for the update cycle. Forge, and other projects have had access to this information for years. As I have stated many times, the concept that Forge is slow to update is a dirty lie spread by people who just want to disparage our good name. 1.13 is a SPECIAL CASE that took a while as a explicit decision. As we took the time to re-write the entire toolchain/codebase. NORMAL updates take less then 24 hours to do. And we will be continuing that tradition now that our rewrite is finished. MCP will still exist, as there are a lot of things that MCP allows us to have that these mappings do not. Documentation, parameter names, better names, better code from injected data/managed data. This is NOT as useful as people are thinking. And with the legal issues it's actually detrimental to the community as a whole. As the only people who benefit from this, are the ones who do not respect Mojang's copyright. There already are projects that just straight up use the mappings, deobf/ship Mojang's named classfiles/decompiled code. Those projects will get popular because there are members of this community who are not respectable. There probably will be a major fanbase harassing everyone about using the names. But, Forge WILL respect Mojang's copyright, so as is we can't publicly use these names.1 point
-
Here is my basic ConfigHandler class, maybe help you. package net.xwerswoodx.vrenchant; import java.io.File; import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; public class ConfigHandler { public static Configuration config; private static String file = "config/modID.cfg"; public static void init() { config = new Configuration(new File(file)); try { config.load(); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } /* * Removes specific category from configuration file. */ public static void removeConfig(String category) { config = new Configuration(new File(file)); try { config.load(); if (config.hasCategory(category)) config.removeCategory(new ConfigCategory(category)); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } /* * Removes specific key in specific category from configuration file. */ public static void removeConfig(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) config.getCategory(category).remove(key); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static int getInt(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return config.get(category, key, 0).getInt(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return 0; } public static double getDouble(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return config.get(category, key, 0D).getDouble(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return 0D; } public static float getFloat(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return (float)config.get(category, key, 0D).getDouble(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return 0f; } public static String getString(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return config.get(category, key, "").getString(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return ""; } public static long getLong(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return config.get(category, key, 0L).getLong(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return 0L; } public static short getShort(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return (short)config.get(category, key, (short)0).getInt(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return (short)0; } public static byte getByte(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) { return (byte)config.get(category, key, (byte)0).getInt(); } } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return (byte)0; } public static boolean getBoolean(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (config.getCategory(category).containsKey(key)) return config.get(category, key, false).getBoolean(); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return false; } public static void writeConfig(String category, String key, String value) { config = new Configuration(new File(file)); try { config.load(); String set = config.get(category, key, value).getString(); config.getCategory(category).get(key).set(value); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, int value) { config = new Configuration(new File(file)); try { config.load(); int set = config.get(category, key, value).getInt(); config.getCategory(category).get(key).set(value); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, boolean value) { config = new Configuration(new File(file)); try { config.load(); boolean set = config.get(category, key, value).getBoolean(); config.getCategory(category).get(key).set(value); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, long value) { config = new Configuration(new File(file)); try { config.load(); long set = config.get(category, key, value).getLong(); config.getCategory(category).get(key).set(value); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, double value) { config = new Configuration(new File(file)); try { config.load(); double set = config.get(category, key, value).getDouble(); config.getCategory(category).get(key).set(value); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, short value) { config = new Configuration(new File(file)); try { config.load(); int set = config.get(category, key, value).getInt(); config.getCategory(category).get(key).set(Integer.valueOf(value)); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, byte value) { config = new Configuration(new File(file)); try { config.load(); int set = config.get(category, key, value).getInt(); config.getCategory(category).get(key).set(Integer.valueOf(value)); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static void writeConfig(String category, String key, float value) { config = new Configuration(new File(file)); try { config.load(); double set = config.get(category, key, value).getDouble(); config.getCategory(category).get(key).set(Double.valueOf(value)); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } } public static boolean hasCategory(String category) { config = new Configuration(new File(file)); try { config.load(); return config.hasCategory(category); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return false; } public static boolean hasKey(String category, String key) { config = new Configuration(new File(file)); try { config.load(); if (!config.hasCategory(category)) return false; return config.getCategory(category).containsKey(key); } catch (Exception e) { System.out.println("Cannot load configuration file!"); } finally { config.save(); } return false; } public static void setFile(String filename) { file = "config/" + filename; } public static String getFile() { return file; } } Just put this code to ConfigHandler.java (Or you can give another name) and you can write, remove or get values like; writeConfig(category[String], key[String], value[String, int, long, short, byte, boolean, double, float]); ConfigHandler.writeConfig("My Category", "Name", "Hamit"); //Write string ("Hamit") to config. ConfigHandler.writeConfig("My Category", "isPlayer", true); //Write boolean ("true") to config. setFile(fileName[String]); ConfigHandler.setFile("Hamit.cfg"); //Changes default file (which is set at the beginning of ConfigHandler class) getString(category[String], key[String]); //You can use getInt, getLong, getShort etc. ConfigHandler.getString("My Category", "Name"); //Get string value of "Name" from the category - named "My Category". out.println("isPlayer " + ConfigHandler.getString("My Category", "isPlayer").toString() + " boolean value has written in file: " + ConfigHandler.getFile()); @EventHandler public void onInitialization(FMLInitializationEvent event) { ConfigHandler.writeConfig("My Category", "Name", "Hamit"); System.out.println("Name " + ConfigHandler.getString("My Category", "Name") + " string value has written in file: " + ConfigHandler.getFile()); ConfigHandler.setFile("Mehmet.cfg"); ConfigHandler.writeConfig("My Category", "Age", 22); System.out.println("Name " + String.valueOf(ConfigHandler.getInt("My Category", "Age")) + " integer value has written in file: " + ConfigHandler.getFile()); ConfigHandler.setFile("Batuhan.cfg"); ConfigHandler.writeConfig("My Category", "isPlayer", false); System.out.println("isPlayer " + ConfigHandler.getBoolean("My Category", "isPlayer").toString() + " boolean value has written in file: " + ConfigHandler.getFile()); }1 point