ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDeath.java

58 lines
1.9 KiB
Java
Raw Normal View History

/*
2016-05-16 22:52:27 +02:00
* This file ("LensDeath.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items.lens;
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.mod.misc.DamageSources;
import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import java.util.List;
2021-02-27 16:33:00 +01:00
2019-05-02 09:10:29 +02:00
public class LensDeath extends Lens {
@Override
2021-02-26 22:15:48 +01:00
public boolean invoke(BlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) {
List<LivingEntity> entities = tile.getWorldObject().getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX() + 1, hitBlock.getY() + 1, hitBlock.getZ() + 1));
for (LivingEntity entity : entities) {
2016-11-02 18:49:57 +01:00
int use = this.getUsePerEntity();
2019-05-02 09:10:29 +02:00
if (tile.getEnergy() >= use) {
2016-11-02 18:49:57 +01:00
tile.extractEnergy(use);
2016-11-02 18:49:57 +01:00
this.onAttacked(entity, tile);
}
}
return !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock);
}
protected void onAttacked(LivingEntity entity, IAtomicReconstructor tile) {
2016-11-02 18:49:57 +01:00
entity.attackEntityFrom(DamageSources.DAMAGE_ATOMIC_RECONSTRUCTOR, 20F);
}
2019-05-02 09:10:29 +02:00
protected int getUsePerEntity() {
2016-11-02 18:49:57 +01:00
return 350;
}
@Override
2019-05-02 09:10:29 +02:00
public float[] getColor() {
2021-02-27 16:33:00 +01:00
return new float[]{188F / 255F, 222F / 255F, 1F};
}
@Override
2019-05-02 09:10:29 +02:00
public int getDistance() {
return 15;
}
}