Guest User

Untitled

a guest
Jul 7th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.90 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.                     nbt.setLong("totalWorldTime", player.world.getTotalWorldTime());
  54.                     stack.setTagCompound(nbt);
  55.                 }
  56.                 else
  57.                 {
  58.                     int cooldown = this.getCoolDown(stack);
  59.                     long totWorldTime = this.getStoredWorldTime(stack);
  60.                     long currentWorldTime = player.world.getWorldTime();
  61.                     //Check for Reagent
  62.                     if (player.inventory.hasItemStack(new ItemStack(eAngelusItems.mystalDust)))
  63.                     {
  64.                         System.out.println("Current World Time: " + currentWorldTime);
  65.                         System.out.println("Current Stored Time: " + totWorldTime);
  66.                         //if ((stack.getTagCompound() != null) && (cooldown == 0))
  67.                         if ((stack.getTagCompound() != null) && (currentWorldTime > totWorldTime + 200 ))
  68.                         {
  69.                             if (player.isRiding())
  70.                             {
  71.                                 player.dismountRidingEntity();
  72.                             }
  73.                             double posX = nbt.getDouble("PosX");
  74.                             double posY = nbt.getDouble("PosY");
  75.                             double posZ = nbt.getDouble("PosZ");
  76.                             player.setPositionAndUpdate(posX + 0.6, posY, posZ + 0.6);
  77.                             //this.startCoolDown(stack);
  78.                             this.setNewWorldTime(stack, player);
  79.                             this.consumeReagent(stack, world, player);
  80.                         }
  81.                         else
  82.                         {
  83.                             ChatUtil.sendNoSpam(player, "\u00A74The Scrying Orb is on cooldown.");
  84.                         }
  85.                     }
  86.                     else
  87.                     {
  88.                         ChatUtil.sendNoSpam(player,"\u00A74The Scrying Orb requires Mystal Dust for use.");
  89.                     }
  90.                 }
  91.             }
  92.             else
  93.                 player.sendMessage(new TextComponentString("You must sneak and right click to store Scrying data."));
  94.         }
  95.         return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  96.     }
  97.  
  98.     @Override
  99.     @SideOnly(Side.CLIENT)
  100.     public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
  101.     {
  102.         tooltip.add("");
  103.         tooltip.add("\u00A76" + "An orb used to store location data.");
  104.         tooltip.add("\u00A76" + "After storing, it grants the ability");
  105.         tooltip.add("\u00A76" + "to teleport to stored location.");
  106.         tooltip.add("");
  107.         if (stack.getTagCompound() != null)
  108.         {
  109.             NBTTagCompound nbt = stack.getTagCompound();
  110.             int dimID = nbt.getInteger("Dim");
  111.             double posX = nbt.getDouble("PosX");
  112.             double posY = nbt.getDouble("PosY");
  113.             double posZ = nbt.getDouble("PosZ");
  114.             tooltip.add("\u00A73" + "DIM: "+ dimID);
  115.             tooltip.add("\u00A7d" + "X: "  + posX);
  116.             tooltip.add("\u00A72" + "Y: "  + posY);
  117.             tooltip.add("\u00A7c" + "Z: "  + posZ);
  118.             tooltip.add("");
  119.             /*if (stack.getTagCompound().getInteger("coolDown") != 0) {
  120.                 tooltip.add("\u00A74" + "Cooldown: " + getCooldownReal(stack) + " Min");
  121.             }
  122.             else
  123.             {
  124.                 tooltip.add("\u00A72" + "Scrying Orb is ready for use.");
  125.             }*/
  126.         }
  127.     }
  128.  
  129.     protected void startCoolDown(ItemStack stack)
  130.     {
  131.         if (stack.getTagCompound() != null)
  132.         {
  133.             stack.getTagCompound().setInteger("coolDown", 6000);
  134.         }
  135.     }
  136.  
  137.     protected void setNewWorldTime(ItemStack stack, EntityPlayer player)
  138.     {
  139.         if (stack.getTagCompound() != null)
  140.         {
  141.             stack.getTagCompound().removeTag("totalWorldTime");
  142.             stack.getTagCompound().setLong("totalWorldTime", player.world.getTotalWorldTime());
  143.         }
  144.     }
  145.  
  146.     protected int getCoolDown(ItemStack stack) {
  147.         if ( (stack.getTagCompound() != null) && (stack.getTagCompound().hasKey("coolDown")) )
  148.         {
  149.             return stack.getTagCompound().getInteger("coolDown");
  150.         }
  151.         return 0;
  152.     }
  153.  
  154.     protected 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.     protected void consumeReagent(ItemStack stack, World worldIn, EntityPlayer entityLiving) {
  163.         entityLiving.inventory.clearMatchingItems(scryingReagent(stack), -1, 1, null);
  164.     }
  165.  
  166.     protected Item scryingReagent(ItemStack itemStackIn)
  167.     {
  168.         return eAngelusItems.mystalDust;
  169.     }
  170.  
  171.     //Cooldown Handlers\\
  172.     public static int getCooldownReal(ItemStack stack) {
  173.         int time = (int) Math.abs(stack.getTagCompound().getInteger("coolDown"));
  174.         return (int)((float)time / 1000F);
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment