Guest User

Untitled

a guest
Jul 7th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.21 KB | None | 0 0
  1. package halestormxv.eAngelus.items;
  2.  
  3. import halestormxv.eAngelus.main.Reference;
  4. import halestormxv.eAngelus.main.init.eAngelusItems;
  5. import halestormxv.eAngelus.network.packets.ChatUtil;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.item.EnumAction;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.util.ActionResult;
  13. import net.minecraft.util.EnumActionResult;
  14. import net.minecraft.util.EnumHand;
  15. import net.minecraft.util.text.TextComponentString;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.fml.relauncher.Side;
  18. import net.minecraftforge.fml.relauncher.SideOnly;
  19.  
  20. import java.util.List;
  21.  
  22. /**
  23.  * Created by Blaze on 7/6/2017.
  24.  */
  25.  
  26. public class ModItemScryingOrb extends Item
  27. {
  28.     public ModItemScryingOrb(String name)
  29.     {
  30.         super();
  31.         this.setUnlocalizedName(name);
  32.         this.setCreativeTab(Reference.eaCreativeTab);
  33.     }
  34.  
  35.     public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
  36.     {
  37.         if(!world.isRemote)
  38.         {
  39.             ItemStack stack = player.getHeldItem(hand);
  40.             NBTTagCompound nbt = stack.getTagCompound();
  41.  
  42.  
  43.             if (player.isSneaking())
  44.             {
  45.                 if (nbt == null)
  46.                 {
  47.                     nbt = new NBTTagCompound();
  48.                     player.sendMessage(new TextComponentString("The Scrying Orb has stored your location data."));
  49.                     nbt.setInteger("Dim", player.dimension);
  50.                     nbt.setDouble("PosX", player.getPosition().getX());
  51.                     nbt.setDouble("PosY", player.getPosition().getY());
  52.                     nbt.setDouble("PosZ", player.getPosition().getZ());
  53.                     stack.setTagCompound(nbt);
  54.                 }
  55.                 else
  56.                 {
  57.                     int cooldown = this.getCoolDown(stack);
  58.                     //Check for Reagent
  59.                     if (player.inventory.hasItemStack(new ItemStack(eAngelusItems.mystalDust)))
  60.                     {
  61.                         if ((stack.getTagCompound() != null) && (cooldown == 0))
  62.                         {
  63.                             if (player.isRiding())
  64.                             {
  65.                                 player.dismountRidingEntity();
  66.                             }
  67.                             double posX = nbt.getDouble("PosX");
  68.                             double posY = nbt.getDouble("PosY");
  69.                             double posZ = nbt.getDouble("PosZ");
  70.                             player.setPositionAndUpdate(posX + 0.6, posY, posZ + 0.6);
  71.                             this.startCoolDown(stack);
  72.                             this.consumeReagent(stack, world, player);
  73.                         }
  74.                         else
  75.                         {
  76.                             ChatUtil.sendNoSpam(player, "\u00A74The Scrying Orb is on cooldown.");
  77.                         }
  78.                     }
  79.                     else
  80.                     {
  81.                         ChatUtil.sendNoSpam(player,"\u00A74The Scrying Orb requires Mystal Dust for use.");
  82.                     }
  83.                 }
  84.             }
  85.             else
  86.                 player.sendMessage(new TextComponentString("You must sneak and right click to store Scrying data."));
  87.         }
  88.         return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  89.     }
  90.  
  91.     @Override
  92.     @SideOnly(Side.CLIENT)
  93.     public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
  94.     {
  95.         tooltip.add("");
  96.         tooltip.add("\u00A76" + "An orb used to store location data.");
  97.         tooltip.add("\u00A76" + "After storing, it grants the ability");
  98.         tooltip.add("\u00A76" + "to teleport to stored location.");
  99.         tooltip.add("");
  100.         if (stack.getTagCompound() != null)
  101.         {
  102.             NBTTagCompound nbt = stack.getTagCompound();
  103.             int dimID = nbt.getInteger("Dim");
  104.             double posX = nbt.getDouble("PosX");
  105.             double posY = nbt.getDouble("PosY");
  106.             double posZ = nbt.getDouble("PosZ");
  107.             tooltip.add("\u00A73" + "DIM: "+ dimID);
  108.             tooltip.add("\u00A7d" + "X: "  + posX);
  109.             tooltip.add("\u00A72" + "Y: "  + posY);
  110.             tooltip.add("\u00A7c" + "Z: "  + posZ);
  111.             tooltip.add("");
  112.             if (stack.getTagCompound().getInteger("coolDown") != 0) {
  113.                 tooltip.add("\u00A74" + "Cooldown: " + getCooldownReal(stack) + " Min.");
  114.             }
  115.             else
  116.             {
  117.                 tooltip.add("\u00A72" + "Scrying Orb is ready for use.");
  118.             }
  119.         }
  120.     }
  121.  
  122.     protected void startCoolDown(ItemStack stack)
  123.     {
  124.         if (stack.getTagCompound() != null)
  125.         {
  126.             stack.getTagCompound().setInteger("coolDown", 6000);
  127.         }
  128.     }
  129.  
  130.     @Override
  131.     public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
  132.         if (!world.isRemote)
  133.         {
  134.             int coolDown = this.getCoolDown(stack);
  135.             if (coolDown > 0) {
  136.                 stack.getTagCompound().setInteger("coolDown", coolDown - 1);
  137.             }
  138.             else if (coolDown < 0)
  139.             {
  140.                 stack.getTagCompound().setInteger("coolDown", 0);
  141.             }
  142.         }
  143.     }
  144.  
  145.     protected int getCoolDown(ItemStack stack) {
  146.         if ( (stack.getTagCompound() != null) && (stack.getTagCompound().hasKey("coolDown")) )
  147.         {
  148.             return stack.getTagCompound().getInteger("coolDown");
  149.         }
  150.         return 0;
  151.     }
  152.  
  153.     protected void consumeReagent(ItemStack stack, World worldIn, EntityPlayer entityLiving) {
  154.         entityLiving.inventory.clearMatchingItems(scryingReagent(stack), -1, 1, null);
  155.     }
  156.  
  157.     protected Item scryingReagent(ItemStack itemStackIn)
  158.     {
  159.         return eAngelusItems.mystalDust;
  160.     }
  161.  
  162.     //Cooldown Handlers\\
  163.     public static int getCooldownReal(ItemStack stack) {
  164.         int time = (int) Math.abs(stack.getTagCompound().getInteger("coolDown"));
  165.         return (int)((float)time / 1000F);
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment