diff --git a/gradle.properties b/gradle.properties index ea9d88c..44ab20e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable. # LOCAL to test local config updates. -gtnh.settings.blowdryerTag = 0.2.0 +gtnh.settings.blowdryerTag = 0.2.2 # Human-readable mod name, available for mcmod.info population. modName = The Spice of Life - Carrot Edition @@ -112,7 +112,7 @@ usesShadowedDependencies = true # If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access # their own classes, making the minimization unreliable. -minimizeShadowedDependencies = false +minimizeShadowedDependencies = true # If disabled, won't rename the shadowed classes. relocateShadowedDependencies = true diff --git a/src/main/java/squeek/spiceoflife/ModConfig.java b/src/main/java/squeek/spiceoflife/ModConfig.java index 7de47b4..95e2082 100644 --- a/src/main/java/squeek/spiceoflife/ModConfig.java +++ b/src/main/java/squeek/spiceoflife/ModConfig.java @@ -29,7 +29,7 @@ public class ModConfig implements IPackable, IPacketProcessor { public static final String ITEM_LUNCH_BOX_NAME = "lunchbox"; public static final String ITEM_LUNCH_BAG_NAME = "lunchbag"; private static final String COMMENT_SERVER_SIDE_OPTIONS = "These config settings are server-side only\n" - + "Their values will get synced to all clients on the server"; + + "Their values will get synced to all clients on the server"; /* * MAIN */ @@ -38,6 +38,36 @@ public class ModConfig implements IPackable, IPacketProcessor { private static final String FOOD_MODIFIER_ENABLED_NAME = "food.modifier.enabled"; private static final boolean FOOD_MODIFIER_ENABLED_DEFAULT = true; private static final String FOOD_MODIFIER_ENABLED_COMMENT = "If false, disables the entire diminishing returns part of the mod"; + /* + * CARROT + */ + private static final String CATEGORY_CARROT = " carrot module "; + private static final String CATEGORY_CARROT_COMMENT = COMMENT_SERVER_SIDE_OPTIONS; + private static final String EXTRA_HEARTS_NAME = "hearts.milestones.enable"; + private static final String EXTRA_HEARTS_COMMENT = "Enable extra hearts module"; + private static final boolean EXTRA_HEARTS_DEFAULT = true; + public static boolean EXTRA_HEARTS_ENABLE = ModConfig.EXTRA_HEARTS_DEFAULT; + private static final String FOOD_MILESTONE_NAME = "hearts.milestones.base"; + private static final String FOOD_MILESTONE_COMMENT = "Base requirement for each Food Milestones (in food points) to award extra hearts"; + private static final int FOOD_MILESTONE_DEFAULT = 50; + public static int FOOD_MILESTONE_VALUE = ModConfig.FOOD_MILESTONE_DEFAULT; + private static final String MILESTONE_INCREMENT_NAME = "hearts.milestones.increment"; + private static final String MILESTONE_INCREMENT_COMMENT = "The increase per Milestone to the base Food Milestones value (in food points)"; + private static final int MILESTONE_INCREMENT_DEFAULT = 0; + public static int MILESTONE_INCREMENT_VALUE = ModConfig.MILESTONE_INCREMENT_DEFAULT; + private static final String HEARTS_PER_MILESTONE_NAME = "hearts.milestones.reward"; + private static final String HEARTS_PER_MILESTONE_COMMENT = "Extra hearts awarded per milestone achieved"; + private static final int HEARTS_PER_MILESTONE_DEFAULT = 1; + public static int HEARTS_PER_MILESTONE_VALUE = ModConfig.HEARTS_PER_MILESTONE_DEFAULT; + + private static final String MAX_MILESTONE_NAME = "hearts.milestones.maximum"; + private static final String MAX_MILESTONE_COMMENT = "The maximum allowed number of Milestones a player can achieve"; + private static final int MAX_MILESTONE_DEFAULT = -1; + public static int MAX_MILESTONE_VALUE = ModConfig.MAX_MILESTONE_DEFAULT; + private static final String FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_NAME = "hearts.milestones.persists.through.death"; + private static final String FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_COMMENT = "If true, milestone progress will not get reset after every death"; + private static final boolean FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_DEFAULT = true; + public static boolean FOOD_MILESTONES_PERSISTS_THROUGH_DEATH = ModConfig.FOOD_HISTORY_PERSISTS_THROUGH_DEATH_DEFAULT; /* * DEV */ @@ -66,72 +96,72 @@ public class ModConfig implements IPackable, IPacketProcessor { private static final String FOOD_HUNGER_ROUNDING_MODE_NAME = "food.hunger.rounding.mode"; private static final String FOOD_HUNGER_ROUNDING_MODE_DEFAULT = "round"; private static final String FOOD_HUNGER_ROUNDING_MODE_COMMENT = "Rounding mode used on the hunger value of foods\n" - + "Valid options: 'round', 'floor', 'ceiling'"; + + "Valid options: 'round', 'floor', 'ceiling'"; private static final String AFFECT_FOOD_HUNGER_VALUES_NAME = "affect.food.hunger.values"; private static final boolean AFFECT_FOOD_HUNGER_VALUES_DEFAULT = true; private static final String AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_NAME = "affect.negative.food.hunger.values"; private static final boolean AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_DEFAULT = false; private static final String AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_COMMENT = "If true, foods with negative hunger values will be made more negative as nutritional value decreases\n" - + "NOTE: " - + AFFECT_FOOD_HUNGER_VALUES_NAME - + " must be true for this to have any affect"; + + "NOTE: " + + AFFECT_FOOD_HUNGER_VALUES_NAME + + " must be true for this to have any affect"; private static final String AFFECT_FOOD_SATURATION_MODIFIERS_NAME = "affect.food.saturation.modifiers"; private static final String AFFECT_FOOD_HUNGER_VALUES_COMMENT = "If true, foods' hunger value will be multiplied by the current nutritional value\n" - + "Setting this to false and " - + ModConfig.AFFECT_FOOD_SATURATION_MODIFIERS_NAME - + " to true will make diminishing returns affect saturation only"; + + "Setting this to false and " + + ModConfig.AFFECT_FOOD_SATURATION_MODIFIERS_NAME + + " to true will make diminishing returns affect saturation only"; private static final boolean AFFECT_FOOD_SATURATION_MODIFIERS_DEFAULT = false; private static final String AFFECT_FOOD_SATURATION_MODIFIERS_COMMENT = "If true, foods' saturation modifier will be multiplied by the current nutritional value\n" - + "NOTE: When " - + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME - + " is true, saturation bonuses of foods will automatically decrease as the hunger value of the food decreases\n" - + "Setting this to true when " - + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME - + " is true will make saturation bonuses decrease disproportionately more than hunger values\n" - + "Setting this to true and " - + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME - + " to false will make diminishing returns affect saturation only"; + + "NOTE: When " + + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME + + " is true, saturation bonuses of foods will automatically decrease as the hunger value of the food decreases\n" + + "Setting this to true when " + + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME + + " is true will make saturation bonuses decrease disproportionately more than hunger values\n" + + "Setting this to true and " + + ModConfig.AFFECT_FOOD_HUNGER_VALUES_NAME + + " to false will make diminishing returns affect saturation only"; private static final String AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_NAME = "affect.negative.food.saturation.modifiers"; private static final boolean AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT = false; private static final String AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_COMMENT = "If true, foods with negative saturation modifiers will be made more negative as nutritional value decreases\n" - + "NOTE: " - + AFFECT_FOOD_SATURATION_MODIFIERS_NAME - + " must be true for this to have any affect"; + + "NOTE: " + + AFFECT_FOOD_SATURATION_MODIFIERS_NAME + + " must be true for this to have any affect"; private static final String FOOD_EATING_SPEED_MODIFIER_NAME = "food.eating.speed.modifier"; private static final float FOOD_EATING_SPEED_MODIFIER_DEFAULT = 1; private static final String FOOD_EATING_SPEED_MODIFIER_COMMENT = "If set to greater than zero, food eating speed will be affected by nutritional value\n" - + "(meaning the lower the nutrtional value, the longer it will take to eat it)\n" - + "Eating duration is calcualted using the formula (eating_duration / (nutritional_value^eating_speed_modifier))"; + + "(meaning the lower the nutrtional value, the longer it will take to eat it)\n" + + "Eating duration is calcualted using the formula (eating_duration / (nutritional_value^eating_speed_modifier))"; private static final String FOOD_EATING_DURATION_MAX_NAME = "food.eating.duration.max"; private static final int FOOD_EATING_DURATION_MAX_DEFAULT = 0; private static final String FOOD_EATING_DURATION_MAX_COMMENT = "The maximum time it takes to eat a food after being modified by " - + ModConfig.FOOD_EATING_SPEED_MODIFIER_NAME - + "\n" - + "The default eating duration is 32. Set this to 0 to remove the limit on eating speed.\n" - + "Note: If this is set to 0 and " - + ModConfig.FOOD_EATING_SPEED_MODIFIER_NAME - + " is > 0, a food with 0% nutrtional value will take nearly infinite time to eat"; + + ModConfig.FOOD_EATING_SPEED_MODIFIER_NAME + + "\n" + + "The default eating duration is 32. Set this to 0 to remove the limit on eating speed.\n" + + "Note: If this is set to 0 and " + + ModConfig.FOOD_EATING_SPEED_MODIFIER_NAME + + " is > 0, a food with 0% nutrtional value will take nearly infinite time to eat"; private static final String FOOD_MODIFIER_FORMULA_STRING_NAME = "food.modifier.formula"; private static final String FOOD_MODIFIER_FORMULA_STRING_DEFAULT = "MAX(0, (1 - count/12))^MIN(8, food_hunger_value)"; private static final String FOOD_MODIFIER_FORMULA_STRING_COMMENT = "Uses the EvalEx expression parser\n" - + "See: https://github.com/uklimaschewski/EvalEx for syntax/function documentation\n\n" - + "Available variables:\n" - + "\tcount : The number of times the food (or its food group) has been eaten within the food history\n" - + "\thunger_count : The total amount of hunger that the food (or its food group) has restored within the food history (1 hunger unit = 1/2 hunger bar)\n" - + "\tsaturation_count : The total amount of saturation that the food (or its food group) has restored within the food history (1 saturation unit = 1/2 saturation bar)\n" - + "\tmax_history_length : The maximum length of the food history (see " - + FOOD_HISTORY_LENGTH_NAME - + ")\n" - + "\tcur_history_length : The current length of the food history (<= max_history_length)\n" - + "\tfood_hunger_value : The default amount of hunger the food would restore in hunger units (1 hunger unit = 1/2 hunger bar)\n" - + "\tfood_saturation_mod : The default saturation modifier of the food\n" - + "\tcur_hunger : The current hunger value of the player in hunger units (20 = full)\n" - + "\tcur_saturation : The current saturation value of the player\n" - + "\ttotal_food_eaten : The all-time total number of times any food has been eaten by the player\n" - + "\tfood_group_count : The number of food groups that the food belongs to\n" - + "\tdistinct_food_groups_eaten : The number of distinct food groups in the player's current food history\n" - + "\ttotal_food_groups : The total number of enabled food groups\n" - + "\texact_count : The number of times the food (ignoring food groups) has been eaten within the food history\n"; + + "See: https://github.com/uklimaschewski/EvalEx for syntax/function documentation\n\n" + + "Available variables:\n" + + "\tcount : The number of times the food (or its food group) has been eaten within the food history\n" + + "\thunger_count : The total amount of hunger that the food (or its food group) has restored within the food history (1 hunger unit = 1/2 hunger bar)\n" + + "\tsaturation_count : The total amount of saturation that the food (or its food group) has restored within the food history (1 saturation unit = 1/2 saturation bar)\n" + + "\tmax_history_length : The maximum length of the food history (see " + + FOOD_HISTORY_LENGTH_NAME + + ")\n" + + "\tcur_history_length : The current length of the food history (<= max_history_length)\n" + + "\tfood_hunger_value : The default amount of hunger the food would restore in hunger units (1 hunger unit = 1/2 hunger bar)\n" + + "\tfood_saturation_mod : The default saturation modifier of the food\n" + + "\tcur_hunger : The current hunger value of the player in hunger units (20 = full)\n" + + "\tcur_saturation : The current saturation value of the player\n" + + "\ttotal_food_eaten : The all-time total number of times any food has been eaten by the player\n" + + "\tfood_group_count : The number of food groups that the food belongs to\n" + + "\tdistinct_food_groups_eaten : The number of distinct food groups in the player's current food history\n" + + "\ttotal_food_groups : The total number of enabled food groups\n" + + "\texact_count : The number of times the food (ignoring food groups) has been eaten within the food history\n"; private static final String GIVE_FOOD_JOURNAL_ON_START_NAME = "give.food.journal.as.starting.item"; private static final boolean GIVE_FOOD_JOURNAL_ON_START_DEFAULT = false; private static final String GIVE_FOOD_JOURNAL_ON_START_COMMENT = "If true, a food journal will be given to each player as a starting item"; @@ -153,7 +183,7 @@ public class ModConfig implements IPackable, IPacketProcessor { private static final String CATEGORY_FOODGROUPS = "foodgroups"; private static final String CATEGORY_FOODGROUPS_COMMENT = "Food groups are defined using .json files in /config/SpiceOfLife/\n" - + "See /config/SpiceOfLife/example-food-group.json"; + + "See /config/SpiceOfLife/example-food-group.json"; // whether or not food modifier is actually enabled (we either are the server or know the server has it enabled) public static boolean FOOD_MODIFIER_ENABLED = false; // the value written in the config file @@ -191,139 +221,192 @@ public static void init(File file) { /* * MAIN */ - config.getCategory(CATEGORY_MAIN).setComment(CATEGORY_MAIN_COMMENT); - FOOD_MODIFIER_ENABLED_CONFIG_VAL = config.get( + config.getCategory(CATEGORY_MAIN) + .setComment(CATEGORY_MAIN_COMMENT); + FOOD_MODIFIER_ENABLED_CONFIG_VAL = config + .get( CATEGORY_MAIN, FOOD_MODIFIER_ENABLED_NAME, FOOD_MODIFIER_ENABLED_DEFAULT, - FOOD_MODIFIER_ENABLED_COMMENT).getBoolean(FOOD_MODIFIER_ENABLED_DEFAULT); + FOOD_MODIFIER_ENABLED_COMMENT) + .getBoolean(FOOD_MODIFIER_ENABLED_DEFAULT); // only use the config value immediately when server-side; the client assumes false until the server syncs the // config - if (FMLCommonHandler.instance().getSide() == Side.SERVER) - FOOD_MODIFIER_ENABLED = FOOD_MODIFIER_ENABLED_CONFIG_VAL; - + if (FMLCommonHandler.instance() + .getSide() == Side.SERVER) FOOD_MODIFIER_ENABLED = FOOD_MODIFIER_ENABLED_CONFIG_VAL; + /* + * CARROT + */ + config.getCategory(CATEGORY_CARROT) + .setComment(CATEGORY_CARROT_COMMENT); + EXTRA_HEARTS_ENABLE = config.get(CATEGORY_CARROT, EXTRA_HEARTS_NAME, EXTRA_HEARTS_DEFAULT, EXTRA_HEARTS_COMMENT) + .getBoolean(EXTRA_HEARTS_DEFAULT); + + FOOD_MILESTONE_VALUE = config + .get(CATEGORY_CARROT, FOOD_MILESTONE_NAME, FOOD_MILESTONE_DEFAULT, FOOD_MILESTONE_COMMENT) + .getInt(FOOD_MILESTONE_DEFAULT); + + MILESTONE_INCREMENT_VALUE = config + .get(CATEGORY_CARROT, MILESTONE_INCREMENT_NAME, MILESTONE_INCREMENT_DEFAULT, MILESTONE_INCREMENT_COMMENT) + .getInt(MILESTONE_INCREMENT_DEFAULT); + + HEARTS_PER_MILESTONE_VALUE = config + .get(CATEGORY_CARROT, HEARTS_PER_MILESTONE_NAME, HEARTS_PER_MILESTONE_DEFAULT, HEARTS_PER_MILESTONE_COMMENT) + .getInt(HEARTS_PER_MILESTONE_DEFAULT); + + MAX_MILESTONE_VALUE = config + .get(CATEGORY_CARROT, MAX_MILESTONE_NAME, MAX_MILESTONE_DEFAULT, MAX_MILESTONE_COMMENT) + .getInt(MAX_MILESTONE_DEFAULT); + + FOOD_MILESTONES_PERSISTS_THROUGH_DEATH = config + .get( + CATEGORY_CARROT, + FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_NAME, + FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_DEFAULT, + FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_COMMENT) + .getBoolean(FOOD_MILESTONES_PERSISTS_THROUGH_DEATH_DEFAULT); /* * DEV */ - config.getCategory(CATEGORY_DEV).setComment(CATEGORY_DEV_COMMENT); + config.getCategory(CATEGORY_DEV) + .setComment(CATEGORY_DEV_COMMENT); DEV_LOGGING_ENABLED = config - .get(CATEGORY_DEV, DEV_LOGGING_ENABLED_NAME, DEV_LOGGING_ENABLED_DEFAULT, DEV_LOGGING_ENABLED_COMMENT) - .getBoolean(DEV_LOGGING_ENABLED_DEFAULT); + .get(CATEGORY_DEV, DEV_LOGGING_ENABLED_NAME, DEV_LOGGING_ENABLED_DEFAULT, DEV_LOGGING_ENABLED_COMMENT) + .getBoolean(DEV_LOGGING_ENABLED_DEFAULT); /* * SERVER */ - config.getCategory(CATEGORY_SERVER).setComment(CATEGORY_SERVER_COMMENT); + config.getCategory(CATEGORY_SERVER) + .setComment(CATEGORY_SERVER_COMMENT); Property FOOD_MODIFIER_PROPERTY = config.get( - CATEGORY_SERVER, - FOOD_MODIFIER_FORMULA_STRING_NAME, - FOOD_MODIFIER_FORMULA_STRING_DEFAULT, - FOOD_MODIFIER_FORMULA_STRING_COMMENT); + CATEGORY_SERVER, + FOOD_MODIFIER_FORMULA_STRING_NAME, + FOOD_MODIFIER_FORMULA_STRING_DEFAULT, + FOOD_MODIFIER_FORMULA_STRING_COMMENT); // enforce the new default if the config has the old default if (FOOD_MODIFIER_PROPERTY.getString() - .equals("MAX(0, (1 - count/12))^MAX(0, food_hunger_value-ROUND(MAX(0, 1 - count/12), 0))")) + .equals("MAX(0, (1 - count/12))^MAX(0, food_hunger_value-ROUND(MAX(0, 1 - count/12), 0))")) FOOD_MODIFIER_PROPERTY.set(FOOD_MODIFIER_FORMULA_STRING_DEFAULT); FOOD_MODIFIER_FORMULA = FOOD_MODIFIER_PROPERTY.getString(); - FOOD_HISTORY_LENGTH = config.get( - CATEGORY_SERVER, - FOOD_HISTORY_LENGTH_NAME, - FOOD_HISTORY_LENGTH_DEFAULT, - FOOD_HISTORY_LENGTH_COMMENT).getInt(FOOD_HISTORY_LENGTH_DEFAULT); + FOOD_HISTORY_LENGTH = config + .get(CATEGORY_SERVER, FOOD_HISTORY_LENGTH_NAME, FOOD_HISTORY_LENGTH_DEFAULT, FOOD_HISTORY_LENGTH_COMMENT) + .getInt(FOOD_HISTORY_LENGTH_DEFAULT); FOOD_HISTORY_PERSISTS_THROUGH_DEATH = config - .get( - CATEGORY_SERVER, - FOOD_HISTORY_PERSISTS_THROUGH_DEATH_NAME, - FOOD_HISTORY_PERSISTS_THROUGH_DEATH_DEFAULT, - FOOD_HISTORY_PERSISTS_THROUGH_DEATH_COMMENT) - .getBoolean(FOOD_HISTORY_PERSISTS_THROUGH_DEATH_DEFAULT); - FOOD_EATEN_THRESHOLD = config.get( + .get( CATEGORY_SERVER, - FOOD_EATEN_THRESHOLD_NAME, - FOOD_EATEN_THRESHOLD_DEFAULT, - FOOD_EATEN_THRESHOLD_COMMENT).getInt(FOOD_EATEN_THRESHOLD_DEFAULT); - USE_FOOD_GROUPS_AS_WHITELISTS = config.get( + FOOD_HISTORY_PERSISTS_THROUGH_DEATH_NAME, + FOOD_HISTORY_PERSISTS_THROUGH_DEATH_DEFAULT, + FOOD_HISTORY_PERSISTS_THROUGH_DEATH_COMMENT) + .getBoolean(FOOD_HISTORY_PERSISTS_THROUGH_DEATH_DEFAULT); + FOOD_EATEN_THRESHOLD = config + .get(CATEGORY_SERVER, FOOD_EATEN_THRESHOLD_NAME, FOOD_EATEN_THRESHOLD_DEFAULT, FOOD_EATEN_THRESHOLD_COMMENT) + .getInt(FOOD_EATEN_THRESHOLD_DEFAULT); + USE_FOOD_GROUPS_AS_WHITELISTS = config + .get( CATEGORY_SERVER, USE_FOOD_GROUPS_AS_WHITELISTS_NAME, USE_FOOD_GROUPS_AS_WHITELISTS_DEFAULT, - USE_FOOD_GROUPS_AS_WHITELISTS_COMMENT).getBoolean(USE_FOOD_GROUPS_AS_WHITELISTS_DEFAULT); - AFFECT_FOOD_HUNGER_VALUES = config.get( + USE_FOOD_GROUPS_AS_WHITELISTS_COMMENT) + .getBoolean(USE_FOOD_GROUPS_AS_WHITELISTS_DEFAULT); + AFFECT_FOOD_HUNGER_VALUES = config + .get( CATEGORY_SERVER, AFFECT_FOOD_HUNGER_VALUES_NAME, AFFECT_FOOD_HUNGER_VALUES_DEFAULT, - AFFECT_FOOD_HUNGER_VALUES_COMMENT).getBoolean(AFFECT_FOOD_HUNGER_VALUES_DEFAULT); + AFFECT_FOOD_HUNGER_VALUES_COMMENT) + .getBoolean(AFFECT_FOOD_HUNGER_VALUES_DEFAULT); AFFECT_NEGATIVE_FOOD_HUNGER_VALUES = config - .get( - CATEGORY_SERVER, - AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_NAME, - AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_DEFAULT, - AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_COMMENT) - .getBoolean(AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_DEFAULT); - AFFECT_FOOD_SATURATION_MODIFIERS = config.get( + .get( + CATEGORY_SERVER, + AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_NAME, + AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_DEFAULT, + AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_COMMENT) + .getBoolean(AFFECT_NEGATIVE_FOOD_HUNGER_VALUES_DEFAULT); + AFFECT_FOOD_SATURATION_MODIFIERS = config + .get( CATEGORY_SERVER, AFFECT_FOOD_SATURATION_MODIFIERS_NAME, AFFECT_FOOD_SATURATION_MODIFIERS_DEFAULT, - AFFECT_FOOD_SATURATION_MODIFIERS_COMMENT).getBoolean(AFFECT_FOOD_SATURATION_MODIFIERS_DEFAULT); + AFFECT_FOOD_SATURATION_MODIFIERS_COMMENT) + .getBoolean(AFFECT_FOOD_SATURATION_MODIFIERS_DEFAULT); AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS = config - .get( - CATEGORY_SERVER, - AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_NAME, - AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT, - AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_COMMENT) - .getBoolean(AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT); - FOOD_EATING_SPEED_MODIFIER = (float) config.get( + .get( + CATEGORY_SERVER, + AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_NAME, + AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT, + AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_COMMENT) + .getBoolean(AFFECT_NEGATIVE_FOOD_SATURATION_MODIFIERS_DEFAULT); + FOOD_EATING_SPEED_MODIFIER = (float) config + .get( CATEGORY_SERVER, FOOD_EATING_SPEED_MODIFIER_NAME, FOOD_EATING_SPEED_MODIFIER_DEFAULT, - FOOD_EATING_SPEED_MODIFIER_COMMENT).getDouble(FOOD_EATING_SPEED_MODIFIER_DEFAULT); - FOOD_EATING_DURATION_MAX = config.get( + FOOD_EATING_SPEED_MODIFIER_COMMENT) + .getDouble(FOOD_EATING_SPEED_MODIFIER_DEFAULT); + FOOD_EATING_DURATION_MAX = config + .get( CATEGORY_SERVER, FOOD_EATING_DURATION_MAX_NAME, FOOD_EATING_DURATION_MAX_DEFAULT, - FOOD_EATING_DURATION_MAX_COMMENT).getInt(FOOD_EATING_DURATION_MAX_DEFAULT); - GIVE_FOOD_JOURNAL_ON_START = config.get( + FOOD_EATING_DURATION_MAX_COMMENT) + .getInt(FOOD_EATING_DURATION_MAX_DEFAULT); + GIVE_FOOD_JOURNAL_ON_START = config + .get( CATEGORY_SERVER, GIVE_FOOD_JOURNAL_ON_START_NAME, GIVE_FOOD_JOURNAL_ON_START_DEFAULT, - GIVE_FOOD_JOURNAL_ON_START_COMMENT).getBoolean(GIVE_FOOD_JOURNAL_ON_START_DEFAULT); - FOOD_CONTAINERS_MAX_STACKSIZE = config.get( + GIVE_FOOD_JOURNAL_ON_START_COMMENT) + .getBoolean(GIVE_FOOD_JOURNAL_ON_START_DEFAULT); + FOOD_CONTAINERS_MAX_STACKSIZE = config + .get( CATEGORY_SERVER, FOOD_CONTAINERS_MAX_STACKSIZE_NAME, FOOD_CONTAINERS_MAX_STACKSIZE_DEFAULT, - FOOD_CONTAINERS_MAX_STACKSIZE_COMMENT).getInt(FOOD_CONTAINERS_MAX_STACKSIZE_DEFAULT); + FOOD_CONTAINERS_MAX_STACKSIZE_COMMENT) + .getInt(FOOD_CONTAINERS_MAX_STACKSIZE_DEFAULT); - FOOD_HUNGER_ROUNDING_MODE_STRING = config.get( + FOOD_HUNGER_ROUNDING_MODE_STRING = config + .get( CATEGORY_SERVER, FOOD_HUNGER_ROUNDING_MODE_NAME, FOOD_HUNGER_ROUNDING_MODE_DEFAULT, - FOOD_HUNGER_ROUNDING_MODE_COMMENT).getString(); + FOOD_HUNGER_ROUNDING_MODE_COMMENT) + .getString(); setRoundingMode(); /* * CLIENT */ - config.getCategory(CATEGORY_CLIENT).setComment(CATEGORY_CLIENT_COMMENT); + config.getCategory(CATEGORY_CLIENT) + .setComment(CATEGORY_CLIENT_COMMENT); - LEFT_CLICK_OPENS_FOOD_CONTAINERS = config.get( + LEFT_CLICK_OPENS_FOOD_CONTAINERS = config + .get( CATEGORY_CLIENT, LEFT_CLICK_OPENS_FOOD_CONTAINERS_NAME, LEFT_CLICK_OPENS_FOOD_CONTAINERS_DEFAULT, - LEFT_CLICK_OPENS_FOOD_CONTAINERS_COMMENT).getBoolean(LEFT_CLICK_OPENS_FOOD_CONTAINERS_DEFAULT); + LEFT_CLICK_OPENS_FOOD_CONTAINERS_COMMENT) + .getBoolean(LEFT_CLICK_OPENS_FOOD_CONTAINERS_DEFAULT); /* * FOOD GROUPS */ - config.getCategory(CATEGORY_FOODGROUPS).setComment(CATEGORY_FOODGROUPS_COMMENT); + config.getCategory(CATEGORY_FOODGROUPS) + .setComment(CATEGORY_FOODGROUPS_COMMENT); FoodGroupConfig.setup(file.getParentFile()); // remove obsolete config options - config.getCategory(CATEGORY_SERVER).remove("use.food.groups"); - config.getCategory(CATEGORY_FOODGROUPS).clear(); + config.getCategory(CATEGORY_SERVER) + .remove("use.food.groups"); + config.getCategory(CATEGORY_FOODGROUPS) + .clear(); save(); } @@ -345,8 +428,8 @@ public static void setRoundingMode() { } } if (FOOD_HUNGER_ROUNDING_MODE == null) { - ModSpiceOfLife.Log.warn( - "Rounding mode '" + FOOD_HUNGER_ROUNDING_MODE_STRING + "' not recognized; defaulting to 'round'"); + ModSpiceOfLife.Log + .warn("Rounding mode '" + FOOD_HUNGER_ROUNDING_MODE_STRING + "' not recognized; defaulting to 'round'"); FOOD_HUNGER_ROUNDING_MODE_STRING = "round"; FOOD_HUNGER_ROUNDING_MODE = RoundingMode.ROUND; } @@ -357,7 +440,8 @@ public static void save() { } public static void sync(EntityPlayerMP player) { - PacketDispatcher.get().sendTo(new PacketConfigSync(), player); + PacketDispatcher.get() + .sendTo(new PacketConfigSync(), player); } @SideOnly(Side.CLIENT) @@ -407,7 +491,8 @@ public PacketBase processAndReply(Side side, EntityPlayer player) { if (FOOD_MODIFIER_ENABLED) { setRoundingMode(); FoodModifier.onGlobalFormulaChanged(); - FoodHistory.get(player).onHistoryTypeChanged(); + FoodHistory.get(player) + .onHistoryTypeChanged(); FoodGroupRegistry.clear(); } diff --git a/src/main/java/squeek/spiceoflife/ModContent.java b/src/main/java/squeek/spiceoflife/ModContent.java index 15d916e..037e3a4 100644 --- a/src/main/java/squeek/spiceoflife/ModContent.java +++ b/src/main/java/squeek/spiceoflife/ModContent.java @@ -27,13 +27,13 @@ public static void registerItems() { public static void registerRecipes() { GameRegistry - .addShapelessRecipe(new ItemStack(foodJournal), new ItemStack(Items.wheat), new ItemStack(Items.paper)); + .addShapelessRecipe(new ItemStack(foodJournal), new ItemStack(Items.wheat), new ItemStack(Items.paper)); GameRegistry.addShapedRecipe( - new ItemStack(lunchBox), - "_ _", - " _ ", - '_', - new ItemStack(Blocks.heavy_weighted_pressure_plate)); + new ItemStack(lunchBox), + "_ _", + " _ ", + '_', + new ItemStack(Blocks.heavy_weighted_pressure_plate)); GameRegistry.addShapedRecipe(new ItemStack(lunchBag), "p p", " p ", 'p', new ItemStack(Items.paper)); } } diff --git a/src/main/java/squeek/spiceoflife/ModSpiceOfLife.java b/src/main/java/squeek/spiceoflife/ModSpiceOfLife.java index c1ac11f..1f29134 100644 --- a/src/main/java/squeek/spiceoflife/ModSpiceOfLife.java +++ b/src/main/java/squeek/spiceoflife/ModSpiceOfLife.java @@ -52,7 +52,9 @@ public void preInit(FMLPreInitializationEvent event) { public void init(FMLInitializationEvent event) { GuiHelper.init(); FoodTracker foodTracker = new FoodTracker(); - FMLCommonHandler.instance().bus().register(foodTracker); + FMLCommonHandler.instance() + .bus() + .register(foodTracker); MinecraftForge.EVENT_BUS.register(foodTracker); MinecraftForge.EVENT_BUS.register(new FoodModifier()); diff --git a/src/main/java/squeek/spiceoflife/compat/PacketDispatcherNetty.java b/src/main/java/squeek/spiceoflife/compat/PacketDispatcherNetty.java index 666839d..d760518 100644 --- a/src/main/java/squeek/spiceoflife/compat/PacketDispatcherNetty.java +++ b/src/main/java/squeek/spiceoflife/compat/PacketDispatcherNetty.java @@ -22,11 +22,11 @@ public void sendTo(PacketBase packet, EntityPlayerMP player) { @Override public void sendToAllAround(PacketBase packet, PacketTarget packetTarget) { NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint( - packetTarget.dimension, - packetTarget.x, - packetTarget.y, - packetTarget.z, - packetTarget.range); + packetTarget.dimension, + packetTarget.x, + packetTarget.y, + packetTarget.z, + packetTarget.range); PacketHandler.channel.sendToAllAround(packet, targetPoint); } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/FoodEaten.java b/src/main/java/squeek/spiceoflife/foodtracker/FoodEaten.java index eae48d0..6211f64 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/FoodEaten.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/FoodEaten.java @@ -32,7 +32,8 @@ public String toString() { @Override public int hashCode() { - return itemStack.getItem().hashCode(); + return itemStack.getItem() + .hashCode(); } @Override @@ -42,9 +43,9 @@ public boolean equals(Object obj) { if (other.itemStack == null || this.itemStack == null) return false; final Item item = itemStack.getItem(); final Item otherItem = other.itemStack.getItem(); - return (Item.itemRegistry.getNameForObject(item).equals(Item.itemRegistry.getNameForObject(otherItem)) - && item.equals(otherItem) - && this.itemStack.getItemDamage() == other.itemStack.getItemDamage()); + return (Item.itemRegistry.getNameForObject(item) + .equals(Item.itemRegistry.getNameForObject(otherItem)) && item.equals(otherItem) + && this.itemStack.getItemDamage() == other.itemStack.getItemDamage()); } public static FoodEaten loadFromNBTData(NBTTagCompound nbtFood) { diff --git a/src/main/java/squeek/spiceoflife/foodtracker/FoodHistory.java b/src/main/java/squeek/spiceoflife/foodtracker/FoodHistory.java index 19cd57a..6444467 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/FoodHistory.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/FoodHistory.java @@ -81,7 +81,8 @@ public int getFoodCountForFoodGroup(ItemStack food, FoodGroup foodGroup) { for (FoodEaten foodEaten : recentHistory) { if (foodEaten.itemStack == null) continue; - if (food.isItemEqual(foodEaten.itemStack) || foodEaten.getFoodGroups().contains(foodGroup)) { + if (food.isItemEqual(foodEaten.itemStack) || foodEaten.getFoodGroups() + .contains(foodGroup)) { count += 1; } } @@ -106,7 +107,7 @@ public boolean containsFoodOrItsFoodGroups(ItemStack food) { if (foodEaten.itemStack == null) continue; if (food.isItemEqual(foodEaten.itemStack) - || MiscHelper.collectionsOverlap(foodGroups, foodEaten.getFoodGroups())) { + || MiscHelper.collectionsOverlap(foodGroups, foodEaten.getFoodGroups())) { return true; } } @@ -124,7 +125,8 @@ public FoodValues getTotalFoodValuesForFoodGroup(ItemStack food, FoodGroup foodG for (FoodEaten foodEaten : recentHistory) { if (foodEaten.itemStack == null) continue; - if (food.isItemEqual(foodEaten.itemStack) || foodEaten.getFoodGroups().contains(foodGroup)) { + if (food.isItemEqual(foodEaten.itemStack) || foodEaten.getFoodGroups() + .contains(foodGroup)) { totalHunger += foodEaten.foodValues.hunger; totalSaturation += foodEaten.foodValues.getSaturationIncrement(); } @@ -269,21 +271,22 @@ private static void spawnParticles(EntityPlayer player, String type, int count) // this function sends a packet to the client world.func_147487_a( - type, - (float) player.posX, - (float) player.posY + 2, - (float) player.posZ, - count, - 1F, - 1F, - 1F, - 0.20000000298023224D); + type, + (float) player.posX, + (float) player.posY + 2, + (float) player.posZ, + count, + 1F, + 1F, + 1F, + 0.20000000298023224D); } @Override // null compound parameter means save persistent data only public void writeToNBTData(NBTTagCompound data) { - NBTTagCompound rootPersistentCompound = player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound rootPersistentCompound = player.getEntityData() + .getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); NBTTagCompound nonPersistentCompound = new NBTTagCompound(); NBTTagCompound persistentCompound = new NBTTagCompound(); @@ -298,9 +301,15 @@ public void writeToNBTData(NBTTagCompound data) { } } if (fullHistory.size() > 0) { - NBTTagCompound nbtFullHistory = new NBTTagCompound(); - fullHistory.writeToNBTData(nbtFullHistory); - persistentCompound.setTag("FullHistory", nbtFullHistory); + if (data != null || ModConfig.FOOD_MILESTONES_PERSISTS_THROUGH_DEATH) { + NBTTagCompound nbtFullHistory = new NBTTagCompound(); + + fullHistory.writeToNBTData(nbtFullHistory); + + if (ModConfig.FOOD_MILESTONES_PERSISTS_THROUGH_DEATH) + persistentCompound.setTag("FullHistory", nbtFullHistory); + else nonPersistentCompound.setTag("FullHistory", nbtFullHistory); + } } if (totalFoodsEatenAllTime > 0) { persistentCompound.setInteger("Total", totalFoodsEatenAllTime); @@ -316,8 +325,10 @@ public void writeToNBTData(NBTTagCompound data) { if (!persistentCompound.hasNoTags()) rootPersistentCompound.setTag(TAG_KEY, persistentCompound); - if (!player.getEntityData().hasKey(EntityPlayer.PERSISTED_NBT_TAG)) - player.getEntityData().setTag(EntityPlayer.PERSISTED_NBT_TAG, rootPersistentCompound); + if (!player.getEntityData() + .hasKey(EntityPlayer.PERSISTED_NBT_TAG)) + player.getEntityData() + .setTag(EntityPlayer.PERSISTED_NBT_TAG, rootPersistentCompound); } @Override @@ -331,15 +342,23 @@ public void init(Entity entity, World world) {} @Override // null compound parameter means load persistent data only public void readFromNBTData(NBTTagCompound data) { - NBTTagCompound rootPersistentCompound = player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); + NBTTagCompound rootPersistentCompound = player.getEntityData() + .getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); NBTTagCompound persistentCompound = rootPersistentCompound.getCompoundTag(TAG_KEY); if ((data != null && data.hasKey(TAG_KEY)) || rootPersistentCompound.hasKey(TAG_KEY)) { NBTTagCompound nonPersistentCompound = data != null ? data.getCompoundTag(TAG_KEY) : new NBTTagCompound(); NBTTagCompound nbtHistory = ModConfig.FOOD_HISTORY_PERSISTS_THROUGH_DEATH - ? persistentCompound.getCompoundTag("History") - : nonPersistentCompound.getCompoundTag("History"); + ? persistentCompound.getCompoundTag("History") + : nonPersistentCompound.getCompoundTag("History"); + + NBTTagCompound nbtFullHistory = ModConfig.FOOD_MILESTONES_PERSISTS_THROUGH_DEATH + ? persistentCompound.getCompoundTag("FullHistory") + : nonPersistentCompound.getCompoundTag("FullHistory"); + + fullHistory.readFromNBTData(nbtHistory); + fullHistory.readFromNBTData(nbtFullHistory); recentHistory.readFromNBTData(nbtHistory); @@ -348,6 +367,5 @@ public void readFromNBTData(NBTTagCompound data) { ticksActive = persistentCompound.getLong("Ticks"); } - fullHistory.readFromNBTData(persistentCompound.getCompoundTag("FullHistory")); } } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/FoodLists.java b/src/main/java/squeek/spiceoflife/foodtracker/FoodLists.java index 6a9ad7b..566258e 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/FoodLists.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/FoodLists.java @@ -23,8 +23,10 @@ public final class FoodLists { public static void setUp() { if (ModConfig.DEV_LOGGING_ENABLED) ModSpiceOfLife.Log.info("Starting populating food list."); Stream stream = StreamSupport.stream(Item.itemRegistry.spliterator(), false); - allFoods = stream.map(ItemStack::new).filter(FoodHelper::isFood) - .sorted(Comparator.comparing(ItemStack::getDisplayName)).collect(Collectors.toList()); + allFoods = stream.map(ItemStack::new) + .filter(FoodHelper::isFood) + .sorted(Comparator.comparing(ItemStack::getDisplayName)) + .collect(Collectors.toList()); allFoods.forEach((i -> { FoodValues fv = FoodHelper.getFoodValues(i); diff --git a/src/main/java/squeek/spiceoflife/foodtracker/FoodModifier.java b/src/main/java/squeek/spiceoflife/foodtracker/FoodModifier.java index 9741cf3..ec2e49c 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/FoodModifier.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/FoodModifier.java @@ -46,7 +46,7 @@ public void getFoodValues(FoodEvent.GetPlayerFoodValues event) { ItemStack actualFood = event.food; if (FoodHelper.isFoodContainer(event.food)) { actualFood = ((ItemFoodContainer) event.food.getItem()) - .getBestFoodForPlayerToEat(event.food, event.player); + .getBestFoodForPlayerToEat(event.food, event.player); } if (actualFood != null) { @@ -91,7 +91,8 @@ public static float getFoodModifier(FoodHistory foodHistory, ItemStack food) { // if this food has mutliple food groups, calculate the modifier for each individually // and then take the average // for foods with <= 1 food group, this just means dividing the modifier by 1 - FoodGroup[] foodGroups = FoodGroupRegistry.getFoodGroupsForFood(food).toArray(new FoodGroup[0]); + FoodGroup[] foodGroups = FoodGroupRegistry.getFoodGroupsForFood(food) + .toArray(new FoodGroup[0]); int numIterations = Math.max(1, foodGroups.length); float modifierSum = 0f; @@ -112,19 +113,36 @@ public static float getFoodGroupModifier(FoodHistory foodHistory, ItemStack food if (foodValues != null) { BigDecimal result = effectiveFoodModifier.expression.with("count", new BigDecimal(count)) - .and("cur_history_length", new BigDecimal(historySize)) - .and("food_hunger_value", new BigDecimal(foodValues.hunger)) - .and("food_saturation_mod", new BigDecimal(foodValues.saturationModifier)) - .and("cur_hunger", new BigDecimal(foodHistory.player.getFoodStats().getFoodLevel())) - .and("cur_saturation", new BigDecimal(foodHistory.player.getFoodStats().getSaturationLevel())) - .and("total_food_eaten", new BigDecimal(foodHistory.totalFoodsEatenAllTime)) - .and("max_history_length", new BigDecimal(ModConfig.FOOD_HISTORY_LENGTH)) - .and("hunger_count", new BigDecimal(totalFoodValues.hunger)) - .and("saturation_count", new BigDecimal(totalFoodValues.saturationModifier)) - .and("food_group_count", new BigDecimal(FoodGroupRegistry.getFoodGroupsForFood(food).size())) - .and("distinct_food_groups_eaten", new BigDecimal(foodHistory.getDistinctFoodGroups().size())) - .and("total_food_groups", new BigDecimal(FoodGroupRegistry.numFoodGroups())) - .and("exact_count", new BigDecimal(foodHistory.getFoodCountIgnoringFoodGroups(food))).eval(); + .and("cur_history_length", new BigDecimal(historySize)) + .and("food_hunger_value", new BigDecimal(foodValues.hunger)) + .and("food_saturation_mod", new BigDecimal(foodValues.saturationModifier)) + .and( + "cur_hunger", + new BigDecimal( + foodHistory.player.getFoodStats() + .getFoodLevel())) + .and( + "cur_saturation", + new BigDecimal( + foodHistory.player.getFoodStats() + .getSaturationLevel())) + .and("total_food_eaten", new BigDecimal(foodHistory.totalFoodsEatenAllTime)) + .and("max_history_length", new BigDecimal(ModConfig.FOOD_HISTORY_LENGTH)) + .and("hunger_count", new BigDecimal(totalFoodValues.hunger)) + .and("saturation_count", new BigDecimal(totalFoodValues.saturationModifier)) + .and( + "food_group_count", + new BigDecimal( + FoodGroupRegistry.getFoodGroupsForFood(food) + .size())) + .and( + "distinct_food_groups_eaten", + new BigDecimal( + foodHistory.getDistinctFoodGroups() + .size())) + .and("total_food_groups", new BigDecimal(FoodGroupRegistry.numFoodGroups())) + .and("exact_count", new BigDecimal(foodHistory.getFoodCountIgnoringFoodGroups(food))) + .eval(); return result.floatValue(); } @@ -137,7 +155,7 @@ public void getFoodEatingSpeed(PlayerUseItemEvent.Start event) { ItemStack actualFood = event.item; if (FoodHelper.isFoodContainer(event.item)) { actualFood = ((ItemFoodContainer) event.item.getItem()) - .getBestFoodForPlayerToEat(event.item, event.entityPlayer); + .getBestFoodForPlayerToEat(event.item, event.entityPlayer); } if (actualFood != null) { diff --git a/src/main/java/squeek/spiceoflife/foodtracker/FoodTracker.java b/src/main/java/squeek/spiceoflife/foodtracker/FoodTracker.java index d660bea..c91f061 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/FoodTracker.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/FoodTracker.java @@ -24,11 +24,13 @@ public class FoodTracker { public static int getFoodHistoryLengthInRelevantUnits(EntityPlayer player) { - return FoodHistory.get(player).getHistoryLength(); + return FoodHistory.get(player) + .getHistoryLength(); } public static ItemStack getFoodLastEatenBy(EntityPlayer player) { - return FoodHistory.get(player).getLastEatenFood().itemStack; + return FoodHistory.get(player) + .getLastEatenFood().itemStack; } /** @@ -46,9 +48,10 @@ public void onFoodEaten(FoodEvent.FoodEaten event) { public static void addFoodEatenByPlayer(FoodEaten foodEaten, EntityPlayer player) { // client needs to be told by the server otherwise the client can get out of sync easily - if (!player.worldObj.isRemote && player instanceof EntityPlayerMP) - PacketDispatcher.get().sendTo(new PacketFoodHistory(foodEaten), (EntityPlayerMP) player); - FoodHistory.get(player).addFood(foodEaten); + if (!player.worldObj.isRemote && player instanceof EntityPlayerMP) PacketDispatcher.get() + .sendTo(new PacketFoodHistory(foodEaten), (EntityPlayerMP) player); + FoodHistory.get(player) + .addFood(foodEaten); } /** @@ -85,10 +88,12 @@ public void onPlayerLogin(PlayerLoggedInEvent event) { } public static void syncFoodHistory(FoodHistory foodHistory) { - PacketDispatcher.get().sendTo( + PacketDispatcher.get() + .sendTo( new PacketFoodEatenAllTime(foodHistory.totalFoodsEatenAllTime), (EntityPlayerMP) foodHistory.player); - PacketDispatcher.get().sendTo(new PacketFoodHistory(foodHistory, true), (EntityPlayerMP) foodHistory.player); + PacketDispatcher.get() + .sendTo(new PacketFoodHistory(foodHistory, true), (EntityPlayerMP) foodHistory.player); MaxHealthHandler.updateFoodHPModifier(foodHistory.player); } @@ -106,8 +111,9 @@ public void onPlayerChangedDimension(PlayerChangedDimensionEvent event) { */ @SubscribeEvent public void onLivingDeathEvent(LivingDeathEvent event) { - if (FMLCommonHandler.instance().getEffectiveSide().isClient() || !(event.entity instanceof EntityPlayer)) - return; + if (FMLCommonHandler.instance() + .getEffectiveSide() + .isClient() || !(event.entity instanceof EntityPlayer)) return; EntityPlayer player = (EntityPlayer) event.entity; @@ -120,7 +126,9 @@ public void onLivingDeathEvent(LivingDeathEvent event) { */ @SubscribeEvent public void onPlayerRespawn(PlayerRespawnEvent event) { - if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return; + if (FMLCommonHandler.instance() + .getEffectiveSide() + .isClient()) return; // load any persistent food history data FoodHistory foodHistory = FoodHistory.get(event.player); @@ -135,6 +143,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { */ @SubscribeEvent public void onClientConnectedToServer(ClientConnectedToServerEvent event) { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) ModConfig.assumeClientOnly(); + if (FMLCommonHandler.instance() + .getEffectiveSide() == Side.CLIENT) ModConfig.assumeClientOnly(); } } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/MaxHealthHandler.java b/src/main/java/squeek/spiceoflife/foodtracker/MaxHealthHandler.java index 084bfae..1899fdb 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/MaxHealthHandler.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/MaxHealthHandler.java @@ -7,6 +7,8 @@ import net.minecraft.entity.ai.attributes.IAttributeInstance; import net.minecraft.entity.player.EntityPlayer; +import squeek.spiceoflife.ModConfig; + public class MaxHealthHandler { private static final UUID SOL_HEALTH_MODIFIER_ID = UUID.fromString("f88d6ac1-4193-4ff0-85f5-f0357fe89d17"); @@ -16,10 +18,13 @@ public static boolean updateFoodHPModifier(EntityPlayer player) { return false; } + if (!ModConfig.EXTRA_HEARTS_ENABLE) { + return false; + } + final IAttributeInstance attribute = player.getAttributeMap() - .getAttributeInstance(SharedMonsterAttributes.maxHealth); + .getAttributeInstance(SharedMonsterAttributes.maxHealth); final AttributeModifier prevModifier = attribute.getModifier(SOL_HEALTH_MODIFIER_ID); - final FoodHistory foodHistory = FoodHistory.get(player); ProgressInfo progressInfo = foodHistory.getProgressInfo(); final int milestonesAchieved = progressInfo.milestonesAchieved(); @@ -28,10 +33,10 @@ public static boolean updateFoodHPModifier(EntityPlayer player) { boolean hasChanged = prevModifier == null || prevModifier.getAmount() != totalHealthModifier; AttributeModifier modifier = new AttributeModifier( - SOL_HEALTH_MODIFIER_ID, - "Health gained from trying new foods", - totalHealthModifier, - 0); + SOL_HEALTH_MODIFIER_ID, + "Health gained from trying new foods", + totalHealthModifier, + 0); updateHealthModifier(player, modifier); @@ -41,7 +46,8 @@ public static boolean updateFoodHPModifier(EntityPlayer player) { private static void updateHealthModifier(EntityPlayer player, AttributeModifier modifier) { float oldMax = player.getMaxHealth(); - IAttributeInstance attribute = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth); + IAttributeInstance attribute = player.getAttributeMap() + .getAttributeInstance(SharedMonsterAttributes.maxHealth); attribute.removeModifier(modifier); attribute.applyModifier(modifier); diff --git a/src/main/java/squeek/spiceoflife/foodtracker/ProgressInfo.java b/src/main/java/squeek/spiceoflife/foodtracker/ProgressInfo.java index 872ec5a..95f7803 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/ProgressInfo.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/ProgressInfo.java @@ -1,22 +1,35 @@ package squeek.spiceoflife.foodtracker; +import static java.lang.Math.floor; +import static java.lang.Math.max; +import static java.lang.Math.sqrt; + import net.minecraft.item.ItemStack; +import squeek.spiceoflife.ModConfig; + /** * contains all relevant variables for current progress */ public final class ProgressInfo { - public static final int HAUNCHES_PER_MILESTONE = 50; - public static final int HEARTS_PER_MILESTONE = 1; + public static final int FOOD_POINTS_PER_MILESTONE = ModConfig.FOOD_MILESTONE_VALUE; + public static final double INCREMENT_PER_MILESTONE = ModConfig.MILESTONE_INCREMENT_VALUE; + public static final int HEARTS_PER_MILESTONE = ModConfig.HEARTS_PER_MILESTONE_VALUE; + public static final int MAX_MILESTONE_VALUE = ModConfig.MAX_MILESTONE_VALUE; + public boolean hasCap = MAX_MILESTONE_VALUE > 0; + /** - * the number of haunches from unique foods eaten + * the number of food points from unique foods eaten */ - public final int foodsHaunchesEaten; + public final int foodsPointsEaten; ProgressInfo(FoodHistory foodList) { - foodsHaunchesEaten = foodList.getFullHistory().stream().filter(eaten -> shouldCount(eaten.itemStack)) - .mapToInt(eaten -> eaten.foodValues.hunger).sum(); + foodsPointsEaten = foodList.getFullHistory() + .stream() + .filter(eaten -> shouldCount(eaten.itemStack)) + .mapToInt(eaten -> eaten.foodValues.hunger) + .sum(); } public static boolean shouldCount(ItemStack food) { @@ -24,23 +37,58 @@ public static boolean shouldCount(ItemStack food) { } /** - * the number of foods remaining until the next milestone, or a negative value if the maximum has been reached + * the number of foods remaining until the next milestone, or 0 if the maximum has been reached */ - public int foodsUntilNextMilestone() { - return nextMilestone() - foodsHaunchesEaten; + public int foodPointsUntilNextMilestone() { + return Math.max(0, nextMilestoneFoodPoints() - foodsPointsEaten); } /** - * the next milestone to reach, or a negative value if the maximum has been reached + * the next milestone to reach, or 0 if the maximum has been reached */ - public int nextMilestone() { - return (milestonesAchieved() + 1) * HAUNCHES_PER_MILESTONE; + public int nextMilestoneFoodPoints() { + int nextMilestone = (milestonesAchieved() + 1); + + if (hasCap && nextMilestone > MAX_MILESTONE_VALUE) { + return 0; + } + + // Quadratic Progression + if (INCREMENT_PER_MILESTONE > 0) { + double quadraticIncrement = INCREMENT_PER_MILESTONE * 0.5; + double quadraticBase = FOOD_POINTS_PER_MILESTONE - quadraticIncrement; + + return (int) ((quadraticBase * nextMilestone) + (quadraticIncrement * nextMilestone * nextMilestone)); + } + + // Linear Progression + return nextMilestone * FOOD_POINTS_PER_MILESTONE; } /** - * the number of milestones achieved, doubling as the index of the next milestone + * the number of milestones achieved based on foodPointsEaten, doubling as the index of the next milestone */ public int milestonesAchieved() { - return (int) Math.floor((double) foodsHaunchesEaten / (double) HAUNCHES_PER_MILESTONE); + int milestonesTotal; + + if (INCREMENT_PER_MILESTONE > 0) { + // Quadratic Progression + double quadraticIncrement = INCREMENT_PER_MILESTONE * 0.5; + double quadraticBase = FOOD_POINTS_PER_MILESTONE - quadraticIncrement; + + double discriminant = sqrt(quadraticBase * quadraticBase + 4 * quadraticIncrement * foodsPointsEaten); + + double milestone1 = (-quadraticBase + discriminant) / (2 * quadraticIncrement); + double milestone2 = (-quadraticBase - discriminant) / (2 * quadraticIncrement); + + milestonesTotal = (int) floor(max(milestone1, milestone2)); + } else { + // Linear Progression + milestonesTotal = (int) Math.floor((double) foodsPointsEaten / (double) FOOD_POINTS_PER_MILESTONE); + } + + if (hasCap && milestonesTotal >= MAX_MILESTONE_VALUE) return MAX_MILESTONE_VALUE; + + return milestonesTotal; } } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandFoodList.java b/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandFoodList.java index 54d13ae..74b13aa 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandFoodList.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandFoodList.java @@ -32,8 +32,10 @@ public boolean canCommandSenderUseCommand(ICommandSender commandSender) { @Override public List addTabCompletionOptions(ICommandSender commandSender, String[] curArgs) { if (curArgs.length == 1) return Arrays.asList("size", "sync"); - else if (curArgs.length == 2) - return getListOfStringsMatchingLastWord(curArgs, MinecraftServer.getServer().getAllUsernames()); + else if (curArgs.length == 2) return getListOfStringsMatchingLastWord( + curArgs, + MinecraftServer.getServer() + .getAllUsernames()); else return null; } @@ -63,33 +65,33 @@ public void processCommand(ICommandSender commandSender, String[] args) { if (args.length > 0) { final boolean isOp = commandSender.canCommandSenderUseCommand(4, "targetOtherPlayer"); final EntityPlayerMP player = (isOp && args.length > 1) ? getPlayer(commandSender, args[1]) - : getCommandSenderAsPlayer(commandSender); + : getCommandSenderAsPlayer(commandSender); final FoodHistory foodHistory = FoodHistory.get(player); if (args[0].equals("size")) { final ProgressInfo progressInfo = foodHistory.getProgressInfo(); - final int foodsEaten = progressInfo.foodsHaunchesEaten; + final int foodsEaten = progressInfo.foodsPointsEaten; final int milestone = progressInfo.milestonesAchieved(); - final int foodsUntilNextMilestone = progressInfo.foodsUntilNextMilestone(); + final int foodsUntilNextMilestone = progressInfo.foodPointsUntilNextMilestone(); commandSender.addChatMessage( - new ChatComponentText( - "" + EnumChatFormatting.BOLD - + EnumChatFormatting.DARK_AQUA - + player.getDisplayName() - + "'s" - + EnumChatFormatting.RESET - + " food stats:")); + new ChatComponentText( + "" + EnumChatFormatting.BOLD + + EnumChatFormatting.DARK_AQUA + + player.getDisplayName() + + "'s" + + EnumChatFormatting.RESET + + " food stats:")); commandSender.addChatMessage(new ChatComponentText("Half-Shanks worth eaten: " + foodsEaten)); commandSender.addChatMessage( - new ChatComponentText("Bonus Hearts: " + (milestone * ProgressInfo.HEARTS_PER_MILESTONE))); + new ChatComponentText("Bonus Hearts: " + (milestone * ProgressInfo.HEARTS_PER_MILESTONE))); commandSender.addChatMessage( - new ChatComponentText("Half-Shanks until next bonus heart: " + foodsUntilNextMilestone)); + new ChatComponentText("Half-Shanks until next bonus heart: " + foodsUntilNextMilestone)); return; } else if (args[0].equals("sync")) { FoodTracker.syncFoodHistory(foodHistory); commandSender - .addChatMessage(new ChatComponentText("Synced food history for " + player.getDisplayName())); + .addChatMessage(new ChatComponentText("Synced food history for " + player.getDisplayName())); return; } } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandResetHistory.java b/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandResetHistory.java index 5a2c576..f6f0cf0 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandResetHistory.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/commands/CommandResetHistory.java @@ -19,8 +19,10 @@ public class CommandResetHistory extends CommandBase { @Override public List addTabCompletionOptions(ICommandSender commandSender, String[] curArgs) { if (curArgs.length == 1) return Collections.singletonList("reset"); - else if (curArgs.length == 2) - return getListOfStringsMatchingLastWord(curArgs, MinecraftServer.getServer().getAllUsernames()); + else if (curArgs.length == 2) return getListOfStringsMatchingLastWord( + curArgs, + MinecraftServer.getServer() + .getAllUsernames()); else return null; } @@ -50,15 +52,15 @@ public void processCommand(ICommandSender commandSender, String[] args) { if (args.length > 0) { if (args[0].equals("reset")) { EntityPlayerMP playerToReset = args.length > 1 ? getPlayer(commandSender, args[1]) - : getCommandSenderAsPlayer(commandSender); + : getCommandSenderAsPlayer(commandSender); FoodHistory foodHistoryToReset = FoodHistory.get(playerToReset); foodHistoryToReset.reset(); FoodTracker.syncFoodHistory(foodHistoryToReset); func_152374_a( - commandSender, - this, - 0, - "Reset all 'The Spice of Life' mod data for " + playerToReset.getDisplayName()); + commandSender, + this, + 0, + "Reset all 'The Spice of Life' mod data for " + playerToReset.getDisplayName()); return; } } diff --git a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroup.java b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroup.java index 2b2ee1f..c69f8a1 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroup.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroup.java @@ -53,7 +53,7 @@ public FoodGroup(String identifier, String name) { public void initFromConfig() { if (foodStringsByType == null) throw new RuntimeException( - toString() + " food group (" + identifier + ".json) missing required \"food\" property"); + toString() + " food group (" + identifier + ".json) missing required \"food\" property"); formatting = EnumChatFormatting.getValueByName(color); if (formatting == null) formatting = DEFAULT_FORMATTING; @@ -152,12 +152,12 @@ public void init() { public boolean isFoodIncluded(ItemStack food) { return !isFoodExcluded(food) && matchingItemHashes.contains(OreDictionaryHelper.getItemStackHash(food)) - || matchingItemHashes.contains(OreDictionaryHelper.getWildCardItemStackHash(food)); + || matchingItemHashes.contains(OreDictionaryHelper.getWildCardItemStackHash(food)); } public boolean isFoodExcluded(ItemStack food) { return excludedItemHashes.contains(OreDictionaryHelper.getItemStackHash(food)) - || excludedItemHashes.contains(OreDictionaryHelper.getWildCardItemStackHash(food)); + || excludedItemHashes.contains(OreDictionaryHelper.getWildCardItemStackHash(food)); } public Set getMatchingItemStackHashes() { diff --git a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupConfig.java b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupConfig.java index ade5d61..7c88f66 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupConfig.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupConfig.java @@ -21,7 +21,9 @@ public class FoodGroupConfig { - private static final Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create(); + private static final Gson gson = new GsonBuilder().enableComplexMapKeySerialization() + .setPrettyPrinting() + .create(); private static File[] configFiles; public static void setup(File configDirectory) { @@ -44,7 +46,7 @@ public static void writeExampleFoodGroup(File configDirectory) { FileHelper.copyFile(sourceFile, exampleFoodGroupDest, shouldOverwrite); } else { InputStream exampleFoodGroupInputStream = FoodGroupConfig.class.getClassLoader() - .getResourceAsStream(exampleFoodGroupRelativePath); + .getResourceAsStream(exampleFoodGroupRelativePath); FileHelper.copyFile(exampleFoodGroupInputStream, exampleFoodGroupDest, shouldOverwrite); exampleFoodGroupInputStream.close(); } @@ -63,7 +65,7 @@ public static boolean shouldOverwriteExampleFoodGroup(File exampleFoodGroup) thr BufferedReader exampleFoodGroupReader = null; try { exampleFoodGroupReader = new BufferedReader( - new InputStreamReader(exampleFoodGroupStream, StandardCharsets.UTF_8)); + new InputStreamReader(exampleFoodGroupStream, StandardCharsets.UTF_8)); String firstLine = exampleFoodGroupReader.readLine(); return firstLine == null || !firstLine.equals("// Mod Version: " + ModInfo.VERSION); } catch (IOException e) { @@ -75,7 +77,8 @@ public static boolean shouldOverwriteExampleFoodGroup(File exampleFoodGroup) thr public static void load() { for (File configFile : configFiles) { - boolean isJson = FilenameUtils.getExtension(configFile.getName()).equalsIgnoreCase("json"); + boolean isJson = FilenameUtils.getExtension(configFile.getName()) + .equalsIgnoreCase("json"); if (!isJson) continue; InputStreamReader reader = null; diff --git a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupRegistry.java b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupRegistry.java index 6bc5e5f..195d48d 100644 --- a/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupRegistry.java +++ b/src/main/java/squeek/spiceoflife/foodtracker/foodgroups/FoodGroupRegistry.java @@ -58,7 +58,7 @@ public static boolean isFoodBlacklisted(ItemStack food) { public static Set getFoodGroupsForFood(ItemStack food) { Set wildCardFoodGroups = foodToIncludedFoodGroups - .get(OreDictionaryHelper.getWildCardItemStackHash(food)); + .get(OreDictionaryHelper.getWildCardItemStackHash(food)); Set exactFoodGroups = foodToIncludedFoodGroups.get(OreDictionaryHelper.getItemStackHash(food)); Set allFoodGroups = new HashSet<>(); @@ -85,7 +85,8 @@ private static boolean isAnyFoodGroupBlacklist(Collection foodGroups) public static void sync(EntityPlayerMP player) { for (FoodGroup foodGroup : foodGroups.values()) { - PacketDispatcher.get().sendTo(new PacketFoodGroup(foodGroup), player); + PacketDispatcher.get() + .sendTo(new PacketFoodGroup(foodGroup), player); } } @@ -96,7 +97,8 @@ public static void setInStone() { foodGroup.init(); for (Integer itemHash : foodGroup.getMatchingItemStackHashes()) { foodToIncludedFoodGroups.computeIfAbsent(itemHash, k -> new HashSet<>()); - foodToIncludedFoodGroups.get(itemHash).add(foodGroup); + foodToIncludedFoodGroups.get(itemHash) + .add(foodGroup); } } } diff --git a/src/main/java/squeek/spiceoflife/gui/GuiFoodContainer.java b/src/main/java/squeek/spiceoflife/gui/GuiFoodContainer.java index 5c3d452..c5f6be9 100644 --- a/src/main/java/squeek/spiceoflife/gui/GuiFoodContainer.java +++ b/src/main/java/squeek/spiceoflife/gui/GuiFoodContainer.java @@ -18,8 +18,8 @@ public class GuiFoodContainer extends GuiContainer { public static final ResourceLocation guiTexture = new ResourceLocation( - ModInfo.MODID.toLowerCase(Locale.ROOT), - "textures/gui/foodcontainer.png"); + ModInfo.MODID.toLowerCase(Locale.ROOT), + "textures/gui/foodcontainer.png"); public int xStart; public int yStart; protected IInventory playerInventory = null; @@ -43,17 +43,17 @@ public void initGui() { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.fontRendererObj.drawString( - this.inventory.hasCustomInventoryName() ? this.inventory.getInventoryName() - : I18n.format(this.inventory.getInventoryName()), - 8, - 6, - 4210752); + this.inventory.hasCustomInventoryName() ? this.inventory.getInventoryName() + : I18n.format(this.inventory.getInventoryName()), + 8, + 6, + 4210752); this.fontRendererObj.drawString( - this.playerInventory.hasCustomInventoryName() ? this.playerInventory.getInventoryName() - : I18n.format(this.playerInventory.getInventoryName()), - 8, - this.ySize - 96 + 3, - 4210752); + this.playerInventory.hasCustomInventoryName() ? this.playerInventory.getInventoryName() + : I18n.format(this.playerInventory.getInventoryName()), + 8, + this.ySize - 96 + 3, + 4210752); super.drawGuiContainerForegroundLayer(mouseX, mouseY); } @@ -61,7 +61,8 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { @Override protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(guiTexture); + this.mc.getTextureManager() + .bindTexture(guiTexture); this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize); int slotsX = ((ContainerFoodContainer) inventorySlots).slotsX - 1; @@ -69,12 +70,12 @@ protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) for (int slotNum = 0; slotNum < inventory.getSizeInventory(); slotNum++) { int x = slotsX + slotNum * GuiHelper.STANDARD_SLOT_WIDTH; drawTexturedModalRect( - xStart + x, - yStart + slotsY, - GuiHelper.STANDARD_GUI_WIDTH, - 0, - GuiHelper.STANDARD_SLOT_WIDTH, - GuiHelper.STANDARD_SLOT_WIDTH); + xStart + x, + yStart + slotsY, + GuiHelper.STANDARD_GUI_WIDTH, + 0, + GuiHelper.STANDARD_SLOT_WIDTH, + GuiHelper.STANDARD_SLOT_WIDTH); } } } diff --git a/src/main/java/squeek/spiceoflife/gui/GuiScreenFoodJournal.java b/src/main/java/squeek/spiceoflife/gui/GuiScreenFoodJournal.java index 9212a19..fbcb801 100644 --- a/src/main/java/squeek/spiceoflife/gui/GuiScreenFoodJournal.java +++ b/src/main/java/squeek/spiceoflife/gui/GuiScreenFoodJournal.java @@ -50,23 +50,17 @@ public void initGui() { super.initGui(); this.buttonList.add( - buttonPrevPage = new WidgetButtonNextPage( - 1, - (this.width - this.bookImageWidth) / 2 + 38, - 2 + 154, - false)); + buttonPrevPage = new WidgetButtonNextPage(1, (this.width - this.bookImageWidth) / 2 + 38, 2 + 154, false)); this.buttonList.add( - buttonNextPage = new WidgetButtonNextPage( - 2, - (this.width - this.bookImageWidth) / 2 + 120, - 2 + 154, - true)); + buttonNextPage = new WidgetButtonNextPage(2, (this.width - this.bookImageWidth) / 2 + 120, 2 + 154, true)); foodEatenWidgets.clear(); FoodHistory foodHistory = FoodHistory.get(mc.thePlayer); Set recent = new HashSet<>(foodHistory.getRecentHistory()); - foodHistory.getFullHistory().stream().sorted(Comparator.comparing(i -> i.itemStack.getDisplayName())) - .forEach(f -> foodEatenWidgets.add(new WidgetFoodEaten(f, recent.contains(f)))); + foodHistory.getFullHistory() + .stream() + .sorted(Comparator.comparing(i -> i.itemStack.getDisplayName())) + .forEach(f -> foodEatenWidgets.add(new WidgetFoodEaten(f, recent.contains(f)))); numPages = 1 + (int) Math.ceil((float) foodEatenWidgets.size() / numPerPage); @@ -80,7 +74,8 @@ private void updateButtons() { public void drawHalfShank(int x, int y) { GL11.glColor3f(1, 1, 1); - mc.getTextureManager().bindTexture(Gui.icons); + mc.getTextureManager() + .bindTexture(Gui.icons); GuiUtils.drawTexturedModalRect(this, x, y, 16, 27, 9, 9); GuiUtils.drawTexturedModalRect(this, x, y, 61, 27, 9, 9); } @@ -106,7 +101,8 @@ public List splitWithDifWidth(String text, int firstLineWidth, int other @Override public void drawScreen(int mouseX, int mouseY, float f) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(bookGuiTextures); + this.mc.getTextureManager() + .bindTexture(bookGuiTextures); int x = (this.width - this.bookImageWidth) / 2; int y = 2; this.drawTexturedModalRect(x, y, 0, 0, this.bookImageWidth, this.bookImageHeight); @@ -124,9 +120,9 @@ public void drawScreen(int mouseX, int mouseY, float f) { FoodHistory foodHistory = FoodHistory.get(mc.thePlayer); if (pageNum == 0) { final ProgressInfo progressInfo = foodHistory.getProgressInfo(); - final int foodsEaten = progressInfo.foodsHaunchesEaten; + final int foodsEaten = progressInfo.foodsPointsEaten; final int extraHearts = progressInfo.milestonesAchieved() * ProgressInfo.HEARTS_PER_MILESTONE; - final int foodsUntilNextMilestone = progressInfo.foodsUntilNextMilestone(); + final int foodsUntilNextMilestone = progressInfo.foodPointsUntilNextMilestone(); int localX = x + leftMargin; int drawWidth = (bookImageWidth - rightMargin) - leftMargin; // width in which text can be drawn, so it @@ -137,11 +133,11 @@ public void drawScreen(int mouseX, int mouseY, float f) { String foodHistoryTitle = I18n.format("spiceoflife.gui.food_history.title"); int foodTitleWidth = fontRendererObj.getStringWidth(foodHistoryTitle); GuiUtils.drawText( - fontRendererObj, - foodHistoryTitle, - localX + drawWidth / 2 - foodTitleWidth / 2, - localY, - Color.BLUE); + fontRendererObj, + foodHistoryTitle, + localX + drawWidth / 2 - foodTitleWidth / 2, + localY, + Color.BLUE); int verticalIndent = 8; @@ -154,23 +150,19 @@ public void drawScreen(int mouseX, int mouseY, float f) { drawHalfShank(localX, localY); String worthEaten = I18n.format("spiceoflife.gui.food_history.worth_eaten"); List list = splitWithDifWidth( - worthEaten + " " + foodsEaten, - widthMinusPadding - hungerOffset, - widthMinusPadding); + worthEaten + " " + foodsEaten, + widthMinusPadding - hungerOffset, + widthMinusPadding); for (int i = 0; i < list.size(); i++) { - GuiUtils.drawText( - fontRendererObj, - list.get(i), - localX + (i == 0 ? hungerOffset : 0), - localY, - blackColor); + GuiUtils + .drawText(fontRendererObj, list.get(i), localX + (i == 0 ? hungerOffset : 0), localY, blackColor); localY += fontRendererObj.FONT_HEIGHT; } localY += verticalIndent; String bonusHearts = I18n.format("spiceoflife.gui.food_history.bonus_hearts"); list = GuiUtils - .listFormattedStringToWidth(fontRendererObj, bonusHearts + " " + extraHearts, widthMinusPadding); + .listFormattedStringToWidth(fontRendererObj, bonusHearts + " " + extraHearts, widthMinusPadding); for (String s : list) { GuiUtils.drawText(fontRendererObj, s, localX, localY, blackColor); localY += fontRendererObj.FONT_HEIGHT; @@ -180,16 +172,12 @@ public void drawScreen(int mouseX, int mouseY, float f) { drawHalfShank(localX, localY); String nextHeart = I18n.format("spiceoflife.gui.food_history.next_heart"); list = splitWithDifWidth( - nextHeart + " " + foodsUntilNextMilestone, - widthMinusPadding - hungerOffset, - widthMinusPadding); + nextHeart + " " + foodsUntilNextMilestone, + widthMinusPadding - hungerOffset, + widthMinusPadding); for (int i = 0; i < list.size(); i++) { - GuiUtils.drawText( - fontRendererObj, - list.get(i), - localX + (i == 0 ? hungerOffset : 0), - localY, - blackColor); + GuiUtils + .drawText(fontRendererObj, list.get(i), localX + (i == 0 ? hungerOffset : 0), localY, blackColor); localY += fontRendererObj.FONT_HEIGHT; } } else { @@ -199,16 +187,13 @@ public void drawScreen(int mouseX, int mouseY, float f) { if (totalNum > 0) { int firstItemNum = startIndex + 1; int lastItemNum = Math.min(totalNum, endIndex); - String pageIndicator = StatCollector.translateToLocalFormatted( - "spiceoflife.gui.items.on.page", - firstItemNum, - lastItemNum, - totalNum); + String pageIndicator = StatCollector + .translateToLocalFormatted("spiceoflife.gui.items.on.page", firstItemNum, lastItemNum, totalNum); fontRendererObj.drawString( - pageIndicator, - x + this.bookImageWidth - this.fontRendererObj.getStringWidth(pageIndicator) - 44, - y + 16, - 0); + pageIndicator, + x + this.bookImageWidth - this.fontRendererObj.getStringWidth(pageIndicator) - 44, + y + 16, + 0); } String numFoodsEatenAllTime = Integer.toString(foodHistory.totalFoodsEatenAllTime); @@ -244,42 +229,42 @@ public void drawScreen(int mouseX, int mouseY, float f) { hoveredStack = foodEatenWidget.foodEaten.itemStack; if (hoveredStack != null) this.renderToolTip(hoveredStack, mouseX, mouseY); } else if (isMouseInsideBox( - mouseX, - mouseY, - localX + WidgetFoodEaten.PADDING_LEFT, - localY, - foodEatenWidget.width(), - 16)) { - List toolTipStrings = new ArrayList<>(); - if (foodEatenWidget.eatenRecently) { - toolTipStrings.add( - EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.ITALIC - + "Eaten Recently"); - } else { - toolTipStrings.add( - EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC - + "Not Eaten Recently!"); - } - this.drawHoveringText(toolTipStrings, mouseX, mouseY, fontRendererObj); + mouseX, + mouseY, + localX + WidgetFoodEaten.PADDING_LEFT, + localY, + foodEatenWidget.width(), + 16)) { + List toolTipStrings = new ArrayList<>(); + if (foodEatenWidget.eatenRecently) { + toolTipStrings.add( + EnumChatFormatting.DARK_PURPLE.toString() + EnumChatFormatting.ITALIC + + "Eaten Recently"); + } else { + toolTipStrings.add( + EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC + + "Not Eaten Recently!"); } + this.drawHoveringText(toolTipStrings, mouseX, mouseY, fontRendererObj); + } foodEatenIndex++; } } else { this.fontRendererObj.drawSplitString( - StatCollector.translateToLocal("spiceoflife.gui.no.recent.food.eaten"), - x + 36, - y + 16 + 16, - 116, - 0x404040); + StatCollector.translateToLocal("spiceoflife.gui.no.recent.food.eaten"), + x + 36, + y + 16 + 16, + 116, + 0x404040); } if (isMouseInsideBox(mouseX, mouseY, allTimeX, allTimeY, allTimeW, fontRendererObj.FONT_HEIGHT)) { this.drawHoveringText( - Collections.singletonList(StatCollector.translateToLocal("spiceoflife.gui.alltime.food.eaten")), - mouseX, - mouseY, - fontRendererObj); + Collections.singletonList(StatCollector.translateToLocal("spiceoflife.gui.alltime.food.eaten")), + mouseX, + mouseY, + fontRendererObj); } } @@ -291,7 +276,8 @@ protected void drawItemStack(ItemStack par1ItemStack, int par2, int par3) { this.zLevel = 200.0F; itemRender.zLevel = 200.0F; FontRenderer font = null; - if (par1ItemStack != null) font = par1ItemStack.getItem().getFontRenderer(par1ItemStack); + if (par1ItemStack != null) font = par1ItemStack.getItem() + .getFontRenderer(par1ItemStack); if (font == null) font = fontRendererObj; itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), par1ItemStack, par2, par3); this.zLevel = 0.0F; diff --git a/src/main/java/squeek/spiceoflife/gui/TooltipHandler.java b/src/main/java/squeek/spiceoflife/gui/TooltipHandler.java index ee48442..219edc3 100644 --- a/src/main/java/squeek/spiceoflife/gui/TooltipHandler.java +++ b/src/main/java/squeek/spiceoflife/gui/TooltipHandler.java @@ -36,9 +36,8 @@ public class TooltipHandler { @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event) { if (event == null || event.entityPlayer == null - || event.itemStack == null - || !FoodHelper.isValidFood(event.itemStack)) - return; + || event.itemStack == null + || !FoodHelper.isValidFood(event.itemStack)) return; int totalFoodEaten = FoodHistory.get(event.entityPlayer).totalFoodsEatenAllTime; List toolTipStringsToAdd = new ArrayList<>(); @@ -47,33 +46,33 @@ public void onItemTooltip(ItemTooltipEvent event) { if (ModConfig.FOOD_MODIFIER_ENABLED && !visibleFoodGroups.isEmpty()) { String foodGroupString = visibleFoodGroups.size() > 1 - ? StatCollector.translateToLocal("spiceoflife.tooltip.food.groups") - : StatCollector.translateToLocal("spiceoflife.tooltip.food.group"); + ? StatCollector.translateToLocal("spiceoflife.tooltip.food.groups") + : StatCollector.translateToLocal("spiceoflife.tooltip.food.group"); String joinedFoodGroups = joinFoodGroupsForDisplay( - visibleFoodGroups, - ", ", - EnumChatFormatting.GRAY.toString()); + visibleFoodGroups, + ", ", + EnumChatFormatting.GRAY.toString()); toolTipStringsToAdd.add( - EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC - + foodGroupString - + EnumChatFormatting.GRAY - + EnumChatFormatting.ITALIC - + joinedFoodGroups); + EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC + + foodGroupString + + EnumChatFormatting.GRAY + + EnumChatFormatting.ITALIC + + joinedFoodGroups); } if (ModConfig.FOOD_EATEN_THRESHOLD > 0 && totalFoodEaten < ModConfig.FOOD_EATEN_THRESHOLD) { if (ModConfig.FOOD_MODIFIER_ENABLED) { int timesUntilMeetsThreshold = ModConfig.FOOD_EATEN_THRESHOLD - totalFoodEaten; toolTipStringsToAdd.add( - EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC - + StatCollector.translateToLocal("spiceoflife.tooltip.food.until.enabled.1")); + EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC + + StatCollector.translateToLocal("spiceoflife.tooltip.food.until.enabled.1")); toolTipStringsToAdd.add( - EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC - + StatCollector.translateToLocalFormatted( - "spiceoflife.tooltip.food.until.enabled.2", - timesUntilMeetsThreshold, - timesUntilMeetsThreshold == 1 - ? StatCollector.translateToLocal("spiceoflife.tooltip.times.singular") - : StatCollector.translateToLocal("spiceoflife.tooltip.times.plural"))); + EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.ITALIC + + StatCollector.translateToLocalFormatted( + "spiceoflife.tooltip.food.until.enabled.2", + timesUntilMeetsThreshold, + timesUntilMeetsThreshold == 1 + ? StatCollector.translateToLocal("spiceoflife.tooltip.times.singular") + : StatCollector.translateToLocal("spiceoflife.tooltip.times.plural"))); } } else { FoodHistory foodHistory = FoodHistory.get(event.entityPlayer); @@ -83,28 +82,27 @@ public void onItemTooltip(ItemTooltipEvent event) { if (FoodHelper.canFoodDiminish(event.itemStack) && (foodOrItsFoodGroupsEatenRecently || foodModifier != 1)) toolTipStringsToAdd.add( - 0, - EnumChatFormatting.GRAY - + StatCollector.translateToLocal("spiceoflife.tooltip.nutritional.value") - + getNutritionalValueString(foodModifier) - + (foodValues.hunger == 0 && foodModifier != 0f ? EnumChatFormatting.DARK_RED + " (" - + foodValues.hunger - + " " - + StatCollector.translateToLocal("spiceoflife.tooltip.hunger") - + ")" : "")); + 0, + EnumChatFormatting.GRAY + StatCollector.translateToLocal("spiceoflife.tooltip.nutritional.value") + + getNutritionalValueString(foodModifier) + + (foodValues.hunger == 0 && foodModifier != 0f ? EnumChatFormatting.DARK_RED + " (" + + foodValues.hunger + + " " + + StatCollector.translateToLocal("spiceoflife.tooltip.hunger") + + ")" : "")); boolean shouldShowPressShift = visibleFoodGroups.size() > 1 && !KeyHelper.isShiftKeyDown(); boolean shouldShowFoodGroupDetails = visibleFoodGroups.size() <= 1 || KeyHelper.isShiftKeyDown(); String bulletPoint = EnumChatFormatting.DARK_GRAY + "- " + EnumChatFormatting.GRAY; if (shouldShowPressShift) toolTipStringsToAdd.add( - bulletPoint + EnumChatFormatting.DARK_GRAY - + StatCollector.translateToLocalFormatted( - "spiceoflife.tooltip.hold.key.for.details", - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.ITALIC - + "Shift" - + EnumChatFormatting.RESET - + EnumChatFormatting.DARK_GRAY)); + bulletPoint + EnumChatFormatting.DARK_GRAY + + StatCollector.translateToLocalFormatted( + "spiceoflife.tooltip.hold.key.for.details", + EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.ITALIC + + "Shift" + + EnumChatFormatting.RESET + + EnumChatFormatting.DARK_GRAY)); if (shouldShowFoodGroupDetails) { int foodGroupsToShow = Math.max(1, visibleFoodGroups.size()); @@ -115,11 +113,11 @@ public void onItemTooltip(ItemTooltipEvent event) { boolean shouldShowNutritionalValue = foodGroupsToShow > 1; String prefix = (foodGroupsToShow > 1 ? bulletPoint : ""); toolTipStringsToAdd.add( - prefix + getEatenRecentlyTooltip( - foodHistory, - event.itemStack, - foodGroup, - shouldShowNutritionalValue)); + prefix + getEatenRecentlyTooltip( + foodHistory, + event.itemStack, + foodGroup, + shouldShowNutritionalValue)); toolTipStringsToAdd.add(getFullHistoryToolTip(foodHistory, event.itemStack)); } } @@ -140,7 +138,7 @@ public static String joinFoodGroupsForDisplay(Set foodGroups, String List stringsToJoin = new ArrayList<>(); for (FoodGroup foodGroup : foodGroups) { stringsToJoin - .add(foodGroup.formatString(EnumChatFormatting.ITALIC.toString() + foodGroup) + resetFormatting); + .add(foodGroup.formatString(EnumChatFormatting.ITALIC.toString() + foodGroup) + resetFormatting); } return StringHelper.join(stringsToJoin, delimiter); } @@ -150,34 +148,32 @@ public String getNutritionalValueString(float foodModifier) { } public String getEatenRecentlyTooltip(FoodHistory foodHistory, ItemStack itemStack, FoodGroup foodGroup, - boolean shouldShowNutritionalValue) { + boolean shouldShowNutritionalValue) { final int count = foodHistory.getFoodCountForFoodGroup(itemStack, foodGroup); final String prefix = "Diminishing Returns: " - + (foodGroup != null ? foodGroup.formatString(EnumChatFormatting.ITALIC.toString() + foodGroup) + " " - : "") - + EnumChatFormatting.RESET.toString() - + EnumChatFormatting.DARK_AQUA.toString() - + EnumChatFormatting.ITALIC; + + (foodGroup != null ? foodGroup.formatString(EnumChatFormatting.ITALIC.toString() + foodGroup) + " " : "") + + EnumChatFormatting.RESET.toString() + + EnumChatFormatting.DARK_AQUA.toString() + + EnumChatFormatting.ITALIC; final String eatenRecently; final String nutritionalValue = shouldShowNutritionalValue - ? EnumChatFormatting.DARK_GRAY + " [" - + getNutritionalValueString( - FoodModifier.getFoodGroupModifier(foodHistory, itemStack, foodGroup)) - + EnumChatFormatting.DARK_GRAY - + "]" - : ""; + ? EnumChatFormatting.DARK_GRAY + " [" + + getNutritionalValueString(FoodModifier.getFoodGroupModifier(foodHistory, itemStack, foodGroup)) + + EnumChatFormatting.DARK_GRAY + + "]" + : ""; if (count > 0) eatenRecently = StatCollector.translateToLocalFormatted( - "spiceoflife.tooltip.eaten.recently", - StringHelper.getQuantityDescriptor(count), - ModConfig.FOOD_HISTORY_LENGTH); + "spiceoflife.tooltip.eaten.recently", + StringHelper.getQuantityDescriptor(count), + ModConfig.FOOD_HISTORY_LENGTH); else eatenRecently = StatCollector.translateToLocal("spiceoflife.tooltip.not.eaten.recently"); return prefix + (foodGroup != null ? StringHelper.decapitalize(eatenRecently, StringHelper.getMinecraftLocale()) - : eatenRecently) + nutritionalValue; + : eatenRecently) + nutritionalValue; } public String getFullHistoryToolTip(FoodHistory foodHistory, ItemStack itemStack) { final String prefix = "Extra Hearts: " + EnumChatFormatting.DARK_AQUA.toString() - + EnumChatFormatting.ITALIC.toString(); + + EnumChatFormatting.ITALIC.toString(); if (!foodHistory.hasEverEaten(itemStack)) { return prefix + StatCollector.translateToLocal("spiceoflife.tooltip.not.eaten.ever"); } else { @@ -192,7 +188,8 @@ static class FoodGroupComparator implements Comparator, Serializable @Override public int compare(FoodGroup a, FoodGroup b) { - return a.getLocalizedName().compareToIgnoreCase(b.getLocalizedName()); + return a.getLocalizedName() + .compareToIgnoreCase(b.getLocalizedName()); } } } diff --git a/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonNextPage.java b/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonNextPage.java index cebfc6b..b58a245 100644 --- a/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonNextPage.java +++ b/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonNextPage.java @@ -30,10 +30,11 @@ public WidgetButtonNextPage(int par1, int par2, int par3, boolean par4) { public void drawButton(Minecraft par1Minecraft, int par2, int par3) { if (this.visible) { boolean flag = par2 >= this.xPosition && par3 >= this.yPosition - && par2 < this.xPosition + this.width - && par3 < this.yPosition + this.height; + && par2 < this.xPosition + this.width + && par3 < this.yPosition + this.height; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - par1Minecraft.getTextureManager().bindTexture(bookGui); + par1Minecraft.getTextureManager() + .bindTexture(bookGui); int k = 0; int l = 192; diff --git a/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonSortDirection.java b/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonSortDirection.java index 90a680f..23cff56 100644 --- a/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonSortDirection.java +++ b/src/main/java/squeek/spiceoflife/gui/widget/WidgetButtonSortDirection.java @@ -16,8 +16,8 @@ public class WidgetButtonSortDirection extends GuiButton { private static final ResourceLocation modIcons = new ResourceLocation( - ModInfo.MODID.toLowerCase(Locale.ROOT), - "textures/icons.png"); + ModInfo.MODID.toLowerCase(Locale.ROOT), + "textures/icons.png"); /** * True for sorted descending (newest first), false for sorted ascending (oldest first). @@ -36,10 +36,11 @@ public WidgetButtonSortDirection(int id, int x, int y, boolean sortDesc) { public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (this.visible) { boolean isHovered = mouseX >= this.xPosition && mouseY >= this.yPosition - && mouseX < this.xPosition + this.width - && mouseY < this.yPosition + this.height; + && mouseX < this.xPosition + this.width + && mouseY < this.yPosition + this.height; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.getTextureManager().bindTexture(modIcons); + mc.getTextureManager() + .bindTexture(modIcons); int x = 0; int y = 0; diff --git a/src/main/java/squeek/spiceoflife/gui/widget/WidgetFoodEaten.java b/src/main/java/squeek/spiceoflife/gui/widget/WidgetFoodEaten.java index 1572c90..fb50cf3 100644 --- a/src/main/java/squeek/spiceoflife/gui/widget/WidgetFoodEaten.java +++ b/src/main/java/squeek/spiceoflife/gui/widget/WidgetFoodEaten.java @@ -56,7 +56,7 @@ public int hungerBarsNeeded() { if (defaultFoodValues == null) return 0; return (int) Math - .max(1, Math.ceil(Math.abs(Math.max(foodEaten.foodValues.hunger, defaultFoodValues.hunger)) / 2f)); + .max(1, Math.ceil(Math.abs(Math.max(foodEaten.foodValues.hunger, defaultFoodValues.hunger)) / 2f)); } public void draw(int x, int y) { @@ -72,15 +72,16 @@ public void draw(int x, int y) { if (defaultFoodValues == null) return; mc.fontRenderer.drawString( - getDisplayName(), - x, - y, - ColorHelper.getRelativeColorInt(foodEaten.foodValues.hunger, 0, defaultFoodValues.hunger)); + getDisplayName(), + x, + y, + ColorHelper.getRelativeColorInt(foodEaten.foodValues.hunger, 0, defaultFoodValues.hunger)); int barsNeeded = hungerBarsNeeded(); GL11.glColor4f(1, 1, 1, 1); - mc.getTextureManager().bindTexture(Gui.icons); + mc.getTextureManager() + .bindTexture(Gui.icons); y += mc.fontRenderer.FONT_HEIGHT; for (int i = 0; i < barsNeeded * 2; i += 2) { this.drawTexturedModalRect(x, y, 16, 27, 9, 9); diff --git a/src/main/java/squeek/spiceoflife/helpers/ColorHelper.java b/src/main/java/squeek/spiceoflife/helpers/ColorHelper.java index 0b888bc..ceb00d5 100644 --- a/src/main/java/squeek/spiceoflife/helpers/ColorHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/ColorHelper.java @@ -5,11 +5,11 @@ public class ColorHelper { private static final EnumChatFormatting[] colorRange = { EnumChatFormatting.DARK_RED, EnumChatFormatting.RED, - EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN, - EnumChatFormatting.AQUA }; + EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN, + EnumChatFormatting.AQUA }; private static final EnumChatFormatting[] booleanColorRange = { EnumChatFormatting.DARK_RED, EnumChatFormatting.RED, - EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN }; + EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN }; public static String getRelativeColor(double val, double min, double max) { if (min == max) return EnumChatFormatting.RESET.toString(); @@ -34,7 +34,7 @@ public static int getRelativeColorInt(double val, double min, double max) { int[] minColor = new int[] { 150, 0, 0 }; int[] maxColor = new int[] { 0, 100, 0 }; int[] color = new int[] { (int) (maxColor[0] * f2 + minColor[0] * f1), - (int) (maxColor[1] * f2 + minColor[1] * f1), (int) (maxColor[2] * f2 + minColor[2] * f1) }; + (int) (maxColor[1] * f2 + minColor[1] * f1), (int) (maxColor[2] * f2 + minColor[2] * f1) }; return fromRGBA(color[0], color[1], color[2], 255); } diff --git a/src/main/java/squeek/spiceoflife/helpers/GuiHelper.java b/src/main/java/squeek/spiceoflife/helpers/GuiHelper.java index 6c1b921..b9fc9dd 100644 --- a/src/main/java/squeek/spiceoflife/helpers/GuiHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/GuiHelper.java @@ -28,12 +28,12 @@ public static boolean openGuiOfItemStack(EntityPlayer player, ItemStack itemStac if (!player.worldObj.isRemote) { if (itemStack.getItem() instanceof ItemFoodContainer) { player.openGui( - ModSpiceOfLife.instance, - GuiIds.FOOD_CONTAINER.ordinal(), - player.worldObj, - (int) player.posX, - (int) player.posY, - (int) player.posZ); + ModSpiceOfLife.instance, + GuiIds.FOOD_CONTAINER.ordinal(), + player.worldObj, + (int) player.posX, + (int) player.posY, + (int) player.posZ); return true; } return false; @@ -64,14 +64,14 @@ public Object getClientGuiElement(int guiId, EntityPlayer player, World world, i } public Object getSidedGuiElement(boolean isClientSide, int guiId, EntityPlayer player, World world, int x, int y, - int z) { + int z) { if (GuiIds.values()[guiId] == GuiIds.FOOD_CONTAINER) { ItemStack heldItem = player.getHeldItem(); if (heldItem != null && heldItem.getItem() instanceof ItemFoodContainer) { FoodContainerInventory foodContainerInventory = ((ItemFoodContainer) heldItem.getItem()) - .getInventory(heldItem); + .getInventory(heldItem); return isClientSide ? new GuiFoodContainer(player.inventory, foodContainerInventory) - : new ContainerFoodContainer(player.inventory, foodContainerInventory); + : new ContainerFoodContainer(player.inventory, foodContainerInventory); } } return null; diff --git a/src/main/java/squeek/spiceoflife/helpers/InventoryHelper.java b/src/main/java/squeek/spiceoflife/helpers/InventoryHelper.java index 6c2ea45..e2678d7 100644 --- a/src/main/java/squeek/spiceoflife/helpers/InventoryHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/InventoryHelper.java @@ -16,13 +16,13 @@ public class InventoryHelper { public static final Method hopperInsertIntoInventory = ReflectionHelper.findMethod( - TileEntityHopper.class, - null, - new String[] { "func_145899_c", "c" }, - IInventory.class, - ItemStack.class, - int.class, - int.class); + TileEntityHopper.class, + null, + new String[] { "func_145899_c", "c" }, + IInventory.class, + ItemStack.class, + int.class, + int.class); public static IInventory getInventoryAtLocation(World world, int x, int y, int z) { return TileEntityHopper.func_145893_b(world, x, y, z); @@ -33,7 +33,7 @@ public static ItemStack insertStackIntoInventory(ItemStack itemStack, IInventory } public static ItemStack insertStackIntoInventory(ItemStack itemStack, IInventory inventory, - ForgeDirection direction) { + ForgeDirection direction) { return TileEntityHopper.func_145889_a(inventory, itemStack, direction.ordinal()); } @@ -47,13 +47,13 @@ public static ItemStack insertStackIntoInventoryOnce(ItemStack itemStack, IInven * @return The remainder */ public static ItemStack insertStackIntoInventoryOnce(ItemStack itemStack, IInventory inventory, - ForgeDirection direction) { + ForgeDirection direction) { int originalStackSize = itemStack.stackSize; for (int l = 0; l < inventory.getSizeInventory(); ++l) { try { itemStack = (ItemStack) hopperInsertIntoInventory - .invoke(null, inventory, itemStack, l, direction.ordinal()); + .invoke(null, inventory, itemStack, l, direction.ordinal()); } catch (RuntimeException e) { throw e; } catch (Exception e) { diff --git a/src/main/java/squeek/spiceoflife/helpers/MealPrioritizationHelper.java b/src/main/java/squeek/spiceoflife/helpers/MealPrioritizationHelper.java index ad33b7d..628f010 100644 --- a/src/main/java/squeek/spiceoflife/helpers/MealPrioritizationHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/MealPrioritizationHelper.java @@ -16,16 +16,17 @@ public class MealPrioritizationHelper { public static final Comparator hungerComparator = (a, - b) -> integerCompare(a.modifiedFoodValues.hunger, b.modifiedFoodValues.hunger); + b) -> integerCompare(a.modifiedFoodValues.hunger, b.modifiedFoodValues.hunger); public static final Comparator diminishedComparator = (a, b) -> Float - .compare(b.diminishingReturnsModifier, a.diminishingReturnsModifier); + .compare(b.diminishingReturnsModifier, a.diminishingReturnsModifier); public static int findBestFoodForPlayerToEat(EntityPlayer player, IInventory inventory) { List allFoodInfo = getFoodInfoFromInventoryForPlayer(player, inventory); InventoryFoodInfo bestFoodInfo = null; if (allFoodInfo.size() > 0) { - int hungerMissingFromPlayer = 20 - player.getFoodStats().getFoodLevel(); + int hungerMissingFromPlayer = 20 - player.getFoodStats() + .getFoodLevel(); allFoodInfo.sort(new FoodInfoComparator(hungerMissingFromPlayer)); bestFoodInfo = allFoodInfo.get(0); } @@ -46,14 +47,14 @@ public static List getFoodInfoFromInventoryForPlayer(EntityPl } public static List findBestFoodsForPlayerAccountingForVariety(EntityPlayer player, - IInventory inventory, int limit) { + IInventory inventory, int limit) { List bestFoods = findBestFoodsForPlayerAccountingForVariety(player, inventory); if (bestFoods.size() > limit) bestFoods = bestFoods.subList(0, limit); return bestFoods; } public static List findBestFoodsForPlayerAccountingForVariety(EntityPlayer player, - IInventory inventory) { + IInventory inventory) { List allFoodInfo = getFoodInfoFromInventoryForPlayer(player, inventory); Collections.shuffle(allFoodInfo); allFoodInfo.sort(diminishedComparator); @@ -100,7 +101,7 @@ public InventoryFoodInfo(int slotNum, ItemStack itemStack, EntityPlayer player) if (FoodHelper.canFoodDiminish(this.itemStack)) { this.diminishingReturnsModifier = FoodModifier.getFoodModifier(player, itemStack); this.modifiedFoodValues = FoodModifier - .getModifiedFoodValues(defaultFoodValues, diminishingReturnsModifier); + .getModifiedFoodValues(defaultFoodValues, diminishingReturnsModifier); } else { this.diminishingReturnsModifier = Float.NaN; this.modifiedFoodValues = defaultFoodValues; @@ -138,8 +139,8 @@ public int compare(InventoryFoodInfo a, InventoryFoodInfo b) { } // better food over worse food if (compareResult == 0) compareResult = Float.compare( - b.modifiedFoodValues.saturationModifier * b.modifiedFoodValues.hunger, - a.modifiedFoodValues.saturationModifier * a.modifiedFoodValues.hunger); + b.modifiedFoodValues.saturationModifier * b.modifiedFoodValues.hunger, + a.modifiedFoodValues.saturationModifier * a.modifiedFoodValues.hunger); return compareResult; } diff --git a/src/main/java/squeek/spiceoflife/helpers/MiscHelper.java b/src/main/java/squeek/spiceoflife/helpers/MiscHelper.java index 3ff8226..8727495 100644 --- a/src/main/java/squeek/spiceoflife/helpers/MiscHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/MiscHelper.java @@ -28,7 +28,8 @@ else if (mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.B int y = mc.objectMouseOver.blockY; int z = mc.objectMouseOver.blockZ; - return mc.theWorld.getBlock(x, y, z).getMaterial() == Material.air; + return mc.theWorld.getBlock(x, y, z) + .getMaterial() == Material.air; } return false; } diff --git a/src/main/java/squeek/spiceoflife/helpers/StringHelper.java b/src/main/java/squeek/spiceoflife/helpers/StringHelper.java index 12c647d..ea7f5b5 100644 --- a/src/main/java/squeek/spiceoflife/helpers/StringHelper.java +++ b/src/main/java/squeek/spiceoflife/helpers/StringHelper.java @@ -14,8 +14,8 @@ public class StringHelper { public static String getQuantityDescriptor(int quantity) { return quantity == 1 ? StatCollector.translateToLocal("spiceoflife.quantity.one.time") - : (quantity == 2 ? StatCollector.translateToLocalFormatted("spiceoflife.quantity.two.times", quantity) - : StatCollector.translateToLocalFormatted("spiceoflife.quantity.x.times", quantity)); + : (quantity == 2 ? StatCollector.translateToLocalFormatted("spiceoflife.quantity.two.times", quantity) + : StatCollector.translateToLocalFormatted("spiceoflife.quantity.x.times", quantity)); } public static String join(Collection values, String delimiter) { @@ -34,11 +34,14 @@ public static String join(Collection values, String delimiter) { public static String decapitalize(final String string, final Locale locale) { if (string == null || string.isEmpty()) return string; - else return string.substring(0, 1).toLowerCase(locale) + string.substring(1); + else return string.substring(0, 1) + .toLowerCase(locale) + string.substring(1); } public static Locale getMinecraftLocale() { - String[] parts = FMLCommonHandler.instance().getCurrentLanguage().split("_"); + String[] parts = FMLCommonHandler.instance() + .getCurrentLanguage() + .split("_"); String langCode = parts[0]; String regionCode = parts.length > 1 ? parts[1] : null; return regionCode != null ? new Locale(langCode, regionCode) : new Locale(langCode); diff --git a/src/main/java/squeek/spiceoflife/inventory/ContainerFoodContainer.java b/src/main/java/squeek/spiceoflife/inventory/ContainerFoodContainer.java index e115286..dec6e35 100644 --- a/src/main/java/squeek/spiceoflife/inventory/ContainerFoodContainer.java +++ b/src/main/java/squeek/spiceoflife/inventory/ContainerFoodContainer.java @@ -23,7 +23,7 @@ public ContainerFoodContainer(InventoryPlayer playerInventory, FoodContainerInve this.heldSlotId = playerInventory.currentItem; slotsX = (int) (GuiHelper.STANDARD_GUI_WIDTH / 2f - - (inventory.getSizeInventory() * GuiHelper.STANDARD_SLOT_WIDTH / 2f)); + - (inventory.getSizeInventory() * GuiHelper.STANDARD_SLOT_WIDTH / 2f)); slotsY = 19; this.addSlotsOfType(SlotFiltered.class, inventory, slotsX, slotsY); @@ -69,7 +69,8 @@ public ItemStack getItemStack() { public boolean isFoodContainerWithUUID(ItemStack itemStack, UUID uuid) { return itemStack != null && itemStack.getItem() instanceof ItemFoodContainer - && ((ItemFoodContainer) itemStack.getItem()).getUUID(itemStack).equals(uuid); + && ((ItemFoodContainer) itemStack.getItem()).getUUID(itemStack) + .equals(uuid); } @Override @@ -85,9 +86,9 @@ public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPla if (isFoodContainerWithUUID(pickedUpStack, getUUID())) { setFoodContainerItemStack(pickedUpStack); } else if (slotNum >= 0 && isFoodContainerWithUUID(putDownStack, getUUID()) - && isFoodContainerWithUUID(getSlot(slotNum).getStack(), getUUID())) { - setFoodContainerItemStack(getSlot(slotNum).getStack()); - } + && isFoodContainerWithUUID(getSlot(slotNum).getStack(), getUUID())) { + setFoodContainerItemStack(getSlot(slotNum).getStack()); + } return pickedUpStack; } diff --git a/src/main/java/squeek/spiceoflife/inventory/ContainerGeneric.java b/src/main/java/squeek/spiceoflife/inventory/ContainerGeneric.java index a37813b..be4310b 100644 --- a/src/main/java/squeek/spiceoflife/inventory/ContainerGeneric.java +++ b/src/main/java/squeek/spiceoflife/inventory/ContainerGeneric.java @@ -26,7 +26,7 @@ protected void addSlotOfType(Class slotClass, IInventory invento } protected void addSlotsOfType(Class slotClass, IInventory inventory, int xStart, int yStart, - int numSlots, int rows) { + int numSlots, int rows) { int numSlotsPerRow = numSlots / rows; for (int i = 0, col = 0, row = 0; i < numSlots; ++i, ++col) { if (col >= numSlotsPerRow) { @@ -36,8 +36,8 @@ protected void addSlotsOfType(Class slotClass, IInventory invent try { this.addSlotToContainer( - slotClass.getConstructor(IInventory.class, int.class, int.class, int.class) - .newInstance(inventory, getNextSlotIndex(), xStart + col * 18, yStart + row * 18)); + slotClass.getConstructor(IInventory.class, int.class, int.class, int.class) + .newInstance(inventory, getNextSlotIndex(), xStart + col * 18, yStart + row * 18)); } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -56,7 +56,7 @@ protected void addSlots(IInventory inventory, int xStart, int yStart) { } protected void addSlotsOfType(Class slotClass, IInventory inventory, int xStart, int yStart, - int rows) { + int rows) { addSlotsOfType(slotClass, inventory, xStart, yStart, inventory.getSizeInventory(), rows); } @@ -81,7 +81,7 @@ protected void addPlayerInventorySlots(InventoryPlayer playerInventory, int xSta for (int row = 0; row < 3; ++row) { for (int col = 0; col < 9; ++col) { this.addSlotToContainer( - new Slot(playerInventory, col + row * 9 + 9, xStart + col * 18, yStart + row * 18)); + new Slot(playerInventory, col + row * 9 + 9, xStart + col * 18, yStart + row * 18)); } } @@ -101,10 +101,10 @@ public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) { // transferring from the container to the player inventory if (slotNum < this.inventory.getSizeInventory()) { if (!this.mergeItemStack( - stackToTransfer, - this.inventory.getSizeInventory(), - this.inventorySlots.size(), - true)) { + stackToTransfer, + this.inventory.getSizeInventory(), + this.inventorySlots.size(), + true)) { return null; } } @@ -167,14 +167,14 @@ protected boolean mergeItemStack(ItemStack itemStack, int startSlotNum, int endS if (itemStack.isStackable()) { while (itemStack.stackSize > 0 - && (!checkBackwards && k < endSlotNum || checkBackwards && k >= startSlotNum)) { + && (!checkBackwards && k < endSlotNum || checkBackwards && k >= startSlotNum)) { slot = (Slot) this.inventorySlots.get(k); itemstack1 = slot.getStack(); if (itemstack1 != null && itemstack1.getItem() == itemStack.getItem() - && (!itemStack.getHasSubtypes() || itemStack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(itemStack, itemstack1) - && slot.isItemValid(itemStack)) { + && (!itemStack.getHasSubtypes() || itemStack.getItemDamage() == itemstack1.getItemDamage()) + && ItemStack.areItemStackTagsEqual(itemStack, itemstack1) + && slot.isItemValid(itemStack)) { int l = itemstack1.stackSize + itemStack.stackSize; int effectiveMaxStackSize = getEffectiveMaxStackSizeForSlot(k, itemStack); diff --git a/src/main/java/squeek/spiceoflife/inventory/FoodContainerInventory.java b/src/main/java/squeek/spiceoflife/inventory/FoodContainerInventory.java index c775ef5..cbc6191 100644 --- a/src/main/java/squeek/spiceoflife/inventory/FoodContainerInventory.java +++ b/src/main/java/squeek/spiceoflife/inventory/FoodContainerInventory.java @@ -26,7 +26,8 @@ public FoodContainerInventory(ItemFoodContainer itemFoodContainer, ItemStack ite public void onInventoryChanged() { // the itemstack on the client can change, so make sure we always get the // new itemstack when making changes to the nbt tag - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + if (FMLCommonHandler.instance() + .getEffectiveSide() == Side.CLIENT) { findMatchingClientItemStack(); } @@ -37,11 +38,12 @@ public void onInventoryChanged() { @SideOnly(Side.CLIENT) public void findMatchingClientItemStack() { - EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer; + EntityPlayer player = FMLClientHandler.instance() + .getClient().thePlayer; if (player.openContainer != null && player.openContainer instanceof ContainerFoodContainer) { ContainerFoodContainer openFoodContainer = (ContainerFoodContainer) player.openContainer; ItemStack matchingFoodContainer = openFoodContainer - .findFoodContainerWithUUID(itemFoodContainer.getUUID(itemStackFoodContainer)); + .findFoodContainerWithUUID(itemFoodContainer.getUUID(itemStackFoodContainer)); if (matchingFoodContainer != null) itemStackFoodContainer = matchingFoodContainer; } } diff --git a/src/main/java/squeek/spiceoflife/inventory/NBTInventory.java b/src/main/java/squeek/spiceoflife/inventory/NBTInventory.java index 32d72d5..f84171a 100644 --- a/src/main/java/squeek/spiceoflife/inventory/NBTInventory.java +++ b/src/main/java/squeek/spiceoflife/inventory/NBTInventory.java @@ -46,8 +46,7 @@ public boolean isInventoryEmpty() { public boolean isInventoryFull() { for (ItemStack itemStack : inventoryItems) { if (itemStack == null - || itemStack.stackSize < Math.min(getInventoryStackLimit(), itemStack.getMaxStackSize())) - return false; + || itemStack.stackSize < Math.min(getInventoryStackLimit(), itemStack.getMaxStackSize())) return false; } return true; } diff --git a/src/main/java/squeek/spiceoflife/items/ItemFoodContainer.java b/src/main/java/squeek/spiceoflife/items/ItemFoodContainer.java index 335cd93..41d281b 100644 --- a/src/main/java/squeek/spiceoflife/items/ItemFoodContainer.java +++ b/src/main/java/squeek/spiceoflife/items/ItemFoodContainer.java @@ -81,7 +81,8 @@ public FoodContainerInventory getInventory(ItemStack itemStack) { // necessary to catch tossing items while still in an inventory @SubscribeEvent public void onItemToss(ItemTossEvent event) { - if (event.entityItem.getEntityItem().getItem() instanceof ItemFoodContainer) { + if (event.entityItem.getEntityItem() + .getItem() instanceof ItemFoodContainer) { onDroppedByPlayer(event.entityItem.getEntityItem(), event.player); } } @@ -100,7 +101,10 @@ public NBTTagCompound getOrInitBaseTag(ItemStack itemStack) { NBTTagCompound baseTag = itemStack.getTagCompound(); - if (!baseTag.hasKey(TAG_KEY_UUID)) baseTag.setString(TAG_KEY_UUID, UUID.randomUUID().toString()); + if (!baseTag.hasKey(TAG_KEY_UUID)) baseTag.setString( + TAG_KEY_UUID, + UUID.randomUUID() + .toString()); return baseTag; } @@ -138,7 +142,8 @@ public void setIsOpen(ItemStack itemStack, boolean isOpen) { */ @Override public FoodValues getFoodValues(ItemStack itemStack) { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + if (FMLCommonHandler.instance() + .getEffectiveSide() == Side.CLIENT) { // the client uses the food values for tooltips/etc, so it should // inherit them from the food that will be eaten return FoodValues.get(getBestFoodForPlayerToEat(itemStack, NetworkHelper.getClientPlayer())); @@ -179,7 +184,7 @@ public void tryDumpFoodInto(ItemStack itemStack, IInventory inventory, EntityPla public void tryPullFoodFrom(ItemStack itemStack, IInventory inventory, EntityPlayer player) { List foodsToPull = MealPrioritizationHelper - .findBestFoodsForPlayerAccountingForVariety(player, inventory); + .findBestFoodsForPlayerAccountingForVariety(player, inventory); if (foodsToPull.size() > 0) { FoodContainerInventory foodContainerInventory = getInventory(itemStack); for (InventoryFoodInfo foodToPull : foodsToPull) { @@ -202,22 +207,25 @@ public boolean canBeEatenFrom(ItemStack stack) { } public boolean isOpen(ItemStack itemStack) { - return itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean(TAG_KEY_OPEN); + return itemStack.hasTagCompound() && itemStack.getTagCompound() + .getBoolean(TAG_KEY_OPEN); } @Override public boolean onDroppedByPlayer(ItemStack itemStack, EntityPlayer player) { if (!player.worldObj.isRemote && player.openContainer != null - && player.openContainer instanceof ContainerFoodContainer) { + && player.openContainer instanceof ContainerFoodContainer) { ContainerFoodContainer openFoodContainer = (ContainerFoodContainer) player.openContainer; UUID droppedUUID = getUUID(itemStack); - if (openFoodContainer.getUUID().equals(droppedUUID)) { + if (openFoodContainer.getUUID() + .equals(droppedUUID)) { // if the cursor item is the open food container, then it will create an infinite loop // due to the container dropping the cursor item when it is closed ItemStack itemOnTheCursor = player.inventory.getItemStack(); if (itemOnTheCursor != null && itemOnTheCursor.getItem() instanceof ItemFoodContainer) { - if (((ItemFoodContainer) itemOnTheCursor.getItem()).getUUID(itemOnTheCursor).equals(droppedUUID)) { + if (((ItemFoodContainer) itemOnTheCursor.getItem()).getUUID(itemOnTheCursor) + .equals(droppedUUID)) { player.inventory.setItemStack(null); } } @@ -248,12 +256,11 @@ public void addInformation(ItemStack itemStack, EntityPlayer player, List toolTi String openCloseLineColor = EnumChatFormatting.GRAY.toString(); if (isOpen(itemStack)) { toolTip.add( - openCloseLineColor - + StatCollector.translateToLocalFormatted("spiceoflife.tooltip.to.close.food.container")); + openCloseLineColor + + StatCollector.translateToLocalFormatted("spiceoflife.tooltip.to.close.food.container")); } else toolTip.add( - openCloseLineColor - + StatCollector.translateToLocalFormatted("spiceoflife.tooltip.to.open.food.container")); + openCloseLineColor + StatCollector.translateToLocalFormatted("spiceoflife.tooltip.to.open.food.container")); } @Override @@ -271,7 +278,7 @@ public IIcon getIcon(ItemStack itemStack, int renderPass) { @Override public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, - float hitX, float hitY, float hitZ) { + float hitX, float hitY, float hitZ) { if (!world.isRemote && isOpen(itemStack)) { IInventory inventoryHit = InventoryHelper.getInventoryAtLocation(world, x, y, z); if (inventoryHit != null && inventoryHit.isUseableByPlayer(player)) { @@ -306,7 +313,7 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer @Override public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) { if (entityLiving.worldObj.isRemote && ModConfig.LEFT_CLICK_OPENS_FOOD_CONTAINERS - && MiscHelper.isMouseOverNothing()) { + && MiscHelper.isMouseOverNothing()) { PacketHandler.channel.sendToServer(new PacketToggleFoodContainer()); return true; } diff --git a/src/main/java/squeek/spiceoflife/items/ItemFoodJournal.java b/src/main/java/squeek/spiceoflife/items/ItemFoodJournal.java index 3c23650..974b971 100644 --- a/src/main/java/squeek/spiceoflife/items/ItemFoodJournal.java +++ b/src/main/java/squeek/spiceoflife/items/ItemFoodJournal.java @@ -33,11 +33,11 @@ public static void giveToPlayer(EntityPlayer player) { // try add, otherwise spawn in the world if (!player.inventory.addItemStackToInventory(itemStack)) { EntityItem entityItem = new EntityItem( - player.worldObj, - player.posX + 0.5f, - player.posY + 0.5f, - player.posZ + 0.5f, - itemStack); + player.worldObj, + player.posX + 0.5f, + player.posY + 0.5f, + player.posZ + 0.5f, + itemStack); player.worldObj.spawnEntityInWorld(entityItem); } } @@ -46,7 +46,8 @@ public static void giveToPlayer(EntityPlayer player) { @SideOnly(Side.CLIENT) @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { - if (world.isRemote) Minecraft.getMinecraft().displayGuiScreen(new GuiScreenFoodJournal()); + if (world.isRemote) Minecraft.getMinecraft() + .displayGuiScreen(new GuiScreenFoodJournal()); return super.onItemRightClick(itemStack, world, player); } } diff --git a/src/main/java/squeek/spiceoflife/network/NetworkHelper.java b/src/main/java/squeek/spiceoflife/network/NetworkHelper.java index 331129c..fa04452 100644 --- a/src/main/java/squeek/spiceoflife/network/NetworkHelper.java +++ b/src/main/java/squeek/spiceoflife/network/NetworkHelper.java @@ -15,6 +15,7 @@ public static EntityPlayer getSidedPlayer(MessageContext ctx) { @SideOnly(Side.CLIENT) public static EntityPlayer getClientPlayer() { - return FMLClientHandler.instance().getClientPlayerEntity(); + return FMLClientHandler.instance() + .getClientPlayerEntity(); } } diff --git a/src/main/java/squeek/spiceoflife/network/PacketFoodGroup.java b/src/main/java/squeek/spiceoflife/network/PacketFoodGroup.java index 50d2023..67252a3 100644 --- a/src/main/java/squeek/spiceoflife/network/PacketFoodGroup.java +++ b/src/main/java/squeek/spiceoflife/network/PacketFoodGroup.java @@ -41,10 +41,10 @@ public void unpack(IByteIO data) { @Override public PacketBase processAndReply(Side side, EntityPlayer player) { if (++foodGroupsRecieved > totalFoodGroups) throw new RuntimeException( - "Recieved more food groups than should exist (recieved: " + foodGroupsRecieved - + ", total: " - + totalFoodGroups - + ")"); + "Recieved more food groups than should exist (recieved: " + foodGroupsRecieved + + ", total: " + + totalFoodGroups + + ")"); FoodGroupRegistry.addFoodGroup(foodGroup); diff --git a/src/main/java/squeek/spiceoflife/network/PacketFoodHistory.java b/src/main/java/squeek/spiceoflife/network/PacketFoodHistory.java index 6874b9c..8571e54 100644 --- a/src/main/java/squeek/spiceoflife/network/PacketFoodHistory.java +++ b/src/main/java/squeek/spiceoflife/network/PacketFoodHistory.java @@ -48,14 +48,17 @@ public PacketBase processAndReply(Side side, EntityPlayer player) { FoodHistory foodHistory = FoodHistory.get(player); if (shouldOverwrite) { - foodHistory.getRecentHistory().clear(); + foodHistory.getRecentHistory() + .clear(); foodHistory.ticksActive = this.foodHistory.ticksActive; } else { foodHistory.totalFoodsEatenAllTime++; } - this.foodHistory.getRecentHistory().forEach(foodHistory::addFoodRecent); - this.foodHistory.getFullHistory().forEach(foodHistory::addFoodFullHistory); + this.foodHistory.getRecentHistory() + .forEach(foodHistory::addFoodRecent); + this.foodHistory.getFullHistory() + .forEach(foodHistory::addFoodFullHistory); return null; } diff --git a/src/main/java/squeek/spiceoflife/network/simpleimpl/BetterSimpleChannelHandlerWrapper.java b/src/main/java/squeek/spiceoflife/network/simpleimpl/BetterSimpleChannelHandlerWrapper.java index a1320e9..3fd8dea 100644 --- a/src/main/java/squeek/spiceoflife/network/simpleimpl/BetterSimpleChannelHandlerWrapper.java +++ b/src/main/java/squeek/spiceoflife/network/simpleimpl/BetterSimpleChannelHandlerWrapper.java @@ -24,7 +24,7 @@ * multiple message types See FML's SimpleChannelHandlerWrapper for general documentation */ public class BetterSimpleChannelHandlerWrapper - extends SimpleChannelInboundHandler { + extends SimpleChannelInboundHandler { protected static Constructor messageContextConstructor = null; @@ -43,7 +43,7 @@ public class BetterSimpleChannelHandlerWrapper> handler, Side side, - Class messageType) { + Class messageType) { super(messageType); try { messageHandler = handler.newInstance(); @@ -55,12 +55,17 @@ public BetterSimpleChannelHandlerWrapper(Class void registerMessage( - Class> messageHandler, Class messageType, - int discriminator, Side side) { + Class> messageHandler, Class messageType, + int discriminator, Side side) { packetCodec.addDiscriminator(discriminator, messageType); FMLEmbeddedChannel channel = channels.get(side); String type = channel.findChannelHandlerNameForType(SimpleIndexedCodec.class); @@ -54,29 +54,29 @@ public void registerMessage( } private void addServerHandlerAfter( - FMLEmbeddedChannel channel, String type, Class> messageHandler, - Class messageType) { + FMLEmbeddedChannel channel, String type, Class> messageHandler, + Class messageType) { BetterSimpleChannelHandlerWrapper handler = getHandlerWrapper( - messageHandler, - Side.SERVER, - messageType); + messageHandler, + Side.SERVER, + messageType); channel.pipeline() - .addAfter(type, messageHandler.getName() + messageType.getName() + Side.SERVER.name(), handler); + .addAfter(type, messageHandler.getName() + messageType.getName() + Side.SERVER.name(), handler); } private void addClientHandlerAfter( - FMLEmbeddedChannel channel, String type, Class> messageHandler, - Class messageType) { + FMLEmbeddedChannel channel, String type, Class> messageHandler, + Class messageType) { BetterSimpleChannelHandlerWrapper handler = getHandlerWrapper( - messageHandler, - Side.CLIENT, - messageType); + messageHandler, + Side.CLIENT, + messageType); channel.pipeline() - .addAfter(type, messageHandler.getName() + messageType.getName() + Side.CLIENT.name(), handler); + .addAfter(type, messageHandler.getName() + messageType.getName() + Side.CLIENT.name(), handler); } private BetterSimpleChannelHandlerWrapper getHandlerWrapper( - Class> messageHandler, Side side, Class messageType) { + Class> messageHandler, Side side, Class messageType) { return new BetterSimpleChannelHandlerWrapper<>(messageHandler, side, messageType); } @@ -87,7 +87,8 @@ private BetterSimpleChannelHandle * @return A minecraft {@link Packet} suitable for use in minecraft APIs */ public Packet getPacketFrom(IMessage message) { - return channels.get(Side.SERVER).generatePacketFrom(message); + return channels.get(Side.SERVER) + .generatePacketFrom(message); } /** @@ -96,8 +97,12 @@ public Packet getPacketFrom(IMessage message) { * @param message The message to send */ public void sendToAll(IMessage message) { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); - channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.ALL); + channels.get(Side.SERVER) + .writeAndFlush(message) + .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } /** @@ -108,10 +113,15 @@ public void sendToAll(IMessage message) { * @param player The player to send it to */ public void sendTo(IMessage message, EntityPlayerMP player) { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.PLAYER); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); - channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.PLAYER); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) + .set(player); + channels.get(Side.SERVER) + .writeAndFlush(message) + .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } /** @@ -122,10 +132,15 @@ public void sendTo(IMessage message, EntityPlayerMP player) { * @param point The {@link TargetPoint} around which to send */ public void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); - channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) + .set(point); + channels.get(Side.SERVER) + .writeAndFlush(message) + .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } /** @@ -136,10 +151,15 @@ public void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) * @param dimensionId The dimension id to target */ public void sendToDimension(IMessage message, int dimensionId) { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.DIMENSION); - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId); - channels.get(Side.SERVER).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.DIMENSION); + channels.get(Side.SERVER) + .attr(FMLOutboundHandler.FML_MESSAGETARGETARGS) + .set(dimensionId); + channels.get(Side.SERVER) + .writeAndFlush(message) + .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } /** @@ -148,8 +168,11 @@ public void sendToDimension(IMessage message, int dimensionId) { * @param message The message to send */ public void sendToServer(IMessage message) { - channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET) - .set(FMLOutboundHandler.OutboundTarget.TOSERVER); - channels.get(Side.CLIENT).writeAndFlush(message).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + channels.get(Side.CLIENT) + .attr(FMLOutboundHandler.FML_MESSAGETARGET) + .set(FMLOutboundHandler.OutboundTarget.TOSERVER); + channels.get(Side.CLIENT) + .writeAndFlush(message) + .addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } }