Guest User

Untitled

a guest
Mar 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. package se.resonantri.stargazerutil.common.items.researchitems.manuscripts;
  2.  
  3. import com.google.common.collect.BiMap;
  4. import com.google.common.collect.HashBiMap;
  5. import net.darkhax.gamestages.capabilities.PlayerDataHandler;
  6. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  7. import net.minecraft.client.resources.I18n;
  8. import net.minecraft.client.util.ITooltipFlag;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.Item;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.util.*;
  15. import net.minecraft.util.text.TextFormatting;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.client.model.ModelLoader;
  18. import org.lwjgl.input.Keyboard;
  19. import se.resonantri.stargazerutil.utils.Constants;
  20. import se.resonantri.stargazerutil.utils.CreativeTab;
  21.  
  22. import javax.annotation.Nullable;
  23. import java.util.List;
  24.  
  25. public class ItemManuscriptAtlas extends Item {
  26.  
  27. public static BiMap<String, String> biMapster = HashBiMap.create();
  28.  
  29. public ItemManuscriptAtlas() {
  30. setMaxStackSize(1);
  31. setCreativeTab(CreativeTab.stargazerUtils);
  32. setUnlocalizedName(Constants.MODID + ".itematlas");
  33. setRegistryName(new ResourceLocation(Constants.MODID, "itematlas"));
  34. }
  35.  
  36. public void initModel() {
  37. ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  38. }
  39.  
  40. public static void setBiMapsterValues(){
  41. biMapster.put("Nether Atlas", "Nether");
  42. biMapster.put("End Atlas", "End");
  43. biMapster.put("Aether Atlas", "Aether");
  44. biMapster.put("Betweenlands Atlas", "Betweenlands");
  45. biMapster.put("Twilight Forest Atlas", "TwilightForest");
  46. biMapster.put("Hunting Dimension Atlas", "Hunting_Dim");
  47. }
  48.  
  49. @Override
  50. public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
  51. if (this.isInCreativeTab(tab)) {
  52. int value = biMapster.size();
  53. for (int i = 0; i < value; i++){
  54. ItemStack stack = new ItemStack(this);
  55. NBTTagCompound nbt = new NBTTagCompound();
  56. nbt.setString("Manuscript", biMapster.entrySet().iterator().toString());
  57. stack.setTagCompound(nbt);
  58. items.add(stack);
  59. }
  60. }
  61. }
  62.  
  63. @Override
  64. public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
  65. ItemStack stack = playerIn.getHeldItem(handIn);
  66. NBTTagCompound nbt = stack.getTagCompound();
  67. if (stack.hasTagCompound()){
  68. if (biMapster.get(nbt.getString("Manuscript")) != null){
  69. PlayerDataHandler.getStageData(playerIn).unlockStage(biMapster.get(nbt.getString("Manuscript")));
  70. return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
  71. }
  72. }
  73. return ActionResult.newResult(EnumActionResult.PASS, stack);
  74. }
  75.  
  76. @Override
  77. public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
  78. NBTTagCompound nbt = stack.getTagCompound();
  79.  
  80. if (!stack.hasTagCompound()) {
  81. stack.setTagCompound(new NBTTagCompound());
  82. }
  83.  
  84. if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
  85. if (nbt.hasKey("Manuscript")) {
  86. tooltip.add(TextFormatting.GRAY + "Manuscript: " + TextFormatting.LIGHT_PURPLE + I18n.format(nbt.getString("Manuscript")));
  87. } else if (!nbt.hasKey("Manuscript")) {
  88. tooltip.add(TextFormatting.GRAY + "Manuscript: " + TextFormatting.DARK_PURPLE + "NULL");
  89. }
  90. } else if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
  91. tooltip.add(TextFormatting.GRAY + "Press Shift for Manuscript Information");
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment