NaturesAura/src/main/java/de/ellpeck/naturesaura/items/ItemLootFinder.java

61 lines
2.6 KiB
Java
Raw Normal View History

2020-02-28 15:36:12 +01:00
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
2021-12-04 15:40:09 +01:00
import net.minecraft.entity.player.Player;
2020-02-28 15:36:12 +01:00
import net.minecraft.item.ItemStack;
2021-12-04 15:40:09 +01:00
import net.minecraft.tileentity.MobSpawnerBlockEntity;
2020-02-28 15:36:12 +01:00
import net.minecraft.util.ActionResult;
2021-12-04 15:40:09 +01:00
import net.minecraft.util.InteractionResult;
2020-02-28 15:36:12 +01:00
import net.minecraft.util.Hand;
import net.minecraft.util.math.AABB;
2020-02-28 15:36:12 +01:00
import net.minecraft.util.math.BlockPos;
2021-12-04 15:40:09 +01:00
import net.minecraft.level.Level;
2020-02-28 15:36:12 +01:00
import net.minecraftforge.items.CapabilityItemHandler;
public class ItemLootFinder extends ItemImpl {
public ItemLootFinder() {
super("loot_finder");
}
@Override
2021-12-04 15:40:09 +01:00
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
2020-02-28 15:36:12 +01:00
ItemStack stack = playerIn.getHeldItem(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 100000, false))
2021-12-04 15:40:09 +01:00
return new ActionResult<>(InteractionResult.FAIL, stack);
if (levelIn.isClientSide) {
2020-02-28 15:36:12 +01:00
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition();
2021-12-04 19:17:21 +01:00
Helper.getBlockEntitiesInArea(levelIn, pos, 64, tile -> {
2021-12-04 15:40:09 +01:00
if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent() || tile instanceof MobSpawnerBlockEntity) {
2020-02-28 15:36:12 +01:00
inst.spawnMagicParticle(
tile.getPos().getX() + 0.5F, tile.getPos().getY() + 0.5F, tile.getPos().getZ() + 0.5F,
0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true);
}
return false;
});
for (Entity entity : levelIn.getEntitiesWithinAABB(Entity.class, new AABB(pos).grow(64))) {
2020-02-28 15:36:12 +01:00
if (!(entity instanceof LivingEntity) && entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()) {
inst.spawnMagicParticle(
entity.getPosX(), entity.getPosYEye(), entity.getPosZ(),
0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true);
}
}
inst.setParticleDepth(true);
inst.setParticleSpawnRange(32);
inst.setParticleCulling(true);
playerIn.swingArm(handIn);
}
playerIn.getCooldownTracker().setCooldown(this, 20 * 60);
2021-12-04 15:40:09 +01:00
return new ActionResult<>(InteractionResult.SUCCESS, stack);
2020-02-28 15:36:12 +01:00
}
}