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

55 lines
2.3 KiB
Java
Raw Normal View History

2020-10-13 23:30:47 +02:00
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
2021-12-04 15:40:09 +01:00
import net.minecraft.entity.player.Player;
2020-10-13 23:30:47 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
2021-12-04 15:40:09 +01:00
import net.minecraft.util.InteractionResult;
2020-10-13 23:30:47 +02:00
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
2021-12-04 15:40:09 +01:00
import net.minecraft.level.Level;
2020-10-13 23:30:47 +02:00
public class ItemNetheriteFinder extends ItemImpl {
public ItemNetheriteFinder() {
super("netherite_finder", new Properties().maxStackSize(1));
}
@Override
2021-12-04 15:40:09 +01:00
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
2020-10-13 23:30:47 +02:00
ItemStack stack = playerIn.getHeldItem(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 200000, false))
2021-12-04 15:40:09 +01:00
return new ActionResult<>(InteractionResult.FAIL, stack);
if (levelIn.isClientSide) {
2020-10-13 23:30:47 +02:00
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition();
int range = 12;
2020-10-13 23:30:47 +02:00
for (int x = -range; x <= range; x++) {
for (int y = 0; y <= 128; y++) {
for (int z = -range; z <= range; z++) {
BlockPos offset = new BlockPos(pos.getX() + x, y, pos.getZ() + z);
2021-12-04 15:40:09 +01:00
BlockState state = levelIn.getBlockState(offset);
2020-10-13 23:30:47 +02:00
if (state.getBlock() == Blocks.ANCIENT_DEBRIS || state.getBlock().getRegistryName().toString().contains("netherite")) {
inst.spawnMagicParticle(
offset.getX() + 0.5F, offset.getY() + 0.5F, offset.getZ() + 0.5F,
0F, 0F, 0F, 0xab4d38, 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-10-13 23:30:47 +02:00
}
}