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

68 lines
2.9 KiB
Java
Raw Normal View History

2019-02-19 17:23:03 +01:00
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2019-10-20 22:30:49 +02:00
import net.minecraft.block.BlockState;
2019-11-04 19:08:49 +01:00
import net.minecraft.entity.EntitySpawnPlacementRegistry;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.player.PlayerEntity;
2019-02-19 17:23:03 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
2019-10-20 22:30:49 +02:00
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
2019-02-19 17:23:03 +01:00
import net.minecraft.util.math.BlockPos;
2019-10-20 22:30:49 +02:00
import net.minecraft.world.LightType;
2019-02-19 17:23:03 +01:00
import net.minecraft.world.World;
2020-01-26 01:41:49 +01:00
public class ItemCaveFinder extends ItemImpl {
public ItemCaveFinder() {
2020-02-07 23:50:16 +01:00
super("cave_finder", new Properties().maxStackSize(1));
2019-02-19 17:23:03 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
2019-02-19 17:23:03 +01:00
ItemStack stack = playerIn.getHeldItem(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 20000, worldIn.isRemote))
2019-10-20 22:30:49 +02:00
return new ActionResult<>(ActionResultType.FAIL, stack);
2019-02-19 17:23:03 +01:00
if (worldIn.isRemote) {
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
2020-02-28 15:36:12 +01:00
inst.setParticleCulling(false);
2019-02-19 17:23:03 +01:00
BlockPos pos = playerIn.getPosition();
int range = 30;
for (int x = -range; x <= range; x++)
for (int y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) {
BlockPos offset = pos.add(x, y, z);
2019-10-20 22:30:49 +02:00
BlockState state = worldIn.getBlockState(offset);
try {
if (!state.getBlock().canCreatureSpawn(state, worldIn, offset, EntitySpawnPlacementRegistry.PlacementType.ON_GROUND, null))
continue;
} catch (Exception e) {
2019-02-19 17:23:03 +01:00
continue;
}
2019-02-19 17:23:03 +01:00
BlockPos offUp = offset.up();
2019-10-20 22:30:49 +02:00
BlockState stateUp = worldIn.getBlockState(offUp);
2019-11-04 19:08:49 +01:00
if (stateUp.isNormalCube(worldIn, offUp) || stateUp.getMaterial().isLiquid())
2019-02-19 17:23:03 +01:00
continue;
2019-10-20 22:30:49 +02:00
int sky = worldIn.getLightFor(LightType.SKY, offUp);
int block = worldIn.getLightFor(LightType.BLOCK, offUp);
2019-02-19 17:23:03 +01:00
if (sky > 7 || block > 7)
continue;
inst.spawnMagicParticle(
offset.getX() + 0.5F, offset.getY() + 1.5F, offset.getZ() + 0.5F,
0F, 0F, 0F, 0x992101, 2.5F, 20 * 30, 0F, false, true);
}
inst.setParticleDepth(true);
inst.setParticleSpawnRange(32);
2020-02-28 15:36:12 +01:00
inst.setParticleCulling(true);
2019-02-19 17:23:03 +01:00
playerIn.swingArm(handIn);
}
playerIn.getCooldownTracker().setCooldown(this, 20 * 30);
2019-10-20 22:30:49 +02:00
return new ActionResult<>(ActionResultType.SUCCESS, stack);
2019-02-19 17:23:03 +01:00
}
}