Skip to content

Commit

Permalink
Use a bit less memory for dark steel upgrade recipes
Browse files Browse the repository at this point in the history
This is a safer but not as efficient version of #5060
  • Loading branch information
HenryLoenwind committed May 8, 2019
1 parent cfbdaad commit 80ca65d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -151,7 +152,11 @@ public static void addBasicTooltipEntries(@Nonnull ItemStack itemstack, EntityPl
}
}

public static boolean skipUpgradeTooltips = false;
public static void setSkipUpgradeTooltips(boolean skipUpgradeTooltips) {
DarkSteelRecipeManager.skipUpgradeTooltips = skipUpgradeTooltips;
}

private static boolean skipUpgradeTooltips = false;

public static void addAdvancedTooltipEntries(@Nonnull ItemStack itemstack, EntityPlayer entityplayer, @Nonnull List<String> list, boolean flag) {
SpecialTooltipHandler.addDetailedTooltipFromResources(list, itemstack.getUnlocalizedName());
Expand Down Expand Up @@ -179,13 +184,9 @@ public static void addAdvancedTooltipEntries(@Nonnull ItemStack itemstack, Entit
}

public static @Nonnull String getUpgradesAsString(@Nonnull ItemStack stack) {
String result = "";
for (IDarkSteelUpgrade upgrade : UpgradeRegistry.getUpgrades()) {
if (upgrade.hasUpgrade(stack)) {
result += "/" + upgrade.getUnlocalizedName();
}
}
return result.isEmpty() ? "" : NullHelper.first(result.substring(1), "");
return NullHelper.first(UpgradeRegistry.getUpgrades().stream().filter(upgrade -> upgrade.hasUpgrade(stack))
.map(upgrade -> "" + UpgradeRegistry.getId(upgrade)).collect(Collectors.joining("/")), "");
// Note: Using the numeric ID here to keep the string short and save memory
}

public static NNList<ItemStack> getRecipes(@Nonnull Set<UpgradePath> list, @Nonnull NNList<ItemStack> input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry.AddCallback;
import net.minecraftforge.registries.IForgeRegistry.ClearCallback;
Expand Down Expand Up @@ -59,4 +60,8 @@ public static void registerRegistry(@Nonnull RegistryEvent.NewRegistry event) {
return REGISTRY.getValue(id);
}

public static int getId(IDarkSteelUpgrade upgrade) {
return ((ForgeRegistry<IDarkSteelUpgrade>) REGISTRY).getID(upgrade);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void apply(@Nonnull Item item) {
ItemStack itemStack = new ItemStack(item);
NNList<String> allTooltips;
try {
DarkSteelRecipeManager.skipUpgradeTooltips = true;
DarkSteelRecipeManager.setSkipUpgradeTooltips(true);
allTooltips = SpecialTooltipHandler.getAllTooltips(itemStack);
} finally {
DarkSteelRecipeManager.skipUpgradeTooltips = false;
DarkSteelRecipeManager.setSkipUpgradeTooltips(false);
}

NNList<UpgradePath> list = DarkSteelRecipeManager.getAllRecipes(new NNList<>(itemStack));
Expand Down

0 comments on commit 80ca65d

Please sign in to comment.