Guest User

Magnetic

a guest
May 30th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. package net.mcreator.minerology;
  2.  
  3. import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
  4.  
  5. import net.minecraftforge.fml.common.Mod;
  6. import net.minecraftforge.eventbus.api.SubscribeEvent;
  7. import net.minecraftforge.event.TickEvent.PlayerTickEvent;
  8.  
  9. import net.minecraft.world.World;
  10. import net.minecraft.item.Items;
  11. import net.minecraft.util.math.BlockPos;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.inventory.EquipmentSlotType;
  14.  
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItem;
  18. import net.minecraft.entity.player.PlayerEntity;
  19.  
  20. import net.minecraft.enchantment.Enchantments;
  21. import net.minecraft.enchantment.EnchantmentType;
  22. import net.minecraft.enchantment.EnchantmentHelper;
  23. import net.minecraft.enchantment.Enchantment;
  24. import net.minecraft.util.EnumParticleTypes;
  25. import net.minecraft.util.EnumActionResult;
  26.  
  27. public class MagneticEnchant extends Enchantment {
  28. /**
  29. * Do not remove this constructor
  30. */
  31. public MagneticEnchant(Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType[] slots) {
  32. super(rarityIn, typeIn, slots);
  33. }
  34. public int getMaxLevel() {
  35. return 5;
  36. }
  37. public int getMinLevel() {
  38. return 1;
  39. }
  40. protected boolean canApplyTogetger(Enchantment ench){
  41. return super.canApplyTogether(ench);
  42. }
  43. public int getMinEnchantability(int enchantmentLevel) {
  44. return enchzntmentLevel * 10;
  45. }
  46. public getMaxEnchantability(int enchantmentLevel) {
  47. return thiss.getMinEnchantability(enchantmentLevel) + 15;
  48. }
  49. public static void class MagneticEquipped {
  50. public static void doStuff(PlayerTickEvent event) {
  51. PlayerEntity playerIn = event.player;
  52. World worldIn = playerIn.world;
  53. int x = (int) playerIn.getPosX();
  54. int y = (int) playerIn.getPosY();
  55. int x = (int) playerIn.getPosZ();
  56. ItemStack hand = playerIn.getItemStackFromSlot(EquipmentSlotType.HAND);
  57. int enchantLevel = EnchantmentHelper.getEnchantmentLevel(EnchantmentInit.MAGNETIC.get(), playerIn.getItemStackFromSlotType.HAND));
  58. int radius = 5 * enchantLevel;
  59. int radSq = radius * radius;
  60. AxisAlignedBB area = new AxisAlignedBB(player.getPosition().add(-radius, -radius, -radius), player.getPosition().add(1 + radius, 1 + radius, 1 + radius));
  61. List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, area, EntitySelectors.IS_ALIVE);
  62. if(EnchantmentHelper.getEnchantmentLevel(EnchantmentInit.MAGNETIC.get(), playerIn.getJeldItemMainhand()) > 0) {
  63. if (ServerHelper.isClientWorld(world)){
  64. for(EntityItem item : items){
  65. if(item.getPositionVector().squareDistanceTo(player.getPositionVector()) <= radSq){
  66. worlld.spawnParticile(EnumParticleTypes.CLOUD, item.posX, item.posY, item.posZ, 0, 0, 0, 0);
  67. }
  68. }
  69. }else {
  70. int itemCount = 0;
  71. for (EntityItem item : items){
  72. if(item.getPositionVector().squareDistanceTo(traceResult.hitvec) <= radSq){
  73. item.setPosition(player.posX, player.posY, player.posZ);
  74. item.setPickupDelay(0);
  75. itemCount++;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment