Started by
RedInventor
on
Topic category: Help with Minecraft modding (Java Edition)
I am working on a procedure where a player with an item that has a custom NBT tag to attract nearby items to come to the player.
Is this possible with the procedure or does it need to be code in?
P.S. If more detail needs to be provided, let me know.
I think it has to be coded in here is a snippet I made for you,
Keep in mind you can change the NBT to whatever you like :D.
I went with an enchant instead, but I am kind of lost for how to get the item to move.
Enchants.java
public class Enchants {
public static final DeferredRegister<Enchantment> ENCHANTMENTS = new DeferredRegister<>(ForgeRegistries.ENCHANTMENTS, "minerology");
public static final RegistryObject<Enchantment> MAGNETIC = ENCHANTMENTS.register("magnetic", () -> new MagneticEnchant(Rarity.RARE, EnchantmentType.DIGGER, new EquipmentSlotType[]{EquipmentSlotType.MAINHAND}));
}
MagneticEnchant.java
public class MagneticEnchant extends Enchantment {
public MagneticEnchant(Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType[] slots) {
super(rarityIn, typeIn, slots);
}
public int getMaxLevel() {
return 5;
}
public int getMinLevel() {
return 1;
}
public int getMinEnchantability(int enchantmentLevel) {
return enchantmentLevel * 10;
}
public getMaxEnchantability(int enchantmentLevel) {
return this.getMinEnchantability(enchantmentLevel) + 15;
}
public static class MagneticEquipped {
PlayerEntity playerIn = event.player;
World worldIn = playerIn.world;
int x = (int) playerIn.getPosX();
int y = (int) playerIn.getPosY();
int x = (int) playerIn.getPosZ();
ItemStack hand = playerIn.getItemStackFromSlot(EquipmentSlotType.HAND);
int enchantLevel = EnchantmentHelper.getEnchantmentLevel(EnchantmentInit.MAGNETIC.get(), playerIn.getItemStackFromSlotType.HAND));
int radius = 5 * enchantLevel;
int radSq = radius * radius;
AxisAlignedBB area = new AxisAlignedBB(player.getPosition().add(-radius, -radius, -radius), player.getPosition().add(1 + radius, 1 + radius, 1 + radius));
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, area, EntitySelectors.IS_ALIVE);
if(EnchantmentHelper.getEnchantmentLevel(EnchantmentInit.MAGNETIC.get(), playerIn.getJeldItemMainhand()) > 0) {
int itemCount = 0;
for (EntityItem item : items){
if(item.getPositionVector().squareDistanceTo(traceResult.hitvec) <= radSq){
item.setPosition(player.posX, player.posY, player.posZ);
item.setPickupDelay(0);
itemCount++;
}
}
}
That is what the nifty code I provided with you was for,
You can play with the speed and the bounding box, or you increase the speed and bounding box depending on your enchantment level🤔. This code will work best in a tick method by the way.