Guest User

Untitled

a guest
Feb 1st, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.client.items;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.annotation.Nullable;
  6.  
  7. import com.TheRPGAdventurer.ROTD.DragonMounts;
  8. import com.TheRPGAdventurer.ROTD.client.initialization.EnumItemBreedTypes;
  9. import com.TheRPGAdventurer.ROTD.client.userinput.StatCollector;
  10. import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon;
  11. import com.TheRPGAdventurer.ROTD.server.entity.breeds.EnumDragonBreed;
  12. import com.TheRPGAdventurer.ROTD.server.entity.helper.EnumDragonLifeStage;
  13.  
  14. import net.minecraft.block.BlockFence;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.client.util.ITooltipFlag;
  17. import net.minecraft.entity.Entity;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.item.Item;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.nbt.NBTTagCompound;
  22. import net.minecraft.util.EnumActionResult;
  23. import net.minecraft.util.EnumFacing;
  24. import net.minecraft.util.EnumHand;
  25. import net.minecraft.util.math.BlockPos;
  26. import net.minecraft.util.math.MathHelper;
  27. import net.minecraft.world.World;
  28. import net.minecraftforge.fml.relauncher.Side;
  29. import net.minecraftforge.fml.relauncher.SideOnly;
  30.  
  31. public class ItemDragonEssence extends Item {
  32.  
  33. public EnumItemBreedTypes type;
  34. public EnumDragonBreed breed;
  35.  
  36. public ItemDragonEssence(EnumItemBreedTypes type, EnumDragonBreed breed) {
  37. this.breed = breed;
  38. this.setUnlocalizedName(type.toString().toLowerCase() + "_dragon_essence");
  39. this.setRegistryName(type.toString().toLowerCase() + "_dragon_essence");
  40. this.setCreativeTab(DragonMounts.TAB);
  41. this.maxStackSize = 1;
  42. this.type = type;
  43. }
  44.  
  45. public void setDragonNBT(EntityTameableDragon dragon, ItemStack stack) {
  46. NBTTagCompound nbt = stack.getTagCompound();
  47. if (stack.hasTagCompound()) {
  48. nbt = stack.getTagCompound();
  49. } else {
  50. nbt = new NBTTagCompound();
  51. }
  52.  
  53. stack.setTagCompound(nbt);
  54.  
  55. if(stack.getTagCompound() != null) {
  56. nbt.setUniqueId("essenceDragonId", dragon.getUniqueID());
  57. nbt.setUniqueId("essenceOwnerId" , dragon.getOwnerId ());
  58. if(dragon.hasCustomName()) nbt.setString("name", dragon.getCustomNameTag());
  59. }
  60. }
  61.  
  62. @Override
  63. @SideOnly(Side.CLIENT)
  64. public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
  65. tooltip.add(type.color + StatCollector.translateToLocal("dragon." + type.toString().toLowerCase()) + stack.getTagCompound().getUniqueId("essenceDragonId"));
  66. }
  67.  
  68. @Override
  69. public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side,
  70. float hitX, float hitY, float hitZ) {
  71.  
  72. ItemStack stack = player.getHeldItem(hand);
  73. if (world.isRemote) {
  74. return EnumActionResult.SUCCESS;
  75. } else if (!player.canPlayerEdit(pos.offset(side), side, stack)) {
  76. return EnumActionResult.PASS;
  77. } else {
  78. IBlockState state = world.getBlockState(pos);
  79.  
  80. pos = pos.offset(side);
  81. double yOffset = 0.0D;
  82.  
  83. if (side == EnumFacing.UP && state.getBlock() instanceof BlockFence) {
  84. yOffset = 0.5D;
  85. }
  86.  
  87. EntityTameableDragon EntityTameableDragon = this.spawnEntityTameableDragon(world, player, stack, pos.getX() + 0.5D, pos.getY() + yOffset, pos.getZ() + 0.5D);
  88.  
  89. if (EntityTameableDragon != null) {
  90. if (stack.hasDisplayName()) {
  91. EntityTameableDragon.setCustomNameTag(stack.getDisplayName());
  92. }
  93. // no just no!
  94. if (!player.capabilities.isCreativeMode) {
  95. stack.shrink(1);
  96. }
  97.  
  98. world.spawnEntity(EntityTameableDragon);
  99. EntityTameableDragon.playLivingSound();
  100. }
  101. } return EnumActionResult.SUCCESS;
  102. }
  103.  
  104.  
  105. public EntityTameableDragon spawnEntityTameableDragon(World world, EntityPlayer player, ItemStack stack, double x, double y, double z) {
  106. EntityTameableDragon dragon = new EntityTameableDragon(world);
  107. try {
  108. NBTTagCompound nbt = stack.getTagCompound();
  109. if (stack.hasTagCompound()) {
  110. nbt = stack.getTagCompound();
  111. } else {
  112. nbt = new NBTTagCompound();
  113. }
  114.  
  115. stack.setTagCompound(nbt);
  116. if(stack.getTagCompound().hasKey("essenceDragonId")) {
  117. dragon.setUniqueId(stack.getTagCompound().getUniqueId("essenceDragonId"));
  118. dragon.tamedFor(world.getPlayerEntityByUUID(stack.getTagCompound().getUniqueId("essenceOwnerId")), true);
  119. dragon.setPosition(x, y, z);
  120. dragon.setLocationAndAngles(x, y, z, MathHelper.wrapDegrees(world.rand.nextFloat() * 360.0F), 0.0F);
  121. dragon.rotationYawHead = dragon.rotationYaw;
  122. dragon.renderYawOffset = dragon.rotationYaw;
  123. dragon.setBreedType(breed);
  124. dragon.setHealth(dragon.getMaxHealth());
  125. return dragon;
  126. }
  127. } catch (Exception e) {
  128. e.printStackTrace();
  129. }
  130.  
  131. return null;
  132. }
  133.  
  134. @Override
  135. public boolean hasEffect(ItemStack stack) {
  136. // TODO Auto-generated method stub
  137. return super.hasEffect(stack);
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment