Skip to content

Commit

Permalink
Merge pull request #5 from GTNewHorizons/new_features
Browse files Browse the repository at this point in the history
Save string ids instead of int ids.
  • Loading branch information
mitchej123 authored Jan 5, 2020
2 parents f40272f + 935a82d commit 7e4eec1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mc_version=1.7.10
forge_version=10.13.4.1614-1.7.10
ccl_version=1.1.3.138
ccc_version=1.0.7.+
mod_version=2.0.0-pre-10-GTNH
mod_version=2.0.0-pre-11-GTNH
31 changes: 29 additions & 2 deletions src/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package codechicken.nei;

import cpw.mods.fml.common.registry.GameData;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
Expand Down Expand Up @@ -36,10 +38,35 @@ public void addOrRemoveItem(ItemStack item) {
saveBookmarks();
}

public static NBTTagCompound itemStackToNBT(ItemStack stack, NBTTagCompound nbTag)
{
String strId = Item.itemRegistry.getNameForObject(stack.getItem());
nbTag.setString("strId", strId);
nbTag.setByte("Count", (byte)stack.stackSize);
nbTag.setShort("Damage", (short)stack.getItemDamage());

if (stack.stackTagCompound != null)
{
nbTag.setTag("tag", stack.stackTagCompound);
}

return nbTag;
}

public static ItemStack loadFromNBT(NBTTagCompound nbtTag)
{
if (!nbtTag.hasKey("id")) {
final short id = (short)GameData.getItemRegistry().getId(nbtTag.getString("strId"));
nbtTag.setShort("id", id);
}
ItemStack stack = ItemStack.loadItemStackFromNBT(nbtTag);
return stack;
}

public void saveBookmarks() {
List<String> strings = new ArrayList<>();
for (ItemStack item:_items) {
strings.add(item.writeToNBT(new NBTTagCompound()).toString());
strings.add(itemStackToNBT(item, new NBTTagCompound()).toString());
}
File file = NEIClientConfig.bookmarkFile;
if(file != null) {
Expand Down Expand Up @@ -68,7 +95,7 @@ public void loadBookmarks() {
for (String itemStr: itemStrings) {
try {
NBTTagCompound itemStackNBT = (NBTTagCompound)JsonToNBT.func_150315_a(itemStr);
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemStackNBT);
ItemStack itemStack = loadFromNBT(itemStackNBT);
if (itemStack != null) {
_items.add(itemStack);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/codechicken/nei/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean handleClick(int mousex, int mousey, int button) {
public void onTextChange(String oldText) {
final String newText = text();
if( newText.length() > 0)
NEIClientConfig.logger.info("Searching for " + text());
NEIClientConfig.logger.debug("Searching for " + text());

NEIClientConfig.setSearchExpression(newText);
ItemList.updateFilter.restart();
Expand Down
1 change: 0 additions & 1 deletion src/codechicken/nei/SubsetWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ public static void addTag(SubsetTag tag) {
updateState.stop();
synchronized (root) {
root.addTag(tag);
NEIClientConfig.logger.info("Adding Tag {}", tag.displayName());
updateState.reallocate();
}
}
Expand Down

0 comments on commit 7e4eec1

Please sign in to comment.