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

79 lines
3.3 KiB
Java
Raw Normal View History

2016-05-05 00:06:02 +02:00
package de.ellpeck.actuallyadditions.mod.items.lens;
import java.util.ArrayList;
2016-05-05 00:06:02 +02:00
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.Lens;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2017-07-16 19:34:21 +02:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
2016-05-05 00:06:02 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
2016-05-05 00:06:02 +02:00
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2019-05-02 09:10:29 +02:00
public class LensDisruption extends Lens {
2016-05-05 00:06:02 +02:00
private static final int ENERGY_USE = 150000;
2016-05-05 00:06:02 +02:00
@Override
2019-05-02 09:10:29 +02:00
public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) {
if (ConfigIntValues.ELEVEN.getValue() == 11 && tile.getEnergy() >= ENERGY_USE && hitBlock != null && !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock)) {
2016-05-05 00:06:02 +02:00
int range = 2;
2019-05-02 09:10:29 +02:00
ArrayList<EntityItem> items = (ArrayList<EntityItem>) tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX() - range, hitBlock.getY() - range, hitBlock.getZ() - range, hitBlock.getX() + range, hitBlock.getY() + range, hitBlock.getZ() + range));
for (EntityItem item : items) {
ItemStack stack = item.getItem();
2019-05-02 09:10:29 +02:00
if (!item.isDead && StackUtil.isValid(stack)) {
if (!stack.hasTagCompound() || !stack.getTagCompound().getBoolean(ActuallyAdditions.MODID + "DisruptedAlready")) {
2016-05-05 00:06:02 +02:00
2016-07-09 17:44:16 +02:00
ItemStack newStack;
2019-05-02 09:10:29 +02:00
do {
if (tile.getWorldObject().rand.nextBoolean()) {
2016-11-02 19:36:32 +01:00
newStack = new ItemStack(Item.REGISTRY.getRandomObject(tile.getWorldObject().rand));
2019-05-02 09:10:29 +02:00
} else {
2016-11-02 19:36:32 +01:00
newStack = new ItemStack(Block.REGISTRY.getRandomObject(tile.getWorldObject().rand));
2016-05-05 00:06:02 +02:00
}
2019-05-02 09:10:29 +02:00
} while (!StackUtil.isValid(newStack));
2016-07-07 17:59:45 +02:00
newStack.setCount(stack.getCount());
2016-05-05 00:06:02 +02:00
2019-05-02 09:10:29 +02:00
if (!newStack.hasTagCompound()) {
2016-05-05 00:06:02 +02:00
newStack.setTagCompound(new NBTTagCompound());
}
2019-05-02 09:10:29 +02:00
newStack.getTagCompound().setBoolean(ActuallyAdditions.MODID + "DisruptedAlready", true);
2016-05-05 00:06:02 +02:00
item.setDead();
EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, newStack);
2016-11-26 21:32:27 +01:00
tile.getWorldObject().spawnEntity(newItem);
2016-05-05 00:06:02 +02:00
tile.extractEnergy(ENERGY_USE);
2016-05-05 00:06:02 +02:00
}
}
}
return true;
}
return false;
}
@Override
2019-05-02 09:10:29 +02:00
public float[] getColor() {
return new float[] { 246F / 255F, 255F / 255F, 183F / 255F };
2016-05-05 00:06:02 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public int getDistance() {
2016-05-05 00:06:02 +02:00
return 3;
}
@Override
2019-05-02 09:10:29 +02:00
public boolean canInvoke(IAtomicReconstructor tile, EnumFacing sideToShootTo, int energyUsePerShot) {
return tile.getEnergy() - energyUsePerShot >= ENERGY_USE;
}
2016-05-05 00:06:02 +02:00
}