Created
December 27, 2013 08:58
-
-
Save Unh0lyTigg/8144353 to your computer and use it in GitHub Desktop.
Centralized item information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import net.minecraft.client.renderer.texture.IconRegister; | |
import net.minecraft.util.Icon; | |
import com.google.common.collect.Maps; | |
public class ItemTexture { | |
public static final ItemTexture INSTANCE = new ItemTexture(); | |
private final Map<Integer, Map<Integer, String>> map; | |
private final Map<Integer, String> modids; | |
private ItemTexture() { | |
map = Maps.newHashMap(); | |
modids = Maps.newHashMap(); | |
} | |
public void set(int itemID, int meta, String modid, String texture) { | |
if (!map.containsKey(Integer.valueOf(itemID))) | |
map.put(Integer.valueOf(itemID), Maps.<Integer, String>newHashMap()); | |
map.get(Integer.valueOf(itemID)).put(Integer.valueOf(meta), texture); | |
modids.put(Integer.valueOf(itemID), modid); | |
} | |
public Icon[] registerIcons(int itemID, IconRegister register) { | |
if (!map.containsKey(Integer.valueOf(itemID))) | |
return null; | |
Icon[] icons = new Icon[map.get(Integer.valueOf(itemID)).size()]; | |
for (Integer meta : map.get(Integer.valueOf(itemID)).keySet()) { | |
String modid = modids.get(Integer.valueOf(itemID)); | |
String texture = map.get(Integer.valueOf(itemID)).get(meta); | |
icons[meta.intValue()] = register.registerIcon(modid + ":" + texture); | |
} | |
return icons; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Map; | |
import net.minecraft.item.ItemStack; | |
import com.google.common.collect.Maps; | |
public class Language { | |
private static final Language INSTANCE = new Language(); | |
private final Map<List<Integer>, String> map; | |
private final Map<String, String> defaultUnlocalized; | |
private final Map<Integer, String> reverseModIdLookup; | |
private Language() { | |
map = Maps.newHashMap(); | |
defaultUnlocalized = Maps.newHashMap(); | |
reverseModIdLookup = Maps.newHashMap(); | |
} | |
public void setDefault(String modid, String unlocalized) { | |
defaultUnlocalized.put(modid, unlocalized); | |
} | |
public void load(int itemID, int damage, String unlocalized, String modid) { | |
map.put(Arrays.asList(Integer.valueOf(itemID), Integer.valueOf(damage)), unlocalized); | |
reverseModIdLookup.put(Integer.valueOf(itemID), modid); | |
} | |
public String getUnlocalizedName(ItemStack item) { | |
List<Integer> search = Arrays.asList(Integer.valueOf(item.itemID), Integer.valueOf(item.getItemDamage())); | |
String unlocal = map.get(search); | |
if (unlocal == null) { | |
unlocal = defaultUnlocalized.get(reverseModIdLookup.get(Integer.valueOf(item.itemID))); | |
if (unlocal == null) | |
unlocal = "item.null.name"; | |
map.put(search, unlocal); | |
} | |
return unlocal; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment