use of de.sanandrew.mods.claysoldiers.api.IDisruptable in project ClaySoldiersMod by SanAndreasP.
the class ItemDisruptor method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
NBTTagCompound nbt = itemStackIn.getOrCreateSubCompound("disruptor");
long lastTimeMillis = nbt.getLong("lastActivated");
long currTimeMillis = System.currentTimeMillis();
if (lastTimeMillis + 2_000 < currTimeMillis) {
if (!worldIn.isRemote) {
AxisAlignedBB aabb = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 64.0D, 64.0D, 64.0D).offset(playerIn.posX, playerIn.posY, playerIn.posZ).offset(-32.0D, -32.0D, -32.0D);
worldIn.getEntitiesWithinAABB(EntityCreature.class, aabb).stream().filter(entity -> entity instanceof IDisruptable).map(entity -> (IDisruptable) entity).collect(Collectors.toList()).forEach(IDisruptable::disrupt);
nbt.setLong("lastActivated", currTimeMillis);
if (itemStackIn.isItemStackDamageable()) {
itemStackIn.damageItem(1, playerIn);
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
} else {
return super.onItemRightClick(worldIn, playerIn, hand);
}
}
Aggregations