Guest User

TelaykusSword

a guest
Sep 22nd, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | Source Code | 0 0
  1. package net.telaykussword.power;
  2.  
  3. import net.minecraft.entity.EntityType;
  4. import net.minecraft.entity.EquipmentSlot;
  5. import net.minecraft.entity.LightningEntity;
  6. import net.minecraft.entity.LivingEntity;
  7. import net.minecraft.entity.player.PlayerEntity;
  8. import net.minecraft.item.Item;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.util.Hand;
  11. import net.minecraft.util.TypedActionResult;
  12. import net.minecraft.util.math.BlockPos;
  13. import net.minecraft.world.World;
  14.  
  15. public class TelaykusSword extends Item {
  16. public TelaykusSword(Settings settings) {
  17. super(settings);
  18. }
  19.  
  20. public float getAttackDamage() {
  21. return 38.0F;
  22. }
  23. @Override
  24. public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
  25. if (world.isClient) {
  26. return TypedActionResult.pass(user.getStackInHand(hand));
  27. }
  28.  
  29. BlockPos frontOfPlayer = user.getBlockPos().offset(user.getHorizontalFacing(), 2);
  30. double offsetX = user.getHorizontalFacing().getOffsetX() * 2.5;
  31. double offsetZ = user.getHorizontalFacing().getOffsetZ() * 2.5;
  32.  
  33. BlockPos targetPos = frontOfPlayer.add((int) offsetX, 0, (int) offsetZ);
  34.  
  35. LightningEntity lightningBolt = new LightningEntity(EntityType.LIGHTNING_BOLT, world);
  36. lightningBolt.refreshPositionAfterTeleport(targetPos.getX(), targetPos.getY(), targetPos.getZ());
  37. world.spawnEntity(lightningBolt);
  38.  
  39. return TypedActionResult.success(user.getStackInHand(hand));
  40. }
  41.  
  42. @Override
  43. public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
  44. stack.damage(1, attacker, EquipmentSlot.MAINHAND);
  45. return true;
  46. }
  47.  
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment