Guest User

Untitled

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