Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.52 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.                     long cooldown = world.getWorldTime();
  59.  
  60.                     long cooldownDifference = cooldown + this.getCoolDown(stack);
  61.  
  62.                     System.out.println("The cooldown variable is currently: " + cooldownDifference);
  63.  
  64.                     //Check for Reagent
  65.                     if (player.inventory.hasItemStack(new ItemStack(eAngelusItems.mystalDust)))
  66.                     {
  67.                         if ( (stack.getTagCompound() != null) && (cooldownDifference > 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, world);
  78.                             this.consumeReagent(stack, world, player);
  79.                         }
  80.                         else
  81.                         {
  82.                             ChatUtil.sendNoSpam(player, "\u00A74The Scrying Orb is on cooldown.");
  83.                         }
  84.                     }
  85.                     else
  86.                     {
  87.                         ChatUtil.sendNoSpam(player,"\u00A74The Scrying Orb requires Mystal Dust for use.");
  88.                     }
  89.                 }
  90.             }
  91.             else
  92.                 player.sendMessage(new TextComponentString("You must sneak and right click to store Scrying data."));
  93.         }
  94.         return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  95.     }
  96.  
  97.     @Override
  98.     @SideOnly(Side.CLIENT)
  99.     public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
  100.     {
  101.         tooltip.add("");
  102.         tooltip.add("\u00A76" + "An orb used to store location data.");
  103.         tooltip.add("\u00A76" + "After storing, it grants the ability");
  104.         tooltip.add("\u00A76" + "to teleport to stored location.");
  105.         tooltip.add("");
  106.         if (stack.getTagCompound() != null)
  107.         {
  108.             NBTTagCompound nbt = stack.getTagCompound();
  109.             int dimID = nbt.getInteger("Dim");
  110.             double posX = nbt.getDouble("PosX");
  111.             double posY = nbt.getDouble("PosY");
  112.             double posZ = nbt.getDouble("PosZ");
  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 (stack.getTagCompound().getInteger("coolDown") != 0) {
  119.                 tooltip.add("\u00A74" + "Cooldown: " + getCooldownReal(stack) + " Min.");
  120.             }
  121.             else
  122.             {
  123.                 tooltip.add("\u00A72" + "Scrying Orb is ready for use.");
  124.             }*/
  125.         }
  126.     }
  127.  
  128.     protected void startCoolDown(ItemStack stack, World world)
  129.     {
  130.         if (stack.getTagCompound() != null)
  131.         {
  132.             stack.getTagCompound().setLong("coolDown", world.getTotalWorldTime());
  133.         }
  134.     }
  135.  
  136.    /*
  137.    @Override
  138.     public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
  139.         if (!world.isRemote)
  140.         {
  141.             int coolDown = this.getCoolDown(stack);
  142.             if (coolDown > 0) {
  143.                 stack.getTagCompound().setInteger("coolDown", coolDown - 1);
  144.             }
  145.             else if (coolDown < 0)
  146.             {
  147.                 stack.getTagCompound().setInteger("coolDown", 0);
  148.             }
  149.         }
  150.     }*/
  151.  
  152.     protected long getCoolDown(ItemStack stack) {
  153.         if ( (stack.getTagCompound() != null) && (stack.getTagCompound().hasKey("coolDown")) )
  154.         {
  155.             return stack.getTagCompound().getLong("coolDown");
  156.         }
  157.         return 0;
  158.     }
  159.  
  160.     protected void consumeReagent(ItemStack stack, World worldIn, EntityPlayer entityLiving) {
  161.         entityLiving.inventory.clearMatchingItems(scryingReagent(stack), -1, 1, null);
  162.     }
  163.  
  164.     protected Item scryingReagent(ItemStack itemStackIn)
  165.     {
  166.         return eAngelusItems.mystalDust;
  167.     }
  168.  
  169.     //Cooldown Handlers\\
  170.     public static int getCooldownReal(ItemStack stack) {
  171.         int time = (int) Math.abs(stack.getTagCompound().getInteger("coolDown"));
  172.         return (int)((float)time / 1000F);
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement