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

48 lines
1.6 KiB
Java
Raw Normal View History

2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items.lens;
2019-05-02 09:10:29 +02:00
import java.util.ArrayList;
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;
2016-03-18 23:47:22 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2019-05-02 09:10:29 +02:00
public class LensDeath extends Lens {
@Override
2019-05-02 09:10:29 +02:00
public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) {
ArrayList<EntityLivingBase> entities = (ArrayList<EntityLivingBase>) tile.getWorldObject().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX() + 1, hitBlock.getY() + 1, hitBlock.getZ() + 1));
for (EntityLivingBase 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);
}
}
2016-07-04 20:15:41 +02:00
return hitBlock != null && !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock);
}
2019-05-02 09:10:29 +02:00
protected void onAttacked(EntityLivingBase 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() {
return new float[] { 188F / 255F, 222F / 255F, 1F };
}
@Override
2019-05-02 09:10:29 +02:00
public int getDistance() {
return 15;
}
}